[jboss-cvs] JBossAS SVN: r68136 - in trunk/connector/src: main/org/jboss/resource/deployers/management and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 11 08:19:16 EST 2007


Author: alex.loubyansky at jboss.com
Date: 2007-12-11 08:19:15 -0500 (Tue, 11 Dec 2007)
New Revision: 68136

Modified:
   trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java
   trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java
   trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
   trunk/connector/src/resources/deployers/jca-deployers-beans.xml
Log:
JBAS-4671 hacked MCF parsing deplyer to override build method and create managed objects for MCFs in MCF deployment group, modified DsDataSourceTemplateInfo to represent only one kind of MCF at a time

Modified: trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java	2007-12-11 12:41:43 UTC (rev 68135)
+++ trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryParserDeployer.java	2007-12-11 13:19:15 UTC (rev 68136)
@@ -22,6 +22,7 @@
 package org.jboss.resource.deployers;
 
 import java.io.InputStream;
+import java.util.Map;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
@@ -30,9 +31,15 @@
 
 import org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
 import org.jboss.resource.metadata.repository.JCAMetaDataRepository;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
 
 /**
  * A ManagedConnectionFactoryParserDeployer.
@@ -115,4 +122,36 @@
    {
       metaData.setUrl(file.toURL());
    }
+
+   /**
+    * Build managed object.
+    *
+    * @param unit the deployment unit
+    * @param managedObjects map of managed objects
+    * @throws DeploymentException for any deployment exception
+    */
+   @Override
+   public void build(DeploymentUnit unit, Map<String, ManagedObject> managedObjects) throws DeploymentException
+   {
+      super.build(unit, managedObjects);
+      if(isBuildManagedObject())
+      {
+         ManagedConnectionFactoryDeploymentGroup deployment = unit.getAttachment(getOutput());
+         if (deployment != null)
+         {
+            ManagedObjectFactory factory = ManagedObjectFactoryBuilder.create();
+            if(deployment.getDeployments() != null)
+            {
+               for(ManagedConnectionFactoryDeploymentMetaData mcf : deployment.getDeployments())
+               {
+                  ManagedObject mo = factory.initManagedObject(mcf, null, null);
+                  if (mo != null)
+                     // mcf.getClass().getName(), mo.getName() returns JndiName
+                     // which won't work in the DsDataSourceTemplateInfo
+                     managedObjects.put(mcf.getClass().getName(), mo);
+               }
+            }
+         }
+      }
+   }
 }

Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java	2007-12-11 12:41:43 UTC (rev 68135)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java	2007-12-11 13:19:15 UTC (rev 68136)
@@ -89,22 +89,12 @@
    protected void writeTemplate(File dsXml, DeploymentTemplateInfo values)
       throws Exception
    {
-      // Just get the first ManagedProperty to access the ManagedObject
-      //Map<String, ManagedProperty> properties = values.getProperties();
-      //ManagedProperty prop = properties.values().iterator().next();
-      //ManagedObject mo = prop.getManagedObject();
-      //Object group = mo.getAttachment();
+      String cfType = ((DsDataSourceTemplateInfo)values).getConnectionFactoryType();
 
-      Map<String, ManagedProperty> properties = values.getProperties();
-      ManagedProperty prop = properties.get("datasource-type");
-      if(prop == null)
-         throw new IllegalStateException("Required property datasource-type could not be found among: " + properties.keySet());
-
       ManagedConnectionFactoryDeploymentMetaData mcf;
       ManagedObjectFactory mof = ManagedObjectFactoryBuilder.create();
       ManagedObject cfMO;
 
-      Object cfType = prop.getValue();
       if(cfType.equals("local-tx-datasource"))
       {
          mcf = new LocalDataSourceDeploymentMetaData();
@@ -143,8 +133,7 @@
             KnownComponentTypes.DataSourceTypes.NoTx.getType().getSubtype());
       }
       else
-         throw new IllegalStateException("Expected values for datasource-type are " +
-            prop.getLegalValues() + " but got: " + cfType);
+         throw new IllegalStateException("Unexpected value connection factory type: " + cfType);
 
       ManagedConnectionFactoryDeploymentGroup group = new ManagedConnectionFactoryDeploymentGroup();
       group.addManagedConnectionFactoryDeployment(mcf);

Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java	2007-12-11 12:41:43 UTC (rev 68135)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java	2007-12-11 13:19:15 UTC (rev 68136)
@@ -37,6 +37,9 @@
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.profileservice.management.plugins.BasicDeploymentTemplateInfo;
+import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
 
 /**
  * The template for creating 
@@ -48,19 +51,12 @@
 {
    private static final long serialVersionUID = 1;
    private Map<String, String> propertyNameMappings;
-   private String attachmentName;
-   private String dsTypeAttachmentName;
+   private String dsType = "local-tx-datasource";
 
-   public DsDataSourceTemplateInfo(String name, String description, String attachmentName)
+   public DsDataSourceTemplateInfo(String name, String description, String datasourceType)
    {
-      this(name, description, attachmentName, attachmentName);
-   }
-   public DsDataSourceTemplateInfo(String name, String description,
-         String attachmentName, String dsTypeAttachmentName)
-   {
       super(name, description);
-      this.attachmentName = attachmentName;
-      this.dsTypeAttachmentName = dsTypeAttachmentName;
+      this.dsType = datasourceType;
    }
 
    public Map<String, String> getPropertyNameMappings()
@@ -72,17 +68,80 @@
       this.propertyNameMappings = propertyNameMappings;
    }
 
+
+   public String getConnectionFactoryType()
+   {
+      return dsType;
+   }
+
+   public void setConnectionFactoryType(String dsType)
+   {
+      this.dsType = dsType;
+   }
+
    public void start()
    {
-      ManagedObjectImpl mo = new ManagedObjectImpl(attachmentName);
-      // The jndi name field info
-      DefaultFieldsImpl f0 = new DefaultFieldsImpl();
-      setFieldName("jndi-name", f0);
-      f0.setDescription("The jndi name to bind the DataSource under");
-      f0.setMandatory(true);
-      f0.setMetaType(SimpleMetaType.STRING);
-      ManagedPropertyImpl jndiName = new ManagedPropertyImpl(mo, f0);
-      super.addProperty(jndiName);
+/*
+      // The type of the datasource
+      ManagedObjectImpl mo2 = new ManagedObjectImpl(ManagedConnectionFactoryDeploymentGroup.class.getName());
+      DefaultFieldsImpl dsTypeField = new DefaultFieldsImpl();
+      setFieldName("datasource-type", dsTypeField);
+      dsTypeField.setDescription("The type of the DataSource");
+      dsTypeField.setMandatory(true);
+      dsTypeField.setValue("local-tx-datasource");
+      HashSet<MetaValue> values = new HashSet<MetaValue>();
+      values.add(SimpleValueSupport.wrap("local-tx-datasource"));
+      values.add(SimpleValueSupport.wrap("no-tx-datasource"));
+      values.add(SimpleValueSupport.wrap("xa-datasource"));
+      values.add(SimpleValueSupport.wrap("no-tx-connection-factory"));
+      values.add(SimpleValueSupport.wrap("tx-connection-factory"));
+      dsTypeField.setLegalValues(values);
+      dsTypeField.setMetaType(SimpleMetaType.STRING);
+      ManagedPropertyImpl dsTypeProp = new ManagedPropertyImpl(mo2, dsTypeField);
+      super.addProperty(dsTypeProp);
+
+      if(this.dsType != null)
+         dsTypeField.setValue(this.dsType);
+      else
+         this.dsType = (String)dsTypeField.getValue();
+*/
+
+      // DataSource
+      if("local-tx-datasource".equals(dsType))
+         createLocalTxDsTemplate();
+      else if("xa-datasource".equals(dsType))
+         createXaDsTemplate();
+      else
+         throw new IllegalStateException("Unsupported dsType: " + dsType);
+   }
+
+   private void createXaDsTemplate()
+   {
+      ManagedObjectImpl mo = new ManagedObjectImpl(XADataSourceDeploymentMetaData.class.getName());
+      addCommonProperties(mo);
+      // The driver-class field info
+      DefaultFieldsImpl f = new DefaultFieldsImpl();
+      setFieldName("xa-datasource-class", f);
+      f.setDescription("The xa datasource class name");
+      f.setMandatory(true);
+      f.setMetaType(SimpleMetaType.STRING);
+      ManagedPropertyImpl xaDsClass = new ManagedPropertyImpl(mo, f);
+      super.addProperty(xaDsClass);
+      // The xa-datasource-property field info
+      f = new DefaultFieldsImpl();
+      setFieldName("xa-datasource-properties", f);
+      f.setDescription("The xa datasource properties");
+      f.setMandatory(false);
+      // TODO is this right?
+      f.setMetaType(MetaTypeFactory.getInstance().resolve(List.class));
+      ManagedPropertyImpl xaDsProps = new ManagedPropertyImpl(mo, f);
+      super.addProperty(xaDsProps);
+   }
+
+   private void createLocalTxDsTemplate()
+   {
+      ManagedObjectImpl mo = new ManagedObjectImpl(LocalDataSourceDeploymentMetaData.class.getName());
+      addCommonProperties(mo);
       // The connection-url field info
       DefaultFieldsImpl f1 = new DefaultFieldsImpl();
       setFieldName("connection-url", f1);
@@ -107,35 +166,47 @@
       f3.setMetaType(SimpleMetaType.STRING);
       ManagedPropertyImpl password = new ManagedPropertyImpl(mo, f3);
       super.addProperty(password);
-      // The security-domain field info   
+      // The driver-class field info
       DefaultFieldsImpl f4 = new DefaultFieldsImpl();
-      setFieldName("security-domain", f4);
-      f4.setDescription("The security-domain used to validate connections");
-      f4.setMandatory(false);
+      setFieldName("driver-class", f4);
+      f4.setDescription("The jdbc driver class name");
+      f4.setMandatory(true);
       f4.setMetaType(SimpleMetaType.STRING);
-      ManagedPropertyImpl secDomain = new ManagedPropertyImpl(mo, f4);
-      super.addProperty(secDomain);
-      // The driver-class field info
-      DefaultFieldsImpl f5 = new DefaultFieldsImpl();
-      setFieldName("driver-class", f5);
-      f5.setDescription("The jdbc driver class name");
-      f5.setMandatory(true);
-      f5.setMetaType(SimpleMetaType.STRING);
-      ManagedPropertyImpl driverClass = new ManagedPropertyImpl(mo, f5);
+      ManagedPropertyImpl driverClass = new ManagedPropertyImpl(mo, f4);
       super.addProperty(driverClass);
       // The driver connection properties field info
-      DefaultFieldsImpl f6 = new DefaultFieldsImpl();
-      setFieldName("connection-properties", f6);
-      f6.setDescription("The jdbc driver connection properties");
-      f6.setMandatory(false);
+      DefaultFieldsImpl f5 = new DefaultFieldsImpl();
+      setFieldName("connection-properties", f5);
+      f5.setDescription("The jdbc driver connection properties");
+      f5.setMandatory(false);
       String[] itemNames = {"conn-prop1", "conn-prop2"};
       String[] itemDescriptions = {"conn-prop1 description", "conn-prop2 description"};
       MetaType[] itemTypes = {SimpleMetaType.STRING, SimpleMetaType.STRING};
       CompositeMetaType propsType = new ImmutableCompositeMetaType("java.lang.Properties", "DS connection properties",
             itemNames, itemDescriptions, itemTypes);
-      f6.setMetaType(propsType);
-      ManagedPropertyImpl connProps = new ManagedPropertyImpl(mo, f6);
+      f5.setMetaType(propsType);
+      ManagedPropertyImpl connProps = new ManagedPropertyImpl(mo, f5);
       super.addProperty(connProps);
+   }
+
+   private void addCommonProperties(ManagedObjectImpl mo)
+   {
+      // The jndi name field info
+      DefaultFieldsImpl f0 = new DefaultFieldsImpl();
+      setFieldName("jndi-name", f0);
+      f0.setDescription("The jndi name to bind the DataSource under");
+      f0.setMandatory(true);
+      f0.setMetaType(SimpleMetaType.STRING);
+      ManagedPropertyImpl jndiName = new ManagedPropertyImpl(mo, f0);
+      super.addProperty(jndiName);
+      // The security-domain field info
+      DefaultFieldsImpl f4 = new DefaultFieldsImpl();
+      setFieldName("security-domain", f4);
+      f4.setDescription("The security-domain used to validate connections");
+      f4.setMandatory(false);
+      f4.setMetaType(SimpleMetaType.STRING);
+      ManagedPropertyImpl secDomain = new ManagedPropertyImpl(mo, f4);
+      super.addProperty(secDomain);
       // The config-property field info
       DefaultFieldsImpl f = new DefaultFieldsImpl();
       setFieldName("config-property", f);
@@ -153,44 +224,6 @@
       f.setMetaType(SimpleMetaType.STRING);
       ManagedPropertyImpl connectionDef = new ManagedPropertyImpl(mo, f);
       super.addProperty(connectionDef);
-
-      // XA properties
-      // The driver-class field info
-      f = new DefaultFieldsImpl();
-      setFieldName("xa-datasource-class", f);
-      f.setDescription("The xa datasource class name");
-      f.setMandatory(true);
-      f.setMetaType(SimpleMetaType.STRING);
-      ManagedPropertyImpl xaDsClass = new ManagedPropertyImpl(mo, f);
-      super.addProperty(xaDsClass);
-      // The xa-datasource-property field info
-      f = new DefaultFieldsImpl();
-      setFieldName("xa-datasource-properties", f);
-      f.setDescription("The xa datasource properties");
-      f.setMandatory(false);
-      // TODO is this right?
-      f.setMetaType(MetaTypeFactory.getInstance().resolve(List.class));
-      ManagedPropertyImpl xaDsProps = new ManagedPropertyImpl(mo, f);
-      super.addProperty(xaDsProps);
-
-
-      // The type of the datasource
-      ManagedObjectImpl mo2 = new ManagedObjectImpl(dsTypeAttachmentName);
-      DefaultFieldsImpl f21 = new DefaultFieldsImpl();
-      setFieldName("datasource-type", f21);
-      f21.setDescription("The type of the DataSource");
-      f21.setMandatory(true);
-      f21.setValue("local-tx-datasource");
-      HashSet<MetaValue> values = new HashSet<MetaValue>();
-      values.add(SimpleValueSupport.wrap("local-tx-datasource"));
-      values.add(SimpleValueSupport.wrap("no-tx-datasource"));
-      values.add(SimpleValueSupport.wrap("xa-datasource"));
-      values.add(SimpleValueSupport.wrap("no-tx-connection-factory"));
-      values.add(SimpleValueSupport.wrap("tx-connection-factory"));
-      f21.setLegalValues(values);
-      f21.setMetaType(SimpleMetaType.STRING);
-      ManagedPropertyImpl dsType = new ManagedPropertyImpl(mo2, f21);
-      super.addProperty(dsType);
    }
 
    protected void setFieldName(String name, Fields f)

Modified: trunk/connector/src/resources/deployers/jca-deployers-beans.xml
===================================================================
--- trunk/connector/src/resources/deployers/jca-deployers-beans.xml	2007-12-11 12:41:43 UTC (rev 68135)
+++ trunk/connector/src/resources/deployers/jca-deployers-beans.xml	2007-12-11 13:19:15 UTC (rev 68136)
@@ -71,8 +71,19 @@
       <constructor>
          <parameter>DsDataSourceTemplate</parameter>
          <parameter>A template for *-ds.xml deployments</parameter>
-         <parameter>org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup</parameter>
+         <parameter>local-tx-datasource</parameter>
       </constructor>
    </bean>
+   <bean name="XADataSourceTemplate" class="org.jboss.resource.deployers.management.DsDataSourceTemplate">
+      <property name="info"><inject bean="XADataSourceTemplateInfo"/></property>
+   </bean>
+   <bean name="XADataSourceTemplateInfo"
+      class="org.jboss.resource.deployers.management.DsDataSourceTemplateInfo">
+      <constructor>
+         <parameter>XADataSourceTemplate</parameter>
+         <parameter>A template for *-xa-ds.xml deployments</parameter>
+         <parameter>xa-datasource</parameter>
+      </constructor>
+   </bean>
    
 </deployment>




More information about the jboss-cvs-commits mailing list