myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r813791 - in /myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations: ApplicationProxy.java RenderkitProxy.java
Date Fri, 11 Sep 2009 12:09:04 GMT
Author: werpu
Date: Fri Sep 11 12:09:02 2009
New Revision: 813791

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

backport of 2.0 changes into 1.2

Modified:
    myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
    myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java

Modified: myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java?rev=813791&r1=813790&r2=813791&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
Fri Sep 11 12:09:02 2009
@@ -52,14 +52,8 @@
 
     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
@@ -82,7 +76,7 @@
     private void weaveDelegate() {
         if (_delegate != null) {
             _delegate = (Application) ProxyUtils.getWeaver().reloadScriptingInstance(_delegate);
-        }    
+        }
     }
 
     public ELResolver getELResolver() {
@@ -295,12 +289,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 {
@@ -308,16 +297,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() {
@@ -397,6 +381,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);
@@ -414,12 +399,31 @@
         return _delegate.createValueBinding(s);
     }
 
-    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
+        ServletRequest req = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
+        if (req.getAttribute(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz) == null) {
+            req.setAttribute(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz, "");
+            return false;
+        }
+        return true;
+    }
+
 }

Modified: myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java?rev=813791&r1=813790&r2=813791&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java
(original)
+++ myfaces/extensions/scripting/trunk/core/myfaces12-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java
Fri Sep 11 12:09:02 2009
@@ -23,40 +23,24 @@
 import org.apache.myfaces.scripting.core.util.ProxyUtils;
 
 import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
 import javax.faces.render.RenderKit;
 import javax.faces.render.Renderer;
 import javax.faces.render.ResponseStateManager;
-import javax.faces.context.ResponseWriter;
-import javax.faces.context.ResponseStream;
-import java.io.Writer;
-import java.io.OutputStream;
 import javax.servlet.ServletRequest;
+import java.io.OutputStream;
+import java.io.Writer;
 
 /**
  * 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) {
-        //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 true;
-    }
-
     RenderKit _delegate = null;
 
 
@@ -64,26 +48,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() {
@@ -93,15 +69,43 @@
 
     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));
     }
 
     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
+        ServletRequest req = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
+           if (req.getAttribute(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz) == null)
{
+            req.setAttribute(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz, "");
+            return false;
+        }
+        return true;
+    }
+
 }



Mime
View raw message