[jboss-cvs] JBossAS SVN: r60186 - in trunk/profileservice/src/main/org/jboss/profileservice: management/builders and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 2 04:19:47 EST 2007


Author: scott.stark at jboss.org
Date: 2007-02-02 04:19:47 -0500 (Fri, 02 Feb 2007)
New Revision: 60186

Modified:
   trunk/profileservice/src/main/org/jboss/profileservice/management/BaseManagedObject.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/ManagedDeploymentImpl.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java
   trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java
   trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java
   trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java
Log:
Update the component property handling

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/BaseManagedObject.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/BaseManagedObject.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/BaseManagedObject.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -10,18 +10,22 @@
    implements Serializable
 {
    private static final long serialVersionUID = 1;
-   private String name;
+   private String simpleName;
    private Map<String, ManagedProperty> properties;
 
-   public BaseManagedObject(String name, Map<String, ManagedProperty> properties)
+   public BaseManagedObject(String simpleName, Map<String, ManagedProperty> properties)
    {
-      this.name = name;
+      this.simpleName = simpleName;
       this.properties = properties;
    }
 
+   public String getSimpleName()
+   {
+      return simpleName;
+   }
    public String getName()
    {
-      return name;
+      return simpleName;
    }
 
    /**
@@ -62,8 +66,8 @@
     */
    protected void toString(StringBuilder sb)
    {
-      sb.append("name=");
-      sb.append(name);
+      sb.append("simpleName=");
+      sb.append(simpleName);
       sb.append(", properties=");
       sb.append(properties);
    }

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagedDeploymentImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagedDeploymentImpl.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagedDeploymentImpl.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -42,6 +42,7 @@
    implements ManagedDeployment, Serializable
 {
    private static final long serialVersionUID = 1;
+   private String name;
    private Set<String> types;
    private DeploymentPhase phase;
    private ManagedDeployment parent;
@@ -57,11 +58,19 @@
          Map<String, ManagedProperty> properties, ManagedDeployment parent)
    {
       super(ctx.getSimpleName(), properties);
+      this.name = ctx.getName();
       this.types = ctx.getTypes();
       this.phase = ctx.getTransientManagedObjects().getAttachment(DeploymentPhase.class);
       this.parent = parent;
    }
 
+   
+   @Override
+   public String getName()
+   {
+      return name;
+   }
+
    public Set<String> getTypes()
    {
       return types;

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -54,6 +54,7 @@
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.profileservice.aop.DeployerAspects;
+import org.jboss.profileservice.spi.AttachmentsSerializer;
 import org.jboss.profileservice.spi.NoSuchDeploymentException;
 import org.jboss.profileservice.spi.Profile;
 import org.jboss.profileservice.spi.ProfileKey;
@@ -63,6 +64,8 @@
 import org.jboss.virtual.VirtualFile;
 
 /**
+ * The default ManagementView implementation.
+ * 
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */
@@ -79,6 +82,8 @@
    /** */
    private MainDeployer mainDeployer;
    /** */
+   private AttachmentsSerializer serializer;
+   /** */
    private HashMap<String, DeploymentTemplate> templates = new HashMap<String, DeploymentTemplate>();
    /** */
    private ResourceBundle i18n;
@@ -92,6 +97,8 @@
    /** An index of ManagedComponent by ComponentType */
    private HashMap<ComponentType, Set<ManagedComponent>> compByCompType =
       new HashMap<ComponentType, Set<ManagedComponent>>();
+   private HashMap<DeploymentContext, ManagedDeployment> ctxToDeployment = 
+      new HashMap<DeploymentContext, ManagedDeployment>();
 
    public ManagementViewImpl()
    {
@@ -130,6 +137,17 @@
       log.debug("setProfileService: "+ps);
    }
 
+   public AttachmentsSerializer getSerializer()
+   {
+      return serializer;
+   }
+
+   public void setSerializer(AttachmentsSerializer serializer)
+   {
+      this.serializer = serializer;
+      DeployerAspects.setAttachmentsSerializer(serializer);
+   }
+
    public MainDeployer getMainDeployer()
    {
       return mainDeployer;
@@ -377,9 +395,83 @@
    public void updateComponentType(DeploymentUnit unit, ComponentType type)
    {
       DeploymentContext ctx = unit.getDeploymentContext();
+      log.debug("updateComponentType, unit="+unit.getName()+", type="+type);
       ctxToCompType.put(ctx, type);
+      DeploymentContext topCtx = ctx.getTopLevel();
+      if( ctxToDeployment.containsKey(topCtx) == false )
+      {
+         try
+         {
+            ManagedDeployment md = getManagedDeployment(topCtx);
+            indexComponents(md);
+            ctxToDeployment.put(topCtx, md);
+         }
+         catch(Exception e)
+         {
+            log.warn("Failed to create ManagedDeployment for ctx="+ctx);
+         }
+      }
    }
 
+   public void updateDeployment()
+   {
+      
+   }
+   public void updateComponent(ManagedComponent comp)
+      throws Exception
+   {
+      // Find the comp deployment
+      ManagedDeployment md = comp.getDeployment();
+      while( md.getParent() != null )
+         md = md.getParent();
+      String name = md.getSimpleName();
+      DeploymentPhase phase = md.getDeploymentPhase();
+      DeploymentContext mdCtx = activeProfile.getDeployment(name, phase);
+      if( mdCtx == null )
+      {
+         formatter.applyPattern(i18n.getString("ManagementView.NoSuchDeploymentException")); //$NON-NLS-1$
+         Object[] args = {name};
+         String msg = formatter.format(args);
+         throw new NoSuchDeploymentException(msg);
+      }
+
+      // Apply the managed properties
+      Map<String, ManagedObject> mos = mainDeployer.getManagedObjects(mdCtx);
+      log.debug("updateComponent, profile="+activeProfile+", deploymentName="+name+", phase="+phase+", :"+mos);
+      for(ManagedProperty prop : comp.getProperties().values())
+      {
+         // Skip null values
+         if( prop.getValue() == null )
+            continue;
+
+         ManagedObject mo = prop.getManagedObject();
+         ManagedObject ctxMO = mos.get(mo.getName());
+         if( ctxMO == null )
+         {
+            formatter.applyPattern(i18n.getString("ManagementView.InvalidTemplateKey")); //$NON-NLS-1$
+            Object[] args = {mo.getName()};
+            String msg = formatter.format(args);
+            throw new IllegalArgumentException(msg);
+         }
+         ManagedProperty ctxProp = ctxMO.getProperty(prop.getName());
+         // Check for a mapped name
+         if( ctxProp == null )
+         {
+            String mappedName = prop.getMappedName();
+            if( mappedName != null )
+               ctxProp = ctxMO.getProperty(mappedName);
+         }
+         if( ctxProp == null )
+         {
+            formatter.applyPattern(i18n.getString("ManagementView.InvalidTemplateProperty")); //$NON-NLS-1$
+            Object[] args = {prop.getName()};
+            String msg = formatter.format(args);
+            throw new IllegalArgumentException(msg);
+         }
+         ctxProp.setValue((Serializable)prop.getValue());
+      }
+   }
+
    /**
     * Go through the profile deployments and build ManagedDeployments
     * @throws Exception 
@@ -423,6 +515,7 @@
       Map<String, ManagedObject> mdMOs = mainDeployer.getManagedObjects(ctx);
       Map<String, ManagedProperty> mdProps = getProperties(mdMOs);
       ManagedDeploymentImpl md = new ManagedDeploymentImpl(this, ctx, mdProps);
+      log.debug("Created "+md);
       Set<DeploymentContext> children = ctx.getChildren();
       for(DeploymentContext child : children)
       {
@@ -446,10 +539,19 @@
          Map<String, ManagedProperty> compProps = getProperties(compMOs);
          ComponentType type = ctxToCompType.get(comp);
          ManagedComponentImpl mc = new ManagedComponentImpl(comp.getSimpleName(), type, compProps, md);
+         log.debug("Created "+mc);
          md.getComponents().add(mc);
       }      
    }
 
+   /**
+    * Get the map of the ManagedPropertys keyed by the property mapped name.
+    * The mapped name is used as this is the external view of the
+    * property name. The name corresponds to the attachment field name.
+    * 
+    * @param mos
+    * @return
+    */
    private Map<String, ManagedProperty> getProperties(Map<String, ManagedObject> mos)
    {
       HashMap<String, ManagedProperty> props = new HashMap<String, ManagedProperty>();
@@ -457,7 +559,13 @@
       {
          Set<ManagedProperty> moProps = mo.getProperties();
          for(ManagedProperty prop : moProps)
-            props.put(prop.getName(), prop);
+         {
+            // Use the mapped name if it exists
+            String name = prop.getMappedName();
+            if( name == null )
+               name = prop.getName();
+            props.put(name, prop);
+         }
       }
       return props;
    }

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -21,6 +21,8 @@
  */
 package org.jboss.profileservice.management.builders;
 
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -29,12 +31,13 @@
 import org.jboss.deployers.spi.managed.ManagedObjectBuilder;
 import org.jboss.logging.Logger;
 import org.jboss.managed.api.ManagedObject;
-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.managed.plugins.advice.WrapperAdvice;
 import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.system.metadata.ServiceDeployment;
 import org.jboss.system.metadata.ServiceMetaData;
 
@@ -48,17 +51,24 @@
    implements ManagedObjectBuilder
 {
    private static Logger log = Logger.getLogger(ConnectionFactoryDeployerManagedObjectBuilder.class);
+   /**
+    * A mapping from the managed property name to the attachment property name.
+    */
+   private Map<String, String> propertyNameMappings = new HashMap<String, String>();
 
-   private Map<String, String> propertyNameMappings;
-
    public Map<String, String> getPropertyNameMappings()
    {
       return propertyNameMappings;
    }
 
-   public void setPropertyNameMappings(Map<String, String> propertyNameMappings)
+   public void setPropertyNameMappings(Map<String, String> mangedToMBeanNames)
    {
-      this.propertyNameMappings = propertyNameMappings;
+      // Need to reverse the mapping
+      for(String key : mangedToMBeanNames.keySet())
+      {
+         String value = mangedToMBeanNames.get(key);
+         propertyNameMappings.put(value, key);
+      }
    }
 
    public void build(DeploymentUnit unit, Map<String, ManagedObject> map) 
@@ -78,9 +88,27 @@
             throw new DeploymentException("Expected only 1 ServiceMetaData but saw "+services.size()+" in "+unit.getName());
          ServiceMetaData dsMetaData = services.get(0);
          String attachName = ServiceMetaData.class.getName();
-         ManagedObject mo = new ServiceManagedObject(attachName, dsMetaData);
+         ManagedObject mo = new ServiceManagedObject(attachName, dsMetaData, propertyNameMappings);
          ManagedObject wrapMO = WrapperAdvice.wrapManagedObject(mo);
          map.put(attachName, wrapMO);
+         // The datasource type...
+         attachName = "FakeConnectionFactoryDeployer.datasource-type";
+         ManagedObjectImpl typeMO = new ManagedObjectImpl(attachName);
+         DefaultFieldsImpl f21 = new DefaultFieldsImpl();
+         f21.setName("datasource-type");
+         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"));
+         f21.setLegalValues(values);
+         f21.setMetaType(SimpleMetaType.STRING);
+         ManagedPropertyImpl dsType = new ManagedPropertyImpl(typeMO, f21);
+         typeMO.getProperties().add(dsType);
+         wrapMO = WrapperAdvice.wrapManagedObject(typeMO);
+         map.put(attachName, wrapMO);
       }
    }
 }

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -83,7 +83,7 @@
    {
       if (VALUE.equals(name))
       {
-         String string = (String) value;
+         String string = value.toString();
          ServiceTextValueMetaData text = new ServiceTextValueMetaData(string);
          this.metaData.setValue(text);
          return;

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -51,6 +51,15 @@
    {
       this(attachmentName, metaData, null);
    }
+   /**
+    * Create a mapping for ServiceMetaData by creating a ServiceAttributeFields
+    * instance for each entry in propertyNameMappings.
+    * 
+    * @param attachmentName - the ServiceMetaData attachment key
+    * @param metaData - the ServiceMetaData attachment
+    * @param propertyNameMappings - A mapping from the managed
+    *    property name to the attachment property name.
+    */
    public ServiceManagedObject(String attachmentName, ServiceMetaData metaData,
          Map<String, String> propertyNameMappings)
    {

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -21,6 +21,7 @@
  */
 package org.jboss.profileservice.management.templates;
 
+import java.util.HashSet;
 import java.util.Map;
 
 import org.jboss.managed.api.Fields;
@@ -28,6 +29,8 @@
 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.profileservice.management.plugins.BasicDeploymentTemplateInfo;
 import org.jboss.system.metadata.ServiceDeployment;
 
@@ -58,7 +61,6 @@
    {
       return propertyNameMappings;
    }
-
    public void setPropertyNameMappings(Map<String, String> propertyNameMappings)
    {
       this.propertyNameMappings = propertyNameMappings;
@@ -113,8 +115,24 @@
       f5.setDescription("The jdbc driver class name");
       f5.setMandatory(true);
       f5.setMetaType(SimpleMetaType.STRING);
-      ManagedPropertyImpl dc = new ManagedPropertyImpl(mo, f5);
-      super.addProperty(dc);
+      ManagedPropertyImpl driverClass = new ManagedPropertyImpl(mo, f5);
+      super.addProperty(driverClass);
+
+      // The type of the datasource
+      ManagedObjectImpl mo2 = new ManagedObjectImpl("FakeConnectionFactoryDeployer.datasource-type");
+      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"));
+      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/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -25,12 +25,12 @@
 import java.io.FileWriter;
 import java.net.URI;
 import java.util.ArrayList;
-import java.util.List;
+import java.util.Map;
 
-import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
 import org.jboss.deployers.spi.management.DeploymentTemplate;
 import org.jboss.deployers.spi.management.DeploymentTemplateInfo;
 import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.managed.api.ManagedProperty;
 import org.jboss.profileservice.mock.ds.DataSourceDeployment;
 import org.jboss.profileservice.mock.ds.FakeDataSourceDeployer;
 import org.jboss.system.metadata.ServiceDeployment;
@@ -38,7 +38,7 @@
 import org.jboss.virtual.VirtualFile;
 
 /**
- * A template for creating a datasource(*-ds.xml) deployments.
+ * A template for creating a datasource(*-dsf.xml) deployments.
  * 
  * @author Scott.Stark at jboss.org
  * @version $Revision:$
@@ -46,9 +46,26 @@
 public class FakeDsXmlDataSourceTemplate
    implements DeploymentTemplate
 {
+   /**
+    * The managed property information
+    */
    private DeploymentTemplateInfo info;
+   /**
+    * The deployer used to 
+    */
    private FakeDataSourceDeployer deployer;
-   
+   private Map<String, String> propertyNameMappings;
+
+   public Map<String, String> getPropertyNameMappings()
+   {
+      return propertyNameMappings;
+   }
+
+   public void setPropertyNameMappings(Map<String, String> propertyNameMappings)
+   {
+      this.propertyNameMappings = propertyNameMappings;
+   }
+
    public FakeDataSourceDeployer getDeployer()
    {
       return deployer;
@@ -60,7 +77,8 @@
    }
 
    /**
-    * Creates a root/{deploymentBaseName}-dsf.xml base descriptor.
+    * Creates a root/{deploymentBaseName}-dsf.xml base descriptor
+    * with minimal fields containing default values.
     */
    public VirtualFile applyTemplate(VirtualFile root, String deploymentBaseName,
          DeploymentTemplateInfo values)
@@ -73,6 +91,12 @@
       VirtualFile dsXmlVF = root.findChild(dsName);
       return dsXmlVF;
    }
+   /**
+    * Update the ctx with the metadata values that correspond to the
+    * template info values.
+    * @param ctx - the DeploymentContext to associate metadata to
+    * @param values - the managed property values passed to apply.
+    */
    public void updateTemplateDeployment(DeploymentContext ctx,
          DeploymentTemplateInfo values)
       throws Exception
@@ -81,6 +105,7 @@
       ServiceDeployment service = new ServiceDeployment();
       ArrayList<ServiceMetaData> services = new ArrayList<ServiceMetaData>();
       DataSourceDeployment ds = new DataSourceDeployment();
+      ds.parse(values.getProperties());
       ServiceMetaData dsMetaData = deployer.createDsServiceMetaData(ds);
       services.add(dsMetaData);
       service.setServices(services);
@@ -100,8 +125,18 @@
       throws Exception
    {
       FileWriter fw = new FileWriter(dsXml);
+      Map<String, ManagedProperty> properties = values.getProperties();
+      ManagedProperty type = properties.get("datasource-type");
+      String typeTag = "local-tx-datasource";
+      if( type != null && type.getValue() != null )
+         typeTag = type.getValue().toString();
+
+      /* Write out a minimal template with the datasource type and
+         some defaults. All other properties will be applied to the
+         attachment metdata. 
+       */
       fw.write("<datasources>\n");
-      fw.write("<local-tx-datasource>\n");
+      fw.write("<"+typeTag+">\n");
       fw.write("<jndi-name>default</jndi-name>\n");
       fw.write("<connection-url>jdbc:...</connection-url>\n");
       fw.write("<driver-class>default</driver-class>\n");
@@ -110,7 +145,7 @@
       fw.write("<min-pool-size>1</min-pool-size>\n");
       fw.write("<max-pool-size>10</max-pool-size>\n");
       fw.write("<security-domain>default</security-domain>\n");
-      fw.write("</local-tx-datasource>\n");
+      fw.write("</"+typeTag+">\n");
       fw.write("</datasources>\n");
       fw.flush();
       fw.close();

Modified: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -3,10 +3,10 @@
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import org.jboss.logging.Logger;
-import org.jboss.system.metadata.ServiceAttributeMetaData;
-import org.jboss.system.metadata.ServiceDependencyMetaData;
+import org.jboss.managed.api.ManagedProperty;
 import org.jboss.util.StringPropertyReplacer;
 import org.jboss.util.xml.DOMUtils;
 import org.w3c.dom.Document;
@@ -14,6 +14,13 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+/**
+ * The deployment metadata used to represent the FakeDataSourceDeployer
+ * attachment. This is a javabean form of the *-dsf.xml fields.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
 public class DataSourceDeployment
    implements Serializable
 {
@@ -22,6 +29,7 @@
    private static Logger log = Logger.getLogger(DataSourceDeployment.class);
 
    private boolean replace = true;
+   private String type;
    private String jndiName;
    private String driverClass;
    private String typeMapping;
@@ -33,6 +41,17 @@
    private String maxPoolSize;
    private ArrayList<String> depends = new ArrayList<String>();
 
+   
+   public String getType()
+   {
+      return type;
+   }
+
+   public void setType(String type)
+   {
+      this.type = type;
+   }
+
    public String getDriverClass()
    {
       return driverClass;
@@ -140,7 +159,8 @@
 
    public void parse(Document document)
    {
-      NodeList datasources = document.getElementsByTagName("local-tx-datasource");
+      type = "local-tx-datasource";
+      NodeList datasources = document.getElementsByTagName(type);
       for (int i = 0; i < datasources.getLength(); ++i)
       {
          Node node = datasources.item(i);
@@ -207,6 +227,70 @@
       }
    }
 
+   /**
+    * Map the managed properties onto this javabean's properties
+    * @param propertyNameMappings
+    * @param properties
+    */
+   public void parse(Map<String, ManagedProperty> properties)
+   {
+      for(ManagedProperty property : properties.values())
+      {
+         String name = property.getName();
+         Object value = property.getValue();
+         if( value == null )
+            continue;
+
+         if( name.equals("") )
+         {
+            this.type = value.toString();
+         }
+         else if (name.equals("jndi-name"))
+         {
+            jndiName = value.toString();
+         }
+         else if (name.equals("connection-url"))
+         {
+            this.jdbcURL = value.toString();
+         }
+         else if (name.equals("user-name"))
+         {
+            this.username = value.toString();
+         }
+         else if (name.equals("driver-class"))
+         {
+            this.driverClass = value.toString();
+         }
+         else if (name.equals("password"))
+         {
+            this.password = value.toString();
+            if(this.password == null)
+               this.password = "";
+         }
+         else if (name.equals("min-pool-size"))
+         {
+            this.minPoolSize = value.toString();
+         }
+         else if (name.equals("max-pool-size"))
+         {
+            this.maxPoolSize = value.toString();
+         }
+         else if (name.equals("security-domain"))
+         {
+            this.securityDomain = value.toString();
+         }
+         else if (name.equals("type-mapping"))
+         {
+            this.typeMapping = value.toString();
+         }
+         else if (name.equals("depends"))
+         {
+            String depends = value.toString();
+            addDepends(depends);
+         }
+      }
+   }
+
    @Override
    public String toString()
    {

Modified: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -23,6 +23,8 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -34,7 +36,13 @@
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
 import org.jboss.deployers.spi.managed.ManagedObjectBuilder;
 import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
 import org.jboss.managed.plugins.advice.WrapperAdvice;
+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.builders.ServiceManagedObject;
 import org.jboss.system.metadata.ServiceAttributeMetaData;
 import org.jboss.system.metadata.ServiceConstructorMetaData;
@@ -55,23 +63,30 @@
  */
 public class FakeDataSourceDeployer extends JAXPDeployer<ServiceDeployment>
    implements ManagedObjectBuilder
-{
-   
+{  
+   /**
+    * A mapping from the managed property name to the attachment property name.
+    */
+   private Map<String, String> propertyNameMappings = new HashMap<String, String>();
+
    public FakeDataSourceDeployer()
    {
       super(ServiceDeployment.class);
    }
 
-   private Map<String, String> propertyNameMappings;
-
    public Map<String, String> getPropertyNameMappings()
    {
       return propertyNameMappings;
    }
 
-   public void setPropertyNameMappings(Map<String, String> propertyNameMappings)
+   public void setPropertyNameMappings(Map<String, String> mangedToMBeanNames)
    {
-      this.propertyNameMappings = propertyNameMappings;
+      // Need to reverse the mapping
+      for(String key : mangedToMBeanNames.keySet())
+      {
+         String value = mangedToMBeanNames.get(key);
+         propertyNameMappings.put(value, key);
+      }
    }
 
    public void build(DeploymentUnit unit, Map<String, ManagedObject> map) 
@@ -91,9 +106,27 @@
             throw new DeploymentException("Expected only 1 ServiceMetaData but saw "+services.size()+" in "+unit.getName());
          ServiceMetaData dsMetaData = services.get(0);
          String attachName = ServiceMetaData.class.getName();
-         ManagedObject mo = new ServiceManagedObject(attachName, dsMetaData);
+         ManagedObject mo = new ServiceManagedObject(attachName, dsMetaData, propertyNameMappings);
          ManagedObject wrapMO = WrapperAdvice.wrapManagedObject(mo);
          map.put(attachName, wrapMO);
+         // The datasource type...
+         attachName = "FakeConnectionFactoryDeployer.datasource-type";
+         ManagedObjectImpl typeMO = new ManagedObjectImpl(attachName);
+         DefaultFieldsImpl f21 = new DefaultFieldsImpl();
+         f21.setName("datasource-type");
+         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"));
+         f21.setLegalValues(values);
+         f21.setMetaType(SimpleMetaType.STRING);
+         ManagedPropertyImpl dsType = new ManagedPropertyImpl(typeMO, f21);
+         typeMO.getProperties().add(dsType);
+         wrapMO = WrapperAdvice.wrapManagedObject(typeMO);
+         map.put(attachName, wrapMO);
       }
    }
 

Modified: trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java	2007-02-02 09:18:50 UTC (rev 60185)
+++ trunk/profileservice/src/main/org/jboss/profileservice/remoting/ProxyFactory.java	2007-02-02 09:19:47 UTC (rev 60186)
@@ -143,6 +143,7 @@
    public void stop()
       throws Exception
    {
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
       Dispatcher.singleton.unregisterTarget(dispatchName);
       String mvDispatchName = dispatchName+".ManagementView";
       Dispatcher.singleton.unregisterTarget(mvDispatchName);




More information about the jboss-cvs-commits mailing list