[jboss-cvs] JBossAS SVN: r61511 - trunk/connector/src/main/org/jboss/resource/deployers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 21 00:36:58 EDT 2007
Author: weston.price at jboss.com
Date: 2007-03-21 00:36:58 -0400 (Wed, 21 Mar 2007)
New Revision: 61511
Added:
trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java
trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java
Log:
[JBAS-1425] New deployers for MCF.
Added: trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java (rev 0)
+++ trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java 2007-03-21 04:36:58 UTC (rev 61511)
@@ -0,0 +1,565 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.resource.deployers;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.resource.connectionmanager.JBossManagedConnectionPool;
+import org.jboss.resource.connectionmanager.NoTxConnectionManager;
+import org.jboss.resource.connectionmanager.TxConnectionManager;
+import org.jboss.resource.deployers.builder.AbstractBuilder;
+import org.jboss.resource.metadata.ConnectorMetaData;
+import org.jboss.resource.metadata.mcf.DataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryTransactionSupportMetaData;
+import org.jboss.resource.metadata.repository.JCAMetaDataRepository;
+import org.jboss.system.metadata.ServiceAttributeMetaData;
+import org.jboss.system.metadata.ServiceConstructorMetaData;
+import org.jboss.system.metadata.ServiceDependencyValueMetaData;
+import org.jboss.system.metadata.ServiceDeployment;
+import org.jboss.system.metadata.ServiceMetaData;
+import org.jboss.system.metadata.ServiceTextValueMetaData;
+
+/**
+ * A ManagedConnectionFactoryDeployer.
+ *
+ * @author <a href="weston.price at jboss.org">Weston Price</a>
+ * @version $Revision: 1.1 $
+ */
+public class ManagedConnectionFactoryDeployer extends AbstractSimpleRealDeployer<ManagedConnectionFactoryDeploymentGroup>
+{
+ /** The suffix */
+ private String suffix;
+ private JCAMetaDataRepository repository;
+ private List builders;
+
+
+ public void setBuilders(List builders)
+ {
+ this.builders = builders;
+ }
+
+ public List getBuilders()
+ {
+ return Collections.unmodifiableList(builders);
+
+ }
+
+ /**
+ * Get the repository.
+ *
+ * @return the repository.
+ */
+ public JCAMetaDataRepository getRepository()
+ {
+ return repository;
+ }
+
+ /**
+ * Set the repository.
+ *
+ * @param repository The repository to set.
+ */
+ public void setRepository(JCAMetaDataRepository repository)
+ {
+ this.repository = repository;
+ }
+
+ public ManagedConnectionFactoryDeployer()
+ {
+ super(ManagedConnectionFactoryDeploymentGroup.class);
+ setRelativeOrder(PARSER_DEPLOYER + 1);
+
+ }
+
+ /**
+ * Get the suffix.
+ *
+ * @return the suffix.
+ */
+ public String getSuffix()
+ {
+ return suffix;
+ }
+
+ /**
+ * Set the suffix.
+ *
+ * @param suffix The suffix to set.
+ */
+ public void setSuffix(String suffix)
+ {
+ this.suffix = suffix;
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit, ManagedConnectionFactoryDeploymentGroup group) throws DeploymentException
+ {
+
+ final List<ManagedConnectionFactoryDeploymentMetaData> deployments = group.getDeployments();
+ ServiceDeployment serviceDeployment = new ServiceDeployment();
+ List<ServiceMetaData> componentServices = new ArrayList<ServiceMetaData>();
+
+ try
+ {
+
+ for (ManagedConnectionFactoryDeploymentMetaData deployment : deployments)
+ {
+
+ ServiceMetaData managedConnectionFactory = buildManagedConnectionFactory(deployment);
+
+ List<ServiceMetaData> embeddedDepends = deployment.getDependsServices();
+
+ for (ServiceMetaData data : embeddedDepends)
+ {
+ ServiceDependencyValueMetaData value = new ServiceDependencyValueMetaData();
+ value.setObjectName(data.getObjectName());
+ ServiceAttributeMetaData att = new ServiceAttributeMetaData();
+
+ //NEED OPTIONAL ATTRIBUTE DEPENDS
+ att.setValue(value);
+ managedConnectionFactory.getAttributes().add(att);
+ componentServices.add(data);
+ }
+
+ componentServices.add(managedConnectionFactory);
+
+ ServiceMetaData managedConnectionPool = buildConnectionPool(deployment);
+
+ List<ServiceAttributeMetaData> poolAttributes = managedConnectionPool.getAttributes();
+ ServiceDependencyValueMetaData dependValue = new ServiceDependencyValueMetaData();
+ dependValue.setDependency(managedConnectionFactory.getObjectName().toString());
+
+ ServiceAttributeMetaData attribute = new ServiceAttributeMetaData();
+ attribute.setName("ManagedConnectionFactoryName");
+ attribute.setValue(dependValue);
+ poolAttributes.add(attribute);
+
+ componentServices.add(managedConnectionPool);
+
+ //ConnectionManager
+ ServiceMetaData cmMetaData = buildConnectionManager(deployment);
+ List<ServiceAttributeMetaData> cmAttributes = cmMetaData.getAttributes();
+ dependValue = new ServiceDependencyValueMetaData();
+ dependValue.setObjectName(managedConnectionPool.getObjectName());
+
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("ManagedConnectionPool");
+ attribute.setValue(dependValue);
+
+ cmAttributes.add(attribute);
+ componentServices.add(cmMetaData);
+
+ //DS/CF binding
+ ServiceMetaData bindingMetaData = buildConnectionFactoryBinding(deployment);
+ List<ServiceAttributeMetaData> bindingAttributes = bindingMetaData.getAttributes();
+ dependValue = new ServiceDependencyValueMetaData();
+ dependValue.setObjectName(cmMetaData.getObjectName());
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("ConnectionManager");
+ attribute.setValue(dependValue);
+ bindingAttributes.add(attribute);
+
+ componentServices.add(bindingMetaData);
+
+ //TypeMapping
+
+ if(deployment.getTypeMapping() != null)
+ {
+ ServiceMetaData typeMapping = buildTypeMapping(deployment);
+ componentServices.add(typeMapping);
+
+ }
+
+ serviceDeployment.setServices(componentServices);
+
+ }
+
+ //Standalone MBeans
+ List<ServiceMetaData> services = group.getServices();
+
+ for (ServiceMetaData data : services)
+ {
+ serviceDeployment.getServices().add(data);
+ }
+
+ unit.addAttachment(ServiceDeployment.class, serviceDeployment);
+
+
+ }catch(Exception e)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error creating ManagedConnectionFactory deployment " + unit.getName(), e);
+
+ }
+
+
+
+ }
+ @Override
+ public void undeploy(DeploymentUnit unit, ManagedConnectionFactoryDeploymentGroup deployment)
+ {
+ }
+
+ private List<ServiceAttributeMetaData> getPoolAttributes(ManagedConnectionFactoryDeploymentMetaData deployment)
+ {
+ List<ServiceAttributeMetaData> poolAttributes = new ArrayList<ServiceAttributeMetaData>();
+ ServiceAttributeMetaData poolAttribute = null;
+
+// ConnectionPoolDeploymentMetaData pmd = null; //deployment.getConnectionPoolMetaData();
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("PoolJndiName");
+// poolAttribute.setValue(new ServiceTextValueMetaData(deployment.getJndiName()));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("MinSize");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.getMinSize())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("MaxSize");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.getMaxSize())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("BlockingTimeoutMillis");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.getBlockingTimeout())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("IdleTimeoutMinutes");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.getIdleTimeout())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("BackGroundValidation");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.isBackGroundValidation())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("BackGroundValidationMinutes");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.getBackgroundValidationMinutes())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("PreFill");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.isPrefill())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("StrictMin");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.isStrictMin())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("StatisticsFormatter");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.getStatisticsFormatter())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("UseFastFail");
+// poolAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(pmd.isUseFastFail())));
+// poolAttributes.add(poolAttribute);
+//
+// poolAttribute = new ServiceAttributeMetaData();
+// poolAttribute.setName("Criteria");
+// poolAttribute.setValue(new ServiceTextValueMetaData(deployment.getSecurityMetaData().getCriteria()));
+// poolAttributes.add(poolAttribute);
+
+ return poolAttributes;
+
+ }
+
+ private ServiceMetaData buildConnectionPool(ManagedConnectionFactoryDeploymentMetaData deployment) throws Exception
+ {
+ ServiceMetaData poolMetaData = new ServiceMetaData();
+ ObjectName poolName = new ObjectName("jboss.jca:service=ManagedConnectionPool,name=" + deployment.getJndiName());
+ poolMetaData.setObjectName(poolName);
+ poolMetaData.setCode(JBossManagedConnectionPool.class.getName());
+ ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
+ constructor.setParameters(new Object[]{});
+ constructor.setParams(new String[]{});
+ poolMetaData.setConstructor(constructor);
+
+ List<ServiceAttributeMetaData> poolAttributes = getPoolAttributes(deployment);
+ poolMetaData.setAttributes(poolAttributes);
+
+ return poolMetaData;
+
+
+ }
+
+
+ private ServiceMetaData buildManagedConnectionFactory(ManagedConnectionFactoryDeploymentMetaData deployment) throws Exception
+ {
+ String jndiName = deployment.getJndiName();
+ ServiceMetaData serviceMetaData = new ServiceMetaData();
+ ObjectName mcfName = new ObjectName("jboss.jca:service=ManagedConnectionFactory,name=" + jndiName);
+ serviceMetaData.setObjectName(mcfName);
+// serviceMetaData.setCode(ManagedConnectionFactoryDeployment.class.getName());
+
+ //TODO new constructor
+ ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
+
+ ConnectorMetaData md = null;//repository.getConnectorMetaDataForRARName(deployment.getRarName());
+ constructor.setParameters(new Object[]{md, deployment});
+ constructor.setSignature(new String[]{md.getClass().getName(), ManagedConnectionFactoryDeploymentMetaData.class.getName()});
+ serviceMetaData.setConstructor(constructor);
+
+ List<ServiceAttributeMetaData> attributes = new ArrayList<ServiceAttributeMetaData>();
+ ServiceAttributeMetaData attribute = null;
+
+ //TODO look up RAR from repository
+ ServiceDependencyValueMetaData dep = new ServiceDependencyValueMetaData();
+ dep.setDependency("jboss.jca:service=RARDeployment,name='" + deployment.getRarName() + "'");
+
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("OldRarDeployment");
+ attribute.setValue(dep);
+ attribute.setTrim(false);
+ attributes.add(attribute);
+ serviceMetaData.setAttributes(attributes);
+
+ return serviceMetaData;
+ }
+
+ private ServiceMetaData buildConnectionManager(ManagedConnectionFactoryDeploymentMetaData deployment) throws Exception
+ {
+ ServiceMetaData cmMetaData = new ServiceMetaData();
+ String jndiName = deployment.getJndiName();
+
+ String cmType = "jboss.jca:service=";
+
+ ManagedConnectionFactoryTransactionSupportMetaData txnMetaData = deployment.getTransactionSupportMetaData();
+
+ if(txnMetaData.equals(ManagedConnectionFactoryTransactionSupportMetaData.NONE))
+ {
+ cmType += "NoTxCM,name=" + jndiName;
+ cmMetaData.setCode(NoTxConnectionManager.class.getName());
+
+ }else if(txnMetaData.equals(ManagedConnectionFactoryTransactionSupportMetaData.LOCAL))
+ {
+
+ if(deployment instanceof DataSourceDeploymentMetaData)
+ {
+ cmType += "LocalTxCM,name=" + jndiName;
+
+ }
+ else
+ {
+ cmType += "TxCM,name=" + jndiName;
+
+ }
+ cmMetaData.setCode(TxConnectionManager.class.getName());
+
+ }else
+ {
+ if(deployment instanceof DataSourceDeploymentMetaData)
+ {
+ cmType += "XATxCM,name=" + jndiName;
+
+ }
+ else
+ {
+ cmType += "TxCM,name=" + jndiName;
+
+ }
+
+ cmMetaData.setCode(TxConnectionManager.class.getName());
+
+ }
+
+ ObjectName cmName = new ObjectName(cmType);
+ cmMetaData.setObjectName(cmName);
+ List<ServiceAttributeMetaData> cmAttributes = new ArrayList<ServiceAttributeMetaData>();
+ ServiceAttributeMetaData cmAttribute = null;
+ ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
+ constructor.setParameters(new Object[]{});
+ constructor.setParams(new String[]{});
+ cmMetaData.setConstructor(constructor);
+
+ cmAttribute = new ServiceAttributeMetaData();
+ cmAttribute.setName("JndiName");
+ cmAttribute.setValue(new ServiceTextValueMetaData(jndiName));
+ cmAttributes.add(cmAttribute);
+
+
+ ServiceDependencyValueMetaData ccmValue = new ServiceDependencyValueMetaData();
+ ccmValue.setDependency("jboss.jca:service=CachedConnectionManager");
+ cmAttribute = new ServiceAttributeMetaData();
+ cmAttribute.setName("CachedConnectionManager");
+ cmAttribute.setValue(ccmValue);
+ cmAttributes.add(cmAttribute);
+
+ //Security domain
+
+ if(deployment.getSecurityMetaData().requiresDomain())
+ {
+ cmAttribute = new ServiceAttributeMetaData();
+ cmAttribute.setName("SecurityDomainJndiName");
+// cmAttribute.setValue(new ServiceTextValueMetaData(deployment.getSecurityMetaData().getSecurityDomainName()));
+ cmAttributes.add(cmAttribute);
+ }
+
+ ServiceDependencyValueMetaData jaasValue = new ServiceDependencyValueMetaData();
+ jaasValue.setDependency("jboss.security:service=JaasSecurityManager");
+
+ cmAttribute = new ServiceAttributeMetaData();
+ cmAttribute.setName("JaasSecurityManagerService");
+ cmAttribute.setValue(jaasValue);
+ cmAttributes.add(cmAttribute);
+
+ if(deployment.getTransactionSupportMetaData().equals(ManagedConnectionFactoryTransactionSupportMetaData.LOCAL)
+ || deployment.getTransactionSupportMetaData().equals(ManagedConnectionFactoryTransactionSupportMetaData.XA))
+ {
+
+ ServiceDependencyValueMetaData txnValue = new ServiceDependencyValueMetaData();
+ txnValue.setDependency("jboss:service=TransactionManager");
+
+ cmAttribute = new ServiceAttributeMetaData();
+ cmAttribute.setName("TransactionManagerService");
+ cmAttribute.setValue(txnValue);
+ cmAttributes.add(cmAttribute);
+
+ cmAttribute = new ServiceAttributeMetaData();
+ cmAttribute.setName("LocalTransactions");
+// cmAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(deployment.isLocalTransactions())));
+ cmAttributes.add(cmAttribute);
+
+ cmAttribute = new ServiceAttributeMetaData();
+ cmAttribute.setName("TrackConnectionByTx");
+// cmAttribute.setValue(new ServiceTextValueMetaData(String.valueOf(deployment.isTrackConnectionByTransaction())));
+ cmAttributes.add(cmAttribute);
+
+ }
+
+
+ cmMetaData.setAttributes(cmAttributes);
+
+ return cmMetaData;
+
+ }
+
+ private ServiceMetaData buildConnectionFactoryBinding(ManagedConnectionFactoryDeploymentMetaData deployment) throws Exception
+ {
+ ServiceMetaData binding = getBinding(deployment);
+ ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
+ constructor.setParameters(new Object[]{});
+ constructor.setParams(new String[]{});
+ binding.setConstructor(constructor);
+
+ return binding;
+
+ }
+
+ private ServiceMetaData getBinding(ManagedConnectionFactoryDeploymentMetaData deployment) throws Exception
+ {
+ ServiceMetaData bindingMetaData = new ServiceMetaData();
+ String jndiName = deployment.getJndiName();
+
+ //Constructor
+ if(deployment instanceof DataSourceDeploymentMetaData)
+ {
+ bindingMetaData.setObjectName(new ObjectName("jboss.jca:service=DataSourceBinding,name=" + jndiName));
+ bindingMetaData.setCode("org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService");
+
+ if(!deployment.isUseJavaContext())
+ {
+ ServiceDependencyValueMetaData depends = new ServiceDependencyValueMetaData();
+ depends.setDependency(deployment.getJmxInvokerName());
+ ServiceAttributeMetaData invAtt = new ServiceAttributeMetaData();
+ invAtt.setName("JMXInvokerName");
+ invAtt.setValue(depends);
+ }
+
+ }else
+ {
+ bindingMetaData.setObjectName(new ObjectName("jboss.jca:service=ConnectionFactoryBinding,name=" + jndiName));
+ bindingMetaData.setCode("org.jboss.resource.connectionmanager.ConnectionFactoryBindingService");
+
+ }
+
+ List<ServiceAttributeMetaData> attributes = new ArrayList<ServiceAttributeMetaData>();
+ ServiceAttributeMetaData attribute = new ServiceAttributeMetaData();
+ attribute.setName("JndiName");
+ attribute.setValue(new ServiceTextValueMetaData(jndiName));
+ attributes.add(attribute);
+
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("UseJavaContext");
+ attribute.setValue(new ServiceTextValueMetaData(String.valueOf(deployment.isUseJavaContext())));
+ attributes.add(attribute);
+
+ bindingMetaData.setAttributes(attributes);
+
+
+ return bindingMetaData;
+ }
+
+ private ServiceMetaData buildTypeMapping(ManagedConnectionFactoryDeploymentMetaData deployment) throws Exception
+ {
+ ServiceMetaData typeMetaData = new ServiceMetaData();
+ typeMetaData.setObjectName(new ObjectName("jboss.jdbc:service=metadata,datasource=" + deployment.getJndiName()));
+ typeMetaData.setCode("org.jboss.ejb.plugins.cmp.jdbc.metadata.DataSourceMetaData");
+
+ ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
+ constructor.setParameters(new Object[]{});
+ constructor.setParams(new String[]{});
+ typeMetaData.setConstructor(constructor);
+
+ List<ServiceAttributeMetaData> attributes = new ArrayList<ServiceAttributeMetaData>();
+ ServiceDependencyValueMetaData depends = new ServiceDependencyValueMetaData();
+ depends.setDependency("jboss.jdbc:service=metadata");
+ ServiceAttributeMetaData invAtt = new ServiceAttributeMetaData();
+ invAtt.setName("MetadataLibrary");
+ invAtt.setValue(depends);
+ attributes.add(invAtt);
+
+ ServiceAttributeMetaData attribute = new ServiceAttributeMetaData();
+ attribute.setName("TypeMapping");
+ attribute.setValue(new ServiceTextValueMetaData(deployment.getTypeMapping()));
+ attributes.add(attribute);
+
+ typeMetaData.setAttributes(attributes);
+
+ return typeMetaData;
+
+ }
+
+ ServiceAttributeMetaData buildTextAttribute(String name, String value)
+ {
+ ServiceAttributeMetaData attribute = new ServiceAttributeMetaData();
+ attribute.setName(name);
+ attribute.setValue(new ServiceTextValueMetaData(value));
+ return attribute;
+ }
+
+}
Added: trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java (rev 0)
+++ trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java 2007-03-21 04:36:58 UTC (rev 61511)
@@ -0,0 +1,119 @@
+package org.jboss.resource.deployers;
+
+import java.io.InputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+import org.jboss.deployers.plugins.deployers.helpers.AbstractParsingDeployer;
+import org.jboss.deployers.plugins.deployers.helpers.JAXBDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
+import org.jboss.resource.metadata.repository.JCAMetaDataRepository;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A ManagedConnectionFactoryParserDeployer.
+ *
+ * @author <a href="weston.price at jboss.org">Weston Price</a>
+ * @version $Revision: 1.1 $
+ *
+ * Note, this is currently a total hack until we can rework the JAXBDeployer
+ */
+public class ManagedConnectionFactoryParserDeployer extends AbstractParsingDeployer<ManagedConnectionFactoryDeploymentGroup>
+{
+ private JAXBContext context;
+ private JCAMetaDataRepository repository;
+ private String suffix;
+
+ public ManagedConnectionFactoryParserDeployer()
+ {
+ super(ManagedConnectionFactoryDeploymentGroup.class);
+ }
+
+ /**
+ * Get the suffix.
+ *
+ * @return the suffix.
+ */
+ public String getSuffix()
+ {
+ return suffix;
+ }
+
+ /**
+ * Set the suffix.
+ *
+ * @param suffix The suffix to set.
+ */
+ public void setSuffix(String suffix)
+ {
+ this.suffix = suffix;
+ }
+
+
+ /**
+ * Get the repository.
+ *
+ * @return the repository.
+ */
+ public JCAMetaDataRepository getRepository()
+ {
+ return repository;
+ }
+
+ /**
+ * Set the repository.
+ *
+ * @param repository The repository to set.
+ */
+ public void setRepository(JCAMetaDataRepository repository)
+ {
+ this.repository = repository;
+ }
+
+ public void create() throws Exception
+ {
+ context = JAXBContext.newInstance(new Class[]{getDeploymentType()});
+ }
+
+ @Override
+ protected ManagedConnectionFactoryDeploymentGroup parse(DeploymentUnit unit, VirtualFile file, ManagedConnectionFactoryDeploymentGroup root) throws Exception
+ {
+ //TODO do we need to this every time?
+ Unmarshaller um = context.createUnmarshaller();
+ InputStream is = file.openStream();
+
+ try
+ {
+ JAXBElement<ManagedConnectionFactoryDeploymentGroup> elem = um.unmarshal(new StreamSource(is), ManagedConnectionFactoryDeploymentGroup.class);
+ ManagedConnectionFactoryDeploymentGroup deployment = elem.getValue();
+ return deployment;
+
+ //TODO add to repository
+ }
+ finally
+ {
+ if(is != null)
+ is.close();
+ }
+
+
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ createMetaData(unit, unit.getName(), getSuffix());
+
+ }
+
+ @Override
+ protected void init(DeploymentUnit unit, ManagedConnectionFactoryDeploymentGroup metaData, VirtualFile file) throws Exception
+ {
+ metaData.setUrl(file.toURL());
+ }
+}
More information about the jboss-cvs-commits
mailing list