Author: kentam
Date: Tue Dec 14 17:26:05 2004
New Revision: 111908

URL: http://svn.apache.org/viewcvs?view=rev&rev=111908
Log:
Implement controls support for externally defined (top-level, not nested) 
PropertySets.  This permits easier sharing of property sets between different 
controls. Using the feature happens in 2 steps:

1) Define an external property set by using the @PropertySet annotation on a 
top-level @interface.  See ExtPropertySet.java for an example.

2) Refer or "import" the external property set into a control interface or 
extension using the @ExternalPropertySets annotation.  See Props.java for an 
example.

The presence of the @ExternalPropertySets annotation results in a generated 
ControlBean that has properties support for the specified property sets, in 
addition to any "normal" (nested) property sets.

DRT: controls (windows)


Added:
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ExternalPropertySets.java
   (contents, props changed)
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/ExtPropertySet.java
   (contents, props changed)
Modified:
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseMap.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java
   
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/ControlAnnotationProcessorFactory.java
   incubator/beehive/trunk/controls/test/build.xml
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/Props.java
   
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropsBeans.java

Added: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ExternalPropertySets.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ExternalPropertySets.java?view=auto&rev=111908
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/ExternalPropertySets.java
     Tue Dec 14 17:26:05 2004
@@ -0,0 +1,35 @@
+package org.apache.beehive.controls.api.bean;
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Used on control interfaces to specify any external property sets that
+ * the control uses.  External property sets are property sets that are
+ * their own top-level interfaces, i.e. not nested.
+ */
[EMAIL PROTECTED](RetentionPolicy.RUNTIME)
[EMAIL PROTECTED]({ElementType.TYPE})
+public @interface ExternalPropertySets
+{
+    Class[] value();
+}

Modified: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseMap.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseMap.java?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseMap.java&r1=111907&p2=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseMap.java&r2=111908
==============================================================================
--- 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseMap.java
    (original)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/BaseMap.java
    Tue Dec 14 17:26:05 2004
@@ -91,8 +91,13 @@
         if (checkClass.isAnnotationPresent(PropertySet.class))
         {
             Class declaringClass = checkClass.getDeclaringClass();
-            if (declaringClass != null && 
-                declaringClass.isAssignableFrom(_mapClass))
+
+            // External property sets are always compatible.
+            // TODO: Could do a more extensive check..
+            if (declaringClass == null)
+                return true;
+
+            if (declaringClass.isAssignableFrom(_mapClass))
                 return true;
         }
 

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java&r1=111907&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java&r2=111908
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
 Tue Dec 14 17:26:05 2004
@@ -33,10 +33,12 @@
 import com.sun.mirror.declaration.TypeDeclaration;
 import com.sun.mirror.type.DeclaredType;
 import com.sun.mirror.type.InterfaceType;
+import com.sun.mirror.type.MirroredTypesException;
 
 import org.apache.beehive.controls.api.bean.ControlChecker;
 import org.apache.beehive.controls.api.bean.ControlExtension;
 import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.bean.ExternalPropertySets;
 import org.apache.beehive.controls.api.events.EventSet;
 import org.apache.beehive.controls.api.packaging.FeatureInfo;
 import org.apache.beehive.controls.api.packaging.ManifestAttribute;
@@ -226,13 +228,46 @@
     }
 
     /**
-     * Initializes the list of PropertySets declared by this 
AptControlInterface
+     * Initializes the list of PropertySets declared or referenced by this 
AptControlInterface
      */
     private ArrayList<AptPropertySet> initPropertySets()
     {
         ArrayList<AptPropertySet> propSets = new ArrayList<AptPropertySet>();
 
-        if ( _intfDecl == null || _intfDecl.getNestedTypes() == null )
+        if ( _intfDecl == null )
+            return propSets;
+
+        //
+        // Handle external property sets
+        //
+        ExternalPropertySets extPropsAnnotation = 
_intfDecl.getAnnotation(ExternalPropertySets.class);
+        if ( extPropsAnnotation != null )
+        {
+            try
+            {
+                Class[] extProps = extPropsAnnotation.value();
+            }
+            catch ( MirroredTypesException mte )
+            {
+                Collection<String> extProps = mte.getQualifiedNames();
+                for ( String extPropName : extProps )
+                {
+                    TypeDeclaration extPropDecl = _env.getTypeDeclaration( 
extPropName );
+                    if ( extPropDecl != null )
+                    {
+                        AptPropertySet extPropSet = new AptPropertySet( null, 
extPropDecl, _env );
+                        propSets.add( extPropSet );
+                    }
+                    else
+                    {
+                        _env.getMessager().printError(_intfDecl.getPosition(),
+                            "Unable to load type declaration for externally 
referenced PropertySet " + extPropName );
+                    }
+                }
+            }
+        }
+
+        if ( _intfDecl.getNestedTypes() == null )
             return propSets;
 
         // TODO: enforce presence of prefixes when multiple property sets w/ 
the same
@@ -473,7 +508,7 @@
         map.put("intf", this);                  // the control interface
         map.put("bean", _bean);
 
-        ArrayList<GeneratorOutput> genList = new ArrayList();
+        ArrayList<GeneratorOutput> genList = new ArrayList<GeneratorOutput>();
 
         //
         // the ControlBean class
@@ -508,7 +543,7 @@
         map.put("intf", this);                  // the control interface
         map.put("bean", _bean);
 
-        ArrayList<GeneratorOutput> genList = new ArrayList();
+        ArrayList<GeneratorOutput> genList = new ArrayList<GeneratorOutput>();
 
         //
         // the ControlBean MANIFEST.MF section

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java&r1=111907&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java&r2=111908
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java
      (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptPropertySet.java
      Tue Dec 14 17:26:05 2004
@@ -26,6 +26,7 @@
 import com.sun.mirror.declaration.AnnotationTypeDeclaration;
 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
 import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.Declaration;
 
 import org.apache.beehive.controls.api.properties.PropertySet;
 
@@ -37,15 +38,23 @@
 {
     /**
      * Constructs a new AptPropertySet instance from APT metadata
-     * @param controlIntf the declaring bean interface
+     * @param controlIntf the declaring bean interface.  May be null (external 
property set)
      * @param propertySet the PropertySet declaration
      * @param env the AnnotationProcessorEnvironment
      */
-    public AptPropertySet(AptControlInterface controlIntf, 
AnnotationTypeDeclaration propertySet,
+    public AptPropertySet(AptControlInterface controlIntf, Declaration 
propertySet,
                           AnnotationProcessorEnvironment env)
     {
         _controlIntf = controlIntf;
-        _propertySet = propertySet;
+
+        if (!(propertySet instanceof AnnotationTypeDeclaration))
+        {
+            env.getMessager().printError(propertySet.getPosition(),
+              "The PropertySet annotation may only be used on a Java 
annotation interface");
+            return;
+        }
+        _propertySet = (AnnotationTypeDeclaration)propertySet;
+
         _env = env;
         _properties = initProperties();
     }
@@ -116,7 +125,7 @@
     }
 
     private AnnotationTypeDeclaration _propertySet;
-    private AptControlInterface _controlIntf;
+    private AptControlInterface _controlIntf;           // may be null if an 
external property set
     private ArrayList<AptProperty> _properties;
     private AnnotationProcessorEnvironment _env;
 }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java&r1=111907&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java&r2=111908
==============================================================================
--- 
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
      Tue Dec 14 17:26:05 2004
@@ -36,13 +36,9 @@
 import org.apache.beehive.controls.api.bean.ControlExtension;
 import org.apache.beehive.controls.api.bean.ControlImplementation;
 import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.properties.PropertySet;
 
-import org.apache.beehive.controls.runtime.generator.AptControlImplementation;
-import org.apache.beehive.controls.runtime.generator.AptControlInterface;
-import org.apache.beehive.controls.runtime.generator.CodeGenerationException;
-import org.apache.beehive.controls.runtime.generator.CodeGenerator;
-import org.apache.beehive.controls.runtime.generator.Generator;
-import org.apache.beehive.controls.runtime.generator.GeneratorOutput;
+import org.apache.beehive.controls.runtime.generator.*;
 
 public class ControlAnnotationProcessor extends TwoPhaseAnnotationProcessor
 {
@@ -61,7 +57,7 @@
         {
             genClass = new AptControlInterface(decl, env);
         }
-        if (decl.getAnnotation(ControlExtension.class) != null)
+        else if (decl.getAnnotation(ControlExtension.class) != null)
         {
             genClass = new AptControlInterface(decl, env);
         }
@@ -69,7 +65,11 @@
         {
             genClass = new AptControlImplementation(decl, env);
         }
-        
+        else if (decl.getAnnotation(PropertySet.class) != null)
+        {
+            new AptPropertySet(null, decl, env);
+        }
+
         if ( genClass != null )
         {
             try

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessorFactory.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessorFactory.java?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessorFactory.java&r1=111907&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessorFactory.java&r2=111908
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessorFactory.java
       (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessorFactory.java
       Tue Dec 14 17:26:05 2004
@@ -36,7 +36,8 @@
                 Arrays.asList(new String[] {
                     "org.apache.beehive.controls.api.bean.ControlInterface",
                     "org.apache.beehive.controls.api.bean.ControlExtension",
-                    
"org.apache.beehive.controls.api.bean.ControlImplementation"
+                    
"org.apache.beehive.controls.api.bean.ControlImplementation",
+                    "org.apache.beehive.controls.api.properties.PropertySet"
                     }));
 
     private static final Collection<String> _supportedOptions =

Modified: incubator/beehive/trunk/controls/test/build.xml
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/build.xml?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/test/build.xml&r1=111907&p2=incubator/beehive/trunk/controls/test/build.xml&r2=111908
==============================================================================
--- incubator/beehive/trunk/controls/test/build.xml     (original)
+++ incubator/beehive/trunk/controls/test/build.xml     Tue Dec 14 17:26:05 2004
@@ -186,6 +186,7 @@
              classpathref="test.classpath" compileByExtension="true"
              srcExtensions="*.java,*.jcx,*.jcs" >
             <include name="**/composition/InnerControl*"/>
+            <include name="**/property/ExtPropertySet*"/>
         </apt>
 
         <echo message="** Phase Two **"/>

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/ExtPropertySet.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/ExtPropertySet.java?view=auto&rev=111908
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/ExtPropertySet.java
   Tue Dec 14 17:26:05 2004
@@ -0,0 +1,22 @@
+package org.apache.beehive.controls.test.controls.property;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.properties.PropertySet;
+
+/**
+ * An externally defined property set.
+ */
[EMAIL PROTECTED]
[EMAIL PROTECTED](RetentionPolicy.RUNTIME)
[EMAIL PROTECTED]( {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD} )
+public @interface ExtPropertySet
+{
+    public static final int AGE_DEFAULT = 5;
+    public int age() default AGE_DEFAULT;
+}

Modified: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/Props.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/Props.java?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/Props.java&r1=111907&p2=incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/Props.java&r2=111908
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/Props.java
    (original)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/Props.java
    Tue Dec 14 17:26:05 2004
@@ -7,6 +7,7 @@
 import java.lang.annotation.Target;
 
 import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.bean.ExternalPropertySets;
 import org.apache.beehive.controls.api.properties.PropertyKey;
 import org.apache.beehive.controls.api.properties.PropertySet;
 
@@ -15,6 +16,7 @@
  * as well as nested an array property types.
  */
 @ControlInterface
[EMAIL PROTECTED]({ExtPropertySet.class})
 public interface Props
 {
     //

Modified: 
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropsBeans.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropsBeans.java?view=diff&rev=111908&p1=incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropsBeans.java&r1=111907&p2=incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropsBeans.java&r2=111908
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropsBeans.java
     (original)
+++ 
incubator/beehive/trunk/controls/test/src/drivers/org/apache/beehive/controls/test/driver/property/DrivePropsBeans.java
     Tue Dec 14 17:26:05 2004
@@ -10,6 +10,7 @@
 import org.apache.beehive.controls.api.properties.PropertyMap;
 
 import org.apache.beehive.controls.test.controls.util.TestBeanContext;
+import org.apache.beehive.controls.test.controls.property.ExtPropertySet;
 import org.apache.beehive.controls.test.controls.property.Props;
 import org.apache.beehive.controls.test.controls.property.Props.ArrayProps;
 import org.apache.beehive.controls.test.controls.property.Props.SimpleEnum;
@@ -366,6 +367,24 @@
                        report.setMessage("bad get value for annotation Class:" 
+ simpleAnnot.simpleClass());
                        return report;
                }
+
+        //
+        // External PropertySet test
+        //
+        int age = propBean.getAge();
+        if (age != ExtPropertySet.AGE_DEFAULT){
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("bad default for age:" + age);
+                       return report;
+               }
+        propBean.setAge(60);
+        age = propBean.getAge();
+        if (age != 60){
+                       report.setStatus(Report.FAIL);
+                       report.setMessage("bad get value for age:" + age);
+                       return report;
+               }
+
 
                report.setStatus(Report.PASS);
                return report;

Reply via email to