/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.deployment;

import java.net.URL;

import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;

/**
 * A simple subdeployer that deploys a managed object after parsing the 
 * deployment's xml file using an ObjectModelFactory.
 *
 * @author  <a href="adrian@jboss.com">Adrian Brock</a>
 * @version $Revision: 1.2.2.2 $
 */
public abstract class ObjectModelFactorySimpleSubDeployerSupport extends SimpleSubDeployerSupport
{
   /**
    * Get the object model factory 
    * 
    * @return the object model factory
    */
   public abstract ObjectModelFactory getObjectModelFactory();

   protected void parseMetaData(DeploymentInfo di, URL url) throws DeploymentException
   {
      try
      {
         Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
         ObjectModelFactory factory = getObjectModelFactory();
         di.metaData = unmarshaller.unmarshal(url.toString(), factory, null);
      }
      catch (Throwable t)
      {
         DeploymentException.rethrowAsDeploymentException("Error parsing meta data " + url, t);
      }
   }
}
