Author: apetrelli
Date: Sun Jul 27 08:20:00 2008
New Revision: 680124

URL: http://svn.apache.org/viewvc?rev=680124&view=rev
Log:
TILES-286
Merge from trunk to TILES_2_0_X branch.
Now method calling via reflection forces the method to be accessible.
Moved ClassUtil in tiles-api.
Added @since tags.

Added:
    
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/
   (props changed)
      - copied from r680116, 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/
    
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
      - copied, changed from r680116, 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
    
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/package.html
      - copied unchanged from r680116, 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/package.html
Modified:
    
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
    
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactory.java
    
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
    
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/preparer/BasicPreparerFactory.java

Modified: 
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java?rev=680124&r1=680123&r2=680124&view=diff
==============================================================================
--- 
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
 (original)
+++ 
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
 Sun Jul 27 08:20:00 2008
@@ -25,6 +25,7 @@
 import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.TilesContainer;
 import org.apache.tiles.TilesException;
+import org.apache.tiles.reflect.ClassUtil;
 
 import java.lang.reflect.Method;
 
@@ -121,8 +122,9 @@
     private static Object getAttribute(Object context, String attributeName) {
         try {
             Class<?> contextClass = context.getClass();
-            Method attrMethod = contextClass.getMethod("getAttribute", 
String.class);
-            return attrMethod.invoke(context, attributeName);
+            Method attrMethod = ClassUtil.getForcedAccessibleMethod(
+                    contextClass, "getAttribute", String.class);
+            return ClassUtil.invokeMethod(context, attrMethod, attributeName);
         } catch (Exception e) {
             LOG.warn("Unable to retrieve container from specified context: '" 
+ context + "'", e);
             return null;
@@ -140,13 +142,10 @@
      */
     private static void setAttribute(Object context, String name, Object value)
         throws TilesException {
-        try {
-            Class<?> contextClass = context.getClass();
-            Method attrMethod = contextClass.getMethod("setAttribute", 
String.class, Object.class);
-            attrMethod.invoke(context, name, value);
-        } catch (Exception e) {
-            throw new TilesException("Unable to set attribute for specified 
context: '" + context + "'");
-        }
+        Class<?> contextClass = context.getClass();
+        Method attrMethod = ClassUtil.getForcedAccessibleMethod(
+                contextClass, "setAttribute", String.class, Object.class);
+        ClassUtil.invokeMethod(context, attrMethod, name, value);
     }
 
     /**
@@ -158,12 +157,9 @@
      */
     private static void removeAttribute(Object context, String name)
         throws TilesException {
-        try {
-            Class<?> contextClass = context.getClass();
-            Method attrMethod = contextClass.getMethod("removeAttribute", 
String.class);
-            attrMethod.invoke(context, name);
-        } catch (Exception e) {
-            throw new TilesException("Unable to remove attribute for specified 
context: '" + context + "'");
-        }
+        Class<?> contextClass = context.getClass();
+        Method attrMethod = ClassUtil.getForcedAccessibleMethod(
+                contextClass, "removeAttribute", String.class);
+        ClassUtil.invokeMethod(context, attrMethod, name);
     }
 }

Propchange: 
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: 
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
 (from r680116, 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java)
URL: 
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java?p2=tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java&p1=tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java&r1=680116&r2=680124&rev=680124&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
 (original)
+++ 
tiles/framework/branches/TILES_2_0_X/tiles-api/src/main/java/org/apache/tiles/reflect/ClassUtil.java
 Sun Jul 27 08:20:00 2008
@@ -23,6 +23,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
+import org.apache.tiles.TilesException;
+
 
 /**
  * Utilities to work with dynamic class loading and instantiation.
@@ -44,11 +46,11 @@
      *
      * @param className The class name to load and to instantiate.
      * @return The new instance of the class name.
-     * @throws CannotInstantiateObjectException If something goes wrong during
+     * @throws TilesException If something goes wrong during
      * instantiation.
      * @since 2.0.7
      */
-    public static Object instantiate(String className) {
+    public static Object instantiate(String className) throws TilesException {
         return instantiate(className, false);
     }
 
@@ -61,10 +63,11 @@
      * returns <code>true</code>, otherwise it throws a
      * <code>TilesException</code>.
      * @return The new instance of the class name.
-     * @throws CannotInstantiateObjectException If something goes wrong during 
instantiation.
+     * @throws TilesException If something goes wrong during instantiation.
      * @since 2.0.7
      */
-    public static Object instantiate(String className, boolean returnNull) {
+    public static Object instantiate(String className, boolean returnNull)
+            throws TilesException {
         ClassLoader original = Thread.currentThread().getContextClassLoader();
         if (original == null) {
             
Thread.currentThread().setContextClassLoader(ClassUtil.class.getClassLoader());
@@ -76,13 +79,13 @@
             if (returnNull) {
                 return null;
             }
-            throw new CannotInstantiateObjectException(
+            throw new TilesException(
                     "Unable to resolve factory class: '" + className + "'", e);
         } catch (IllegalAccessException e) {
-            throw new CannotInstantiateObjectException(
+            throw new TilesException(
                     "Unable to access factory class: '" + className + "'", e);
         } catch (InstantiationException e) {
-            throw new CannotInstantiateObjectException(
+            throw new TilesException(
                     "Unable to instantiate factory class: '"
                             + className
                             + "'. Make sure that this class has a default 
constructor",
@@ -99,19 +102,21 @@
      * @param methodName The name of the method.
      * @param parameterTypes The parameter types that the method must match.
      * @return The method, if it is found.
+     * @throws TilesException If something goes when getting the method.
      * @since 2.0.7
      */
     public static Method getForcedAccessibleMethod(Class<?> clazz,
-            String methodName, Class<?>... parameterTypes) {
+            String methodName, Class<?>... parameterTypes)
+            throws TilesException {
         Method method;
         try {
             method = clazz.getMethod(methodName, parameterTypes);
         } catch (SecurityException e) {
-            throw new CannotAccessMethodException("Cannot access method '"
+            throw new TilesException("Cannot access method '"
                     + methodName + "' in class '" + clazz.getName()
                     + "' for security reasons", e);
         } catch (NoSuchMethodException e) {
-            throw new CannotAccessMethodException("The method '"
+            throw new TilesException("The method '"
                     + methodName + "' in class '" + clazz.getName()
                     + "' does not exist", e);
         }
@@ -128,21 +133,23 @@
      * @param method The method to call.
      * @param args The arguments of the method.
      * @return The object returned, if the method is not "void".
+     * @throws TilesException If something goes when invoking the method.
      * @since 2.0.7
      */
-    public static Object invokeMethod(Object obj, Method method, Object... 
args) {
+    public static Object invokeMethod(Object obj, Method method, Object... 
args)
+            throws TilesException {
         try {
             return method.invoke(obj, args);
         } catch (IllegalArgumentException e) {
-            throw new CannotAccessMethodException("The arguments for '"
+            throw new TilesException("The arguments for '"
                     + method.getName() + "' in class '"
                     + obj.getClass().getName() + "' are not valid", e);
         } catch (IllegalAccessException e) {
-            throw new CannotAccessMethodException("Cannot access '"
+            throw new TilesException("Cannot access '"
                     + method.getName() + "' in class '"
                     + obj.getClass().getName() + "'", e);
         } catch (InvocationTargetException e) {
-            throw new CannotAccessMethodException(
+            throw new TilesException(
                     "An exception has been thrown inside '" + method.getName()
                     + "' in class '" + obj.getClass().getName() + "'", e);
         }

Modified: 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactory.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactory.java?rev=680124&r1=680123&r2=680124&view=diff
==============================================================================
--- 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactory.java
 (original)
+++ 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactory.java
 Sun Jul 27 08:20:00 2008
@@ -31,7 +31,7 @@
 import 
org.apache.tiles.impl.KeyedDefinitionsFactoryTilesContainer.KeyExtractor;
 import org.apache.tiles.impl.mgmt.CachingKeyedDefinitionsFactoryTilesContainer;
 import org.apache.tiles.mgmt.MutableTilesContainer;
-import org.apache.tiles.util.ClassUtil;
+import org.apache.tiles.reflect.ClassUtil;
 
 /**
  * Factory that creates instances of container that will extend the

Modified: 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java?rev=680124&r1=680123&r2=680124&view=diff
==============================================================================
--- 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
 (original)
+++ 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
 Sun Jul 27 08:20:00 2008
@@ -32,7 +32,7 @@
 import org.apache.tiles.mgmt.MutableTilesContainer;
 import org.apache.tiles.preparer.BasicPreparerFactory;
 import org.apache.tiles.preparer.PreparerFactory;
-import org.apache.tiles.util.ClassUtil;
+import org.apache.tiles.reflect.ClassUtil;
 
 import java.lang.reflect.Method;
 import java.util.Enumeration;

Modified: 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/preparer/BasicPreparerFactory.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/preparer/BasicPreparerFactory.java?rev=680124&r1=680123&r2=680124&view=diff
==============================================================================
--- 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/preparer/BasicPreparerFactory.java
 (original)
+++ 
tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/preparer/BasicPreparerFactory.java
 Sun Jul 27 08:20:00 2008
@@ -24,7 +24,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.tiles.TilesException;
 import org.apache.tiles.context.TilesRequestContext;
-import org.apache.tiles.util.ClassUtil;
+import org.apache.tiles.reflect.ClassUtil;
 
 import java.util.HashMap;
 import java.util.Map;


Reply via email to