myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r813787 - /myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/
Date Fri, 11 Sep 2009 11:58:46 GMT
Author: werpu
Date: Fri Sep 11 11:58:43 2009
New Revision: 813787

URL: http://svn.apache.org/viewvc?rev=813787&view=rev
Log:
http://issues.apache.org/jira/browse/EXTSCRIPT-1

ongoing jsf2 integration

Removed:
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ResourceHandlerProxy.java
Modified:
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ELResolverProxy.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/LifefcycleProxy.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/NavigationHandlerProxy.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java?rev=813787&r1=813786&r2=813787&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
Fri Sep 11 11:58:43 2009
@@ -32,10 +32,9 @@
 import javax.faces.convert.Converter;
 import javax.faces.el.*;
 import javax.faces.event.ActionListener;
-import javax.faces.event.SystemEventListener;
 import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
 import javax.faces.validator.Validator;
-import javax.servlet.ServletRequest;
 import java.lang.reflect.Proxy;
 import java.util.*;
 
@@ -50,17 +49,10 @@
 
     Application _delegate = null;
 
-    private boolean alreadyWovenInRequest(String clazz) {
-        //todo also enable portlets here
-        ServletRequest req = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
-        if (req.getAttribute(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz) == null) {
-            req.setAttribute(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz, "");
-            return false;
-        }
-        return false;
+    public ApplicationProxy(Application delegate) {
+        _delegate = delegate;
     }
 
-    //TODO add a proxy for the el resolvers as well
 
     public void addELResolver(ELResolver elResolver) {
         weaveDelegate();
@@ -285,12 +277,7 @@
         * code, in the renderer we do it on method base
         * due to the fact that our renderers are recycled via
         * a flyweight pattern*/
-        if (ProxyUtils.isDynamic(component.getClass()) && !alreadyWovenInRequest(component.toString()))
{
-            /*once it was tainted we have to recreate all the time*/
-            component = (UIComponent) ProxyUtils.getWeaver().reloadScriptingInstance(component);
-            alreadyWovenInRequest(component.toString());
-        }
-        return component;
+        return (UIComponent) reloadInstance(component);
     }
 
     public UIComponent createComponent(ValueBinding valueBinding, FacesContext facesContext,
String s) throws FacesException {
@@ -298,16 +285,11 @@
         UIComponent component = _delegate.createComponent(valueBinding, facesContext, s);
 
         /*we are reweaving on the fly because we cannot be sure if
-     * the class is not recycled all the time in the creation
-     * code, in the renderer we do it on method base
-     * due to the fact that our renderers are recycled via
-     * a flyweight pattern*/
-        if (ProxyUtils.isDynamic(component.getClass()) && !alreadyWovenInRequest(component.toString()))
{
-            /*once it was tainted we have to recreate all the time*/
-            component = (UIComponent) ProxyUtils.getWeaver().reloadScriptingInstance(component);
-            alreadyWovenInRequest(component.toString());
-        }
-        return component;
+         * the class is not recycled all the time in the creation
+         * code, in the renderer we do it on method base
+         * due to the fact that our renderers are recycled via
+         * a flyweight pattern*/
+        return (UIComponent) reloadInstance(component);
     }
 
     public Iterator<String> getComponentTypes() {
@@ -387,6 +369,7 @@
 
     public Validator createValidator(String s) throws FacesException {
         weaveDelegate();
+
         Validator retVal = _delegate.createValidator(s);
         if (ProxyUtils.isDynamic(retVal.getClass()) && !Proxy.isProxyClass(retVal.getClass()))
{
             retVal = (Validator) ProxyUtils.createMethodReloadingProxyFromObject(retVal,
Validator.class);
@@ -429,6 +412,10 @@
         //be enough for behavior replacements on the user side, which this mechanism should
         //cover for now
         boolean isDynamic = ProxyUtils.isDynamic(retVal.getClass());
+        //TODO Check how often the behavior is really created if only once
+        //we have to operate over reloading proxies nevertheless
+        //the add and remove behavior listeners being protected might
+        //be a showstopper because we cannot provide the same in our proxies
         if (!isDynamic) {
             return retVal;
         } else if (retVal instanceof BehaviorBase) {
@@ -455,7 +442,7 @@
     @Override
     public UIComponent createComponent(ValueExpression valueExpression, FacesContext facesContext,
String s, String s1) {
         weaveDelegate();
-        return _delegate.createComponent(valueExpression, facesContext, s, s1);
+        return (UIComponent) reloadInstance(_delegate.createComponent(valueExpression, facesContext,
s, s1));
     }
 
     @Override
@@ -490,15 +477,7 @@
     public ResourceHandler getResourceHandler() {
         weaveDelegate();
         ResourceHandler retVal = _delegate.getResourceHandler();
-        if (ProxyUtils.isDynamic(retVal.getClass())) {
-            //we use a proxy here to limit the reloads to some central
-            //points which have a lower calling frequency which is high enough
-            //to get it reloaded upon every request, but which should not drag
-            //down the entire system speedwise
-            retVal = (ResourceHandler) new ResourceHandlerProxy(retVal);
-            setResourceHandler(retVal);
-        }
-        return retVal;
+        return (ResourceHandler) reloadInstance(retVal);
     }
 
     @Override
@@ -543,12 +522,31 @@
         _delegate.unsubscribeFromEvent(aClass, systemEventListener);
     }
 
-    public ApplicationProxy(Application delegate) {
-        _delegate = delegate;
-    }
-
 
     public Object getDelegate() {
         return _delegate;  //To change body of implemented methods use File | Settings |
File Templates.
     }
+
+    private final Object reloadInstance(Object instance) {
+        if (instance == null) {
+            return null;
+        }
+        if (ProxyUtils.isDynamic(instance.getClass()) && !alreadyWovenInRequest(instance.toString()))
{
+            instance = ProxyUtils.getWeaver().reloadScriptingInstance(instance);
+            alreadyWovenInRequest(instance.toString());
+        }
+        return instance;
+    }
+
+
+    private final boolean alreadyWovenInRequest(String clazz) {
+        //portlets now can be enabled thanks to the jsf2 indirections regarding the external
context
+        Map<String, Object> req = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+        if (req.get(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz) == null) {
+            req.put(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz, "");
+            return false;
+        }
+        return true;
+    }
+
 }

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ELResolverProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ELResolverProxy.java?rev=813787&r1=813786&r2=813787&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ELResolverProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ELResolverProxy.java
Fri Sep 11 11:58:43 2009
@@ -38,10 +38,9 @@
  * @author Werner Punz
  */
 public class ELResolverProxy extends ELResolver implements Decorated {
-    Log log = LogFactory.getLog(ELResolverProxy.class);
-
 
-    //Map reinstantiated = new HashMap();
+    Log log = LogFactory.getLog(ELResolverProxy.class);
+    ELResolver _delegate = null;
 
 
     public Object getValue(ELContext elContext, final Object base, final Object property)
throws NullPointerException, PropertyNotFoundException, ELException {
@@ -94,7 +93,6 @@
         _delegate = delegate;
     }
 
-    ELResolver _delegate = null;
 
     public Object getDelegate() {
         return _delegate;  //To change body of implemented methods use File | Settings |
File Templates.

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/LifefcycleProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/LifefcycleProxy.java?rev=813787&r1=813786&r2=813787&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/LifefcycleProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/LifefcycleProxy.java
Fri Sep 11 11:58:43 2009
@@ -33,7 +33,7 @@
  */
 public class LifefcycleProxy extends Lifecycle implements Decorated {
 
- //   GroovyWeaver ProxyUtils.getWeaver() =  ProxyUtils.getWeaver();
+    Lifecycle _delegate = null;
 
     private void weaveDelegate() {
         if(_delegate != null)
@@ -74,7 +74,6 @@
         _delegate.render(facesContext);
     }
 
-    Lifecycle _delegate = null;
 
     public Object getDelegate() {
         return _delegate;  //To change body of implemented methods use File | Settings |
File Templates.

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/NavigationHandlerProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/NavigationHandlerProxy.java?rev=813787&r1=813786&r2=813787&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/NavigationHandlerProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/NavigationHandlerProxy.java
Fri Sep 11 11:58:43 2009
@@ -31,6 +31,8 @@
  */
 public class NavigationHandlerProxy extends NavigationHandler implements Decorated {
 
+    NavigationHandler _delegate;
+
     private void weaveDelegate() {
         _delegate = (NavigationHandler) ProxyUtils.getWeaver().reloadScriptingInstance(_delegate);
     }
@@ -45,7 +47,7 @@
         _delegate.handleNavigation(facesContext, s, s1);
     }
 
-    NavigationHandler _delegate;
+
 
     public Object getDelegate() {
         return _delegate;  //To change body of implemented methods use File | Settings |
File Templates.

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java?rev=813787&r1=813786&r2=813787&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java
Fri Sep 11 11:58:43 2009
@@ -33,32 +33,16 @@
 import java.io.OutputStream;
 import java.util.Iterator;
 import java.util.Map;
-import javax.servlet.ServletRequest;
 
 /**
  * Weaving renderkit which
  * acts as a proxy factory for
- * our internal reloading renerers
+ * our internal reloading referers
  *
  * @author Werner Punz
  */
 public class RenderkitProxy extends RenderKit implements Decorated {
 
-
-    private void weaveDelegate() {
-        _delegate = (RenderKit) ProxyUtils.getWeaver().reloadScriptingInstance(_delegate);
-    }
-
-    private boolean alreadyWovenInRequest(String clazz) {
-        //portlets now can be enabled thanks to the jsf2 indirections regarding the external
context
-        Map<String, Object> req = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
-        if (req.get(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz) == null) {
-            req.put(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz, "");
-            return false;
-        }
-        return true;
-    }
-
     RenderKit _delegate = null;
 
 
@@ -66,26 +50,18 @@
         _delegate = delegate;
     }
 
+
     public void addRenderer(String s, String s1, Renderer renderer) {
         weaveDelegate();
-        if (ProxyUtils.isDynamic(renderer.getClass()) && !alreadyWovenInRequest(renderer.toString()))
{
-            renderer = (Renderer) ProxyUtils.getWeaver().reloadScriptingInstance(renderer);
-            alreadyWovenInRequest(renderer.toString());
-        }
-
+        //wo do it brute force here because we have sometimes casts and hence cannot rely
on proxies
+        //renderers itself are flyweight patterns which means they are shared over objects
+        renderer = (Renderer) reloadInstance(renderer);
         _delegate.addRenderer(s, s1, renderer);
     }
 
     public Renderer getRenderer(String s, String s1) {
         weaveDelegate();
-        Renderer retVal = _delegate.getRenderer(s, s1);
-
-        if (retVal != null && ProxyUtils.isDynamic(retVal.getClass()) &&
!alreadyWovenInRequest(retVal.toString())) {
-            retVal = (Renderer) ProxyUtils.getWeaver().reloadScriptingInstance(retVal);
-            alreadyWovenInRequest(retVal.toString());
-            _delegate.addRenderer(s, s1, retVal);
-        }
-        return retVal;
+        return  (Renderer) reloadInstance(_delegate.getRenderer(s, s1));
     }
 
     public ResponseStateManager getResponseStateManager() {
@@ -95,25 +71,28 @@
 
     public ResponseWriter createResponseWriter(Writer writer, String s, String s1) {
         weaveDelegate();
-        return _delegate.createResponseWriter(writer, s, s1);
+        return (ResponseWriter) reloadInstance(_delegate.createResponseWriter(writer, s,
s1));
     }
 
     public ResponseStream createResponseStream(OutputStream outputStream) {
         weaveDelegate();
-        return _delegate.createResponseStream(outputStream);
+        return (ResponseStream) reloadInstance( _delegate.createResponseStream(outputStream));
     }
 
     //TODO add full support for myfaces 2.0 here
     @Override
-    public void addClientBehaviorRenderer(String s, ClientBehaviorRenderer clientBehaviorRenderer)
{
+    public void addClientBehaviorRenderer(String s, ClientBehaviorRenderer renderer) {
+
         weaveDelegate();
-        _delegate.addClientBehaviorRenderer(s, clientBehaviorRenderer);
+        renderer = (ClientBehaviorRenderer) reloadInstance(renderer);
+        _delegate.addClientBehaviorRenderer(s, renderer);
     }
 
+
     @Override
     public ClientBehaviorRenderer getClientBehaviorRenderer(String s) {
         weaveDelegate();
-        return _delegate.getClientBehaviorRenderer(s);
+        return (ClientBehaviorRenderer) reloadInstance(_delegate.getClientBehaviorRenderer(s));
     }
 
     @Override
@@ -135,6 +114,34 @@
     }
 
     public Object getDelegate() {
-        return _delegate;  //To change body of implemented methods use File | Settings |
File Templates.
+        return _delegate;  
     }
+
+
+     private final void weaveDelegate() {
+        _delegate = (RenderKit) ProxyUtils.getWeaver().reloadScriptingInstance(_delegate);
+    }
+
+    private final Object reloadInstance(Object instance) {
+        if(instance == null) {
+            return null;
+        }
+        if (ProxyUtils.isDynamic(instance.getClass()) && !alreadyWovenInRequest(instance.toString()))
{
+            instance = ProxyUtils.getWeaver().reloadScriptingInstance(instance);
+            alreadyWovenInRequest(instance.toString());
+        }
+        return instance;
+    }
+
+
+    private final boolean alreadyWovenInRequest(String clazz) {
+        //portlets now can be enabled thanks to the jsf2 indirections regarding the external
context
+        Map<String, Object> req = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+        if (req.get(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz) == null) {
+            req.put(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz, "");
+            return false;
+        }
+        return true;
+    }
+
 }



Mime
View raw message