[jboss-cvs] JBossAS SVN: r86627 - in projects/jboss-man/branches/Branch_2_1/managed/src: main/java/org/jboss/managed/api/annotation and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 1 22:13:08 EDT 2009


Author: scott.stark at jboss.org
Date: 2009-04-01 22:13:07 -0400 (Wed, 01 Apr 2009)
New Revision: 86627

Added:
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ActivationPolicy.java
   projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyActivationPolicy.java
Modified:
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/Fields.java
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java
   projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
   projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyReadOnly.java
   projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java
Log:
JBMAN-68, add setModified(boolean) to ManagedProperty
JBMAN-69, add activation policy to ManagedProperty and annotation


Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/Fields.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/Fields.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/Fields.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -79,8 +79,12 @@
    /** The modified flag */
    String MODIFIED = "modified";
 
-   /** The modified flag */
+   /** The read-only flag */
    String READ_ONLY = "readOnly";
+
+   /** The activation-policy flag */
+   String ACTIVATION_POLICY = "activationPolicy";
+
    // TODO other standard fields here
 
    /**

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -26,6 +26,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.jboss.managed.api.annotation.ActivationPolicy;
 import org.jboss.managed.api.annotation.ManagementObjectRef;
 import org.jboss.managed.api.annotation.ViewUse;
 import org.jboss.metatype.api.types.MetaType;
@@ -144,6 +145,12 @@
    boolean hasViewUse(ViewUse use);
 
    /**
+    * Get the activation policy for property value updates.
+    * @return the property activation policy
+    */
+   ActivationPolicy getActivationPolicy();
+
+   /**
     * Get the value
     * 
     * @return the value
@@ -207,6 +214,12 @@
    boolean isModified();
 
    /**
+    * Set the modified state of the property value.
+    * @param flag - whether the property has been modified
+    */
+   public void setModified(boolean flag);
+
+   /**
     * Whether the property has been marked as removed from its ManagedObject.
     * @return true is the property has been removed.
     */

Copied: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ActivationPolicy.java (from rev 86626, projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/ActivationPolicy.java)
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ActivationPolicy.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ActivationPolicy.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.managed.api.annotation;
+
+/** 
+ * When a managed property change is applied
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public enum ActivationPolicy
+{
+   /** Changes are immediately applied to metadata and runtime components */
+   IMMEDIATE,
+   /** Changes are applied to metadata and require a component restart */
+   COMPONENT_RESTART,
+   /** Changes are applied to metadata and require a deployment restart */
+   DEPLOYMENT_RESTART,
+   /** Changes are applied to metadata and require a server restart */
+   SERVER_RESTART
+}
\ No newline at end of file

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -68,6 +68,9 @@
    /** The views this property should be used in */
    ViewUse[] use() default {ViewUse.CONFIGURATION};
 
+   /** The policy for updating property values */
+   ActivationPolicy activationPolicy() default ActivationPolicy.IMMEDIATE;
+
    /** Strings describing free form association to admin views (Ports, Networks, ...} */
    String[] adminViews() default {};
 }

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -35,6 +35,7 @@
 import org.jboss.managed.api.Fields;
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ActivationPolicy;
 import org.jboss.managed.api.annotation.ManagementProperty;
 import org.jboss.managed.api.annotation.ViewUse;
 import org.jboss.metatype.api.types.MetaType;
@@ -280,6 +281,15 @@
 
    public void setValue(MetaValue value)
    {
+      // Check for a change 
+      MetaValue oldValue = getValue();
+      if(oldValue != value)
+      {
+         boolean isModified = true;
+         if(value != null)
+            isModified = ! value.equals(oldValue);
+         setModified(isModified);
+      }
       setField(Fields.VALUE, value);
    }
 
@@ -322,6 +332,16 @@
       setField(Fields.VIEW_USE, use);
    }
 
+   public ActivationPolicy getActivationPolicy()
+   {
+      ActivationPolicy activationPolicy = getField(Fields.ACTIVATION_POLICY, ActivationPolicy.class);
+      return activationPolicy;
+   }
+   public void setActivationPolicy(ActivationPolicy policy)
+   {
+      setField(Fields.ACTIVATION_POLICY, policy);
+   }
+
    @SuppressWarnings("unchecked")
    public Set<MetaValue> getLegalValues()
    {

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -90,8 +90,6 @@
    @SuppressWarnings("unchecked")
    public void setValue(MetaValue value)
    {
-      super.setValue(value);
-
       PropertyInfo propertyInfo = getField(Fields.PROPERTY_INFO, PropertyInfo.class);
       if (propertyInfo != null)
       {
@@ -104,6 +102,8 @@
             icf.setValue(beanInfo, this, attachment, value);
          }
       }
+      // Update the field value only after it has been written to the attachment
+      super.setValue(value);
    }
 
    /**

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -44,6 +44,7 @@
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.MutableManagedObject;
 import org.jboss.managed.api.ManagedOperation.Impact;
+import org.jboss.managed.api.annotation.ActivationPolicy;
 import org.jboss.managed.api.annotation.AnnotationDefaults;
 import org.jboss.managed.api.annotation.ConstraintsPopulatorFactory;
 import org.jboss.managed.api.annotation.FieldsFactory;
@@ -60,6 +61,7 @@
 import org.jboss.managed.api.annotation.ManagementPropertyFactory;
 import org.jboss.managed.api.annotation.ManagementRuntimeRef;
 import org.jboss.managed.api.annotation.RunStateProperty;
+import org.jboss.managed.api.annotation.ViewUse;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
 import org.jboss.managed.api.factory.ManagedObjectDefinition;
 import org.jboss.managed.plugins.DefaultFieldsImpl;
@@ -655,6 +657,19 @@
                boolean managed = false;
                if (managementProperty != null)
                   managed = managementProperty.managed();
+               // View Use
+               if (managementProperty != null)
+               {
+                  ViewUse[] use = managementProperty.use();
+                  fields.setField(Fields.VIEW_USE, use);
+               }
+               // ActivationPolicy
+               ActivationPolicy apolicy = ActivationPolicy.IMMEDIATE;
+               if (managementProperty != null)
+               {
+                  apolicy = managementProperty.activationPolicy();
+               }
+               fields.setField(Fields.ACTIVATION_POLICY, apolicy);
                
                // The managed property type
                MetaType metaType = null;

Copied: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyActivationPolicy.java (from rev 86625, projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyActivationPolicy.java)
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyActivationPolicy.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyActivationPolicy.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.test.managed.factory.support;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.annotation.ActivationPolicy;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Tests of managed property activation policy settings
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject
+public class ManagementPropertyActivationPolicy
+   implements Serializable
+{
+   private static final long serialVersionUID = 1;
+   
+   @ManagementProperty()
+   public String getDefaultProp()
+   {
+      return null;
+   }
+   @ManagementProperty(activationPolicy=ActivationPolicy.IMMEDIATE)
+   public String getImmediateProp()
+   {
+      return null;
+   }
+   @ManagementProperty(activationPolicy=ActivationPolicy.COMPONENT_RESTART)
+   public String getCompRestartProp()
+   {
+      return null;
+   }
+   @ManagementProperty(activationPolicy=ActivationPolicy.DEPLOYMENT_RESTART)
+   public String getDeployRestartProp()
+   {
+      return null;
+   }
+   @ManagementProperty(activationPolicy=ActivationPolicy.SERVER_RESTART)
+   public String getServerRestartProp()
+   {
+      return null;
+   }
+}

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyReadOnly.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyReadOnly.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/ManagementPropertyReadOnly.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -37,37 +37,41 @@
    implements Serializable
 {
    private static final long serialVersionUID = 1;
+   private String readOnly = "readOnly";
+   private String readOnly2 = "readOnly2";
+   private String readWrite = "readWrite";
+   private String readWrite2 = "readWrite2";
 
    public String getReadOnly()
    {
-      return null;
+      return readOnly;
    }
    
    public String getReadOnly2()
    {
-      return null;
+      return readOnly2;
    }
    @ManagementProperty(readOnly=true)
    public void setReadOnly2(String x)
    {
-      
+      readOnly2 = x;
    }
    public String getReadWrite()
    {
-      return null;
+      return readWrite;
    }
    @ManagementProperty(readOnly=false)
    public void setReadWrite(String x)
    {
-      
+      x = readWrite;
    }
    public String getReadWrite2()
    {
-      return null;
+      return readWrite2;
    }
    @ManagementProperty()
    public void setReadWrite2(String x)
    {
-      
+      readWrite2 = x;
    }
 }

Modified: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java	2009-04-02 02:12:02 UTC (rev 86626)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java	2009-04-02 02:13:07 UTC (rev 86627)
@@ -29,6 +29,7 @@
 
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ActivationPolicy;
 import org.jboss.managed.api.annotation.ManagementObjectID;
 import org.jboss.managed.api.annotation.ManagementProperty;
 import org.jboss.managed.api.annotation.ViewUse;
@@ -36,6 +37,7 @@
 import org.jboss.metatype.api.types.SimpleMetaType;
 import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.ManagementPropertyActivationPolicy;
 import org.jboss.test.managed.factory.support.ManagementPropertyAnnotations;
 import org.jboss.test.managed.factory.support.ManagementPropertyDescription;
 import org.jboss.test.managed.factory.support.ManagementPropertyMandatory;
@@ -94,10 +96,10 @@
    public void testReadOnly()
    {
       ManagedObject managedObject = createAndCheckDefaultManagedObject(ManagementPropertyReadOnly.class);
-      checkProperty(managedObject, "readOnly", String.class, "readOnly", false, null);
-      checkProperty(managedObject, "readOnly2", String.class, "readOnly2", false, null);
-      checkProperty(managedObject, "readWrite", String.class, "readWrite", false, null);
-      checkProperty(managedObject, "readWrite2", String.class, "readWrite2", false, null);
+      checkProperty(managedObject, "readOnly", String.class, "readOnly", false, "readOnly");
+      checkProperty(managedObject, "readOnly2", String.class, "readOnly2", false, "readOnly2");
+      checkProperty(managedObject, "readWrite", String.class, "readWrite", false, "readWrite");
+      checkProperty(managedObject, "readWrite2", String.class, "readWrite2", false, "readWrite2");
       ManagedProperty readOnly = managedObject.getProperty("readOnly");
       assertTrue(readOnly.isReadOnly());
       ManagedProperty readOnly2 = managedObject.getProperty("readOnly");
@@ -181,5 +183,63 @@
       mp3.setAnnotations(annotations);
       assertTrue("has ViewUse.RUNTIME", mp3.hasViewUse(ViewUse.RUNTIME));
       assertTrue("has ViewUse.STATISTIC", mp3.hasViewUse(ViewUse.STATISTIC));
+   }
+
+   /**
+    * Tests of the activationPolicy()
+    * @throws Exception
+    */
+   public void testActivationPolicy()
+      throws Exception
+   {
+      ManagedObject managedObject = createAndCheckDefaultManagedObject(ManagementPropertyActivationPolicy.class);
+      ManagedProperty defaultProp = managedObject.getProperty("defaultProp");
+      assertNotNull(defaultProp);
+      assertEquals(ActivationPolicy.IMMEDIATE, defaultProp.getActivationPolicy());
+      ManagedProperty compRestartProp = managedObject.getProperty("compRestartProp");
+      assertNotNull(compRestartProp);
+      assertEquals(ActivationPolicy.COMPONENT_RESTART, compRestartProp.getActivationPolicy());
+      ManagedProperty immediateProp = managedObject.getProperty("immediateProp");
+      assertNotNull(immediateProp);
+      assertEquals(ActivationPolicy.IMMEDIATE, immediateProp.getActivationPolicy());
+      ManagedProperty deployRestartProp = managedObject.getProperty("deployRestartProp");
+      assertNotNull(deployRestartProp);
+      assertEquals(ActivationPolicy.DEPLOYMENT_RESTART, deployRestartProp.getActivationPolicy());
+      ManagedProperty serverRestartProp = managedObject.getProperty("serverRestartProp");
+      assertNotNull(serverRestartProp);
+      assertEquals(ActivationPolicy.SERVER_RESTART, serverRestartProp.getActivationPolicy());
+   }
+
+   /**
+    * Tests of isModified()/setModified()
+    */
+   public void testIsModified()
+      throws Exception
+   {
+      ManagedObject managedObject = createAndCheckDefaultManagedObject(ManagementPropertyReadOnly.class);
+      ManagedProperty readOnly = managedObject.getProperty("readOnly");
+      assertNotNull(readOnly);
+      assertFalse(readOnly.isModified());
+      try
+      {
+         readOnly.setValue(SimpleValueSupport.wrap("readOnly-update"));
+      }
+      catch(Exception e)
+      {
+         e.printStackTrace();
+      }
+      assertFalse(readOnly.isModified());
+      // 
+      ManagedProperty readWrite = managedObject.getProperty("readWrite");
+      assertNotNull(readWrite);
+      assertFalse(readWrite.isModified());
+      readWrite.setValue(SimpleValueSupport.wrap("readWrite-update"));
+      assertTrue("isModified", readWrite.isModified());
+
+      // Validate that clearing/rewriting the same value does not set isModified
+      readWrite.setModified(false);
+      assertFalse(readWrite.isModified());
+      readWrite.setValue(SimpleValueSupport.wrap("readWrite-update"));
+      assertFalse(readWrite.isModified());
+   }
 }
-}




More information about the jboss-cvs-commits mailing list