myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r809890 - in /myfaces/extensions/scripting/trunk: core/src/main/groovy/org/apache/myfaces/groovyloader/core/ core/src/main/java/org/apache/myfaces/scripting/api/ core/src/main/java/org/apache/myfaces/scripting/core/ core/src/main/java/org/a...
Date Tue, 01 Sep 2009 08:45:23 GMT
Author: werpu
Date: Tue Sep  1 08:45:22 2009
New Revision: 809890

URL: http://svn.apache.org/viewvc?rev=809890&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-3
adding java blogging example to identify the weak spots of our relaoding code

Added:
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java
      - copied, changed from r809742, myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/BaseWeaver.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java
  (contents, props changed)
      - copied, changed from r809742, myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ScriptingWeaverHolder.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Blog.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogEntry.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Cast.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/JSFUtil.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Null.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/javablog.xhtml
      - copied, changed from r809742, myfaces/extensions/scripting/trunk/examples/src/main/webapp/blog.xhtml
Removed:
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/BaseWeaver.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/DynamicClassIdentifierHolder.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ScriptingWeaverHolder.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/javaReloading/
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/jsr199/
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/probes/
Modified:
    myfaces/extensions/scripting/trunk/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
    myfaces/extensions/scripting/trunk/core/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/groovy/org/apache/myfaces/groovyloader/blog/Blog.groovy
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java
    myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/web.xml

Modified: myfaces/extensions/scripting/trunk/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy
Tue Sep  1 08:45:22 2009
@@ -18,16 +18,13 @@
  */
 package org.apache.myfaces.groovyloader.core
 
-import org.apache.commons.logging.Log
-import org.apache.commons.logging.LogFactory
 import org.apache.myfaces.groovyloader.core.Groovy2GroovyObjectReloadingProxy
 import org.apache.myfaces.scripting.api.ScriptingConst
 import org.apache.myfaces.scripting.api.ScriptingWeaver
-import org.apache.myfaces.scripting.core.util.ClassUtils
-import org.apache.myfaces.scripting.refresh.FileChangedDaemon
-import org.apache.myfaces.scripting.refresh.ReloadingMetadata
 import org.codehaus.groovy.runtime.InvokerHelper
-import org.apache.myfaces.scripting.core.BaseWeaver
+import org.apache.myfaces.scripting.api.BaseWeaver
+import org.apache.myfaces.scripting.loaders.groovy.DynamicClassIdentifier
+import org.apache.myfaces.scripting.api.BaseWeaver
 
 /**
  * Weaver  which does dynamic class reloading
@@ -47,7 +44,7 @@
 public class GroovyWeaver extends BaseWeaver implements Serializable, ScriptingWeaver {
 
     static ThreadLocal _groovyClassLoaderHolder = new ThreadLocal();
-
+    DynamicClassIdentifier identifier = new DynamicClassIdentifier()
 
 
     public GroovyWeaver() {
@@ -152,4 +149,8 @@
         invoker.metaRegistry.setMetaClass(aclass, myMetaClass)
     }
 
+    public boolean isDynamic(Class clazz) {
+        return identifier.isDynamic(clazz)
+    }
+
 }

Copied: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java
(from r809742, myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/BaseWeaver.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java?p2=myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java&p1=myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/BaseWeaver.java&r1=809742&r2=809890&rev=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/BaseWeaver.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java
Tue Sep  1 08:45:22 2009
@@ -1,4 +1,4 @@
-package org.apache.myfaces.scripting.core;
+package org.apache.myfaces.scripting.api;
 
 import org.apache.myfaces.scripting.api.ScriptingWeaver;
 import org.apache.myfaces.scripting.api.ScriptingConst;
@@ -211,6 +211,8 @@
     protected abstract void mapProperties(Object target, Object src);
     protected abstract Class loadScriptingClassFromFile(String sourceRoot, String file);
 
+    public abstract boolean isDynamic(Class clazz);
+
     public List<String> getScriptPaths() {
         return scriptPaths;
     }

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java
Tue Sep  1 08:45:22 2009
@@ -32,6 +32,7 @@
     public static final String RELOAD_MAP = "reloadMap";
     public static final int TAINT_INTERVAL = 2000;
 
+    public static final int ENGINE_TYPE_ALL = -2;
     public static final int ENGINE_TYPE_NO_ENGINE = -1;
     public static final int ENGINE_TYPE_GROOVY = 0;
     public static final int ENGINE_TYPE_JAVA = 1;

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java
Tue Sep  1 08:45:22 2009
@@ -30,7 +30,7 @@
  * The scripting weaver replaces the classloader for those instances
  * because custom classloaders are inherently problematic in web containers
  */
-public interface ScriptingWeaver {
+public interface ScriptingWeaver  {
 
   /**
      * appends a custom script search path to the original one
@@ -67,4 +67,22 @@
      */
     public Class loadScriptingClassFromName(String className);
 
+
+    /**
+     * returns the engine type for this weaver
+     * 
+     * @return
+     */
+    public int getScriptingEngine();
+
+
+    /**
+     * checks wether a given class can be reloaded
+     * from this weaver or not
+     *
+     * @param clazz
+     * @return
+     */
+    public boolean isDynamic(Class clazz);
+
 }

Copied: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java
(from r809742, myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ScriptingWeaverHolder.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java?p2=myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java&p1=myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ScriptingWeaverHolder.java&r1=809742&r2=809890&rev=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ScriptingWeaverHolder.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java
Tue Sep  1 08:45:22 2009
@@ -23,6 +23,8 @@
 import org.apache.myfaces.scripting.core.util.ProxyUtils;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author werpu
@@ -31,15 +33,19 @@
  * and implements a chain of responsibility pattern
  * on them
  */
-public class ScriptingWeaverHolder implements Serializable,ScriptingWeaver {
+public class CoreWeaver implements Serializable,ScriptingWeaver {
 
     ScriptingWeaver _groovyWeaver = null;
     ScriptingWeaver _javaWeaver = null;
+    List<ScriptingWeaver> _weavers = new ArrayList<ScriptingWeaver>();
 
-    public ScriptingWeaverHolder(ScriptingWeaver groovyWeaver, ScriptingWeaver javaWeaver)
{
-        _groovyWeaver = groovyWeaver;
-        _javaWeaver = javaWeaver;
+    public CoreWeaver(ScriptingWeaver ... weavers) {
+        //_groovyWeaver = groovyWeaver;
+        //_javaWeaver = javaWeaver;
 
+        for(ScriptingWeaver weaver: weavers) {
+            _weavers.add(weaver);
+        }
     }
 
     @Override
@@ -52,16 +58,14 @@
         if(o.getClass().getName().contains("TestBean2")) {
             System.out.println("Debugpoint found");
         }
-        int objectType = ProxyUtils.getEngineType(o.getClass());
-
-
-        switch (objectType) {
-            case ScriptingConst.ENGINE_TYPE_GROOVY:
-                return this._groovyWeaver.reloadScriptingInstance(o);
-            case ScriptingConst.ENGINE_TYPE_JAVA: //java
-                return this._javaWeaver.reloadScriptingInstance(o);
-            default: return o;
+  
+        for(ScriptingWeaver weaver: _weavers) {
+            if(weaver.isDynamic(o.getClass())) {
+                return weaver.reloadScriptingInstance(o);
+            }
         }
+        return o;
+
     }
 
     @Override
@@ -70,14 +74,13 @@
             System.out.println("Debugpoint found");
         }
 
-        int objectType = ProxyUtils.getEngineType(aclass);
-        switch (objectType) {
-            case ScriptingConst.ENGINE_TYPE_GROOVY:
-                return this._groovyWeaver.reloadScriptingClass(aclass);
-            case ScriptingConst.ENGINE_TYPE_JAVA: //java
-                return this._javaWeaver.reloadScriptingClass(aclass);
-            default: return aclass;
+        for(ScriptingWeaver weaver: _weavers) {
+            if(weaver.isDynamic(aclass)) {
+                return weaver.reloadScriptingClass(aclass);
+            }
         }
+        return aclass;
+
     }
 
     @Override
@@ -85,12 +88,27 @@
          if(className.contains("TestBean2")) {
             System.out.println("Debugpoint found");
         }
-        //we try to load from the chain, we cannot determine the engine type upfront here
-        Class retVal = this._groovyWeaver.loadScriptingClassFromName(className);
-        if (retVal == null) {
-            return this._javaWeaver.loadScriptingClassFromName(className);
+
+        for(ScriptingWeaver weaver: _weavers) {
+            Class retVal = weaver.loadScriptingClassFromName(className);
+               if(retVal != null) {
+                   return retVal;
+               }
         }
-        return retVal;
+        return null;
+    }
+
+    public int getScriptingEngine() {
+        return ScriptingConst.ENGINE_TYPE_ALL;  //To change body of implemented methods use
File | Settings | File Templates.
+    }
+
+    public boolean isDynamic(Class clazz) {
+        for(ScriptingWeaver weaver:_weavers) {
+            if(weaver.isDynamic(clazz)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     public ScriptingWeaver get_groovyWeaver() {
@@ -108,5 +126,7 @@
     public void set_javaWeaver(ScriptingWeaver _javaWeaver) {
         this._javaWeaver = _javaWeaver;
     }
+
+
 }
 

Propchange: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java
Tue Sep  1 08:45:22 2009
@@ -21,7 +21,6 @@
 import org.apache.myfaces.scripting.api.Decorated;
 import org.apache.myfaces.scripting.api.ScriptingWeaver;
 import org.apache.myfaces.scripting.api.DynamicClassIdentifier;
-import org.apache.myfaces.scripting.core.DynamicClassIdentifierHolder;
 import org.apache.myfaces.scripting.core.MethodLevelReloadingHandler;
 
 import java.lang.reflect.InvocationHandler;
@@ -48,7 +47,6 @@
      * 
      */
     static ThreadLocal _weaverHolder = new ThreadLocal();
-    static ThreadLocal _identifierHolder = new ThreadLocal();
 
     public static void init() {
 
@@ -120,24 +118,10 @@
     }
 
 
-    public static int getEngineType(Class clazz) {
-        DynamicClassIdentifier identifier = getDynamicClassIdentifier();
-        return identifier.getEngineType(clazz);
-    }
-
     public static boolean isDynamic(Class clazz) {
-        DynamicClassIdentifier identifier = getDynamicClassIdentifier();
-        return identifier.isDynamic(clazz);
+       return getWeaver().isDynamic(clazz);
     }
 
-    private static DynamicClassIdentifier getDynamicClassIdentifier() {
-        DynamicClassIdentifier identifier = (DynamicClassIdentifier) _identifierHolder.get();
-        if(identifier == null) {
-            identifier =  new DynamicClassIdentifierHolder();
-            _identifierHolder.set(identifier);
-        }
-        return identifier;
-    }
 
 
 }

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
Tue Sep  1 08:45:22 2009
@@ -25,7 +25,7 @@
 import org.apache.myfaces.scripting.api.DynamicCompiler;
 import org.apache.myfaces.scripting.api.ScriptingConst;
 import org.apache.myfaces.scripting.api.ScriptingWeaver;
-import org.apache.myfaces.scripting.core.BaseWeaver;
+import org.apache.myfaces.scripting.api.BaseWeaver;
 
 import javax.servlet.ServletContext;
 import java.io.File;
@@ -43,6 +43,7 @@
 
     Log log = LogFactory.getLog(JavaScriptingWeaver.class);
     String classPath = "";
+    DynamicClassIdentifier identifier = new DynamicClassIdentifier();
 
     /**
      * helper to allow initial compiler classpath scanning
@@ -54,6 +55,10 @@
         initClasspath(servletContext);
     }
 
+    public JavaScriptingWeaver() {
+        super(".java", ScriptingConst.ENGINE_TYPE_JAVA);
+    }
+
 
     private void initClasspath(ServletContext context) {
         String webInf = context.getRealPath(File.separator + "WEB-INF");
@@ -155,4 +160,7 @@
         return retVal;
     }
 
+    public boolean isDynamic(Class clazz) {
+        return identifier.isDynamic(clazz);  //To change body of implemented methods use
File | Settings | File Templates.
+    }
 }

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
Tue Sep  1 08:45:22 2009
@@ -21,7 +21,7 @@
 import org.apache.myfaces.groovyloader.core.GroovyWeaver;
 import org.apache.myfaces.scripting.api.ScriptingWeaver;
 import org.apache.myfaces.scripting.core.util.ProxyUtils;
-import org.apache.myfaces.scripting.core.ScriptingWeaverHolder;
+import org.apache.myfaces.scripting.core.CoreWeaver;
 import org.apache.myfaces.scripting.loaders.java.JavaScriptingWeaver;
 import org.apache.myfaces.shared_impl.util.ClassLoaderExtension;
 import org.apache.commons.lang.StringUtils;
@@ -45,7 +45,6 @@
     static String CUSTOM_LOADER_PATHS = "org.apache.myfaces.scripting.groovy.LOADER_PATHS";
     static String CUSTOM_JAVA_LOADER_PATHS = "org.apache.myfaces.scripting.java.LOADER_PATHS";
 
-
     String classRoot = "";
     String scriptingRoot = "";
     ScriptingWeaver scriptingWeaver = null;
@@ -55,14 +54,16 @@
     Log log = LogFactory.getLog(CustomChainLoader.class);
 
 
+    //TODO move the entire init code into the weavers
+    //every weaver should know itself how to initialize itself
     public CustomChainLoader(ServletContext servletContext) {
         ScriptingWeaver groovyWeaver = new GroovyWeaver();
         ScriptingWeaver javaWeaver = new JavaScriptingWeaver(servletContext);
 
-        setupScriptingPaths(servletContext, groovyWeaver,GROOVY_SOURCE_ROOT, CUSTOM_LOADER_PATHS);
+        setupScriptingPaths(servletContext, groovyWeaver, GROOVY_SOURCE_ROOT, CUSTOM_LOADER_PATHS);
         setupScriptingPaths(servletContext, javaWeaver, JAVA_SOURCE_ROOT, CUSTOM_JAVA_LOADER_PATHS);
 
-        this.scriptingWeaver = new ScriptingWeaverHolder(groovyWeaver, javaWeaver);
+        this.scriptingWeaver = new CoreWeaver(groovyWeaver, javaWeaver);
         //we have to store it because our filter
         //does not trigger upon initialisation
         ProxyUtils.setWeaver(this.scriptingWeaver);
@@ -75,7 +76,6 @@
         contextRoot = contextRoot.trim();
         scriptingRoot = contextRoot;
 
-
         additionalLoaderPaths = servletContext.getInitParameter(initParams);
         appendAdditionalPaths(additionalLoaderPaths, weaver);
         weaver.appendCustomScriptPath(scriptingRoot);
@@ -100,7 +100,7 @@
         else if (name.startsWith("com.sun")) /*internal java specific namespace*/
             return null;
         else if (name.startsWith("sun.")) /*internal java specific namespace*/
-             return null;
+            return null;
 
         return scriptingWeaver.loadScriptingClassFromName(name);
     }

Modified: myfaces/extensions/scripting/trunk/core/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java
Tue Sep  1 08:45:22 2009
@@ -21,9 +21,12 @@
 import org.junit.Test;
 import org.junit.Before;
 import static org.junit.Assert.*;
-import org.apache.myfaces.scripting.core.DynamicClassIdentifierHolder;
+import org.apache.myfaces.scripting.core.util.ProxyUtils;
+import org.apache.myfaces.scripting.core.CoreWeaver;
 import org.apache.myfaces.scripting.api.ScriptingConst;
 import org.apache.myfaces.scripting.loaders.java.DynamicClassIdentifier;
+import org.apache.myfaces.scripting.loaders.java.JavaScriptingWeaver;
+
 
 /**
  * @author werpu
@@ -33,29 +36,23 @@
 
      Object probe1 = null;
      Object probe2 = null;
-     DynamicClassIdentifier identifier = new DynamicClassIdentifier();
-     DynamicClassIdentifierHolder identifierHolder = new DynamicClassIdentifierHolder();
+     CoreWeaver weaver = null;
 
      @Before
      public void setUp() {
         probe1 = new Probe1();
-        probe2 = new Probe2(); 
-     }
+        probe2 = new Probe2();
+        weaver = new CoreWeaver(new JavaScriptingWeaver());
+        ProxyUtils.setWeaver(weaver); 
+    }
+
 
      @Test
      public void isDynamic() {
-        assertFalse("Class should be static",identifier.isDynamic(probe1.getClass()));
-        assertTrue("Class should be dynamic",identifier.isDynamic(probe2.getClass()));
+        assertFalse("Class should be static",ProxyUtils.isDynamic(probe1.getClass()));
+        assertTrue("Class should be dynamic",ProxyUtils.isDynamic(probe2.getClass()));
      }
 
-    @Test
-    public void dynamicClassIdentifierHolderTest() {
-        int engineType1 = identifierHolder.getEngineType(probe1.getClass());
-        int engineType2 = identifierHolder.getEngineType(probe2.getClass());
-
-        assertTrue("engine type 1 unknown", engineType1 == ScriptingConst.ENGINE_TYPE_NO_ENGINE);
-        assertTrue("engine type 2 java", engineType2 == ScriptingConst.ENGINE_TYPE_JAVA);
-    }
 
 
 }

Modified: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/faces-config.xml?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/faces-config.xml Tue
Sep  1 08:45:22 2009
@@ -55,6 +55,20 @@
     </managed-bean>
 
 
+    <managed-bean>
+        <managed-bean-name>javaBlogView</managed-bean-name>
+        <managed-bean-class>org.apache.myfaces.javaloader.blog.Blog</managed-bean-class>
+        <managed-bean-scope>request</managed-bean-scope>
+    </managed-bean>
+
+    <managed-bean>
+        <managed-bean-name>javaBlogService</managed-bean-name>
+        <managed-bean-class>org.apache.myfaces.javaloader.blog.BlogService</managed-bean-class>
+        <managed-bean-scope>application</managed-bean-scope>
+    </managed-bean>
+
+
+
     <application>
         <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
         <navigation-handler>

Modified: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/groovy/org/apache/myfaces/groovyloader/blog/Blog.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/groovy/org/apache/myfaces/groovyloader/blog/Blog.groovy?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/groovy/org/apache/myfaces/groovyloader/blog/Blog.groovy
(original)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/groovy/org/apache/myfaces/groovyloader/blog/Blog.groovy
Tue Sep  1 08:45:22 2009
@@ -48,6 +48,7 @@
             log.error("service not found")
         } else {
             log.info("service found")
+            
         }
 
         def entry = new BlogEntry()

Added: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Blog.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Blog.java?rev=809890&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Blog.java
(added)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Blog.java
Tue Sep  1 08:45:22 2009
@@ -0,0 +1,109 @@
+package org.apache.myfaces.javaloader.blog;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.scripting.loaders.java.ScriptingClass;
+
+/**
+ * @author werpu2
+ * @date: 01.09.2009
+ */
+
+@ScriptingClass
+public class Blog {
+
+    String title = "Hello to the myfaces dynamic blogging";
+    String title1 = "You can alter the code for this small blogging application on the fly,
" +
+                    "you even can add new classes on the fly and Grooy will pick it up";
+
+    String firstName = "";
+    String lastName = "";
+    String topic = "";
+
+    String content = "";
+    
+
+    private Log getLog() {
+        return LogFactory.getLog(this.getClass());
+    }
+
+
+    
+    public String addEntry() {
+        getLog().info("adding entry");
+
+       Object service = JSFUtil.resolveVariable("javaBlogService");
+
+       if (service == null) {
+            getLog().error("service not found");
+        } else {
+            getLog().info("service found");
+        }
+
+        BlogEntry entry = new BlogEntry();
+        //we now map it in the verbose way, the lean way would be to do direct introspection
attribute mapping
+
+        entry.setFirstName(firstName);
+        entry.setLastName(lastName);
+        entry.setTopic(topic);
+        entry.setContent(content);
+        
+        if(service != null) {
+            JSFUtil.executeMethod(service, "addEntry", new Cast(Object.class,entry));
+        }
+
+
+        
+        //we stay on the same page
+        return null;
+    }
+
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getTitle1() {
+        return title1;
+    }
+
+    public void setTitle1(String title1) {
+        this.title1 = title1;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public String getTopic() {
+        return topic;
+    }
+
+    public void setTopic(String topic) {
+        this.topic = topic;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

Added: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogEntry.java?rev=809890&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogEntry.java
(added)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogEntry.java
Tue Sep  1 08:45:22 2009
@@ -0,0 +1,48 @@
+package org.apache.myfaces.javaloader.blog;
+
+/**
+ * @author werpu2
+ * @date: 01.09.2009
+ */
+public class BlogEntry {
+
+    String firstName = "";
+    
+    String lastName = "";
+    String topic = "";
+
+    String content = "";
+
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public String getTopic() {
+        return topic;
+    }
+
+    public void setTopic(String topic) {
+        this.topic = topic;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

Added: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java?rev=809890&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
(added)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/BlogService.java
Tue Sep  1 08:45:22 2009
@@ -0,0 +1,45 @@
+package org.apache.myfaces.javaloader.blog;
+
+import org.apache.myfaces.scripting.loaders.java.ScriptingClass;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Collections;
+
+/**
+ * @author werpu2
+ * @date: 01.09.2009
+ */
+@ScriptingClass
+public class BlogService {
+
+    /**
+     * note we cannot cast on dynamically referenced
+     * and recompiled objects which are shared between beans
+     * because due to dynamic recompilation
+     *
+     * Object a->references b does not reference b of the same class
+     * as object c->references b, we have to use introspection in this case
+     * we can use our utils class to make it a tiny bit more comfortable
+     *
+     * Statically compiled types always stay the same however
+     * the same goes for interfaces which are present as compiled code only
+     * 
+     */
+    List<Object> blogEntries = Collections.synchronizedList(new LinkedList<Object>());
+
+    public void addEntry(Object entry) {
+        if(entry != null) {
+            blogEntries.add(entry);
+        }
+    }
+
+
+    public List<Object> getBlogEntries() {
+        return blogEntries;
+    }
+
+    public void setBlogEntries(List<Object> blogEntries) {
+        this.blogEntries = blogEntries;
+    }
+}

Added: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Cast.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Cast.java?rev=809890&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Cast.java
(added)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Cast.java
Tue Sep  1 08:45:22 2009
@@ -0,0 +1,24 @@
+package org.apache.myfaces.javaloader.blog;
+
+/**
+ * @author werpu2
+ * @date: 01.09.2009
+ */
+public class Cast {
+
+    Class clazz;
+    Object value;
+
+    public Cast(Class clazz, Object value) {
+        this.clazz = clazz;
+        this.value = value;
+    }
+
+    public Class getClazz() {
+        return clazz;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+}

Added: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/JSFUtil.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/JSFUtil.java?rev=809890&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/JSFUtil.java
(added)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/JSFUtil.java
Tue Sep  1 08:45:22 2009
@@ -0,0 +1,94 @@
+package org.apache.myfaces.javaloader.blog;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+import javax.faces.context.FacesContext;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+
+/**
+ * @author werpu2
+ * @date: 01.09.2009
+ */
+public class JSFUtil {
+
+    public JSFUtil() {
+    }
+
+    public static Object resolveVariable(String beanName) {
+        Log log = LogFactory.getLog(JSFUtil.class);
+        Object facesContext = FacesContext.getCurrentInstance();
+
+        Object elContext = executeFunction(facesContext, "getELContext");
+        Object elResolver = executeFunction(elContext, "getELResolver");
+
+        log.info("ElResolver Instance:" + elResolver.toString());
+        try {
+            return executeFunction(elResolver, "getValue", new Cast(ClassUtils.classForName("javax.el.ELContext"),
elContext), new Null(Object.class), new Cast(Object.class, beanName));
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+
+    public static void executeMethod(Object obj, String methodName, Object... varargs) {
+        
+        Class[] classes = new Class[varargs.length];
+        for (int cnt = 0; cnt < varargs.length; cnt++) {
+
+            if (varargs[cnt] instanceof Null) {
+                classes[cnt] = ((Null) varargs[cnt]).getNulledClass();
+                varargs[cnt] = null;
+            } else if (varargs[cnt] instanceof Cast) {
+                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+            } else {
+                classes[cnt] = varargs[cnt].getClass();
+            }
+        }
+
+        try {
+            Method m = obj.getClass().getMethod(methodName, classes);
+            m.invoke(obj, varargs);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static Object executeFunction(Object obj, String methodName, Object... varargs)
{
+        Class[] classes = new Class[varargs.length];
+        for (int cnt = 0; cnt < varargs.length; cnt++) {
+
+            if (varargs[cnt] instanceof Null) {
+                classes[cnt] = ((Null) varargs[cnt]).getNulledClass();
+                varargs[cnt] = null;
+            } else if (varargs[cnt] instanceof Cast) {
+                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+            } else {
+                classes[cnt] = varargs[cnt].getClass();
+            }
+        }
+
+        try {
+            Method m = obj.getClass().getMethod(methodName, classes);
+            return m.invoke(obj, varargs);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Null.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Null.java?rev=809890&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Null.java
(added)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/blog/Null.java
Tue Sep  1 08:45:22 2009
@@ -0,0 +1,17 @@
+package org.apache.myfaces.javaloader.blog;
+
+/**
+ * @author werpu2
+ * @date: 01.09.2009
+ */
+public class Null {
+    Class nulledClass = null;
+
+    public Null(Class clazz) {
+        nulledClass = clazz;
+    }
+
+    public Class getNulledClass() {
+        return nulledClass;
+    }
+}

Modified: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java
(original)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/java/org/apache/myfaces/javaloader/test/TestBean2.java
Tue Sep  1 08:45:22 2009
@@ -9,7 +9,7 @@
     String hello3 = "hello from added attribute 2";
 
     public String getSayHello() {
-        return "hello from a Java coded dynamic bean"+TestClass2.hello2+hello3 ;
+        return "hello from a Java  coded dynamic bean"+TestClass2.hello2+hello3 ;
     }
       public String getSayHello2() {
         return hello2;

Modified: myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/web.xml?rev=809890&r1=809889&r2=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/WEB-INF/web.xml Tue Sep  1
08:45:22 2009
@@ -45,21 +45,21 @@
          <param-value>org.apache.myfaces.scripting.servlet.StartupServletContextPluginChainLoader</param-value>
      </context-param>
 
-    <!--
+
     <context-param>
         <description>Additional comma separated loader paths to allow direct editing
on the sources directory instead
         of the deployment dir</description>
         <param-name>org.apache.myfaces.scripting.groovy.LOADER_PATHS</param-name>
-        <param-value>/home/werpu/development/workspace/scriptingextensions/examples/src/main/webapp/WEB-INF/groovy</param-value>
+        <param-value>/Users/werpu2/development/workspace/extensions-scripting/examples/src/main/webapp/WEB-INF/groovy</param-value>
     </context-param>
 
      <context-param>
         <description>Additional comma separated loader paths to allow direct editing
on the sources directory instead
         of the deployment dir</description>
         <param-name>org.apache.myfaces.scripting.java.LOADER_PATHS</param-name>
-        <param-value>/home/werpu/development/workspace/scriptingextensions/examples/src/main/webapp/WEB-INF/java</param-value>
+        <param-value>/Users/werpu2/development/workspace/extensions-scripting/examples/src/main/webapp/WEB-INF/java</param-value>
     </context-param>
-    -->
+
     
     <context-param>
         <description>State saving method: "client" or "server" (= default)

Copied: myfaces/extensions/scripting/trunk/examples/src/main/webapp/javablog.xhtml (from r809742,
myfaces/extensions/scripting/trunk/examples/src/main/webapp/blog.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/src/main/webapp/javablog.xhtml?p2=myfaces/extensions/scripting/trunk/examples/src/main/webapp/javablog.xhtml&p1=myfaces/extensions/scripting/trunk/examples/src/main/webapp/blog.xhtml&r1=809742&r2=809890&rev=809890&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/src/main/webapp/blog.xhtml (original)
+++ myfaces/extensions/scripting/trunk/examples/src/main/webapp/javablog.xhtml Tue Sep  1
08:45:22 2009
@@ -15,25 +15,25 @@
     <ui:define name="body">
         <h:form id="form">
             <h:panelGrid id="grid" columns="1">
-                <h:outputText id="title1" styleClass="title" value="#{blogView.title}"/>
-                <h:outputText id="title11" styleClass="title1" value="#{blogView.title1}"/>
+                <h:outputText id="title1" styleClass="title" value="#{javaBlogView.title}"/>
+                <h:outputText id="title11" styleClass="title1" value="#{javaBlogView.title1}"/>
                 <!--
                 entry.firstName = firstName
                 entry.lastName = lastName
                 entry.topic = topic
                 entry.content = content
             -->
-                <h:outputText value="First Name"/><h:inputText value="#{blogView.firstName}"/>
-                <h:outputText value="Last Name"/><h:inputText value="#{blogView.lastName}"/>
-                <h:outputText value="Topic of entry"/><h:inputText value="#{blogView.topic}"/>
-                <h:outputText value="Content"/><h:inputText value="#{blogView.content}"/>
+                <h:outputText value="First Name"/><h:inputText value="#{javaBlogView.firstName}"/>
+                <h:outputText value="Last Name"/><h:inputText value="#{javaBlogView.lastName}"/>
+                <h:outputText value="Topic of entry"/><h:inputText value="#{javaBlogView.topic}"/>
+                <h:outputText value="Content"/><h:inputText value="#{javaBlogView.content}"/>
 
 
-                <h:commandLink action="#{blogView.addEntry}" value="Add Blog"/>
+                <h:commandLink action="#{javaBlogView.addEntry}" value="Add Blog"/>
             </h:panelGrid>
             <h:panelGrid columns="1">
                 <h:outputText value="Blog Entries"/>
-                <t:dataList value="#{blogService.blogEntries}" var="item">
+                <t:dataList value="#{javaBlogService.blogEntries}" var="item">
 
                     <h:outputText value="#{item.topic}"/>
                     <h:outputText value="#{item.content}"/><br/>



Mime
View raw message