Author: craigmcc
Date: Mon Jun 26 23:40:21 2006
New Revision: 417355

URL: http://svn.apache.org/viewvc?rev=417355&view=rev
Log:
SHALE-185 -- Make it possible to specify the name of the managed property
that is annotated by a @Property annotation (@Value is now deprecated, so
do not bother to be backwards compatible with that).  The default is to make
the property name match the field name, matching the previous hard coded
behavior.  This is also forward compatible with a future scenario where the
@Property annotation might be allowed on a getter or setter method, where
the default property name is derived from the method name, but still
allows overriding the default.

Modified:
    
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/faces/LifecycleListener.java
    
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/managed/Property.java
    
struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean.java

Modified: 
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/faces/LifecycleListener.java
URL: 
http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/faces/LifecycleListener.java?rev=417355&r1=417354&r2=417355&view=diff
==============================================================================
--- 
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/faces/LifecycleListener.java
 (original)
+++ 
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/faces/LifecycleListener.java
 Mon Jun 26 23:40:21 2006
@@ -606,7 +606,11 @@
                 Property property = (Property) 
field.getAnnotation(Property.class);
                 if (property != null) {
                     ManagedPropertyConfig mpc = new ManagedPropertyConfig();
-                    mpc.setName(field.getName());
+                    String name = property.name();
+                    if (name == null) {
+                        name = field.getName();
+                    }
+                    mpc.setName(name);
                     mpc.setType(field.getType().getName()); // FIXME - 
primitives, arrays, etc.
                     mpc.setValue(property.value());
                     mbc.addProperty(mpc);

Modified: 
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/managed/Property.java
URL: 
http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/managed/Property.java?rev=417355&r1=417354&r2=417355&view=diff
==============================================================================
--- 
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/managed/Property.java
 (original)
+++ 
struts/shale/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/managed/Property.java
 Mon Jun 26 23:40:21 2006
@@ -25,13 +25,23 @@
  * <p>Field-level annotation indicating that the decorated field should be
  * initialized to a literal or value binding expression value specified by the
  * <code>value</code> attribute, when a managed instance of the containing
- * class is instantiated.</p>
+ * class is instantiated.  If desired, you may also specify the property name
+ * that corresponds to the annotated field, rather than relying on the default
+ * assumption that the field name is identical to the property name.</p>
  *
  * @since 1.0.3
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.FIELD)
 public @interface Property {
+
+    /**
+     * <p>The name of the JavaBeans property to which this annotation 
corresponds.
+     * If not specified, the name of the field
+     * is presumed to be the name of the property as well.</p>
+     */
+    String name() default "";
+
 
     /**
      * <p>The string representation of the literal value, or value

Modified: 
struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean.java
URL: 
http://svn.apache.org/viewvc/struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean.java?rev=417355&r1=417354&r2=417355&view=diff
==============================================================================
--- 
struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean.java
 (original)
+++ 
struts/shale/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean.java
 Mon Jun 26 23:40:21 2006
@@ -34,8 +34,8 @@
     /**
      * Holds value of property byteProperty.
      */
-    @Property("-1")
-    private byte byteProperty = (byte) 1;
+    @Property(name="byteProperty", value="-1")
+    private byte m_byteProperty = (byte) 1;
 
     /**
      * Getter for property byteProperty.
@@ -43,7 +43,7 @@
      */
     public byte getByteProperty() {
 
-        return this.byteProperty;
+        return this.m_byteProperty;
     }
 
     /**


Reply via email to