Author: kylem
Date: Wed Feb 16 15:03:55 2005
New Revision: 154098

URL: http://svn.apache.org/viewcvs?view=rev&rev=154098
Log:
Added new 'optional' attribute to the @PropertySet annotation type for 
declaring control property sets.  An 'optional' property set is one that 
may/may not be associated with a control.  Its presence (or absence) may imply 
semantics that aren't usefully represented by having PropertySet default 
values.   If a PropertySet is optional, none of the contained properties can be 
exposed to client via getters, because there is no appropriate property value 
representation for an 'unset' property.  A Control Implementation class can 
tell if a PropertySet is set for a given instance using the 
ControlBeanContext.getXXXPropertySet APIs.  These methods will now return 
'null' for optional properties that have not been set, whereas they return a 
'default' value for the PropertySet if it is not optional (the current 
behavior).  The optional attribute is 'false' by default, so @PropertySet 
semantics are
behaviorally back compat with previous usage if optional attribute is 
unspecified.

This resolves BEEHIVE JIRA-179.

Modified:
    
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/PropertySet.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/generator/AptPropertySet.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm

Modified: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/PropertySet.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/PropertySet.java?view=diff&r1=154097&r2=154098
==============================================================================
--- 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/PropertySet.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/properties/PropertySet.java
 Wed Feb 16 15:03:55 2005
@@ -77,6 +77,20 @@
     boolean externalConfig() default true;
 
     /**
+     * The optional member specifies that this property set may optionally be 
associated
+     * with the control.  Because there is no way to represent an 'unset' 
property value,
+     * optional properties will not expose a getter method to clients;  a 
control
+     * implementation class can determine whether a property is/is not set, 
because the
+     * PropertySet query APIs on ControlBeanContext will return null if unset. 
 For
+     * properties that are not optional, a PropertySet instance with all 
default values
+     * will be returned if unset.
+     *
+     * @see 
org.apache.beehive.controls.context.ControlBeanContext.getControlPropertySet
+     * @see 
org.apache.beehive.controls.context.ControlBeanContext.getMethodPropertySet
+     */ 
+    boolean optional() default false;
+
+    /**
      * The hasSetters member defines whether properties in the set will have 
programmatic
      * setter methods.
      */

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?view=diff&r1=154097&r2=154098
==============================================================================
--- 
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
 Wed Feb 16 15:03:55 2005
@@ -41,6 +41,7 @@
 import org.apache.beehive.controls.api.properties.AnnotatedElementMap;
 import org.apache.beehive.controls.api.properties.BeanPropertyMap;
 import org.apache.beehive.controls.api.properties.PropertyMap;
+import org.apache.beehive.controls.api.properties.PropertySet;
 import org.apache.beehive.controls.api.properties.PropertySetProxy;
 
 /**
@@ -495,12 +496,18 @@
     {
         PropertyMap map = _bean.getPropertyMap();
 
-        // TODO: Add a PropertySet meta-attribute that indicates the 
PropertySet is optional.
-        // This implies:  a) no setters/getters, and b) the PropertySet can 
appear to be
-        // 'null' from the impl perspective if unset; otherwise, a PropertySet 
containing all
-        // default values will be returned.
-        //if (!map.containsPropertySet(propertySet))
-        //    return null;
+        //
+        // Optional properties are not exposed to clients using traditional 
JavaBean
+        // setters/getters (because there is way to represent an 'unset' 
value); for
+        // these properties, the impl can tell if the PropertySet is unset 
because
+        // this method will return null.
+        //
+        if (!map.containsPropertySet(propertySet))
+        {
+            PropertySet psAnnot = propertySet.getAnnotation(PropertySet.class);
+            if (psAnnot.optional())
+                return null;
+        }
 
         //
         // Construct a new PropertySet proxy instance that derives its values 
from
@@ -515,8 +522,19 @@
     public <T extends Annotation> T getMethodPropertySet(Method m, Class<T> 
propertySet)
     {
         PropertyMap map = _bean.getAnnotationMap(m);
+
+        //
+        // Optional properties are not exposed to clients using traditional 
JavaBean
+        // setters/getters (because there is way to represent an 'unset' 
value); for
+        // these properties, the impl can tell if the PropertySet is unset 
because
+        // this method will return null.
+        //
         if (!map.containsPropertySet(propertySet))
-            return null;
+        {
+            PropertySet psAnnot = propertySet.getAnnotation(PropertySet.class);
+            if (psAnnot.optional())
+                return null;
+        }
 
         //
         // Construct a new PropertySet proxy instance that derives its values 
from

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&r1=154097&r2=154098
==============================================================================
--- 
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
 Wed Feb 16 15:03:55 2005
@@ -55,6 +55,7 @@
         }
         _propertySet = (AnnotationTypeDeclaration)propertySet;
 
+        _isOptional = _propertySet.getAnnotation(PropertySet.class).optional();
         _hasSetters = 
_propertySet.getAnnotation(PropertySet.class).hasSetters();
 
         _env = env;
@@ -132,6 +133,14 @@
     /**
      * Returns whether or not this propertyset exposes setters
      */
+    public boolean isOptional()
+    {
+        return _isOptional;
+    }
+
+    /**
+     * Returns whether or not this propertyset exposes setters
+     */
     public boolean hasSetters()
     {
         return _hasSetters;
@@ -141,5 +150,6 @@
     private AptControlInterface _controlIntf;           // may be null if an 
external property set
     private ArrayList<AptProperty> _properties;
     private AnnotationProcessorEnvironment _env;
+    private boolean _isOptional;
     private boolean _hasSetters;
 }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm?view=diff&r1=154097&r2=154098
==============================================================================
--- 
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
 Wed Feb 16 15:03:55 2005
@@ -242,10 +242,12 @@
     }
     #end
 
-    public $property.type ${property.readMethod}()
-    {
-        return 
(#toObject($property.type))getControlProperty($property.keyName);
-    }
+    #if (!$property.propertySet.isOptional())
+        public $property.type ${property.readMethod}()
+        {
+            return 
(#toObject($property.type))getControlProperty($property.keyName);
+        }
+    #end
 
 #end
 ##


Reply via email to