[jboss-cvs] JBossAS SVN: r85152 - trunk/profileservice/src/main/org/jboss/profileservice/management.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 3 04:54:48 EST 2009


Author: emuckenhuber
Date: 2009-03-03 04:54:48 -0500 (Tue, 03 Mar 2009)
New Revision: 85152

Modified:
   trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
Log:
restore template mos processing

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java	2009-03-03 09:13:09 UTC (rev 85151)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java	2009-03-03 09:54:48 UTC (rev 85152)
@@ -65,7 +65,7 @@
       this.defaultKey = defaultKey;
    }
    
-   public void applyTemplate(DeploymentTemplate template, String deploymentBaseName, DeploymentTemplateInfo info)
+   public String applyTemplate(DeploymentTemplate template, String deploymentBaseName, DeploymentTemplateInfo info)
       throws Exception
    {
       if(template == null)
@@ -79,6 +79,8 @@
       this.deploymentMgr.loadProfile(defaultKey, false);
       // The virtual file
       VirtualFile base = null;
+      // Deploy the deployment
+      String[] repositoryNames = null;
       try
       {
          // Apply the template
@@ -88,9 +90,7 @@
          base = template.applyTemplate(info);
          if(base == null)
             throw new IllegalStateException("applyTemplate returned null virtual file.");
-         
-         // Deploy the deployment
-         String[] repositoryNames = null;
+
          try
          {
             // Distribute
@@ -147,6 +147,7 @@
          if(base != null)
             base.delete();
       }
+      return repositoryNames[0];
    }
    
    protected String[] distribute(String name, URL url) throws Exception

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-03-03 09:13:09 UTC (rev 85151)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-03-03 09:54:48 UTC (rev 85152)
@@ -905,11 +905,107 @@
          log.trace("applyTemplate, deploymentBaseName="+deploymentBaseName +", info="+info);
       
       // Create, distribute and start a deployment template
-      super.applyTemplate(template, deploymentBaseName, info);
+      String deploymentName = super.applyTemplate(template, deploymentBaseName, info);
       
-      // Force a reload
-      this.forceReload = true;
-
+      /* Scan through the template properties to see if there is a
+      property with an ManagementObjectID annotation that needs
+      to be used to update the associated ManagedObject name.
+      */
+      for(ManagedProperty prop : info.getProperties().values())
+      {
+         // Skip null values
+         if( prop.getValue() == null )
+            continue;
+         Map<String, Annotation> pannotations = prop.getAnnotations();
+         if (pannotations != null)
+         {
+            ManagementObjectID id = (ManagementObjectID) pannotations.get(ManagementObjectID.class.getName());
+            if (id != null)
+            {
+               Object refName = getRefName(prop.getValue());
+               if (refName == null)
+                  refName = id.name();
+               String name = "" + refName;
+               log.debug("Updating template ManagedObject name to:"+name+" from property: "+prop);
+               ManagedObject mo = prop.getManagedObject();
+               if(mo instanceof MutableManagedObject)
+               {
+                  MutableManagedObject mmo = (MutableManagedObject) mo;
+                  mmo.setName(name);
+               }
+               else
+               {
+                  formatter.applyPattern(i18n.getString("ManagementView.InvalidTemplatePropertyMO")); //$NON-NLS-1$
+                  Object[] args = {prop.getName()};
+                  String msg = formatter.format(args);
+                  throw new IllegalArgumentException(msg);
+               }
+            }
+         }
+      }
+   
+      // Now apply the managed properties to get the deployment ManagedObjects
+      Map<String, ManagedObject> mos = mainDeployer.getManagedObjects(deploymentName);
+      log.debug("applyTemplate, deploymentBaseName="+deploymentBaseName+":"+mos);
+      // Map the 
+      String propName = info.getRootManagedPropertyName();
+      if(propName != null)
+      {
+         // Flatten out the root objects
+         ManagedObject rootMO = mos.get(deploymentName);
+         if(rootMO != null)
+            flattenRootObject(rootMO, propName, mos);
+      }
+      for(ManagedProperty prop : info.getProperties().values())
+      {
+         // Skip null values
+         if( prop.getValue() == null )
+            continue;
+   
+         ManagedObject mo = prop.getManagedObject();
+         if (mo == null)
+            throw new IllegalArgumentException("Null managed object: " + prop);
+   
+         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);
+         }
+         // The property value must be a MetaValue
+         Object value = prop.getValue();
+         if ((value instanceof MetaValue) == false)
+         {
+            formatter.applyPattern(i18n.getString("ManagementView.InvalidPropertyValue")); //$NON-NLS-1$
+            Object[] args = {prop.getName(), value.getClass()};
+            String msg = formatter.format(args);
+            throw new IllegalArgumentException(msg);
+         }
+         MetaValue metaValue = (MetaValue)value;
+         ctxProp.setValue(metaValue);
+   
+         // todo - should this also dispatch to runtime component?
+         Object componentName = getComponentName(ctxProp);
+         if (componentName != null)
+            dispatcher.set(componentName, ctxProp.getName(), metaValue);
+      }
    }
    
    public void process() throws DeploymentException




More information about the jboss-cvs-commits mailing list