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/09/17 21:58:21 UTC

svn commit: rev 46269 - in incubator/beehive/trunk: controls/drt/controls/org/apache/beehive/controls/test/beaninfo controls/drt/controls/org/apache/beehive/controls/test/composition controls/src/api/org/apache/beehive/controls/api/context controls/src/runtime/org/apache/beehive/controls/runtime/bean controls/src/runtime/org/apache/beehive/controls/runtime/generator controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo controls/test/src/controls/org/apache/beehive/controls/test/controls/composition test/ant

Author: kylem
Date: Fri Sep 17 12:58:20 2004
New Revision: 46269

Modified:
   incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/beaninfo/InfoTest.java
   incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/composition/Nested.java
   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/ControlBean.java
   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/ControlContainerContext.java
   incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm
   incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlOperation.java
   incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptMethodHelper.java
   incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptOperation.java
   incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptProperty.java
   incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java
   incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/Nested.java
   incubator/beehive/trunk/test/ant/buildWebapp.xml
Log:
- Added additional constraint to semantic validation of primitive-valued properties in Control
PropertySets.  PRIMITIVE PROPERTIES MUST SPECIFY A DEFAULT VALUE AS PART OF THE ANNOTATION TYPE
MEMBER DECLARATION.  The ensures consistent behavior for property accessor methods (they will
return the default value).   Object-valued properties do not have this constraint;  they will
return 'null' if the property has not been set by annotation, client, or external config.

- Added ControlBeanContext.getClassLoader() API, to enable a control implementation to do
resource loading using the same class loader as control type bound to the implementation.

- Removed a synchronization bottleneck in ControlContainerContext.begin/endContext methods.
Since these methods only access thread-local-storage, there is no value (and a high cost) to
doing global synchronization.

- Minor cleanup to codegen to leverage JDK 1.5 autoboxing, on the assumption that it should
be more efficient (or at least equivalent to) explicit casting.

- Tweaked test webapp build target to support composite control scenarios (by setting the
compileByExtension flag on <apt> invocation).



Modified: incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/beaninfo/InfoTest.java
==============================================================================
--- incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/beaninfo/InfoTest.java	(original)
+++ incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/beaninfo/InfoTest.java	Fri Sep 17 12:58:20 2004
@@ -45,9 +45,8 @@
     {
         @PropertyInfo(bound=true, constrained=false)
         @FeatureInfo(name="InfoTest prop1", displayName="InfoTest prop1")
-        public int prop1();
-
-        public boolean prop2();
+        public int prop1() default 0;
+        public boolean prop2() default false;
     }
 
 }

Modified: incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/composition/Nested.java
==============================================================================
--- incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/composition/Nested.java	(original)
+++ incubator/beehive/trunk/controls/drt/controls/org/apache/beehive/controls/test/composition/Nested.java	Fri Sep 17 12:58:20 2004
@@ -17,7 +17,7 @@
     @Retention(RetentionPolicy.RUNTIME)
     public @interface Index
     {
-        int value();
+        int value() default -1;
     }
 
     @EventSet

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	Fri Sep 17 12:58:20 2004
@@ -27,7 +27,7 @@
 
 /**
  * The ControlBeanContext interface defines the basic set of contextual services and lifecycle
- * events for Java Control Beans.
+ * events for Java ControlBean implementations.
  * <p>
  * ControlBeanContext also extends the <code>java.beans.beancontext.BeanContextServices</code>
  * interface, so it also provide core Java Beans services for managing contained controls,
@@ -119,6 +119,14 @@
      * @see org.apache.beehive.control.api.context.ControlHandle
      */
     public ControlHandle getControlHandle();
+
+    /**
+     * Returns the ClassLoader used to load the ControlBean class associated with the control
+     * implementation instance.  This is useful for loading other classes or resources that may 
+     * have been packaged with the public interfaces of the Control type (since they may not 
+     * necessarily have been packaged directly with the implementation class).
+     */
+    public java.lang.ClassLoader getClassLoader();
 
     /**
      * The Lifecycle event interface defines a set of lifecycle events exposed by the

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java	Fri Sep 17 12:58:20 2004
@@ -373,18 +373,6 @@
         }
     }
 
-    //
-    // HACK ALERT: These will be removed and auto-boxing relied upon instead
-    //
-    protected void postInvoke(int retval, Throwable t) { postInvoke(new Integer(retval), t); }
-    protected void postInvoke(short retval, Throwable t) { postInvoke(new Short(retval), t); }
-    protected void postInvoke(long retval, Throwable t) { postInvoke(new Long(retval), t); }
-    protected void postInvoke(float retval, Throwable t) { postInvoke(new Float(retval), t); }
-    protected void postInvoke(double retval, Throwable t) { postInvoke(new Double(retval), t); }
-    protected void postInvoke(char retval, Throwable t) { postInvoke(new Character(retval), t); }
-    protected void postInvoke(byte retval, Throwable t) { postInvoke(new Byte(retval), t); }
-    protected void postInvoke(boolean retval, Throwable t) { postInvoke(new Boolean(retval), t); }
-
     /**
      * Sets the EventNotifier for this ControlBean
      */

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	Fri Sep 17 12:58:20 2004
@@ -615,6 +615,14 @@
     }
 
     //
+    // ControlBeanContext.getClassLoader
+    //
+    public java.lang.ClassLoader getClassLoader()
+    {
+        return getControlInterface().getClassLoader();
+    }
+
+    //
     // ControlBeanContext.addLifeCycleListener
     //
     public void addLifeCycleListener(LifeCycle listener)

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java	Fri Sep 17 12:58:20 2004
@@ -62,7 +62,7 @@
     /**
      * Defines the beginning of a new control container execution context.
      */
-    public synchronized void beginContext()
+    public void beginContext()
     {
         Stack contextStack = (Stack)_threadStacks.get();
         if (contextStack == null)
@@ -76,7 +76,7 @@
     /**
      * Ends the current control container execution context
      */
-    public synchronized void endContext()
+    public void endContext()
     {
         Stack contextStack = (Stack)_threadStacks.get();
         if (contextStack == null)

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm	Fri Sep 17 12:58:20 2004
@@ -33,9 +33,6 @@
 ##
 ## A simple helper macro that converts a object type to the equivalent primitive
 ##
-#macro (toPrimitive $type)#if ($type == "int").intValue()#elseif ($type == "long").longValue()#elseif ($type == "boolean").booleanValue()#elseif ($type == "byte").byteValue()#elseif ($type == "short").shortValue()#elseif ($type == "char").charValue()#elseif ($type == "float").floatValue()#elseif ($type == "double").doubleValue()#end#end
-##
-##
 ## This macro provides the template for declaring the static final Method fields that
 ## are associated with all declared operations
 ##
@@ -114,7 +111,7 @@
      */
     public $returnType ${operation.name}($operation.argDecl) $operation.throwsClause
     {
-        Object [] _argArray = new Object[] { $operation.argObjectArray };
+        Object [] _argArray = new Object[] { $operation.argList };
         Throwable _thrown = null;
         #if (!$intf.isExtension())
         $intf.className _target = ($intf.className)ensureControl();
@@ -139,14 +136,10 @@
             #if (!$intf.isExtension())
             _target.${operation.name}($operation.argList)
             #else
-            ## Remove toObject/toPrimitive once auto-boxing can be assumed
             #if ($returnType != "void")
-            ((#toObject ($returnType))
+            (#toObject ($returnType))
             #end
             _target.invoke(${operation.methodField}, _argArray)
-            #if ($returnType != "void")
-            )#toPrimitive($returnType)
-            #end
             #end
             ;
         }
@@ -205,8 +198,7 @@
     public $property.type get${property.name}()
     #end
     {
-        ## Remove toObject/toPrimitive once auto-boxing can be assumed
-        return ((#toObject($property.type))getControlProperty($property.keyName))#toPrimitive($property.type);
+        return (#toObject($property.type))getControlProperty($property.keyName);
     }
 
 #end

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlOperation.java
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlOperation.java	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlOperation.java	Fri Sep 17 12:58:20 2004
@@ -43,12 +43,6 @@
     }
 
     /**
-     * Returns the body of an Object array initializer based upon method arguments.  All
-     * primitive arguments are converted to the equivalent Object type.
-     */
-    abstract public String getArgObjectArray();
-
-    /**
      * Returns the name of the static field that holds the name of this method.
      */
     public String getMethodField()

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptMethodHelper.java
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptMethodHelper.java	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptMethodHelper.java	Fri Sep 17 12:58:20 2004
@@ -135,49 +135,6 @@
     }
 
     /**
-     * Returns the body of an Object array initializer based upon method arguments.  All
-     * primitive arguments are converted to the equivalent Object type.
-     */
-    public String getArgObjectArray()
-    {
-        StringBuffer sb = new StringBuffer();
-        int i = 0;
-
-        if ( _methodDecl == null || _methodDecl.getParameters() == null )
-            return "";
-        
-        for (ParameterDeclaration paramDecl : _methodDecl.getParameters())
-        {
-            if (i != 0)
-                sb.append(",");
-
-            // BUGBUG: when the MethodDeclaration is derived from Reflection, this seems
-            // to return 'arg0' for all arguments!
-            String argName = paramDecl.getSimpleName();
-            if (argName.equals("arg0"))
-                argName = "arg" + i;
-
-            if ( paramDecl.getType() == null )
-                return "";
-            
-            TypeMirror paramType = paramDecl.getType();
-            if (paramType instanceof PrimitiveType)
-            {
-                sb.append(" new ");
-                sb.append(_primToObject.get(((PrimitiveType)paramType).getKind()));
-                sb.append("(");
-                sb.append(argName);
-                sb.append(")");
-            }
-            else
-                sb.append(argName);
-
-            i++;
-        }
-        return sb.toString();
-    }
-
-    /**
      * Returns the the method argument classes, in a comma separated list
      */
     public String getArgTypes()

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptOperation.java
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptOperation.java	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptOperation.java	Fri Sep 17 12:58:20 2004
@@ -59,7 +59,6 @@
     public String getReturnType() { return _helper.getReturnType(); }
     public String getThrowsClause() { return _helper.getThrowsClause(); }
     public ArrayList getThrowsList() { return _helper.getThrowsList(); }
-    public String getArgObjectArray() { return _helper.getArgObjectArray(); }
 
     MethodDeclaration _operDecl;
     AptMethodHelper _helper;

Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptProperty.java
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptProperty.java	(original)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AptProperty.java	Fri Sep 17 12:58:20 2004
@@ -20,6 +20,7 @@
 import com.sun.mirror.apt.AnnotationProcessorEnvironment;
 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
 import com.sun.mirror.type.AnnotationType;
+import com.sun.mirror.type.PrimitiveType;
 
 import org.apache.beehive.controls.api.packaging.FeatureInfo;
 import org.apache.beehive.controls.api.packaging.PropertyInfo;
@@ -43,6 +44,19 @@
         super(propertySet);
         _propDecl = propDecl;
         _env = env;
+
+        //
+        // Primitive properties must specify a default value, to provide consistent semantics
+        // in cases where no value has been set by annotation, client, or configuration.  Object
+        // typed properties have an optional default, and 'null' in this context means that the
+        // property value has not been set.
+        //
+        if (propDecl.getReturnType() instanceof PrimitiveType &&
+            propDecl.getDefaultValue() == null)
+        {
+            env.getMessager().printError(propDecl.getPosition(),
+                "Primitive property " + propDecl.getSimpleName() + " must specify a default value");
+        }
 
         init();
     }

Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java	(original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/beaninfo/InfoTest.java	Fri Sep 17 12:58:20 2004
@@ -45,9 +45,8 @@
     {
         @PropertyInfo(bound=true, constrained=false)
         @FeatureInfo(name="InfoTest prop1", displayName="InfoTest prop1")
-        public int prop1();
-
-        public boolean prop2();
+        public int prop1() default 0;
+        public boolean prop2() default false;
     }
 
 }

Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/Nested.java
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/Nested.java	(original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/composition/Nested.java	Fri Sep 17 12:58:20 2004
@@ -17,7 +17,7 @@
     @Retention(RetentionPolicy.RUNTIME)
     public @interface Index
     {
-        int value();
+        int value() default -1; 
     }
 
     @EventSet

Modified: incubator/beehive/trunk/test/ant/buildWebapp.xml
==============================================================================
--- incubator/beehive/trunk/test/ant/buildWebapp.xml	(original)
+++ incubator/beehive/trunk/test/ant/buildWebapp.xml	Fri Sep 17 12:58:20 2004
@@ -83,8 +83,10 @@
         <!-- apt generates intermediate files Java files into a tmp directory; WEB-INF/${tmp.sourcegen.dir} here -->
         <echo>========== Generate and compile controls ==========</echo>
         <mkdir dir="${webapp.dir}/WEB-INF/${tmp.sourcegen.dir}"/>
-        <apt srcdir="${webapp.dir}" destdir="${webapp.dir}/WEB-INF/classes" gendir="${webapp.dir}/WEB-INF/${tmp.sourcegen.dir}"
-             classpathref="controls.build.classpath" srcExtensions="*.java,*.jcx,*.jcs">
+        <apt srcdir="${webapp.dir}" destdir="${webapp.dir}/WEB-INF/classes" 
+             gendir="${webapp.dir}/WEB-INF/${tmp.sourcegen.dir}" 
+             classpathref="controls.build.classpath" 
+             compileByExtension="true" srcExtensions="*.java,*.jcx,*.jcs">
         </apt>
 
         <!-- JPF build -->