myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r712155 - /myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java
Date Fri, 07 Nov 2008 15:16:36 GMT
Author: skitching
Date: Fri Nov  7 07:16:23 2008
New Revision: 712155

URL: http://svn.apache.org/viewvc?rev=712155&view=rev
Log:
Get rid of reflection stuff now that orchestra-flow requires JSF1.2 or later.

Modified:
    myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java

Modified: myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java?rev=712155&r1=712154&r2=712155&view=diff
==============================================================================
--- myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java
(original)
+++ myfaces/orchestra/trunk/flow/src/main/java/org/apache/myfaces/orchestra/flow/FlowViewHandler.java
Fri Nov  7 07:16:23 2008
@@ -18,28 +18,14 @@
  */
 package org.apache.myfaces.orchestra.flow;
 
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.Locale;
-
-import javax.faces.FacesException;
 import javax.faces.application.ViewHandler;
+import javax.faces.application.ViewHandlerWrapper;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 
-import org.apache.myfaces.orchestra.lib.OrchestraException;
-
 /**
  * Custom ViewHandler that executes the necessary logic to handle entering and exiting a
Flow.
  * <p>
- * Warning: this class is fragile when later JSF specifications add new methods. The method
is then
- * not properly delegated and instead just falls back to the base class implementation. For
upwards
- * compatibility, we could subclass from ViewHandlerWrapper - but that code would then fail
to run
- * on JSF1.1. Ecch. This class therefore subclasses ViewHandler directly then adds implementations
of
- * all methods added in JSF1.2, and uses reflection to invoke them on the underlying implementation.
- * This is of course not a "real" solution as there will be problems if a later JSF specification
adds
- * more methods. But it does make this class work for both JSF1.1 and JSF1.2.
- * <p>
  * Combining this class with other ViewHandlers can cause unexpected results, particularly
when
  * libararies in the classpath include faces-config.xml files that automatically register
custom
  * ViewHandler classes as in that case the order of ViewHandler nesting is hard to control.
The most
@@ -47,44 +33,11 @@
  * class only actually cares about the createView method, and Facelets does not do anything
significant
  * in its createView implementation.
  */
-public class FlowViewHandler extends ViewHandler
+public class FlowViewHandler extends ViewHandlerWrapper
 {
-    private static final Method CALC_CHAR_ENC_METHOD;
-    private static final Method INIT_VIEW_METHOD;
-
     private ViewHandler delegate;
 
     /**
-     * Static initialization block.
-     */
-    static
-    {
-        CALC_CHAR_ENC_METHOD = getMethodOpt(ViewHandler.class,
-                "calculateCharacterEncoding",
-                new Class[] {FacesContext.class});
-
-        INIT_VIEW_METHOD = getMethodOpt(ViewHandler.class,
-                "initView",
-                new Class[] {FacesContext.class});
-    }
-
-    /**
-     * If the specified class has a method with the specified name and params, return
-     * it else return null.
-     */
-    private static Method getMethodOpt(Class clazz, String methodName, Class[] args)
-    {
-        try
-        {
-            return clazz.getMethod(methodName, args);
-        }
-        catch(NoSuchMethodException e)
-        {
-            return null;
-        }
-    }
-
-    /**
      * Constructor.
      */
     public FlowViewHandler(ViewHandler delegate)
@@ -92,86 +45,10 @@
         this.delegate = delegate;
     }
 
-    /**
-     * Delegate to wrapped instance. 
-     * <p>
-     * This method was added in JSF1.2. We must therefore use reflection
-     * to invoke the method on the wrapped instance. Note that this method
-     * is never invoked unless this is a JSF1.2 environment. 
-     */
-    public java.lang.String calculateCharacterEncoding(FacesContext context)
-    {
-        try
-        {
-            Object ret = CALC_CHAR_ENC_METHOD.invoke(delegate, new Object[] {context});
-            return (String) ret;
-        }
-        catch(Exception e)
-        {
-            throw new OrchestraException("Unable to invoke calculateCharacterEncoding on
wrapped ViewHandler");
-        }
-    }
-
-    /**
-     * Delegate to wrapped instance. 
-     * <p>
-     * This method was added in JSF1.2. We must therefore use reflection
-     * to invoke the method on the wrapped instance. Note that this method
-     * is never invoked unless this is a JSF1.2 environment. 
-     */
-    public void initView(FacesContext context)
-    throws FacesException
-    {
-        try
-        {
-            INIT_VIEW_METHOD.invoke(delegate, new Object[] {context});
-        }
-        catch(Exception e)
-        {
-            throw new OrchestraException("Unable to invoke initView on wrapped ViewHandler");
-        }
-    }
-
-    /** Delegate to wrapped instance. */ 
-    public Locale calculateLocale(FacesContext context)
-    {
-        return delegate.calculateLocale(context);
-    }
-
-    /** Delegate to wrapped instance. */ 
-    public String calculateRenderKitId(FacesContext context)
-    {
-        return delegate.calculateRenderKitId(context);
-    }
-
-    /** Delegate to wrapped instance. */ 
-    public String getActionURL(FacesContext context, String viewId)
-    {
-        return delegate.getActionURL(context, viewId);
-    }
-
-    /** Delegate to wrapped instance. */ 
-    public String getResourceURL(FacesContext context, String path)
-    {
-        return delegate.getResourceURL(context, path);
-    }
-
-    /** Delegate to wrapped instance. */ 
-    public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException,
FacesException
-    {
-        delegate.renderView(context, viewToRender);
-    }
-
-    /** Delegate to wrapped instance. */ 
-    public void writeState(FacesContext context) throws IOException
-    {
-        delegate.writeState(context);
-    }
-
-    /** Delegate to wrapped instance. */ 
-    public UIViewRoot restoreView(FacesContext context, String viewId)
+    @Override
+    protected ViewHandler getWrapped()
     {
-        return delegate.restoreView(context, viewId);
+        return delegate;
     }
 
     /**



Mime
View raw message