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 2012/03/08 13:49:15 UTC

svn commit: r1298374 - in /myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core: ./ src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/context/ src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/ ...

Author: werpu
Date: Thu Mar  8 12:49:14 2012
New Revision: 1298374

URL: http://svn.apache.org/viewvc?rev=1298374&view=rev
Log:
EXTSCRIPT-154: Code Rewrite/Refactoring, ongoing works in the classloader area, integration of jsf2

Added:
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/loader/
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/loader/ThrowAwayClassloader.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/CustomChainLoader.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/MyFacesSPI.java
Modified:
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/pom.xml
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/context/WeavingContext.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/monitor/ResourceMonitor.java
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/startup/StartupServletContextPluginChainLoader.java

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/pom.xml?rev=1298374&r1=1298373&r2=1298374&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/pom.xml (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/pom.xml Thu Mar  8 12:49:14 2012
@@ -39,14 +39,14 @@
         <dependency>
             <groupId>org.apache.myfaces.core</groupId>
             <artifactId>myfaces-api</artifactId>
-            <version>${myfaces12.version}</version>
+            <version>${myfaces2.version}</version>
             <scope>provided</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.myfaces.core</groupId>
             <artifactId>myfaces-impl</artifactId>
-            <version>${myfaces12.version}</version>
+            <version>${myfaces2.version}</version>
             <scope>provided</scope>
         </dependency>
 

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/context/WeavingContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/context/WeavingContext.java?rev=1298374&r1=1298373&r2=1298374&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/context/WeavingContext.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/context/WeavingContext.java Thu Mar  8 12:49:14 2012
@@ -23,6 +23,7 @@ import org.apache.myfaces.extensions.scr
 import rewrite.org.apache.myfaces.extensions.scripting.core.engine.FactoryEngines;
 import rewrite.org.apache.myfaces.extensions.scripting.core.engine.api.ScriptingEngine;
 import rewrite.org.apache.myfaces.extensions.scripting.core.monitor.ClassResource;
+import rewrite.org.apache.myfaces.extensions.scripting.core.monitor.WatchedResource;
 
 import java.io.IOException;
 import java.util.Collection;
@@ -143,6 +144,15 @@ public class WeavingContext
         }
     }
 
+    public WatchedResource getResource(String className) {
+        WatchedResource ret = null;
+        for(ScriptingEngine engine: getEngines()) {
+            ret = engine.getWatchedResources().get(className);
+            if(ret != null) return ret;
+        }
+        return ret;
+    }
+    
     //----------------------------------------------------------------------
     public ClassDependencies getDependencyMap()
     {

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java?rev=1298374&r1=1298373&r2=1298374&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java Thu Mar  8 12:49:14 2012
@@ -20,6 +20,7 @@ package rewrite.org.apache.myfaces.exten
 
 import org.apache.commons.io.FilenameUtils;
 import org.apache.myfaces.extensions.scripting.core.util.FileUtils;
+import org.apache.myfaces.extensions.scripting.monitor.WatchedResource;
 import rewrite.org.apache.myfaces.extensions.scripting.core.common.util.ClassUtils;
 import rewrite.org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api.DependencyRegistry;
 import rewrite.org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.core.ClassDependencies;
@@ -172,6 +173,8 @@ public abstract class BaseEngine
         _dependencyMap = dependencyMap;
     }
 
+
+    
     /**
      * marks all the dependencies of the tainted objects
      * also as tainted to allow proper refreshing.

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java?rev=1298374&r1=1298373&r2=1298374&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java Thu Mar  8 12:49:14 2012
@@ -21,6 +21,7 @@ package rewrite.org.apache.myfaces.exten
 import rewrite.org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api.DependencyRegistry;
 import rewrite.org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.core.ClassDependencies;
 import rewrite.org.apache.myfaces.extensions.scripting.core.monitor.ClassResource;
+import rewrite.org.apache.myfaces.extensions.scripting.core.monitor.WatchedResource;
 
 import javax.servlet.ServletContext;
 import java.util.Collection;
@@ -110,4 +111,6 @@ public interface ScriptingEngine
      * of the corresponding engine
      */
     public String getEngineTypeAsStr();
+
+
 }

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/loader/ThrowAwayClassloader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/loader/ThrowAwayClassloader.java?rev=1298374&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/loader/ThrowAwayClassloader.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/loader/ThrowAwayClassloader.java Thu Mar  8 12:49:14 2012
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package rewrite.org.apache.myfaces.extensions.scripting.core.loader;
+
+import rewrite.org.apache.myfaces.extensions.scripting.core.context.WeavingContext;
+import rewrite.org.apache.myfaces.extensions.scripting.core.monitor.ClassResource;
+
+import java.io.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static java.util.logging.Level.SEVERE;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ThrowAwayClassloader extends ClassLoader
+{
+
+    static final Logger _logger = Logger.getLogger(ThrowAwayClassloader.class.getName());
+
+    public ThrowAwayClassloader(ClassLoader classLoader)
+    {
+        super(classLoader);
+    }
+
+    public ThrowAwayClassloader()
+    {
+    }
+
+    @Override
+    /**
+     * load called either if the class is not loaded at all
+     * or if the class has been recompiled (check upfront)
+     */
+    public Class<?> loadClass(String className) throws ClassNotFoundException
+    {
+        ClassResource res = (ClassResource) WeavingContext.getInstance().getResource(className);
+        if (res == null) return super.loadClass(className);
+        if (!res.isTainted() && res.getAClass() != null) return res.getAClass();
+        File target = resolveClassFile(className);
+        //a load must happen anyway because the target was recompiled
+        int fileLength;
+        byte[] fileContent;
+        FileInputStream iStream = null;
+        //we cannot load while a compile is in progress
+        //we have to wait until it is one
+        try
+        {
+            fileLength = (int) target.length();
+            fileContent = new byte[fileLength];
+            iStream = new FileInputStream(target);
+            int result = iStream.read(fileContent);
+            _logger.log(Level.FINER, "read {0} bytes", String.valueOf(result));
+        }
+        catch (FileNotFoundException e)
+        {
+            throw new ClassNotFoundException(e.toString());
+        }
+        catch (IOException e)
+        {
+            throw new ClassNotFoundException(e.toString());
+        }
+        finally
+        {
+            if (iStream != null)
+            {
+                try
+                {
+                    iStream.close();
+                }
+                catch (Exception e)
+                {
+                    Logger log = Logger.getLogger(this.getClass().getName());
+                    log.log(SEVERE, "", e);
+                }
+            }
+        }
+        //here we use trick17 we can store as many classes of the same name
+        //as long as we store with a new classloader every time it needs refresh
+        //we need to do it because the classloader can call itself recursively
+        //TODO we might run into issues here with inner classes
+        Class retVal;
+        if (res != null) {
+            retVal = (new ThrowAwayClassloader(getParent())).defineClass(className, fileContent, 0, fileLength);
+            res.setAClass(retVal);
+            res.setTainted(false);
+        } else {
+            retVal = super.defineClass(className, fileContent, 0, fileLength);
+        }
+        return retVal;
+
+    }
+
+    @Override
+    public InputStream getResourceAsStream(String name)
+    {
+        File resource = resolveClassFile(name);
+        if (resource.exists())
+        {
+            try
+            {
+                return new FileInputStream(resource);
+            }
+            catch (FileNotFoundException e)
+            {
+                return super.getResourceAsStream(name);
+            }
+        }
+        return super.getResourceAsStream(name);
+    }
+
+    private File resolveClassFile(String name)
+    {
+        return new File(WeavingContext.getInstance().getConfiguration().getCompileTarget().getAbsolutePath() + File
+                .separator + name);
+    }
+
+}

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/monitor/ResourceMonitor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/monitor/ResourceMonitor.java?rev=1298374&r1=1298373&r2=1298374&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/monitor/ResourceMonitor.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/core/monitor/ResourceMonitor.java Thu Mar  8 12:49:14 2012
@@ -18,8 +18,6 @@
  */
 package rewrite.org.apache.myfaces.extensions.scripting.core.monitor;
 
-
-
 import rewrite.org.apache.myfaces.extensions.scripting.core.common.ScriptingConst;
 import rewrite.org.apache.myfaces.extensions.scripting.core.context.WeavingContext;
 
@@ -43,7 +41,8 @@ import java.util.logging.Logger;
  * @author Werner Punz (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-public class ResourceMonitor extends Thread {
+public class ResourceMonitor extends Thread
+{
 
     private static final String CONTEXT_KEY = "extscriptDaemon";
 
@@ -65,44 +64,42 @@ public class ResourceMonitor extends Thr
     Map<Integer, Boolean> _systemRecompileMap = new ConcurrentHashMap<Integer, Boolean>(8, 0.75f, 1);
 
     boolean _running = false;
-//    boolean _contextInitialized = false;
+    //    boolean _contextInitialized = false;
     Logger _log = Logger.getLogger(ResourceMonitor.class.getName());
-//    ScriptingWeaver _weavers = null;
+    //    ScriptingWeaver _weavers = null;
     static WeakReference<ServletContext> _externalContext;
 
-    public static synchronized void startup(ServletContext externalContext) {
+    public static synchronized void startup(ServletContext externalContext)
+    {
 
         if (_externalContext != null) return;
         _externalContext = new WeakReference<ServletContext>(externalContext);
-        if(getInstance() != null) return;
+        if (getInstance() != null) return;
 
         //we currently keep it as singleton but in the long run we will move it into the context
         //like everything else singleton-wise
 
-            _instance = new ResourceMonitor();
-
-            /**
-             * daemon thread to allow forced
-             * shutdowns for web context restarts
-             */
-            _instance.setDaemon(true);
-            _instance.setRunning(true);
-            //_instance.start();
-            _externalContext.get().setAttribute(CONTEXT_KEY, _instance);
+        _instance = new ResourceMonitor();
 
+        /**
+         * daemon thread to allow forced
+         * shutdowns for web context restarts
+         */
+        _instance.setDaemon(true);
+        _instance.setRunning(true);
+        //_instance.start();
+        _externalContext.get().setAttribute(CONTEXT_KEY, _instance);
 
     }
 
-    public static synchronized void clear() {
-
-    }
-
-    public static synchronized ResourceMonitor getInstance() {
+    public static synchronized ResourceMonitor getInstance()
+    {
         //we do it in this complicated manner because of find bugs
         //practically this cannot really happen except for shutdown were it is not important anymore
         ServletContext context = _externalContext.get();
-        if (context != null) {
-           return (ResourceMonitor) context.getAttribute(CONTEXT_KEY);
+        if (context != null)
+        {
+            return (ResourceMonitor) context.getAttribute(CONTEXT_KEY);
         }
         return null;
     }
@@ -111,25 +108,30 @@ public class ResourceMonitor extends Thr
      * Central run method
      * which performs the entire scanning process
      */
-    public void run() {
+    public void run()
+    {
 
-        while(_running) {
-            if(!_running) break;
+        while (_running)
+        {
+            if (!_running) break;
             //we run the full scan on the classes to bring our data structures up to the task
             performMonitoringTask();
             sleep();
         }
 
-        if (_log.isLoggable(Level.INFO)) {
+        if (_log.isLoggable(Level.INFO))
+        {
             _log.info("[EXT-SCRIPTING] Dynamic reloading watch daemon is shutting down");
         }
     }
 
-    public void initialMonitoring() {
+    public void initialMonitoring()
+    {
         WeavingContext context = WeavingContext.getInstance();
         context.initialFullScan();
         //we compile wherever needed, taints are now in place due to our scan already being performed
-        if(context.compile()) {
+        if (context.compile())
+        {
             //we now have to perform a full dependency scan to bring our dependency map to the latest state
             context.scanDependencies();
             //we next retaint all classes according to our dependency graph
@@ -143,7 +145,8 @@ public class ResourceMonitor extends Thr
         context.initialFullScan();
 
         //we compile wherever needed, taints are now in place due to our scan already being performed
-        if(context.compile()) {
+        if (context.compile())
+        {
             //we now have to perform a full dependency scan to bring our dependency map to the latest state
             context.scanDependencies();
             //we next retaint all classes according to our dependency graph
@@ -153,39 +156,19 @@ public class ResourceMonitor extends Thr
 
     private void sleep()
     {
-        try {
+        try
+        {
             Thread.sleep(ScriptingConst.TAINT_INTERVAL);
-        } catch (InterruptedException e) {
+        }
+        catch (InterruptedException e)
+        {
             //if the server shuts down while we are in sleep we get an error
             //which we better should swallow
         }
     }
 
-    /**
-     * central tainted mark method which keeps
-     * track if some file in one of the supported engines has changed
-     * and if yes marks the file as tainted as well
-     * as marks the engine as having to do a full recompile
-     */
-    private final void checkForChanges() {
-   
-    }
-
-    /**
-     * recursive walk over our meta data to taint also the classes
-     * which refer to our refreshing class so that those
-     * are reloaded as well, this helps to avoid classcast
-     * exceptions caused by imports and casts on long running artifacts
-     *
-     * @param className the origin classname which needs to be walked recursively
-     */
-    private void dependencyTainted(String className) {
-    
-    }
-
-
-
-    public void setRunning(boolean running) {
+    public void setRunning(boolean running)
+    {
         this._running = running;
     }
 }

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/CustomChainLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/CustomChainLoader.java?rev=1298374&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/CustomChainLoader.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/CustomChainLoader.java Thu Mar  8 12:49:14 2012
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package rewrite.org.apache.myfaces.extensions.scripting.jsf.adapters;
+
+import org.apache.myfaces.shared.util.ClassLoaderExtension;
+import rewrite.org.apache.myfaces.extensions.scripting.core.common.util.ClassUtils;
+import rewrite.org.apache.myfaces.extensions.scripting.core.context.WeavingContext;
+import rewrite.org.apache.myfaces.extensions.scripting.core.monitor.ClassResource;
+import rewrite.org.apache.myfaces.extensions.scripting.core.loader.ThrowAwayClassloader;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *
+ * The chainloader docks onto the forName handler
+ * in the myfaces classutils which load the
+ * artifacting classes, we dock onto this extension point
+ * neutrally by indirection over the MyFacesSPI
+ */
+
+public class CustomChainLoader extends ClassLoaderExtension
+{
+
+    ThrowAwayClassloader _loader = null;
+
+    static class _Action implements PrivilegedExceptionAction<ThrowAwayClassloader>
+    {
+        ClassLoader _parent;
+
+        _Action(ClassLoader parent)
+        {
+            this._parent = parent;
+        }
+
+        public ThrowAwayClassloader run()
+        {
+            return new ThrowAwayClassloader(_parent);
+        }
+    }
+
+    public CustomChainLoader(ServletContext context)
+    {
+        try
+        {
+            _loader = AccessController.doPrivileged(
+                    new _Action(ClassUtils.getContextClassLoader())
+            );
+        }
+        catch (PrivilegedActionException e)
+        {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+    }
+
+    public Class forName(String name)
+    {
+        if (name.endsWith(";"))
+        {
+            name = name.substring(1, name.length() - 1);
+        }
+
+        if (name.startsWith("java.")) /*the entire java namespace is reserved so no use to do a specific classloading check here*/
+            return null;
+        if (name.startsWith("javax.")) /*the entire java namespace is reserved so no use to do a specific classloading check here*/
+            return null;
+        else if (name.startsWith("com.sun")) /*internal java specific namespace*/
+            return null;
+        else if (name.startsWith("sun.")) /*internal java specific namespace*/
+            return null;
+        else if (name.startsWith("org.apache") && !name.startsWith("org.apache.myfaces"))
+        {
+            return null;
+        } else if (name.startsWith("org.apache") && name.startsWith("org.apache.myfaces.config"))
+        {
+            return null;
+        }
+        try
+        {
+            return loadClass(name);
+        }
+        catch (ClassNotFoundException e)
+        {
+            return null;
+        }
+    }
+
+    private Class loadClass(String name) throws ClassNotFoundException
+    {
+        File targetDirectory = WeavingContext.getInstance().getConfiguration().getCompileTarget();
+        File target = ClassUtils.classNameToFile(targetDirectory.getAbsolutePath(), name);
+        if (!target.exists()) ClassUtils.getContextClassLoader().loadClass(name);
+        //otherwise check if tainted and if not simply return the class stored
+        if(name.contains("TestNavigationHandler")) {
+            System.out.println("debugpoint found");
+        }
+        ClassResource resource = (ClassResource) WeavingContext.getInstance().getResource(name);
+        if (resource == null)
+        {
+            return null;
+        }
+        if (resource.isTainted() || resource.getAClass() == null)
+        {
+            //load the class via the throw away classloader
+            return _loader.loadClass(name);
+        } else
+        {
+            return resource.getAClass();
+        }
+
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/MyFacesSPI.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/MyFacesSPI.java?rev=1298374&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/MyFacesSPI.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/adapters/MyFacesSPI.java Thu Mar  8 12:49:14 2012
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package rewrite.org.apache.myfaces.extensions.scripting.jsf.adapters;
+
+import org.apache.myfaces.extensions.scripting.core.util.Cast;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+import rewrite.org.apache.myfaces.extensions.scripting.core.common.util.ClassUtils;
+
+import javax.servlet.ServletContext;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *
+ * SPI for various myfaces related tasks
+ */
+public class MyFacesSPI
+{
+
+    public void registerClassloadingExtension(ServletContext context) {
+        Object loader = new CustomChainLoader(context); //ReflectUtil.instantiate("extras.org.apache.myfaces.extensions
+        // .scripting.servlet" +
+                //".CustomChainLoader",
+                //new Cast(ServletContext.class, context));
+        ClassUtils.addClassLoadingExtension(loader, true);
+    }
+
+
+    private static MyFacesSPI ourInstance = new MyFacesSPI();
+
+    public static MyFacesSPI getInstance()
+    {
+        return ourInstance;
+    }
+
+    private MyFacesSPI()
+    {
+    }
+}

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/startup/StartupServletContextPluginChainLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/startup/StartupServletContextPluginChainLoader.java?rev=1298374&r1=1298373&r2=1298374&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/startup/StartupServletContextPluginChainLoader.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/rewrite/org/apache/myfaces/extensions/scripting/jsf/startup/StartupServletContextPluginChainLoader.java Thu Mar  8 12:49:14 2012
@@ -20,11 +20,10 @@
 package rewrite.org.apache.myfaces.extensions.scripting.jsf.startup;
 
 import org.apache.myfaces.webapp.StartupListener;
-import rewrite.org.apache.myfaces.extensions.scripting.core.common.util.Cast;
-import rewrite.org.apache.myfaces.extensions.scripting.core.common.util.ClassUtils;
-import rewrite.org.apache.myfaces.extensions.scripting.core.common.util.ReflectUtil;
 import rewrite.org.apache.myfaces.extensions.scripting.core.context.WeavingContext;
 import rewrite.org.apache.myfaces.extensions.scripting.core.monitor.ResourceMonitor;
+import rewrite.org.apache.myfaces.extensions.scripting.jsf.adapters.CustomChainLoader;
+import rewrite.org.apache.myfaces.extensions.scripting.jsf.adapters.MyFacesSPI;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
@@ -83,11 +82,7 @@ public class StartupServletContextPlugin
      */
     private void initChainLoader(ServletContext servletContext)
     {
-        Object loader = ReflectUtil.instantiate("org.apache.myfaces.extensions.scripting.servlet" +
-                ".CustomChainLoader",
-                new Cast(ServletContext.class, servletContext));
-        ClassUtils.addClassLoadingExtension(loader, true);
-
+        MyFacesSPI.getInstance().registerClassloadingExtension(servletContext);
     }
 
     public void postInit(ServletContextEvent evt)