/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.kernel.deployment.jboss;

import java.net.URL;

import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.DeploymentInfo;
import org.jboss.deployment.SchemaBindingSimpleSubDeployerSupport;
import org.jboss.kernel.plugins.deployment.xml.BeanSchemaBinding;
import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;

/**
 * A bean deployer for use with the JBoss JMX Deployers framework 
 *
 * @author  <a href="adrian@jboss.com">Adrian Brock</a>
 * @version $Revision: 1.2.2.4 $
 */
public class JBossBeanDeployer extends SchemaBindingSimpleSubDeployerSupport implements JBossBeanDeployerMBean
{
   protected String extension = ".beans";
   
   protected String metaDataURL = "META-INF/jboss-beans.xml";
   
   public JBossBeanDeployer()
   {
      setEnhancedSuffixes(new String[] { "200:.beans" });
   }
   
   public String getExtension()
   {
      return extension;
   }

   public void setExtension(String extension)
   {
      this.extension = extension;
   }
   
   public String getMetaDataURL()
   {
      return metaDataURL;
   }
   
   public void setMetaDataURL(String metaDataURL)
   {
      this.metaDataURL = metaDataURL;
   }

   public String getObjectName(DeploymentInfo di) throws DeploymentException
   {
      String name = di.shortName;
      di = di.parent;
      while (di != null)
      {
         name = di.shortName + "#" + name;
         di = di.parent;
      }
      return "jboss.beans:service=JBossBeanDeployment,name='" + name + "'";
   }

   public String getDeploymentClass()
   {
      return JBossBeanDeployment.class.getName();
   }

   public SchemaBinding getSchemaBinding()
   {
      return BeanSchemaBinding.getSchemaBinding();
   }

   protected void parseMetaData(DeploymentInfo di, URL url) throws DeploymentException
   {
      super.parseMetaData(di, url);
      KernelDeployment deployment = (KernelDeployment) di.metaData;
      deployment.setName(url.toString());
   }
}
