[jboss-cvs] JBossAS SVN: r64930 - in projects/microcontainer/trunk: deployers-impl/src/tests/org/jboss/test/deployers/managed/test and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 28 17:53:40 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-08-28 17:53:40 -0400 (Tue, 28 Aug 2007)
New Revision: 64930

Added:
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestManagedParameterConstraintsPopulatorFactory.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementParameter.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedParameterImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulator.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulatorFactory.java
Modified:
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedParameter.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/AnnotationDefaults.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java
Log:
Implement the ManagedParameter support

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSServiceMetaData.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -27,6 +27,7 @@
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementObjectID;
 import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementParameter;
 import org.jboss.managed.api.annotation.ManagementProperty;
 
 /**
@@ -85,4 +86,18 @@
    {
       
    }
+   @ManagementOperation(description="Takes a string and returns it", impact=Impact.ReadOnly,
+         params={@ManagementParameter(name="input", description="The string to return")})
+   public String takesString(String arg1)
+   {
+      return arg1;
+   }
+   @ManagementOperation(description="Takes an int and multiples by 10", impact=Impact.ReadOnly,
+         params={@ManagementParameter(name="input", description="The int to multiple",
+         constraintsFactory=TestManagedParameterConstraintsPopulatorFactory.class)})
+   public int constrainedIntx10(int arg1)
+   {
+      return 10*arg1;
+   }
+   
 }

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestManagedParameterConstraintsPopulatorFactory.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestManagedParameterConstraintsPopulatorFactory.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestManagedParameterConstraintsPopulatorFactory.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -0,0 +1,58 @@
+/*
+ * 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.test.deployers.deployer.support;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.reflect.spi.ParameterInfo;
+
+/**
+ * Example ManagedParameterConstraintsPopulatorFactory
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class TestManagedParameterConstraintsPopulatorFactory implements
+      ManagedParameterConstraintsPopulatorFactory
+{
+   public ManagedParameterConstraintsPopulator newInstance()
+   {
+      return new TestManagedParameterConstraintsPopulator();
+   }
+
+   static class TestManagedParameterConstraintsPopulator
+      implements ManagedParameterConstraintsPopulator
+   {
+      public void populateManagedParameter(String methodName, ParameterInfo info, Fields fields)
+      {
+         if (methodName.equals("constrainedIntx10"))
+            populateconstrainedIntx10Arg(fields);
+      }
+
+      void populateconstrainedIntx10Arg(Fields fields)
+      {
+         fields.setField(Fields.MINIMUM_VALUE, SimpleValueSupport.wrap(0));
+         fields.setField(Fields.MAXIMUM_VALUE, SimpleValueSupport.wrap(100));
+      }
+   }
+}


Property changes on: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestManagedParameterConstraintsPopulatorFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -36,9 +36,13 @@
 import org.jboss.managed.api.ManagedDeployment;
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.metatype.api.types.SimpleMetaType;
 import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.test.deployers.AbstractDeployerTest;
 import org.jboss.test.deployers.deployer.support.ConnMetaData;
 import org.jboss.test.deployers.deployer.support.DSMetaData;
@@ -212,23 +216,69 @@
 
       // Validate the operations on the localDataMO
       Set<ManagedOperation> localDataOps = localDataMO.getOperations();
-      assertEquals("localDataOps ops count is 2", 2, localDataOps.size());
+      assertEquals("localDataOps ops count is 4", 4, localDataOps.size());
       ManagedOperation flushPool = null;
       ManagedOperation closePool = null;
+      ManagedOperation takesString = null;
+      ManagedOperation constrainedIntx10 = null;
+      
       for(ManagedOperation op : localDataOps)
       {
          if (op.getName().equals("flushPool"))
             flushPool = op;
          if (op.getName().equals("closePool"))
             closePool = op;
+         if (op.getName().equals("takesString"))
+            takesString = op;
+         if (op.getName().equals("constrainedIntx10"))
+            constrainedIntx10 = op;
+         
       }
-      assertNotNull("flushPool find", flushPool);
-      assertNotNull("closePool find", closePool);
+      // flushPool
+      assertNotNull("flushPool found", flushPool);
+      assertEquals("flushPool", flushPool.getName());
+      assertEquals("Flush the connections in the pool", flushPool.getDescription());
+      assertEquals(ManagedOperation.Impact.WriteOnly, flushPool.getImpact());
+      assertEquals(SimpleMetaType.VOID, flushPool.getReturnType());
+      assertEquals("zero params", 0, flushPool.getParameters().length);
+      // closePool
+      assertNotNull("closePool found", closePool);
+      assertEquals("closePool", closePool.getName());
+      assertEquals("Close the connections in the pool", closePool.getDescription());
+      assertEquals(ManagedOperation.Impact.WriteOnly, closePool.getImpact());
+      assertEquals(SimpleMetaType.VOID, closePool.getReturnType());
+      assertEquals("zero params", 0, closePool.getParameters().length);
+      // takesString
+      assertNotNull("takesString found", takesString);
+      assertEquals("takesString", takesString.getName());
+      assertEquals("Takes a string and returns it", takesString.getDescription());
+      assertEquals(ManagedOperation.Impact.ReadOnly, takesString.getImpact());
+      assertEquals(SimpleMetaType.STRING, takesString.getReturnType());
+      ManagedParameter[] takesStringParams = takesString.getParameters();
+      assertEquals("one params", 1, takesStringParams.length);
+      assertEquals("param name", "input", takesStringParams[0].getName());
+      assertEquals("param description", "The string to return", takesStringParams[0].getDescription());
+      assertEquals("param type", SimpleMetaType.STRING, takesStringParams[0].getMetaType());
+      // constrainedIntx10
+      assertNotNull("constrainedIntx10 found", constrainedIntx10);
+      assertEquals("constrainedIntx10", constrainedIntx10.getName());
+      assertEquals("Takes an int and multiples by 10", constrainedIntx10.getDescription());
+      assertEquals(ManagedOperation.Impact.ReadOnly, constrainedIntx10.getImpact());
+      assertEquals(SimpleMetaType.INTEGER, constrainedIntx10.getReturnType());
+      ManagedParameter[] constrainedIntx10Params = constrainedIntx10.getParameters();
+      assertEquals("one params", 1, constrainedIntx10Params.length);
+      assertEquals("param name", "input", constrainedIntx10Params[0].getName());
+      assertEquals("param description", "The int to multiple", constrainedIntx10Params[0].getDescription());
+      assertEquals("param type", SimpleMetaType.INTEGER, constrainedIntx10Params[0].getMetaType());
+      Object min = constrainedIntx10Params[0].getMinimumValue();
+      assertEquals("param min is 0", new Integer(0), min);
+      assertEquals("param min is 100", new Integer(100), constrainedIntx10Params[0].getMaximumValue());
+      
       // Validate that the localDataMO includes the runtime properties
       ManagedProperty rtp1 = localDataProps.get("runtimeProp1");
       assertNotNull("runtimeProp1", rtp1);
       ManagedProperty rtp2 = localDataProps.get("runtimeProp2");
-      assertNotNull("runtimeProp2", rtp2);      
+      assertNotNull("runtimeProp2", rtp2);
    }
 
    protected DeployerClient getMainDeployer()

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedParameter.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedParameter.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedParameter.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -36,6 +36,31 @@
 public interface ManagedParameter extends Serializable
 {
    /**
+    * Get the fields
+    * 
+    * @return the fields
+    */
+   Fields getFields();
+   
+   /**
+    * Get a field
+    *
+    * @param <T> the expected type
+    * @param fieldName the field name
+    * @param expected the expected type
+    * @return the value
+    */
+   <T> T getField(String fieldName, Class<T> expected);
+   
+   /**
+    * Set a field
+    *
+    * @param fieldName the field name
+    * @param value the value
+    */
+   void setField(String fieldName, Serializable value);
+
+   /**
     * Get the property's name
     * 
     * @return the property's name

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/AnnotationDefaults.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/AnnotationDefaults.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/AnnotationDefaults.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -34,9 +34,16 @@
    private static class COMP_TYPE_CLASS {}
    /** The ManagementComponent uninitialized default */
    public static final ManagementComponent COMP_TYPE = defaultCompType();
+   /** The default uninitialized String value */
+   public static final String EMPTY_STRING = "";
 
+   /**
+    * The unitialized/default ManagementComponent value
+    * @return The unitialized/default ManagementComponent value
+    */
    public static synchronized ManagementComponent defaultCompType()
    {
       return COMP_TYPE_CLASS.class.getAnnotation(ManagementComponent.class);
    }
+
 }

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -54,9 +54,9 @@
     * this is taken from a property annotated with
     * {@linkplain ManagementObjectID}.
     */
-   String type() default "";
+   String type() default AnnotationDefaults.EMPTY_STRING;
    /** The metadata attachment name for the ManagedObject */
-   String attachmentName() default "";
+   String attachmentName() default AnnotationDefaults.EMPTY_STRING;
    /** Is this a runtime extension of another ManagedObject. This
     * is used to tie together
     */

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -40,9 +40,9 @@
    /** An explicit ManagedObject name. If empty, the name is
     * taken from the annotated property.
     */
-   String name() default "";
+   String name() default AnnotationDefaults.EMPTY_STRING;
    /** A qualifier for the name that provides a context to
     * identify the type or scope of the ManagedObject name.
     */
-   String type() default "";
+   String type() default AnnotationDefaults.EMPTY_STRING;
 }

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -40,10 +40,10 @@
     * taken from the annotated property.
     * @see {@linkplain ManagedObject#getExternalName()}
     */
-   String name() default "";
+   String name() default AnnotationDefaults.EMPTY_STRING;
    /** A qualifier for the name that provides a context to
     * identify the type or scope of the ManagedObject name.
     * @see {@linkplain ManagedObject#getExternalNameType()}
     */
-   String type() default "";
+   String type() default AnnotationDefaults.EMPTY_STRING;
 }

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -1,6 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.
  *
@@ -27,6 +27,8 @@
 import java.lang.annotation.Target;
 
 import org.jboss.managed.api.ManagedOperation.Impact;
+import org.jboss.managed.api.annotation.ManagementParameter.NULL_CONSTRAINTS;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
 
 /**
  * An annotation for describing a ManagedOperation
@@ -39,12 +41,17 @@
 public @interface ManagementOperation
 {
    /** The name of the operation */
-   String name() default "";
-   /** The detyped signature (ala jmx) of the operation */
-   String[] signature() default {};
+   String name() default AnnotationDefaults.EMPTY_STRING;
+   /** The parameters of the operation */
+   ManagementParameter[] params() default {};
 
    /** The description */
-   String description() default ManagementConstants.GENERATED;
+   String description() default AnnotationDefaults.EMPTY_STRING;
    /** The side-effect impact of invoking the operation */
    Impact impact() default Impact.Unknown;
+
+   /** The parameter constraints, allowed values populator factory */
+   Class<? extends ManagedParameterConstraintsPopulatorFactory> constraintsFactory()
+      default NULL_CONSTRAINTS.class;
+
 }

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementParameter.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementParameter.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementParameter.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -0,0 +1,58 @@
+/*
+ * 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.managed.api.annotation;
+
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
+
+/**
+ * Annotation for documenting a ManagementOperation parameter.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public @interface ManagementParameter
+{
+   /** The parameter name */
+   String name() default AnnotationDefaults.EMPTY_STRING;
+   /** The parameter description */
+   String description() default AnnotationDefaults.EMPTY_STRING;
+
+   /** The constraints, allowed values populator factory */
+   Class<? extends ManagedParameterConstraintsPopulatorFactory> constraintsFactory()
+      default NULL_CONSTRAINTS.class;
+
+   /**
+    * Used in {@link ManagementParameter#constraintsFactory()} to
+    * signal that the factory be inferred from the type
+    * of the property.
+    */
+   public static final class NULL_CONSTRAINTS
+      implements ManagedParameterConstraintsPopulatorFactory
+   {
+      public ManagedParameterConstraintsPopulator newInstance()
+      {
+         return null;
+      }
+   }
+
+}


Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementParameter.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -48,10 +48,10 @@
    /** The external name of the property. If undefined its taken
     * from the property the annotation is on.
     */
-   String name() default "";
+   String name() default AnnotationDefaults.EMPTY_STRING;
 
    /** The internal name of the property as it relates to metadata */
-   String mappedName() default "";
+   String mappedName() default AnnotationDefaults.EMPTY_STRING;
 
    /** Whether this property is mandatory */
    boolean mandatory() default false;

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedParameterImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedParameterImpl.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedParameterImpl.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -0,0 +1,328 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.plugins;
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedParameter;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class ManagedParameterImpl implements ManagedParameter
+{
+   private static final long serialVersionUID = 1;
+   private static final int VERSION1 = 1;
+   /** The serialization version used by writeObject */
+   private static final int STREAM_VERSION = VERSION1;
+   /** The fields */
+   private Fields fields;
+
+   /** The property name */
+   private transient String name;
+
+   /**
+    * Create a new ManagedProperty that is not associated to
+    * a ManagedObject.
+    *
+    * @param name the managed property name
+    * @throws IllegalArgumentException for null fields or
+    *    missing Fields.NAME
+    */
+   public ManagedParameterImpl(String name)
+   {
+      this(new DefaultFieldsImpl(name));
+   }
+
+   /**
+    * Create a new ManagedProperty that is not associated to
+    * a ManagedObject.
+    * 
+    * @param fields the fields
+    * @throws IllegalArgumentException for null fields or
+    *    missing Fields.NAME
+    */
+   public ManagedParameterImpl(Fields fields)
+   {
+      init(fields);
+   }
+
+   public Fields getFields()
+   {
+      return fields;
+   }
+   
+   // TODO general reconstruction code for metatypes
+   @SuppressWarnings("unchecked")
+   public <T> T getField(String fieldName, Class<T> expected)
+   {
+      if (fieldName == null)
+         throw new IllegalArgumentException("Null field name");
+      if (expected == null)
+         throw new IllegalArgumentException("Null expected type");
+      
+      Serializable field = getFields().getField(fieldName);
+      
+      if (field == null)
+         return null;
+
+      if (expected.isInstance(field))
+         return expected.cast(field);
+      
+      if (field instanceof SimpleValue)
+      {
+         SimpleValue value = (SimpleValue) field;
+         Object result = value.getValue();
+         if (result == null)
+            return null;
+         return expected.cast(result);
+      }
+      
+      throw new IllegalStateException("Field " + fieldName + " with value " + field + " is not of the expected type: " + expected.getName());
+   }
+   
+   // TODO metaType stuff
+   public void setField(String fieldName, Serializable value)
+   {
+      if (fieldName == null)
+         throw new IllegalArgumentException("Null field name");
+      
+      getFields().setField(fieldName, value);
+   }
+   
+   public String getName()
+   {
+      return name;
+   }
+
+   public String getDescription()
+   {
+      return getField(Fields.DESCRIPTION, String.class);
+   }
+   
+   /**
+    * Set the description
+    * 
+    * @param description the description
+    */
+   public void setDescription(String description)
+   {
+      setField(Fields.DESCRIPTION, description);
+   }
+
+
+   /**
+    * Get the annotations associated with the property
+    * @return the annotations associated with the property
+    */
+   @SuppressWarnings("unchecked")
+   public Map<String, Annotation> getAnnotations()
+   {
+      Object set = getField(Fields.ANNOTATIONS, Object.class);
+      return (Map<String, Annotation>) set;
+   }
+   public void setAnnotations(Map<String, Annotation> annotations)
+   {
+      setField(Fields.ANNOTATIONS, (Serializable) annotations);      
+   }
+
+   public MetaType getMetaType()
+   {
+      return getField(Fields.META_TYPE, MetaType.class);
+   }
+   
+   /**
+    * Set the meta type
+    * 
+    * @param type the meta type
+    */
+   public void setMetaType(MetaType type)
+   {
+      setField(Fields.META_TYPE, type);
+   }
+
+   public Object getValue()
+   {
+      return getField(Fields.VALUE, Object.class);
+   }
+
+   public void setValue(Serializable value)
+   {
+      setField(Fields.VALUE, value);
+   }
+
+   @SuppressWarnings("unchecked")
+   public Set<MetaValue> getLegalValues()
+   {
+      return getField(Fields.LEGAL_VALUES, Set.class);
+   }
+   
+   /**
+    * Set the legal values
+    * 
+    * @param values the values
+    */
+   public void setLegalValues(Set<MetaValue> values)
+   {
+      setField(Fields.LEGAL_VALUES, (Serializable)values);
+   }
+
+   public Comparable getMinimumValue()
+   {
+      return getField(Fields.MINIMUM_VALUE, Comparable.class);
+   }
+   
+   /**
+    * Set the minimum value
+    * 
+    * @param value the value
+    */
+   public void setMinimumValue(Comparable value)
+   {
+      setField(Fields.MINIMUM_VALUE, (Serializable)value);
+   }
+
+   public Comparable getMaximumValue()
+   {
+      return getField(Fields.MAXIMUM_VALUE, Comparable.class);
+   }
+
+   /**
+    * Set the maximum value
+    * 
+    * @param value the value
+    */
+   public void setMaximumValue(Comparable value)
+   {
+      setField(Fields.MAXIMUM_VALUE, (Serializable)value);
+   }
+
+   public String checkValidValue(Serializable value)
+   {
+      // TODO check min/max/etc.
+      return null;
+   }
+   
+   @Override
+   public String toString()
+   {
+      StringBuilder tmp = new StringBuilder("ManagedProperty");
+      tmp.append('{');
+      tmp.append(name);
+      tmp.append(",metaType=");
+      tmp.append(this.getMetaType());
+      tmp.append('}');
+      return tmp.toString(); 
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return name.hashCode(); 
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof ManagedParameter == false)
+         return false;
+      
+      ManagedParameter other = (ManagedParameter) obj;
+      return getName().equals(other.getName());
+   }
+
+   /**
+    * Initialise a ManagedPropertyImpl.
+    * 
+    * @param managedObject the managed object, may be null
+    * @param fields the fields
+    * @throws IllegalArgumentException for null fields or
+    *    missing Fields.NAME
+    */
+   private void init(Fields fields)
+   {
+      if (fields == null)
+         throw new IllegalArgumentException("Null fields");
+      
+      this.fields = fields;
+      
+      name = getField(Fields.NAME, String.class);
+      if (name == null)
+         throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
+   }
+
+   /**
+    * Read from a stream
+    * 
+    * @param in the stream
+    * @throws IOException for IO problem
+    * @throws ClassNotFoundException for a classloading problem
+    */
+   private void readObject(ObjectInputStream in)
+      throws IOException, ClassNotFoundException
+   {
+      int version = in.readInt();
+      if( version == VERSION1 )
+         readVersion1(in);
+      else
+         throw new InvalidObjectException("Unknown version="+version);
+   }
+   /**
+    * Write out the property fields
+    * @param out
+    * @throws IOException
+    */
+   private void writeObject(ObjectOutputStream out)
+      throws IOException
+   {
+      out.writeInt(STREAM_VERSION);
+      out.writeObject(fields);
+   }
+
+   /**
+    * The VERSION1 expected format: 
+    * - Fields fields
+    */
+   private void readVersion1(ObjectInputStream in)
+      throws IOException, ClassNotFoundException
+   {
+      fields = (Fields) in.readObject();
+      name = getField(Fields.NAME, String.class);
+      if (name == null)
+         throw new IOException("No " + Fields.NAME + " in fields");
+   }
+
+}


Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedParameterImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -53,15 +53,19 @@
 import org.jboss.managed.api.annotation.ManagementObjectID;
 import org.jboss.managed.api.annotation.ManagementObjectRef;
 import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementParameter;
 import org.jboss.managed.api.annotation.ManagementProperties;
 import org.jboss.managed.api.annotation.ManagementProperty;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
 import org.jboss.managed.plugins.DefaultFieldsImpl;
 import org.jboss.managed.plugins.ManagedObjectImpl;
 import org.jboss.managed.plugins.ManagedOperationImpl;
+import org.jboss.managed.plugins.ManagedParameterImpl;
 import org.jboss.managed.plugins.ManagedPropertyImpl;
 import org.jboss.managed.spi.factory.ManagedObjectBuilder;
 import org.jboss.managed.spi.factory.ManagedObjectPopulator;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
 import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
 import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
 import org.jboss.metatype.api.types.ArrayMetaType;
@@ -591,15 +595,60 @@
       String name = methodInfo.getName();
       String description = opAnnotation.description();
       Impact impact = opAnnotation.impact();
-      ParameterInfo[] params = methodInfo.getParameters();
+      ManagementParameter[] params = opAnnotation.params();
+      ParameterInfo[] paramInfo = methodInfo.getParameters();
       TypeInfo returnInfo = methodInfo.getReturnType();
       MetaType returnType = metaTypeFactory.resolve(returnInfo);
       ArrayList<ManagedParameter> mparams = new ArrayList<ManagedParameter>();
-      if( params != null )
+      Class<? extends ManagedParameterConstraintsPopulatorFactory> opConstraintsFactor
+         = opAnnotation.constraintsFactory();
+
+      if( paramInfo != null )
       {
-         for(ParameterInfo param : params)
+         for(int i = 0; i < paramInfo.length; i ++)
          {
-            
+            ParameterInfo pinfo = paramInfo[i];
+            String pname = pinfo.getName();
+            String pdescription = null;
+            ManagementParameter mpa = null;
+            // Look to ManagementParameter for info
+            if (i < params.length)
+            {
+               mpa = params[i];
+               if (mpa.name().equals(AnnotationDefaults.EMPTY_STRING) == false)
+                  pname = mpa.name();
+               if (mpa.description().equals(AnnotationDefaults.EMPTY_STRING) == false)
+                  pdescription = mpa.description();
+            }
+            // Generate a name if there is none
+            if (pname == null)
+               pname = "arg#" + i;
+            Fields fields =  new DefaultFieldsImpl(pname);
+            if (pdescription != null)
+               fields.setField(Fields.DESCRIPTION, pdescription);
+            MetaType metaType = metaTypeFactory.resolve(pinfo.getParameterType());
+            fields.setField(Fields.META_TYPE, metaType);
+            // Delegate others (legal values, min/max etc.) to the constraints factory
+            try
+            {
+               Class<? extends ManagedParameterConstraintsPopulatorFactory> factoryClass = opConstraintsFactor;
+               if (factoryClass == ManagementParameter.NULL_CONSTRAINTS.class)
+               {
+                  if (mpa != null)
+                     factoryClass = mpa.constraintsFactory();
+               }
+               ManagedParameterConstraintsPopulatorFactory factory = factoryClass.newInstance();
+               ManagedParameterConstraintsPopulator populator = factory.newInstance();
+               if (populator != null)
+                  populator.populateManagedParameter(name, pinfo, fields);
+            }
+            catch(Exception e)
+            {
+               log.debug("Failed to populate constraints for: "+pinfo, e);
+            }
+
+            ManagedParameterImpl mp = new ManagedParameterImpl(fields);
+            mparams.add(mp);
          }
       }
       ManagedParameter[] parameters = new ManagedParameter[mparams.size()];

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulator.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulator.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulator.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -0,0 +1,43 @@
+/*
+ * 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.managed.spi.factory;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.reflect.spi.ParameterInfo;
+
+/**
+ * Plugin for the {@linkplain ManagedParameter} constraint related info.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface ManagedParameterConstraintsPopulator
+{
+   /** Populate the ManagedParameter fields constraint related info.
+    * @param methodName - the name of the method the param is
+    *    associated with
+    * @param info - the ParameterInfo for the method param
+    * @param fields - the fields to add the constraints to
+    */
+   public void populateManagedParameter(String methodName, ParameterInfo info, Fields fields);
+
+}


Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulatorFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulatorFactory.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulatorFactory.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -0,0 +1,33 @@
+/*
+ * 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.managed.spi.factory;
+
+/**
+ * Stateless factory for obtaining a ManagedParameterConstraintsPopulator
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface ManagedParameterConstraintsPopulatorFactory
+{
+   ManagedParameterConstraintsPopulator newInstance();
+}


Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedParameterConstraintsPopulatorFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java	2007-08-28 21:51:06 UTC (rev 64929)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java	2007-08-28 21:53:40 UTC (rev 64930)
@@ -22,7 +22,8 @@
 package org.jboss.managed.spi.factory;
 
 /**
- * Stateless factory for obtaining 
+ * Stateless factory for obtaining a ManagedPropertyConstraintsPopulator
+ * 
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */




More information about the jboss-cvs-commits mailing list