You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2009/10/01 17:28:13 UTC

svn commit: r820688 - in /myfaces/extensions/scripting/trunk: core/core/src/main/java/org/apache/myfaces/scripting/servlet/ core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ core/myfaces2-extensio...

Author: werpu
Date: Thu Oct  1 15:28:06 2009
New Revision: 820688

URL: http://svn.apache.org/viewvc?rev=820688&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-26
bean annotation moving is working, yiehaa

Added:
    myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean3.java
      - copied, changed from r820687, myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java
Modified:
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
    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/jsf2/annotation/BeanImplementationListener.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/JavaAnnotationScanner.java
    myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java?rev=820688&r1=820687&r2=820688&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java Thu Oct  1 15:28:06 2009
@@ -79,8 +79,10 @@
 
         additionalLoaderPaths = servletContext.getInitParameter(initParams);
         appendAdditionalPaths(additionalLoaderPaths, weaver);
-        weaver.appendCustomScriptPath(scriptingRoot);
-        weaver.appendCustomScriptPath(classRoot);
+        if(additionalLoaderPaths == null || additionalLoaderPaths.trim().equals("")) {
+            weaver.appendCustomScriptPath(scriptingRoot);
+            weaver.appendCustomScriptPath(classRoot);
+        }    
     }
 
     private void appendAdditionalPaths(String additionalLoaderPaths, ScriptingWeaver workWeaver) {

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=820688&r1=820687&r2=820688&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 Thu Oct  1 15:28:06 2009
@@ -78,8 +78,9 @@
     public ELResolver getELResolver() {
         weaveDelegate();
         ELResolver retVal = _delegate.getELResolver();
-        if (!(retVal instanceof ELResolverProxy))
+        if (!(retVal instanceof ELResolverProxy)) {
             retVal = new ELResolverProxy(retVal);
+        }    
         return retVal;
 
     }

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=820688&r1=820687&r2=820688&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 Thu Oct  1 15:28:06 2009
@@ -26,6 +26,8 @@
 import javax.el.ELResolver;
 import javax.el.PropertyNotFoundException;
 import javax.el.PropertyNotWritableException;
+import javax.faces.context.FacesContext;
+import javax.faces.bean.ManagedBean;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,6 +37,7 @@
 import org.apache.myfaces.scripting.core.scanEvents.SystemEvent;
 import org.apache.myfaces.scripting.core.scanEvents.events.BeanLoadedEvent;
 import org.apache.myfaces.scripting.core.scanEvents.events.BeanRemovedEvent;
+import org.apache.myfaces.config.RuntimeConfig;
 
 /**
  * EL Resolver which is scripting enabled
@@ -46,75 +49,62 @@
     Log log = LogFactory.getLog(ELResolverProxy.class);
     ELResolver _delegate = null;
 
-    StackingBeanEventListener _listenerStack = new StackingBeanEventListener();
-
-    private void registerListenerStack() {
-        if (!ProxyUtils.getEventProcessor().hasListener(_listenerStack)) {
-            ProxyUtils.getEventProcessor().addListener(_listenerStack);
-        }
-    }
-
+    static ThreadLocal<Boolean> _getValue = new ThreadLocal<Boolean>();
 
     public Object getValue(ELContext elContext, final Object base, final Object property) throws NullPointerException, PropertyNotFoundException, ELException {
+
         Object retVal = _delegate.getValue(elContext, base, property);
         Object newRetVal = null;
-        if (retVal != null && ProxyUtils.isDynamic(retVal.getClass())) {
-
-            //We have to register one listener per el instance
-            //because we have to deal with nesting of
-            //el locading caused by beans referencing other beans
-            //via inversion of object control
-
-            //onfurtunately this flow is somewhat strange because
-            //we shift logic into dynamically registered events
-            //but the event system is the only means of communication
-            //attached modules have to the core
-
-            //the flow is this -> try to load bean bean loading failes because
-            //annotation has moved -> this is notified about it ->
-            //we have to do a full recompile
-            //retry to load but this time without our referencing listener
-            registerListenerStack();
-            BeanEventListener eventListener = new BeanEventListener();
-            _listenerStack.pushListener(eventListener);
-            try {
-                //We register for annotation scanning events
 
-                newRetVal = ProxyUtils.getWeaver().reloadScriptingInstance(retVal); /*once it was tainted or loaded by
+        if (retVal != null && ProxyUtils.isDynamic(retVal.getClass())) {
+            newRetVal = ProxyUtils.getWeaver().reloadScriptingInstance(retVal); /*once it was tainted or loaded by
                  our classloader we have to recreate all the time to avoid classloader issues*/
-                fullRecompileReload(eventListener);
-            } finally {
-                _listenerStack.popListener();
-            }
 
             if (newRetVal != retVal) {
                 _delegate.setValue(elContext, base, property, newRetVal);
             }
 
+            //in case we have an annotation change we have to deal with it differently
+            newRetVal = reloadAnnotatedBean(elContext, base, property, newRetVal);
+
             return newRetVal;
-            //reinstantiated.put(retVal.getClass().getName(), retVal.getClass());
+        } else if (retVal == null) {
+            retVal = reloadAnnotatedBean(elContext, base, property, null);
         }
 
         return retVal;
-
     }
 
+    private Object reloadAnnotatedBean(ELContext elContext, Object base, Object property, Object newRetVal) {
+        //Avoid recursive calls into ourselfs here
 
-    private void fullRecompileReload(BeanEventListener eventListener) {
-        if (eventListener.getBeanEventIssued().size() > 0) {
-            //last was the first event issued
-            SystemEvent beanEvent = eventListener.getBeanEventIssued().removeLast();
-            eventListener.getBeanEventIssued().clear();
-            if (beanEvent instanceof BeanRemovedEvent) {
-
-                if (log.isDebugEnabled()) {
-                    log.debug("ElResolverProxy.getValue bean removed we have to issue a recompile and then try to load the bean anew");
-
+        try {
+            if (_getValue.get() != null && _getValue.get().equals(Boolean.TRUE)) {
+                return newRetVal;
+            }
+            _getValue.set(Boolean.TRUE);
+            if (base == null) {
+                final FacesContext facesContext = FacesContext.getCurrentInstance();
+                RuntimeConfig config = RuntimeConfig.getCurrentInstance(facesContext.getExternalContext());
+                Map<String, org.apache.myfaces.config.element.ManagedBean> mbeans = config.getManagedBeans();
+                if (!mbeans.containsKey(property.toString())) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("ElResolverProxy.getValue bean removed we have to issue a recompile and then try to load the bean anew");
+                    }
+                    _delegate.setValue(elContext, base, property, null);
+
+                    //we only trigger this if the bean was deregistered, we now can reregister it again
+                    ProxyUtils.getWeaver().fullAnnotationScan();
+                    newRetVal = _delegate.getValue(elContext, base, property);
                 }
             }
+        } finally {
+            _getValue.set(Boolean.FALSE);
         }
+        return newRetVal;
     }
 
+
     public Class<?> getType(ELContext elContext, Object o, Object o1) throws NullPointerException, PropertyNotFoundException, ELException {
         Class<?> retVal = _delegate.getType(elContext, o, o1);
         if (retVal != null && ProxyUtils.isDynamic((Class) retVal)) {

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java?rev=820688&r1=820687&r2=820688&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java (original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java Thu Oct  1 15:28:06 2009
@@ -34,10 +34,7 @@
 
 import javax.faces.bean.*;
 import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Collection;
-import java.util.ArrayList;
+import java.util.*;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -115,7 +112,7 @@
         JavaClass clazz = (JavaClass) sourceClass;
 
         RuntimeConfig config = getRuntimeConfig();
-
+        //TODO has to register still needed we have it in the runtime config anyway?
         String beanName = getAnnotatedStringParam(params, "name");
         if (!hasToReregister(beanName, clazz)) {
             return;
@@ -314,6 +311,7 @@
         //We refresh the managed beans, dead references still can cause
         //runtime errors but in this case we cannot do anything
         org.apache.myfaces.config.element.ManagedBean mbeanFound = null;
+        List<String> mbeanKey = new LinkedList<String>();
 
         for (Map.Entry mbean : managedBeans.entrySet()) {
             org.apache.myfaces.config.element.ManagedBean bean = (org.apache.myfaces.config.element.ManagedBean) mbean.getValue();
@@ -321,6 +319,7 @@
                 config.addManagedBean((String) mbean.getKey(), (org.apache.myfaces.config.element.ManagedBean) mbean.getValue());
             } else {
                 mbeanFound = (org.apache.myfaces.config.element.ManagedBean) mbean.getValue();
+                mbeanKey.add(mbeanFound.getManagedBeanName());
             }
         }
         if (mbeanFound != null) {
@@ -332,6 +331,10 @@
                 ProxyUtils.getEventProcessor().dispatchEvent(new BeanRemovedEvent(className, mbeanToDispatch.getManagedBeanName()));
 
             }
+            for(String toRemove: mbeanKey) {
+                _alreadyRegistered.remove(toRemove);
+            }
         }
+
     }
 }

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/JavaAnnotationScanner.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/JavaAnnotationScanner.java?rev=820688&r1=820687&r2=820688&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/JavaAnnotationScanner.java (original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/JavaAnnotationScanner.java Thu Oct  1 15:28:06 2009
@@ -27,6 +27,7 @@
 import org.apache.myfaces.scripting.core.util.ProxyUtils;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.*;
 
 import org.apache.myfaces.scripting.core.scanEvents.events.AnnotatedArtefactRemovedEvent;
@@ -48,7 +49,7 @@
     List<AnnotationScanListener> _listeners = new LinkedList<AnnotationScanListener>();
     JavaDocBuilder _builder = new JavaDocBuilder();
     Map<String, String> _registeredAnnotations = new HashMap<String, String>();
-
+    LinkedList<String> _sourcePaths = new LinkedList<String>();
 
     public JavaAnnotationScanner() {
         initDefaultListeners();
@@ -56,15 +57,14 @@
 
     public JavaAnnotationScanner(String... sourcePaths) {
 
-        initSourcePaths(sourcePaths);
+        for (String source : sourcePaths) {
+            _sourcePaths.addFirst(source);
+        }
         initDefaultListeners();
     }
 
     public void addScanPath(String sourcePath) {
-        File sourcePathFile = new File(sourcePath);
-        if (sourcePathFile.exists()) {
-            _builder.addSourceTree(sourcePathFile);
-        }
+        _sourcePaths.addFirst(sourcePath);
     }
 
     Collection<Annotation> filterAnnotations(Annotation[] anns) {
@@ -107,9 +107,15 @@
     }
 
 
-    private void initSourcePaths(String... sourcePaths) {
-        for (String sourcePath : sourcePaths) {
-            addScanPath(sourcePath);
+    private void initSourcePaths() {
+        _builder = new JavaDocBuilder();
+        for (String sourcePath : _sourcePaths) {
+            File source = new File(sourcePath);
+            if(source.exists() ) {
+
+                    _builder.addSourceTree(source);
+
+            }
         }
     }
 
@@ -127,12 +133,13 @@
      * on the found data
      */
     public void scanPaths() {
+        initSourcePaths();
         JavaSource[] sources = _builder.getSources();
         for (JavaSource source : sources) {
             JavaClass[] classes = source.getClasses();
             for (JavaClass clazz : classes) {
                 Annotation[] anns = clazz.getAnnotations();
-                if (anns != null || anns.length > 0) {
+                if (anns != null && anns.length > 0) {
                     addOrMoveAnnotations(clazz, anns);
                 } else {
                     removeAnnotations(clazz);
@@ -185,7 +192,7 @@
                     if (metaData != null) {
                         metaData.setAnnotated(true);
                     }
-                } 
+                }
             }
         }
     }

Modified: myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java?rev=820688&r1=820687&r2=820688&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java (original)
+++ myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java Thu Oct  1 15:28:06 2009
@@ -3,10 +3,11 @@
 import org.apache.myfaces.scripting.loaders.java.ScriptingClass;
 import javax.faces.bean.ManagedBean;
 import javax.faces.bean.RequestScoped;
+import javax.faces.bean.SessionScoped;
+
+
 
 
-@ManagedBean (name="javatestbean")
-@RequestScoped 
 public class TestBean2 {
     String sayHello = "hello worldgggg";
     String hello2 = "hello from added attribute";

Copied: myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean3.java (from r820687, myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean3.java?p2=myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean3.java&p1=myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java&r1=820687&r2=820688&rev=820688&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java (original)
+++ myfaces/extensions/scripting/trunk/examples/myfaces20-example/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean3.java Thu Oct  1 15:28:06 2009
@@ -3,17 +3,17 @@
 import org.apache.myfaces.scripting.loaders.java.ScriptingClass;
 import javax.faces.bean.ManagedBean;
 import javax.faces.bean.RequestScoped;
-
+import javax.faces.bean.SessionScoped;
 
 @ManagedBean (name="javatestbean")
-@RequestScoped 
-public class TestBean2 {
+@SessionScoped
+public class TestBean3 {
     String sayHello = "hello worldgggg";
     String hello2 = "hello from added attribute";
     String hello3 = "hello from  added attribute 2";
- 
+
     public String getSayHello() {
-        return "Java dynamic  bean - "+TestClass2.hello2 + hello3;
+        return "Java dynamic  bean Testbean3 bla bla bla - "+TestClass2.hello2 + hello3;
     }
 
     public String getSayHello2() {
@@ -27,5 +27,5 @@
     }
 
 
- 
+
 }
\ No newline at end of file