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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jul 7 22:57:37 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-07-07 22:57:37 -0400 (Sat, 07 Jul 2007)
New Revision: 63907

Added:
   trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
Modified:
   trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java
   trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryFields.java
   trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryManagedObject.java
Log:
Checkpoint the managed object changes

Modified: trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java	2007-07-08 02:52:07 UTC (rev 63906)
+++ trunk/connector/src/main/org/jboss/resource/deployers/ManagedConnectionFactoryDeployer.java	2007-07-08 02:57:37 UTC (rev 63907)
@@ -22,17 +22,24 @@
 package org.jboss.resource.deployers;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
+import org.jboss.deployers.spi.management.ComponentType;
+import org.jboss.deployers.spi.management.KnownComponentTypes;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.resource.deployers.builder.AbstractBuilder;
+import org.jboss.resource.deployers.management.ConnectionFactoryManagedObject;
+import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.NoTxDataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData;
 import org.jboss.resource.metadata.repository.DefaultJCAMetaDataRepository;
 import org.jboss.system.metadata.ServiceDeployment;
 import org.jboss.system.metadata.ServiceMetaData;
@@ -41,6 +48,7 @@
  * A ManagedConnectionFactoryDeployer.
  * 
  * @author <a href="weston.price at jboss.org">Weston Price</a>
+ * @author Scott.Stark at jboss.org
  * @author adrian at jboss.org
  * @version $Revision: 1.1 $
  */
@@ -53,8 +61,49 @@
    
    /** The builders */
    private List<AbstractBuilder> builders = new ArrayList<AbstractBuilder>();
-   
+   /** The ManagedConnectionFactoryDeploymentGroup props to manage */
+   private String[] propNames = {
+         "jndiName",
+         "jdbcURL",
+         "userName",
+         "passWord",
+         "driverClass",
+         "minPoolSize",
+         "maxPoolSize",
+         "securityMetaData",
+         "managedConnectionFactoryProperties",
+   };
    /**
+    * A mapping from the managed property name to the attachment property name.
+    */
+   private Map<String, String> propertyNameMappings = new HashMap<String, String>();
+
+   public Map<String, String> getPropertyNameMappings()
+   {
+      return propertyNameMappings;
+   }
+
+   public void setPropertyNameMappings(Map<String, String> mangedToMBeanNames)
+   {
+      // Need to reverse the mapping
+      for(String key : mangedToMBeanNames.keySet())
+      {
+         String value = mangedToMBeanNames.get(key);
+         propertyNameMappings.put(value, key);
+      }
+   }
+
+   public String[] getPropNames()
+   {
+      return propNames;
+   }
+
+   public void setPropNames(String[] propNames)
+   {
+      this.propNames = propNames;
+   }
+
+   /**
     * Create a new ManagedConnectionFactoryDeployer.
     */
    public ManagedConnectionFactoryDeployer()
@@ -72,7 +121,7 @@
    {
       return this.builders;
    }
-   
+
    /**
     * Get the repository.
     * 
@@ -107,22 +156,36 @@
       {
          componentServices.add(data);
       }
-      
+
+      ComponentType type = null;
       for (ManagedConnectionFactoryDeploymentMetaData data : deployments)
-      {         
+      {
+         // TODO: there should be multiple component types
+         if( type == null )
+         {
+            if( data instanceof LocalDataSourceDeploymentMetaData )
+               type = KnownComponentTypes.DataSourceTypes.LocalTx.getType();
+            if( data instanceof NoTxDataSourceDeploymentMetaData )
+               type = KnownComponentTypes.DataSourceTypes.NoTX.getType();
+            if( data instanceof XADataSourceDeploymentMetaData )
+               type = KnownComponentTypes.DataSourceTypes.XA.getType();
+         }
+
          for (AbstractBuilder builder : builders)
          {
             ServiceMetaData candidate = builder.build(data);
             
             if(candidate != null)
             {
-               componentServices.add(candidate);               
+               componentServices.add(candidate);
             }
          }
       }
       
       serviceDeployment.setServices(componentServices);
       unit.addAttachment(ServiceDeployment.class, serviceDeployment);
+      if( type != null )
+         unit.addAttachment(ComponentType.class, type);
    }
 
    @Override
@@ -132,9 +195,21 @@
 
    public void build(DeploymentUnit unit, Map<String, ManagedObject> map) throws DeploymentException
    {
-      ManagedConnectionFactoryDeploymentGroup group = unit.getAttachment(ManagedConnectionFactoryDeploymentGroup.class);
+      String key = ManagedConnectionFactoryDeploymentGroup.class.getName();
+      ManagedConnectionFactoryDeploymentGroup group = unit.getAttachment(key, ManagedConnectionFactoryDeploymentGroup.class);
       if( group == null )
          return;
 
+      try
+      {
+         ConnectionFactoryManagedObject mo = new ConnectionFactoryManagedObject(group,
+            propNames, propertyNameMappings);
+         map.put(key, mo);
+      }
+      catch(Exception e)
+      {
+         throw new DeploymentException(e);
+      }
    }
+
 }

Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryFields.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryFields.java	2007-07-08 02:52:07 UTC (rev 63906)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryFields.java	2007-07-08 02:57:37 UTC (rev 63907)
@@ -22,6 +22,7 @@
 package org.jboss.resource.deployers.management;
 
 import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.reflect.spi.FieldInfo;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
 
 /**
@@ -34,11 +35,11 @@
 
    private ManagedConnectionFactoryDeploymentMetaData metaData;
 
-   ConnectionFactoryFields(ManagedConnectionFactoryDeploymentMetaData metaData, String name)
+   ConnectionFactoryFields(ManagedConnectionFactoryDeploymentMetaData metaData,
+         FieldInfo fi, String name)
    {
       super(name);
       this.metaData = metaData;
    }
-
    
 }

Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryManagedObject.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryManagedObject.java	2007-07-08 02:52:07 UTC (rev 63906)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryManagedObject.java	2007-07-08 02:57:37 UTC (rev 63907)
@@ -21,14 +21,30 @@
  */
 package org.jboss.resource.deployers.management;
 
-import java.lang.reflect.Method;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
+import org.jboss.deployers.spi.management.KnownComponentTypes;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
 import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.reflect.plugins.ClassInfoImpl;
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.FieldInfo;
+import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.NoTxDataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.TxConnectionFactoryDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData;
 
 /**
  * The ManagedObject implementation for the ManagedConnectionFactoryDeploymentGroup.
@@ -40,37 +56,90 @@
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 1L;
+   private Map<String, String> propertyNameMappings;
 
    /**
     * ConnectionFactoryManagedObject ctor
+    * @param metaData - the attachment meta data instance to bind properties to
+    * @param propNames - the meta data property names to create managed properties for.
+    * @param propertyNameMappings - the external managed property name to metaData
+    * property name mappings. 
     */
    public ConnectionFactoryManagedObject(ManagedConnectionFactoryDeploymentGroup metaData,
-         String[] propNames)
+         String[] propNames, Map<String, String> propertyNameMappings)
       throws Exception
    {
-      this(ManagedConnectionFactoryDeploymentGroup.class.getName(), metaData, propNames);
+      this(ManagedConnectionFactoryDeploymentGroup.class.getName(), metaData,
+            propNames, propertyNameMappings);
    }
    /**
     * ConnectionFactoryManagedObject ctor
-    * @param attachmentName - 
+    * @param attachmentName - the name of the deployment attachment.
+    * @param metaData - the attachment meta data instance to bind properties to
+    * @param propNames - the meta data property names to create managed properties for.
+    * @param propertyNameMappings - the external managed property name to metaData
+    * property name mappings. 
     */
    public ConnectionFactoryManagedObject(String attachmentName,
-         ManagedConnectionFactoryDeploymentGroup metaData, String[] propNames)
+         ManagedConnectionFactoryDeploymentGroup metaData, String[] propNames,
+         Map<String, String> propertyNameMappings)
       throws Exception
    {
       super(attachmentName);
 
+      this.propertyNameMappings = propertyNameMappings;
+      IntrospectionTypeInfoFactoryImpl typeInfo = new IntrospectionTypeInfoFactoryImpl();
+
       // Create the ManagedPropertys for the metaData
       Set<ManagedProperty> properties = getProperties();
       List<ManagedConnectionFactoryDeploymentMetaData> deployments = metaData.getDeployments();
+      // TODO: Cannot handle multiple datasource deployments
+      if( deployments.size() > 1 )
+         throw new IllegalStateException("TODO: Cannot support multiple ds deployments currently");
+      String dsType = null;
+
       for(ManagedConnectionFactoryDeploymentMetaData md : deployments)
       {
+         if( md instanceof LocalDataSourceDeploymentMetaData )
+            dsType = "local-tx-datasource";
+         if( md instanceof NoTxDataSourceDeploymentMetaData )
+            dsType = "no-tx-datasource";
+         if( md instanceof XADataSourceDeploymentMetaData )
+            dsType = "xa-datasource";
+         if( md instanceof NoTxConnectionFactoryDeploymentMetaData )
+            dsType = "no-tx-connection-factory";
+         if( md instanceof TxConnectionFactoryDeploymentMetaData )
+            dsType = "tx-connection-factory";
+
+         Class mdClass = md.getClass();
+         ClassInfoImpl info = new ClassInfoImpl(mdClass.getName());
+         info.setType(mdClass);
+         info.setTypeInfoFactory(typeInfo);
+         info.setClassInfoHelper(typeInfo);
+         ClassInfoImpl superClazz = typeInfo.getSuperClass(info);
+         info.setSuperclass(superClazz);
          for(String name : propNames)
          {
-            ConnectionFactoryFields fields = createField(md, name);
+            ConnectionFactoryFields fields = createField(md, name, info);
             ConnectionFactoryProperty p = new ConnectionFactoryProperty(this, fields);
             properties.add(p);
          }
+         // Handle the datasource-type
+         DefaultFieldsImpl f = new DefaultFieldsImpl();
+         f.setName("datasource-type");
+         f.setDescription("The type of the DataSource");
+         f.setMandatory(true);
+         f.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"));
+         f.setLegalValues(values);
+         f.setMetaType(SimpleMetaType.STRING);
+         ManagedPropertyImpl dsTypeProp = new ManagedPropertyImpl(this, f);
+         properties.add(dsTypeProp);
       }
    }
 
@@ -83,12 +152,27 @@
       return tmp.toString();
    }
 
-   ConnectionFactoryFields createField(ManagedConnectionFactoryDeploymentMetaData md, String name)
+   /**
+    * 
+    * @param md
+    * @param name
+    * @return
+    * @throws Exception
+    */
+   ConnectionFactoryFields createField(ManagedConnectionFactoryDeploymentMetaData md, String name,
+         ClassInfo info)
       throws Exception
    {
-      Class[] sig = {};
-      Method getter = md.getClass().getMethod(name, sig);
-      ConnectionFactoryFields fields = null;
+      // Transform external property names to field accessors
+      String propName = propertyNameMappings.get(name);
+      FieldInfo fi = null;
+      ClassInfo ci = info;
+      while( fi == null && ci != null )
+      {
+         fi = ci.getDeclaredField(name);
+         ci = ci.getSuperclass();
+      }
+      ConnectionFactoryFields fields = new ConnectionFactoryFields(md, fi, propName);
       return fields;
    }
 }

Added: trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java	                        (rev 0)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java	2007-07-08 02:57:37 UTC (rev 63907)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.management;
+
+import java.util.HashSet;
+import java.util.Map;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.profileservice.management.plugins.BasicDeploymentTemplateInfo;
+
+/**
+ * The template for creating 
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DsDataSourceTemplateInfo extends BasicDeploymentTemplateInfo
+{
+   private static final long serialVersionUID = 1;
+   private Map<String, String> propertyNameMappings;
+   private String attachmentName;
+   private String dsTypeAttachmentName;
+
+   public DsDataSourceTemplateInfo(String name, String description, String attachmentName)
+   {
+      this(name, description, attachmentName, attachmentName);
+   }
+   public DsDataSourceTemplateInfo(String name, String description,
+         String attachmentName, String dsTypeAttachmentName)
+   {
+      super(name, description);
+      this.attachmentName = attachmentName;
+      this.dsTypeAttachmentName = dsTypeAttachmentName;
+   }
+
+   public Map<String, String> getPropertyNameMappings()
+   {
+      return propertyNameMappings;
+   }
+   public void setPropertyNameMappings(Map<String, String> propertyNameMappings)
+   {
+      this.propertyNameMappings = propertyNameMappings;
+   }
+
+   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 connection-url field info
+      DefaultFieldsImpl f1 = new DefaultFieldsImpl();
+      setFieldName("connection-url", f1);
+      f1.setDescription("The jdbc url of the DataSource");
+      f1.setMandatory(true);
+      f1.setMetaType(SimpleMetaType.STRING);
+      ManagedPropertyImpl conURL = new ManagedPropertyImpl(mo, f1);
+      super.addProperty(conURL);
+      // The user field info
+      DefaultFieldsImpl f2 = new DefaultFieldsImpl();
+      setFieldName("user-name", f2);
+      f2.setDescription("The username for the connection-url");
+      f2.setMandatory(false);
+      f2.setMetaType(SimpleMetaType.STRING);
+      ManagedPropertyImpl user = new ManagedPropertyImpl(mo, f2);
+      super.addProperty(user);
+      // The password field info
+      DefaultFieldsImpl f3 = new DefaultFieldsImpl();
+      setFieldName("password", f3);
+      f3.setDescription("The password for the connection-url");
+      f3.setMandatory(false);
+      f3.setMetaType(SimpleMetaType.STRING);
+      ManagedPropertyImpl password = new ManagedPropertyImpl(mo, f3);
+      super.addProperty(password);
+      // 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 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);
+      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);
+      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);
+      super.addProperty(connProps);
+
+      // 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)
+   {
+      f.setField(Fields.NAME, name);
+      if( propertyNameMappings != null )
+      {
+         String mappedName = propertyNameMappings.get(name);
+         if( mappedName != null )
+            f.setField(Fields.MAPPED_NAME, mappedName);
+      }
+   }
+}


Property changes on: trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list