shale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject svn commit: r477909 - in /shale/framework/trunk/shale-tiger: ./ src/main/java/org/apache/shale/tiger/view/faces/ src/test/java/org/apache/shale/tiger/config/ src/test/java/org/apache/shale/tiger/faces/ src/test/java/org/apache/shale/tiger/view/faces/
Date Tue, 21 Nov 2006 21:46:37 GMT
Author: craigmcc
Date: Tue Nov 21 13:46:36 2006
New Revision: 477909

URL: http://svn.apache.org/viewvc?view=rev&rev=477909
Log:
Scan fields in superclasses for annotations, as well as the originally
annotated class.  Thanks to Ingo Dueppe for the patch!

SHALE-190

Added:
    shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean2.java
  (with props)
Modified:
    shale/framework/trunk/shale-tiger/pom.xml
    shale/framework/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java
    shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/VariableResolverImplTestCase.java
    shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/view/faces/LifecycleListener2TestCase.java

Modified: shale/framework/trunk/shale-tiger/pom.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-tiger/pom.xml?view=diff&rev=477909&r1=477908&r2=477909
==============================================================================
--- shale/framework/trunk/shale-tiger/pom.xml (original)
+++ shale/framework/trunk/shale-tiger/pom.xml Tue Nov 21 13:46:36 2006
@@ -152,6 +152,8 @@
                                 <mkdir dir="${basedir}/target/test-webapp/WEB-INF/classes/org/apache/shale/tiger/config"/>
                                 <copy todir="${basedir}/target/test-webapp/WEB-INF/classes/org/apache/shale/tiger/config"
                                       file="${basedir}/target/test-classes/org/apache/shale/tiger/config/TestBean.class"/>
+                                <copy todir="${basedir}/target/test-webapp/WEB-INF/classes/org/apache/shale/tiger/config"
+                                      file="${basedir}/target/test-classes/org/apache/shale/tiger/config/TestBean2.class"/>
                                 <mkdir dir="${basedir}/target/test-webapp/WEB-INF/classes/org/apache/shale/tiger/faces"/>
                                 <copy todir="${basedir}/target/test-webapp/WEB-INF/classes/org/apache/shale/tiger/faces">
                                     <fileset dir="${basedir}/target/test-classes/org/apache/shale/tiger/faces"

Modified: shale/framework/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java?view=diff&rev=477909&r1=477908&r2=477909
==============================================================================
--- shale/framework/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java
(original)
+++ shale/framework/trunk/shale-tiger/src/main/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java
Tue Nov 21 13:46:36 2006
@@ -1026,6 +1026,29 @@
 
 
     /**
+     * <p>Return an array of all <code>Field</code>s reflecting declared
+     * fields in this class, or in any superclass other than
+     * <code>java.lang.Object</code>.</p>
+     *
+     * @param clazz Class to be analyzed
+     */
+    private Field[] fields(Class clazz) {
+
+        Map<String,Field> fields = new HashMap<String,Field>();
+        do {
+            for (Field field : clazz.getDeclaredFields()) {
+                if (!fields.containsKey(field.getName())) {
+                    fields.put(field.getName(), field);
+                }
+            }
+        } while ((clazz = clazz.getSuperclass()) != Object.class);
+        return (Field[]) fields.values().toArray(new Field[fields.size()]);
+
+    }
+
+
+
+    /**
      * <p>Return a list of URLs to implicit configuration resources
      * embedded in this application.</p>
      *
@@ -1394,8 +1417,8 @@
                 default:
                     break;
             }
-            // FIXME - should we look for inherited fields with @Property/@Value too?
-            for (Field field : clazz.getDeclaredFields()) {
+            Field[] fields = fields(clazz);
+            for (Field field : fields) {
                 if (log().isTraceEnabled()) {
                     log().trace("  Scanning field '" + field.getName() + "'");
                 }

Added: shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean2.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean2.java?view=auto&rev=477909
==============================================================================
--- shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean2.java
(added)
+++ shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean2.java
Tue Nov 21 13:46:36 2006
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+
+package org.apache.shale.tiger.config;
+
+import org.apache.shale.tiger.managed.Bean;
+import org.apache.shale.tiger.managed.Property;
+import org.apache.shale.tiger.managed.Scope;
+import org.apache.shale.tiger.managed.Value;
+
+/**
+ * <p>JavaBean class for testing.</p>
+ */
+@Bean(name="bean2a", scope=Scope.APPLICATION)
+public class TestBean2 extends TestBean {
+    
+    /** Creates a new instance of TestBean2 */
+    public TestBean2() {
+    }
+
+    /**
+     * Holds value of property xtraProperty.
+     */
+    @Value("Xtra Override")
+    private String xtraProperty = "Xtra";
+
+    /**
+     * Getter for property xtraProperty.
+     * @return Value of property xtraProperty.
+     */
+    public String getXtraProperty() {
+
+        return this.xtraProperty;
+    }
+
+    /**
+     * Setter for property xtraProperty.
+     * @param xtraProperty New value of property xtraProperty.
+     */
+    public void setXtraProperty(String xtraProperty) {
+
+        this.xtraProperty = xtraProperty;
+    }
+
+}

Propchange: shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/config/TestBean2.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/VariableResolverImplTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/VariableResolverImplTestCase.java?view=diff&rev=477909&r1=477908&r2=477909
==============================================================================
--- shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/VariableResolverImplTestCase.java
(original)
+++ shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/faces/VariableResolverImplTestCase.java
Tue Nov 21 13:46:36 2006
@@ -219,7 +219,7 @@
             externalContext.getApplicationMap().
             get(LifecycleListener2.FACES_CONFIG_CONFIG);
         assertNotNull(config);
-        assertEquals(8, config.getManagedBeans().size());
+        assertEquals(9, config.getManagedBeans().size());
 
     }
 

Modified: shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/view/faces/LifecycleListener2TestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/view/faces/LifecycleListener2TestCase.java?view=diff&rev=477909&r1=477908&r2=477909
==============================================================================
--- shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/view/faces/LifecycleListener2TestCase.java
(original)
+++ shale/framework/trunk/shale-tiger/src/test/java/org/apache/shale/tiger/view/faces/LifecycleListener2TestCase.java
Tue Nov 21 13:46:36 2006
@@ -162,7 +162,7 @@
         assertNotNull(config);
         Map<String,ManagedBeanConfig> mbMap = fcConfig.getManagedBeans();
         assertNotNull(mbMap);
-        assertEquals(8, mbMap.size());
+        assertEquals(9, mbMap.size());
 
         ManagedPropertyConfig mpConfig = null;
 
@@ -299,6 +299,91 @@
         assertEquals("stringProperty", mpConfig.getName());
         assertEquals("java.lang.String", mpConfig.getType());
         assertEquals("Override The Annotation", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        // Validate configuration of bean2a
+        ManagedBeanConfig bean2a = fcConfig.getManagedBean("bean2a");
+        assertNotNull(bean2a);
+        assertTrue(bean2a == mbMap.get("bean2a"));
+        assertEquals("bean2a", bean2a.getName());
+        assertEquals("org.apache.shale.tiger.config.TestBean2", bean2a.getType());
+        assertEquals("application", bean2a.getScope());
+        assertNull(bean2a.getListEntries());
+        assertNull(bean2a.getMapEntries());
+        Map<String,ManagedPropertyConfig> bean2aMap = bean2a.getProperties();
+        assertNotNull(bean2aMap);
+        assertEquals(9, bean2aMap.size());
+
+        mpConfig = bean2a.getProperty("byteProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("byteProperty"));
+        assertEquals("byteProperty", mpConfig.getName());
+        assertEquals("byte", mpConfig.getType());
+        assertEquals("-1", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("charProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("charProperty"));
+        assertEquals("charProperty", mpConfig.getName());
+        assertEquals("char", mpConfig.getType());
+        assertEquals("z", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("doubleProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("doubleProperty"));
+        assertEquals("doubleProperty", mpConfig.getName());
+        assertEquals("double", mpConfig.getType());
+        assertEquals("-2.0", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("floatProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("floatProperty"));
+        assertEquals("floatProperty", mpConfig.getName());
+        assertEquals("float", mpConfig.getType());
+        assertEquals("-3.0", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("intProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("intProperty"));
+        assertEquals("intProperty", mpConfig.getName());
+        assertEquals("int", mpConfig.getType());
+        assertEquals("-4", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("longProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("longProperty"));
+        assertEquals("longProperty", mpConfig.getName());
+        assertEquals("long", mpConfig.getType());
+        assertEquals("-5", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("shortProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("shortProperty"));
+        assertEquals("shortProperty", mpConfig.getName());
+        assertEquals("short", mpConfig.getType());
+        assertEquals("-6", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("stringProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("stringProperty"));
+        assertEquals("stringProperty", mpConfig.getName());
+        assertEquals("java.lang.String", mpConfig.getType());
+        assertEquals("Annotated", mpConfig.getValue());
+        assertTrue(!mpConfig.isNullValue());
+
+        mpConfig = bean2a.getProperty("xtraProperty");
+        assertNotNull(mpConfig);
+        assertTrue(mpConfig == bean2aMap.get("xtraProperty"));
+        assertEquals("xtraProperty", mpConfig.getName());
+        assertEquals("java.lang.String", mpConfig.getType());
+        assertEquals("Xtra Override", mpConfig.getValue());
         assertTrue(!mpConfig.isNullValue());
 
         // Validate configuration of bean3



Mime
View raw message