You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2009/07/26 13:21:31 UTC

svn commit: r797905 - in /tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles: evaluator/el/ evaluator/mvel/ evaluator/ognl/ util/

Author: apetrelli
Date: Sun Jul 26 11:21:31 2009
New Revision: 797905

URL: http://svn.apache.org/viewvc?rev=797905&view=rev
Log:
TILES-434
Refactored TilesRequestContextBeanInfo into CombinedBeanInfo and now accepts generic classes.

Added:
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/CombinedBeanInfo.java
      - copied, changed from r788728, tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesRequestContextBeanInfo.java
Removed:
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesRequestContextBeanInfo.java
Modified:
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesContextELResolver.java
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/mvel/TilesContextVariableResolverFactory.java
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/ognl/TilesContextPropertyAccessorDelegateFactory.java

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesContextELResolver.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesContextELResolver.java?rev=797905&r1=797904&r2=797905&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesContextELResolver.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesContextELResolver.java Sun Jul 26 11:21:31 2009
@@ -28,6 +28,7 @@
 
 import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.context.TilesRequestContext;
+import org.apache.tiles.util.CombinedBeanInfo;
 
 /**
  * Resolves properties of {@link TilesRequestContext} and
@@ -41,7 +42,8 @@
     /**
      * The beaninfos about {@link TilesRequestContext} and {@link TilesApplicationContext}.
      */
-    private TilesRequestContextBeanInfo requestBeanInfo = new TilesRequestContextBeanInfo();
+    private CombinedBeanInfo requestBeanInfo = new CombinedBeanInfo(
+            TilesRequestContext.class, TilesApplicationContext.class);
 
     /** {@inheritDoc} */
     @Override
@@ -75,11 +77,11 @@
         }
 
         Class<?> retValue = null;
-        if (requestBeanInfo.getRequestProperties().contains(property)) {
+        if (requestBeanInfo.getProperties(TilesRequestContext.class).contains(property)) {
             TilesRequestContext request = (TilesRequestContext) context
                     .getContext(TilesRequestContext.class);
             retValue = super.getType(context, request, property);
-        } else if (requestBeanInfo.getApplicationProperties().contains(property)) {
+        } else if (requestBeanInfo.getProperties(TilesApplicationContext.class).contains(property)) {
             TilesApplicationContext applicationContext = (TilesApplicationContext) context
                     .getContext(TilesApplicationContext.class);
             retValue = super.getType(context, applicationContext, property);
@@ -102,11 +104,12 @@
 
         Object retValue = null;
 
-        if (requestBeanInfo.getRequestProperties().contains(property)) {
+        if (requestBeanInfo.getProperties(TilesRequestContext.class).contains(property)) {
             TilesRequestContext request = (TilesRequestContext) context
                     .getContext(TilesRequestContext.class);
             retValue = super.getValue(context, request, property);
-        } else if (requestBeanInfo.getApplicationProperties().contains(property)) {
+        } else if (requestBeanInfo.getProperties(TilesApplicationContext.class)
+                .contains(property)) {
             TilesApplicationContext applicationContext = (TilesApplicationContext) context
                     .getContext(TilesApplicationContext.class);
             retValue = super.getValue(context, applicationContext, property);

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/mvel/TilesContextVariableResolverFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/mvel/TilesContextVariableResolverFactory.java?rev=797905&r1=797904&r2=797905&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/mvel/TilesContextVariableResolverFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/mvel/TilesContextVariableResolverFactory.java Sun Jul 26 11:21:31 2009
@@ -26,9 +26,11 @@
 import java.lang.reflect.Method;
 import java.util.HashMap;
 
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.context.TilesRequestContext;
 import org.apache.tiles.context.TilesRequestContextHolder;
-import org.apache.tiles.evaluator.el.TilesRequestContextBeanInfo;
 import org.apache.tiles.reflect.CannotAccessMethodException;
+import org.apache.tiles.util.CombinedBeanInfo;
 import org.mvel2.integration.VariableResolver;
 import org.mvel2.integration.impl.BaseVariableResolverFactory;
 
@@ -51,7 +53,8 @@
      * Beaninfo about {@link org.apache.tiles.context.TilesRequestContext} and
      * {@link org.apache.tiles.TilesApplicationContext}.
      */
-    private TilesRequestContextBeanInfo requestBeanInfo = new TilesRequestContextBeanInfo();
+    private CombinedBeanInfo requestBeanInfo = new CombinedBeanInfo(
+            TilesRequestContext.class, TilesApplicationContext.class);
 
     /**
      * Constructor.
@@ -62,11 +65,13 @@
     public TilesContextVariableResolverFactory(TilesRequestContextHolder requestHolder) {
         this.requestHolder = requestHolder;
         variableResolvers = new HashMap<String, VariableResolver>();
-        for (PropertyDescriptor descriptor : requestBeanInfo.getRequestDescriptors().values()) {
+        for (PropertyDescriptor descriptor : requestBeanInfo
+                .getMappedDescriptors(TilesRequestContext.class).values()) {
             String descriptorName = descriptor.getName();
             variableResolvers.put(descriptorName, new RequestVariableResolver(descriptorName));
         }
-        for (PropertyDescriptor descriptor : requestBeanInfo.getApplicationDescriptors().values()) {
+        for (PropertyDescriptor descriptor : requestBeanInfo
+                .getMappedDescriptors(TilesApplicationContext.class).values()) {
             String descriptorName = descriptor.getName();
             variableResolvers.put(descriptorName, new ApplicationVariableResolver(descriptorName));
         }
@@ -128,7 +133,8 @@
          */
         public RequestVariableResolver(String name) {
             this.name = name;
-            descriptor = requestBeanInfo.getRequestDescriptors().get(name);
+            descriptor = requestBeanInfo.getMappedDescriptors(
+                    TilesRequestContext.class).get(name);
         }
 
         /** {@inheritDoc} */
@@ -211,7 +217,8 @@
          */
         public ApplicationVariableResolver(String name) {
             this.name = name;
-            descriptor = requestBeanInfo.getApplicationDescriptors().get(name);
+            descriptor = requestBeanInfo.getMappedDescriptors(
+                    TilesApplicationContext.class).get(name);
         }
 
         /** {@inheritDoc} */

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/ognl/TilesContextPropertyAccessorDelegateFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/ognl/TilesContextPropertyAccessorDelegateFactory.java?rev=797905&r1=797904&r2=797905&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/ognl/TilesContextPropertyAccessorDelegateFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/ognl/TilesContextPropertyAccessorDelegateFactory.java Sun Jul 26 11:21:31 2009
@@ -25,8 +25,9 @@
 
 import ognl.PropertyAccessor;
 
+import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.context.TilesRequestContext;
-import org.apache.tiles.evaluator.el.TilesRequestContextBeanInfo;
+import org.apache.tiles.util.CombinedBeanInfo;
 
 /**
  * Decides the appropriate {@link PropertyAccessor} for the given property name
@@ -68,7 +69,7 @@
      * The bean info of {@link TilesRequestContext} and
      * {@link org.apache.tiles.TilesApplicationContext}.
      */
-    private TilesRequestContextBeanInfo beanInfo;
+    private CombinedBeanInfo beanInfo;
 
     /**
      * Constructor.
@@ -89,7 +90,7 @@
             PropertyAccessor requestScopePropertyAccessor,
             PropertyAccessor sessionScopePropertyAccessor,
             PropertyAccessor applicationScopePropertyAccessor) {
-        beanInfo = new TilesRequestContextBeanInfo();
+        beanInfo = new CombinedBeanInfo(TilesRequestContext.class, TilesApplicationContext.class);
         this.objectPropertyAccessor = objectPropertyAccessor;
         this.applicationContextPropertyAccessor = applicationContextPropertyAccessor;
         this.requestScopePropertyAccessor = requestScopePropertyAccessor;
@@ -101,10 +102,11 @@
     public PropertyAccessor getPropertyAccessor(String propertyName,
             TilesRequestContext request) {
         PropertyAccessor retValue;
-        if (beanInfo.getRequestDescriptors().containsKey(propertyName)) {
+        if (beanInfo.getMappedDescriptors(TilesRequestContext.class)
+                .containsKey(propertyName)) {
             retValue = objectPropertyAccessor;
-        } else if (beanInfo.getApplicationDescriptors().containsKey(
-                propertyName)) {
+        } else if (beanInfo.getMappedDescriptors(TilesApplicationContext.class)
+                .containsKey(propertyName)) {
             retValue = applicationContextPropertyAccessor;
         } else {
             Map<String, Object> scopeMap = request.getRequestScope();

Copied: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/CombinedBeanInfo.java (from r788728, tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesRequestContextBeanInfo.java)
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/CombinedBeanInfo.java?p2=tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/CombinedBeanInfo.java&p1=tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesRequestContextBeanInfo.java&r1=788728&r2=797905&rev=797905&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/evaluator/el/TilesRequestContextBeanInfo.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/CombinedBeanInfo.java Sun Jul 26 11:21:31 2009
@@ -19,7 +19,7 @@
  * under the License.
  */
 
-package org.apache.tiles.evaluator.el;
+package org.apache.tiles.util;
 
 import java.beans.FeatureDescriptor;
 import java.beans.PropertyDescriptor;
@@ -29,51 +29,45 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.tiles.TilesApplicationContext;
-import org.apache.tiles.context.TilesRequestContext;
 import org.apache.tiles.reflect.ClassUtil;
 
 /**
- * Contains the bean infos about {@link TilesRequestContext} and
- * {@link TilesApplicationContext} classes.
+ * Contains the bean infos about one or more classes.
  *
  * @version $Rev$ $Date$
  * @since 2.2.0
  */
-public class TilesRequestContextBeanInfo {
+public class CombinedBeanInfo {
     /**
-     * The descriptors of {@link TilesRequestContext} and
-     * {@link TilesApplicationContext}.
+     * The descriptors of the introspected classes.
      */
     private List<FeatureDescriptor> descriptors;
 
     /**
-     * Maps names of properties of {@link TilesRequestContext} to their descriptors.
+     * Maps analyzed classes to the map of introspected properties.
      */
-    private Map<String, PropertyDescriptor> requestDescriptors;
-
-    /**
-     * Maps names of properties of {@link TilesApplicationContext} to their descriptors.
-     */
-    private Map<String, PropertyDescriptor> applicationDescriptors;
+    private Map<Class<?>, Map<String, PropertyDescriptor>> class2descriptors;
 
     /**
      * Constructor.
+     * @param clazzes The list of classes to analyze and combine.
      *
      * @since 2.2.0
      */
-    public TilesRequestContextBeanInfo() {
+    public CombinedBeanInfo(Class<?>... clazzes) {
         descriptors = new ArrayList<FeatureDescriptor>();
-        requestDescriptors = new LinkedHashMap<String, PropertyDescriptor>();
-        applicationDescriptors = new LinkedHashMap<String, PropertyDescriptor>();
-        ClassUtil.collectBeanInfo(TilesRequestContext.class, requestDescriptors);
-        ClassUtil.collectBeanInfo(TilesApplicationContext.class, applicationDescriptors);
-        descriptors.addAll(requestDescriptors.values());
-        descriptors.addAll(applicationDescriptors.values());
+        class2descriptors = new LinkedHashMap<Class<?>, Map<String, PropertyDescriptor>>();
+        for (int i = 0; i < clazzes.length; i++) {
+            Class<?> clazz = clazzes[i];
+            Map<String, PropertyDescriptor> mappedDescriptors = new LinkedHashMap<String, PropertyDescriptor>();
+            ClassUtil.collectBeanInfo(clazz, mappedDescriptors);
+            descriptors.addAll(mappedDescriptors.values());
+            class2descriptors.put(clazz, mappedDescriptors);
+        }
     }
 
     /**
-     * Returns the descriptors read by this object.
+     * Returns the descriptors of all the introspected classes.
      *
      * @return The feature descriptors.
      * @since 2.2.0
@@ -83,45 +77,24 @@
     }
 
     /**
-     * Returns the request property descriptors, mapped to their property names.
-     *
-     * @return A map in the form: name of the property -> the property
-     * descriptor.
-     * @since 2.2.0
-     */
-    public Map<String, PropertyDescriptor> getRequestDescriptors() {
-        return requestDescriptors;
-    }
-
-    /**
-     * Returns the application context property descriptors, mapped to their
-     * property names.
-     *
-     * @return A map in the form: name of the property -> the property
-     * descriptor.
-     * @since 2.2.0
-     */
-    public Map<String, PropertyDescriptor> getApplicationDescriptors() {
-        return applicationDescriptors;
-    }
-
-    /**
-     * Returns the set of the property names of {@link TilesRequestContext}.
+     * Returns a map of the introspected properties for the given class.
      *
-     * @return The property names.
+     * @param clazz The class to get the properties from.
+     * @return The map of property descriptors.
      * @since 2.2.0
      */
-    public Set<String> getRequestProperties() {
-        return requestDescriptors.keySet();
+    public Map<String, PropertyDescriptor> getMappedDescriptors(Class<?> clazz) {
+        return class2descriptors.get(clazz);
     }
 
     /**
-     * Returns the set of the property names of {@link TilesApplicationContext}.
+     * Returns the set of properties for the given introspected class.
      *
-     * @return The property names.
+     * @param clazz The class to get the properties from.
+     * @return The set of properties.
      * @since 2.2.0
      */
-    public Set<String> getApplicationProperties() {
-        return applicationDescriptors.keySet();
+    public Set<String> getProperties(Class<?> clazz) {
+        return class2descriptors.get(clazz).keySet();
     }
 }