Author: kylem
Date: Wed Aug 25 08:47:11 2004
New Revision: 36862

Modified:
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/AnnotatedElementMap.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/PropertySetProxy.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
   incubator/beehive/trunk/controls/test/build.xml
   incubator/beehive/trunk/controls/test/infra/mantis/mantis.jar
   incubator/beehive/trunk/controls/test/tools/mantis/mantis.xml
   
incubator/beehive/trunk/controls/test/tools/mantis/src/org/apache/beehive/mantis/MantisFactory.java
Log:
Roll-up of submitted patches from non-committers:

Misc mantis framework changes submitted by Jamie Zyskowski

Misc EventSet fixes submitted by Mitch Upton

ControlAnnotationProcessor fix submitted by Mike Kaufman



Modified: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/AnnotatedElementMap.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/AnnotatedElementMap.java
        (original)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/AnnotatedElementMap.java
        Wed Aug 25 08:47:11 2004
@@ -49,11 +49,47 @@
         else if (annotElem instanceof Field)
             setMapClass(((Field)annotElem).getType());
         else if (annotElem instanceof Method)
-            setMapClass(((Method)annotElem).getDeclaringClass());
+        {
+            Class mapClass = getMethodMapClass((Method)annotElem);
+            setMapClass(mapClass);
+        }
         else
             throw new IllegalArgumentException("Unsupported element type: " + 
annotElem.getClass());
 
         _annotElem = annotElem;
+    }
+
+    // For methods, make sure we find a declaring class that is a valid
+    // map class. For extended callback methods, we need to walk up a bit
+    // further in the hierarchy.
+
+    Class getMethodMapClass(Method method) {
+
+        Class origMapClass = method.getDeclaringClass();
+        Class mapClass = origMapClass;
+        while (mapClass != null && !isValidMapClass(mapClass)) {
+            mapClass = mapClass.getDeclaringClass();
+        }
+        if (mapClass == null) {
+            mapClass = origMapClass;
+        }
+        return mapClass;
+    }
+
+    boolean isValidMapClass(Class mapClass) {
+        if (ControlBean.class.isAssignableFrom(mapClass))
+        {
+            return true;
+        }
+        else
+        {
+            if (mapClass.isAnnotation() ||
+                mapClass.isAnnotationPresent(ControlInterface.class) ||
+                mapClass.isAnnotationPresent(ControlExtension.class)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     /**

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
      Wed Aug 25 08:47:11 2004
@@ -27,14 +27,11 @@
 import java.beans.beancontext.BeanContextSupport;
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Method;
-import java.util.EventListener;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.TooManyListenersException;
-import java.util.Vector;
+import java.lang.annotation.Annotation;
+import java.util.*;
 
 import org.apache.beehive.controls.api.ControlException;
+import org.apache.beehive.controls.api.events.EventSet;
 import org.apache.beehive.controls.api.properties.AnnotatedElementMap;
 import org.apache.beehive.controls.api.properties.BeanPropertyMap;
 import org.apache.beehive.controls.api.properties.PropertyKey;
@@ -60,10 +57,9 @@
     public static final char IDSeparator = '/';
     public static final char FactorySeparator = ':';
 
-    /*
-     * TODO: replace private Mutex impl w/ JDK 1.5 mutx
-     */
-
+    //
+    // TODO: Replace this custom Mutex impl w/ JDK 1.5 Mutex
+    //
     /**
      * The Mutex class provides a basic mutex implementation.  It does lock 
counting, so the owner
      * can call lock() multiple times, but will be required to call unlock() 
an equivalent
@@ -396,6 +392,44 @@
     protected void setEventNotifier(Class eventSet, EventNotifier notifier)
     {
         _callbackNotifiers.put(eventSet,notifier);
+
+        //
+        // Register this notifier for all EventSet interfaces up the interface 
inheritance
+        // hiearachy as well
+        //
+        List<Class> superEventSets = new ArrayList<Class>();
+        getSuperEventSets(eventSet, superEventSets);
+        Iterator<Class> i = superEventSets.iterator();
+        while (i.hasNext())
+        {
+            Class superEventSet = i.next();
+            _callbackNotifiers.put(superEventSet,notifier);
+        }
+    }
+
+    /**
+     * Finds all of the EventSets extended by the input EventSet, and adds 
them to
+     * the provided list. 
+     * @param eventSet
+     * @param superEventSets
+     */
+    private void getSuperEventSets(Class eventSet, List<Class> superEventSets)
+    {
+        Class[] superInterfaces = eventSet.getInterfaces();
+        if (superInterfaces != null)
+        {
+            for (int i=0; i < superInterfaces.length; i++)
+            {
+                Class superInterface = superInterfaces[i];
+                if (superInterface.isAnnotationPresent(EventSet.class))
+                {
+                    superEventSets.add(superInterface);
+
+                    // Continue traversing up the EventSet inheritance 
hierarchy
+                    getSuperEventSets(superInterface, superEventSets);
+                }
+            }
+        }
     }
 
     /**

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/PropertySetProxy.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/PropertySetProxy.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/PropertySetProxy.java
 Wed Aug 25 08:47:11 2004
@@ -76,16 +76,37 @@
     //
     public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable
     {
-        // Query the nested value in the property map
-        PropertyKey key = new PropertyKey(_propertySet, method.getName());
-        Object value = _propertyMap.getProperty(key);
+        // Handle cases where Object/Annotation methods are called on this
+        // proxy. We were getting null back from Annotation.annotationType.
+        Object value = null;
+        if (method.getDeclaringClass() == Object.class) {
+            try {
+                if (method.getName().equals("getClass")) {
+                    value = _propertySet;
+                }
+                else {
+                    value = method.invoke(_propertyMap, args);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        } else if (method.getDeclaringClass() == Annotation.class &&
+                   method.getName().equals("annotationType")) {
+            value = _propertySet;
+        }
+        else {
 
-        // If the returned value is itself a PropertyMap (i.e. a nested 
annotation type),
-        // then wrap it in a PropertySetProxy instance before returning.
-        if (value instanceof PropertyMap)
-        {
-            PropertyMap propertyMap = (PropertyMap)value;
-            value = getProxy(propertyMap.getMapClass(), propertyMap);
+            // Query the nested value in the property map
+            PropertyKey key = new PropertyKey(_propertySet, method.getName());
+            value = _propertyMap.getProperty(key);
+
+            // If the returned value is itself a PropertyMap (i.e. a nested 
annotation type),
+            // then wrap it in a PropertySetProxy instance before returning.
+            if (value instanceof PropertyMap)
+            {
+                PropertyMap propertyMap = (PropertyMap)value;
+                value = getProxy(propertyMap.getMapClass(), propertyMap);
+            }
         }
 
         return value;

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
      (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
      Wed Aug 25 08:47:11 2004
@@ -53,6 +53,11 @@
     @Override
     public void check(Declaration decl)
     {
+    }
+
+    @Override
+    public void generate(Declaration decl)
+    {
         AnnotationProcessorEnvironment env = 
getAnnotationProcessorEnvironment();
         GenClass genClass = null;
         if (decl.getAnnotation(ControlInterface.class) != null)
@@ -86,11 +91,6 @@
                 throw new CodeGenerationException("Code generation failure: ", 
ioe);
             }
         }
-    }
-
-    @Override
-    public void generate(Declaration decl)
-    {
     }
 
     /**

Modified: incubator/beehive/trunk/controls/test/build.xml
==============================================================================
--- incubator/beehive/trunk/controls/test/build.xml     (original)
+++ incubator/beehive/trunk/controls/test/build.xml     Wed Aug 25 08:47:11 2004
@@ -173,7 +173,7 @@
     
     
     <!-- =============================================== -->
-    <!-- stuff below this is stuff i added -->
+    <!-- TCH and Mantis targets for running tests -->
     <!-- =============================================== -->
 
     <property name="junit.src.dir" value="${basedir}/src/units"/>
@@ -183,7 +183,22 @@
              classpathref="tch.run.classpath"/>
 
     <echo message="milton.jar: ${milton.jar}"/>
-    
+ 
+               <target name="run-all">
+                       <property name="tch.test.names" 
value="org-apache-beehive-controls-test*.*"/>
+                       <antcall target="run"/>
+               </target>
+ 
+               <target name="run-java">
+                       <property name="tch.test.names" 
value="org-apache-beehive-controls-test-java*.*"/>
+                       <antcall target="run"/>
+               </target>        
+
+               <target name="run-jpf">
+                       <property name="tch.test.names" 
value="org-apache-beehive-controls-test-jpf*.*"/>
+                       <antcall target="run"/>
+               </target>        
+
     <target name="run" depends="mantis">
 
         <gethostname/> <!-- set ${hostname} -->
@@ -191,24 +206,25 @@
         <property name="test.hostname" value="${hostname}" />
         <property name="test.hostname.port" value="8080" /> <!-- tomcat 
default port -->
         <property name="test-suite" value="${mantis.srcgen.dir}/root.xml"/>
-       <property name="tch.base-logfile-name" value="tch"/>
+                               <property name="tch.base-logfile-name" 
value="tch"/>
 
-       <tch tchHome="${tch.home}"
-            testfile="${test-suite}"
-            fork="true"
-            classpathref="tch.run.classpath"
-            failureproperty="run.failed">
-
-            <arg value="-emacs"/>
-            <property name="tch.replication.entry-point" value="ant -f 
${controls.test.dir}/build.xml run"/>
-           <sysproperty key="TEST_HOSTNAME" value="${test.hostname}" />
-           <sysproperty key="TEST_HOSTNAME_PORT" value="${test.hostname.port}" 
/>
+                               <tch tchHome="${tch.home}"
+                               testfile="${test-suite}"
+                               fork="true"
+                               classpathref="tch.run.classpath"
+                               failureproperty="run.failed">
+
+                                <arg value="-emacs"/>
+                               <property name="tch.replication.entry-point" 
value="ant -f ${controls.test.dir}/build.xml run"/>
+                               <property name="tch.test-names" 
value="${tch.test.names}"/>
+                                                       <sysproperty 
key="TEST_HOSTNAME" value="${test.hostname}" />
+                                                       <sysproperty 
key="TEST_HOSTNAME_PORT" value="${test.hostname.port}" />
 
-        </tch>
+                       </tch>
        
-       <ant antfile="${controls.test.infra.dir}/tch/runtime/build.xml" 
target="generate-html-log" dir="${basedir}">
-               <property name="gtlf.file" 
value="${basedir}/${tch.base-logfile-name}.xml"/>
-               <property name="output.file" 
value="${basedir}/${tch.base-logfile-name}.html"/>
+                               <ant 
antfile="${controls.test.infra.dir}/tch/runtime/build.xml" 
target="generate-html-log" dir="${basedir}">
+                                       <property name="gtlf.file" 
value="${basedir}/${tch.base-logfile-name}.xml"/>
+                                       <property name="output.file" 
value="${basedir}/${tch.base-logfile-name}.html"/>
         </ant>
     </target>  
 
@@ -251,6 +267,8 @@
                classpath="${mantis.run.classpath}"
                logdir="${mantis.log.dir}"
                config="${mantis.config}"
+               processor="org.apache.beehive.mantis.TchProcessor"
+               timeout="10000"
                aptcommand="${os.JAVA_HOME}/bin/apt"
     />
   </target>

Modified: incubator/beehive/trunk/controls/test/infra/mantis/mantis.jar
==============================================================================
Binary files. No diff available.

Modified: incubator/beehive/trunk/controls/test/tools/mantis/mantis.xml
==============================================================================
--- incubator/beehive/trunk/controls/test/tools/mantis/mantis.xml       
(original)
+++ incubator/beehive/trunk/controls/test/tools/mantis/mantis.xml       Wed Aug 
25 08:47:11 2004
@@ -14,8 +14,8 @@
        <property 
file="${os.BEEHIVE_HOME}/controls/test/common/path.properties"/>
 
        <!-- mantis properties -->      
-       <property name="mantis.root" value="${basedir}"/>
-       <property name="mantis.jar" value="${mantis.root}/deploy/mantis.jar"/>
+       <property name="mantis.root" value="."/>
+       <property name="mantis.local.deploy.jar" 
value="${mantis.root}/deploy/mantis.jar"/>
        <property name="src.dir" value="${mantis.root}/src"/>
        <property name="mantis.build.dir" value="${mantis.root}/build"/>
        <property name="mantis.srcgen.dir" value="${mantis.root}/srcgen"/>
@@ -30,7 +30,7 @@
        <!-- CLASSPATHS -->
        <!--************-->
        <path id="mantis.run.classpath">
-               <pathelement path="${mantis.jar}"/>
+               <pathelement path="${mantis.local.deploy.jar}"/>
                <pathelement path="${tchschema.jar}"/>
                <pathelement path="${mantis.xbean.jar}"/>
                <pathelement path="${ant.jar}"/>

Modified: 
incubator/beehive/trunk/controls/test/tools/mantis/src/org/apache/beehive/mantis/MantisFactory.java
==============================================================================
--- 
incubator/beehive/trunk/controls/test/tools/mantis/src/org/apache/beehive/mantis/MantisFactory.java
 (original)
+++ 
incubator/beehive/trunk/controls/test/tools/mantis/src/org/apache/beehive/mantis/MantisFactory.java
 Wed Aug 25 08:47:11 2004
@@ -120,7 +120,10 @@
     }
 
     System.out.println("config="+configurl);
-    System.out.println("num processor(s) initialized="+processors.size());
+               if(processors.contains(null))
+                       System.out.println("ERROR: unable to instantiate and 
initialize processor(s)");
+               else
+       System.out.println("num processor(s) initialized="+processors.size());
     
     // create a composite of processors to return
     AnnotationProcessors util = new AnnotationProcessors();
@@ -178,9 +181,14 @@
     // instantiate the specified processors
     try
     {
-      Class definition = Class.forName(p_procname);
+                       System.out.println("INFO: ready to instantiate 
processor class: "+p_procname);
+                       // FIX: in win32 a ClassNotFoundException would be 
thrown w/out a call to trim()
+      Class definition = Class.forName(p_procname.trim());
       AbstractMantisProcessor proc = (AbstractMantisProcessor) 
definition.newInstance();
+                       //System.out.println("INFO: successfully instantiated 
processor class: "+p_procname);
+                       //System.out.println("INFO: ready to initialize 
processor class: "+p_procname);
       proc.init(p_atds,p_env);
+                       System.out.println("INFO: successfully instantiated and 
initialized processor class: "+p_procname);
       return (AnnotationProcessor) proc;
     }
     catch(ClassNotFoundException cnfe)

Reply via email to