You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ky...@apache.org on 2004/10/06 03:00:22 UTC

svn commit: rev 53839 - in incubator/beehive/trunk/controls: drt src/api/org/apache/beehive/controls/api/context src/runtime/org/apache/beehive/controls/runtime/bean

Author: kylem
Date: Tue Oct  5 18:00:20 2004
New Revision: 53839

Removed:
   incubator/beehive/trunk/controls/drt/
Modified:
   incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
   incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
Log:
Added APIs for accessing method parameter names and annotations to ControlBeanContext.  The
implementation of some of them is currently incomplete, as some codegen work needs to be
done to preserve parameter name information.


Modified: incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
==============================================================================
--- incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java	(original)
+++ incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java	Tue Oct  5 18:00:20 2004
@@ -78,13 +78,46 @@
      * Returns the current value of PropertySet for the provided method, or null
      * if the property set has not been bound for this method.
      *
-     * @param m the Method to check for properties
+     * @param m the Method to check for properties.
      * @param propertySet the PropertySet to return
      * @return the requested PropertySet instance, or null if not bound
      *
      * @see org.apache.beehive.controls.api.properties.PropertySet
      */
-    public <T extends Annotation> T getMethodPropertySet(Method m, Class<T> propertySet);
+    public <T extends Annotation> T getMethodPropertySet(Method m, Class<T> propertySet)
+                                    throws IllegalArgumentException;
+
+    /**
+     * Returns the current value of PropertySet for the selected (by index) method parameter,
+     * or null if the property set has not been bound for this method.
+     *
+     * @param m the Method to check for properties
+     * @param i the index of the method parameter to check for the request PropertySet
+     * @param propertySet the PropertySet to return
+     * @return the request PropertySet instance, or null if not bound
+     */
+    public <T extends Annotation> T getParameterPropertySet(Method m, int i, Class<T> propertySet)
+                                    throws IllegalArgumentException, IndexOutOfBoundsException;
+
+    /**
+     * Returns an array containing the parameter names for the specified method
+     *
+     * @param m the Method whose parameter names should be returned.
+     * @return the array of parameter names (or an empty array if no parameters)
+     */
+    public String [] getParameterNames(Method m) throws IllegalArgumentException;
+
+    /**
+     * Returns the value of a named method parameter from the input parameter array.
+     *
+     * @param m the Method associated with the input parameter list
+     * @param parameterName the name of the requested parameter
+     * @param parameters the array of method parameters
+     * @return the element in the input parameter array that corresponds to the requested
+     *         parameter
+     */
+    public Object getParameterValue(Method m, String parameterName, Object [] parameters)
+                  throws IllegalArgumentException;
 
     /**
      * Returns the current set of properties (in PropertyMap format) for the control 

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java	Tue Oct  5 18:00:20 2004
@@ -557,6 +557,69 @@
     }
 
     //
+    // ControlBeanContext.getParameterPropertySet
+    //
+    public <T extends Annotation> T getParameterPropertySet(Method m, int i, Class<T> propertySet)
+                                    throws IllegalArgumentException, IndexOutOfBoundsException
+    {
+        if (i >= m.getParameterTypes().length)
+            throw new IndexOutOfBoundsException("Invalid parameter index for method:" + m);
+
+        //
+        // BUGBUG: Currently, there is no external override mechanism for method parameters
+        //
+        Annotation [] paramAnnots = m.getParameterAnnotations()[i];
+        for (int j = 0; j < paramAnnots.length; j++)
+            if (propertySet.isAssignableFrom(paramAnnots[j].getClass()))
+                return (T)paramAnnots[j];
+
+        return null;
+    }
+
+    //
+    // ControlBeanContext.getParameterNames
+    //
+    public String [] getParameterNames(Method m) throws IllegalArgumentException
+    {
+        //
+        // TEMPORARY HACK IMPLEMENTATION
+        //
+        String [] names = new String [m.getParameterTypes().length];
+        for (int i = 0; i < names.length; i++)
+            names[i] = "arg" + i;
+
+        return names;
+    }
+
+    //
+    // ControlBeanContext.getNamedParameterValue
+    //
+    public Object getParameterValue(Method m, String parameterName, Object [] parameters)
+                  throws IllegalArgumentException
+    {
+        String [] names = getParameterNames(m);    
+
+        // Validate the input parameter array
+        if (parameters.length != names.length)
+            throw new IllegalArgumentException("Expected " + names.length + " parameters," + 
+                                               "Found " + parameters.length);
+
+        // Finding the index of the matching parameter name
+        int i = 0;
+        while (i < names.length)
+        {
+            if (names[i].equals(parameterName))
+                break;
+            i++;
+        }
+        if (i == names.length)
+            throw new IllegalArgumentException("No method parameter with name: " + parameterName);
+
+        // Return the parameter value at the matched index
+        return parameters[i];
+    }
+
+    //
     // ControlBeanContext.getPropertyMap
     //
     public PropertyMap getControlPropertyMap()