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/09/10 12:08:43 UTC

svn commit: r813347 - in /myfaces/extensions/scripting/trunk: core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ core-java6/src/test/ core-java6/src/test/java/ core-java6/src/test/java/org/ core-java6/src/test/java/org/apache/ c...

Author: werpu
Date: Thu Sep 10 10:08:42 2009
New Revision: 813347

URL: http://svn.apache.org/viewvc?rev=813347&view=rev
Log:
http://issues.apache.org/jira/browse/EXTSCRIPT-14
unified the access to the myfaces_shared classutils as much as possible




Added:
    myfaces/extensions/scripting/trunk/core-java6/src/test/
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe1.java
    myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe2.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ReflectUtil.java
Modified:
    myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
    myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.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/loaders/java/jci/CompilerFacade.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/StartupServletContextPluginChainLoader.java

Modified: myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java?rev=813347&r1=813346&r2=813347&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java (original)
+++ myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java Thu Sep 10 10:08:42 2009
@@ -18,7 +18,9 @@
  */
 package org.apache.myfaces.scripting.loaders.java.jsr199;
 
-import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+
+import org.apache.myfaces.scripting.core.util.ClassUtils;
 
 import javax.tools.FileObject;
 import javax.tools.ForwardingJavaFileManager;

Modified: myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java?rev=813347&r1=813346&r2=813347&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java (original)
+++ myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java Thu Sep 10 10:08:42 2009
@@ -23,6 +23,7 @@
 import org.apache.myfaces.scripting.core.util.Null;
 import org.apache.myfaces.scripting.core.util.Cast;
 import org.apache.myfaces.scripting.core.util.ClassUtils;
+import org.apache.myfaces.scripting.core.util.ReflectUtil;
 
 
 import java.io.File;
@@ -55,36 +56,36 @@
         //TODO move this all into the introspection domain
         //so that we can shift to jdk5
         Class toolProviderClass = ClassUtils.forName("javax.tools.ToolProvider");
-        compiler = ClassUtils.executeStaticFunction(toolProviderClass, "getSystemJavaCompiler");
-        diagnosticCollector = ClassUtils.instantiate("javax.tools.DiagnosticCollector");
+        compiler = ReflectUtil.executeStaticFunction(toolProviderClass, "getSystemJavaCompiler");
+        diagnosticCollector = ReflectUtil.instantiate("javax.tools.DiagnosticCollector");
 
-        fileManager = ClassUtils.instantiate("org.apache.myfaces.scripting.loaders.java.jsr199.ContainerFileManager",
-                                  new Cast(ClassUtils.forName("javax.tools.StandardJavaFileManager"), ClassUtils.executeFunction(compiler, "getStandardFileManager", new Cast(ClassUtils.forName("javax.tools.DiagnosticListener"),diagnosticCollector), new Null(Locale.class), new Null(Charset.class))));
+        fileManager = ReflectUtil.instantiate("org.apache.myfaces.scripting.loaders.java.jsr199.ContainerFileManager",
+                                  new Cast(ClassUtils.forName("javax.tools.StandardJavaFileManager"), ReflectUtil.executeFunction(compiler, "getStandardFileManager", new Cast(ClassUtils.forName("javax.tools.DiagnosticListener"),diagnosticCollector), new Null(Locale.class), new Null(Charset.class))));
 
     }
 
 
     public Class compileFile(String sourceRoot, String classPath, String filePath) throws ClassNotFoundException {
-        Object fileObjects = ClassUtils.executeFunction(fileManager, "getJavaFileObjectsSingle",  sourceRoot + FILE_SEPARATOR + filePath)  ;
+        Object fileObjects = ReflectUtil.executeFunction(fileManager, "getJavaFileObjectsSingle",  sourceRoot + FILE_SEPARATOR + filePath)  ;
 
         //TODO add the core jar from our lib dir
         //the javaCompiler otherwise cannot find the file
         String[] options = new String[]{"-cp",
-                                        (String) ClassUtils.executeFunction(fileManager, "getClassPath"), "-d", (String) ClassUtils.executeFunction(ClassUtils.executeFunction(fileManager, "getTempDir"), "getAbsolutePath"), "-sourcepath", sourceRoot, "-g"};
+                                        (String) ReflectUtil.executeFunction(fileManager, "getClassPath"), "-d", (String) ReflectUtil.executeFunction(ReflectUtil.executeFunction(fileManager, "getTempDir"), "getAbsolutePath"), "-sourcepath", sourceRoot, "-g"};
 
-        ClassUtils.executeMethod(ClassUtils.executeFunction(compiler, "getTask", new Null(Writer.class), new Cast(ClassUtils.forName("javax.tools.JavaFileManager"), fileManager),new Cast(ClassUtils.forName("javax.tools.DiagnosticListener"), diagnosticCollector),new Cast(java.lang.Iterable.class, Arrays.asList(options)), new Null(Iterable.class), new Cast(java.lang.Iterable.class,fileObjects)), "call");
+        ReflectUtil.executeMethod(ReflectUtil.executeFunction(compiler, "getTask", new Null(Writer.class), new Cast(ClassUtils.forName("javax.tools.JavaFileManager"), fileManager),new Cast(ClassUtils.forName("javax.tools.DiagnosticListener"), diagnosticCollector),new Cast(java.lang.Iterable.class, Arrays.asList(options)), new Null(Iterable.class), new Cast(java.lang.Iterable.class,fileObjects)), "call");
         //TODO collect the diagnostics and if an error was issued dump it on the log
         //and throw an unmanaged exeption which routes later on into myfaces
-        Collection diagnostics = (Collection) ClassUtils.executeFunction(diagnosticCollector, "getDiagnostics");
+        Collection diagnostics = (Collection) ReflectUtil.executeFunction(diagnosticCollector, "getDiagnostics");
         Integer size = diagnostics.size();
         if (size > 0) {
             Log log = LogFactory.getLog(this.getClass());
             StringBuilder errors = new StringBuilder();
             for (Object diagnostic : diagnostics) {
                 String error = "Error on line" +
-                               ClassUtils.executeFunction(diagnostic, "getMessage", Locale.getDefault()) + "------" +
-                               ClassUtils.executeFunction(diagnostic, "getLineNumber") + " File:" +
-                               ClassUtils.executeFunction(diagnostic, "getSource").toString();
+                               ReflectUtil.executeFunction(diagnostic, "getMessage", Locale.getDefault()) + "------" +
+                               ReflectUtil.executeFunction(diagnostic, "getLineNumber") + " File:" +
+                               ReflectUtil.executeFunction(diagnostic, "getSource").toString();
                 log.error(error);
                 errors.append(error);
 
@@ -95,7 +96,7 @@
         ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
         if (!(oldClassLoader instanceof RecompiledClassLoader)) {
             try {
-                RecompiledClassLoader classLoader = (RecompiledClassLoader) ClassUtils.executeFunction(fileManager, "getClassLoader");
+                RecompiledClassLoader classLoader = (RecompiledClassLoader) ReflectUtil.executeFunction(fileManager, "getClassLoader");
                 Thread.currentThread().setContextClassLoader(classLoader);
                 String classFile = filePath.replaceAll("\\\\", ".").replaceAll("\\/", ".");
                 classFile = classFile.substring(0, classFile.lastIndexOf("."));

Added: myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java?rev=813347&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java (added)
+++ myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/JavaDynamicClassIdentifierTest.java Thu Sep 10 10:08:42 2009
@@ -0,0 +1,58 @@
+/*
+ * 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 org.apache.myfaces.javaloader.core;
+
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
+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
+ */
+
+public class JavaDynamicClassIdentifierTest {
+
+     Object probe1 = null;
+     Object probe2 = null;
+     CoreWeaver weaver = null;
+
+     @Before
+     public void setUp() {
+        probe1 = new Probe1();
+        probe2 = new Probe2();
+        weaver = new CoreWeaver(new JavaScriptingWeaver());
+        ProxyUtils.setWeaver(weaver); 
+    }
+
+
+     @Test
+     public void isDynamic() {
+        assertFalse("Class should be static",ProxyUtils.isDynamic(probe1.getClass()));
+        assertTrue("Class should be dynamic",ProxyUtils.isDynamic(probe2.getClass()));
+     }
+
+
+
+}

Added: myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe1.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe1.java?rev=813347&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe1.java (added)
+++ myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe1.java Thu Sep 10 10:08:42 2009
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.myfaces.javaloader.core;
+
+/**
+ * @author werpu
+ * probe for our unit test
+ */
+public class Probe1 {
+}

Added: myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe2.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe2.java?rev=813347&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe2.java (added)
+++ myfaces/extensions/scripting/trunk/core-java6/src/test/java/org/apache/myfaces/javaloader/core/Probe2.java Thu Sep 10 10:08:42 2009
@@ -0,0 +1,28 @@
+/*
+ * 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 org.apache.myfaces.javaloader.core;
+
+import org.apache.myfaces.scripting.loaders.java.ScriptingClass;
+
+/**
+ * @author werpu
+ */
+@ScriptingClass
+public class Probe2 {
+}

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java?rev=813347&r1=813346&r2=813347&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java Thu Sep 10 10:08:42 2009
@@ -23,6 +23,7 @@
 import org.apache.bcel.util.ClassPath;
 import org.apache.bcel.classfile.JavaClass;
 import org.apache.bcel.generic.ClassGen;
+import org.apache.myfaces.shared_impl.util.ClassLoaderExtension;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
@@ -47,204 +48,13 @@
         }
     }
 
-    public static Object instantiate(String clazz, Object... varargs) {
-        return instantiate(forName(clazz), varargs);
-    }
-
-    public static Object instantiate(Class clazz, Object... varargs) {
-        Class[] classes = new Class[varargs.length];
-        for (int cnt = 0; cnt < varargs.length; cnt++) {
-
-            if (varargs[cnt] instanceof Cast) {
-                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
-                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
-            } else {
-                classes[cnt] = varargs[cnt].getClass();
-            }
-        }
-
-        Constructor constr = null;
-        try {
-            constr = clazz.getConstructor(classes);
-            return (Object) constr.newInstance(varargs);
-        } catch (NoSuchMethodException e) {
-            throw new RuntimeException(e);
-        } catch (InvocationTargetException e) {
-            throw new RuntimeException(e);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException(e);
-        } catch (InstantiationException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-
-    /*this is mostly just a helper to bypass a groovy bug in a more
-   * complex delegation environemt. Groovy throws a classcast
-   * exeption wrongly, delegating the instantiation code to java
-   * fixes that
-   * */
-    public static Object newObject(Class clazz) throws IllegalAccessException, InstantiationException {
-        return clazz.newInstance();
-    }
-
-    /**
-     * executes a method
-     *
-     * @param obj        the target object
-     * @param methodName the method name
-     * @param varargs    a list of objects casts or nulls defining the parameter classes and its values
-     *                   if something occurs on introspection level an unmanaged exception is throw, just like
-     *                   it would happen in a scripting class
-     */
-    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 Cast) {
-                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
-                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
-            } else {
-                classes[cnt] = varargs[cnt].getClass();
-            }
-        }
-
-        try {
-            Method m = getMethod(obj, 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);
-        }
-    }
-
-    /**
-     * executes a function method on a target object
-     *
-     * @param obj        the target object
-     * @param methodName the method name
-     * @param varargs    a list of objects casts or nulls defining the parameter classes and its values
-     *                   if something occurs on introspection level an unmanaged exception is throw, just like
-     *                   it would happen in a scripting class
-     * @return the result object for the function(method) call
-     * @throws RuntimeException an unmanaged runtime exception in case of an introspection error
-     */
-    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 Cast) {
-                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
-                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
-            } else {
-                classes[cnt] = varargs[cnt].getClass();
-            }
-        }
-
-        try {
-            Method m = getMethod(obj, 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);
-        }
-
-    }
-
-    private static Method getMethod(Object obj, String methodName, Class[] classes) throws NoSuchMethodException {
-        Method m = null;
-        try {
-            m = obj.getClass().getDeclaredMethod(methodName, classes);
-        } catch (NoSuchMethodException e) {
-            m = obj.getClass().getMethod(methodName, classes);
-        }
-        return m;
-    }
-
-
-    /**
-     * executes a function method on a target object
-     *
-     * @param obj        the target object
-     * @param methodName the method name
-     * @param varargs    a list of objects casts or nulls defining the parameter classes and its values
-     *                   if something occurs on introspection level an unmanaged exception is throw, just like
-     *                   it would happen in a scripting class
-     * @return the result object for the function(method) call
-     * @throws RuntimeException an unmanaged runtime exception in case of an introspection error
-     */
-    public static Object executeStaticFunction(Class obj, String methodName, Object... varargs) {
-        Class[] classes = new Class[varargs.length];
-        for (int cnt = 0; cnt < varargs.length; cnt++) {
-
-            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 = getStaticMethod(obj, 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);
-        }
-
-    }
-
-    private static Method getStaticMethod(Class obj, String methodName, Class[] classes) throws NoSuchMethodException {
-        Method m = null;
-        try {
-            m = obj.getDeclaredMethod(methodName, classes);
-        } catch (NoSuchMethodException e) {
-            m = obj.getMethod(methodName, classes);
-        }
-        return m;
-    }
-
-    /**
-     * convenience method which makes the code a little bit more readable
-     * use it in conjunction with static imports
-     *
-     * @param clazz the cast target for the method call
-     * @param value the value object to be used as param
-     * @return a Cast object of the parameters
-     */
-    public static Cast cast(Class clazz, Object value) {
-        return new Cast(clazz, value);
-    }
-
-    /**
-     * convenience method which makes the code a little bit more readable
-     * use it in conjunction with static imports
-     *
-     * @param clazz the cast target for the method call
-     * @return a null value Cast object of the parameters
-     */
-    public static Null nullCast(Class clazz) {
-        return new Null(clazz);
-    }
-
 
     /**
      * we use the BCEL here to add a marker interface dynamically on the compiled java class
      * so that later we can identify the marked class as being of dynamic origin
      * that way we dont have to hammer any data structure but can work over introspection
      * to check for an implemented marker interface
-     *
+     * <p/>
      * I cannot use the planned annotation for now
      * because the BCEL has annotation support only
      * in the trunk but in no official release,
@@ -259,7 +69,7 @@
         repo.clear();
         JavaClass javaClass = repo.loadClass(className);
         ClassGen classGen = new ClassGen(javaClass);
-        
+
         classGen.addInterface("org.apache.myfaces.scripting.loaders.java._ScriptingClass");
         classGen.update();
 
@@ -272,7 +82,6 @@
         }
     }
 
-  
 
     public static File classNameToFile(String classPath, String className) {
         String classFileName = classNameToRelativeFileName(className);
@@ -289,4 +98,16 @@
         className = className.substring(0, className.lastIndexOf("."));
         return className;
     }
+
+    public static ClassLoader getContextClassLoader() {
+        return org.apache.myfaces.shared_impl.util.ClassUtils.getContextClassLoader();
+    }
+
+    public static void addClassLoadingExtension(ClassLoaderExtension extension, boolean top) {
+        org.apache.myfaces.shared_impl.util.ClassUtils.addClassLoadingExtension(extension, top);
+    }
+
+    public Class classForName(String name) throws ClassNotFoundException {
+        return org.apache.myfaces.shared_impl.util.ClassUtils.classForName(name);
+    }
 }

Added: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ReflectUtil.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ReflectUtil.java?rev=813347&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ReflectUtil.java (added)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ReflectUtil.java Thu Sep 10 10:08:42 2009
@@ -0,0 +1,219 @@
+/*
+ * 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 org.apache.myfaces.scripting.core.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ReflectUtil {
+    public static Object instantiate(String clazz, Object... varargs) {
+        return instantiate(ClassUtils.forName(clazz), varargs);
+    }
+
+    public static Object instantiate(Class clazz, Object... varargs) {
+        Class[] classes = new Class[varargs.length];
+        for (int cnt = 0; cnt < varargs.length; cnt++) {
+
+            if (varargs[cnt] instanceof Cast) {
+                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+            } else {
+                classes[cnt] = varargs[cnt].getClass();
+            }
+        }
+
+        Constructor constr = null;
+        try {
+            constr = clazz.getConstructor(classes);
+            return (Object) constr.newInstance(varargs);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        } catch (InstantiationException e) {
+            throw new RuntimeException(e);
+        }
+    }/*this is mostly just a helper to bypass a groovy bug in a more
+   * complex delegation environemt. Groovy throws a classcast
+   * exeption wrongly, delegating the instantiation code to java
+   * fixes that
+   * */
+    public static Object newObject(Class clazz) throws IllegalAccessException, InstantiationException {
+        return clazz.newInstance();
+    }
+
+    /**
+     * executes a method
+     *
+     * @param obj        the target object
+     * @param methodName the method name
+     * @param varargs    a list of objects casts or nulls defining the parameter classes and its values
+     *                   if something occurs on introspection level an unmanaged exception is throw, just like
+     *                   it would happen in a scripting class
+     */
+    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 Cast) {
+                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+            } else {
+                classes[cnt] = varargs[cnt].getClass();
+            }
+        }
+
+        try {
+            Method m = getMethod(obj, 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);
+        }
+    }
+
+    /**
+     * executes a function method on a target object
+     *
+     * @param obj        the target object
+     * @param methodName the method name
+     * @param varargs    a list of objects casts or nulls defining the parameter classes and its values
+     *                   if something occurs on introspection level an unmanaged exception is throw, just like
+     *                   it would happen in a scripting class
+     * @return the result object for the function(method) call
+     * @throws RuntimeException an unmanaged runtime exception in case of an introspection error
+     */
+    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 Cast) {
+                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+            } else {
+                classes[cnt] = varargs[cnt].getClass();
+            }
+        }
+
+        try {
+            Method m = getMethod(obj, 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);
+        }
+
+    }
+
+    public static Method getMethod(Object obj, String methodName, Class[] classes) throws NoSuchMethodException {
+        Method m = null;
+        try {
+            m = obj.getClass().getDeclaredMethod(methodName, classes);
+        } catch (NoSuchMethodException e) {
+            m = obj.getClass().getMethod(methodName, classes);
+        }
+        return m;
+    }
+
+    /**
+     * executes a function method on a target object
+     *
+     * @param obj        the target object
+     * @param methodName the method name
+     * @param varargs    a list of objects casts or nulls defining the parameter classes and its values
+     *                   if something occurs on introspection level an unmanaged exception is throw, just like
+     *                   it would happen in a scripting class
+     * @return the result object for the function(method) call
+     * @throws RuntimeException an unmanaged runtime exception in case of an introspection error
+     */
+    public static Object executeStaticFunction(Class obj, String methodName, Object... varargs) {
+        Class[] classes = new Class[varargs.length];
+        for (int cnt = 0; cnt < varargs.length; cnt++) {
+
+            if (varargs[cnt] instanceof Cast) {
+                classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+                varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+            } else {
+                classes[cnt] = varargs[cnt].getClass();
+            }
+        }
+
+        //TODO add autocasting instead of manual casting
+
+        try {
+            Method m = getStaticMethod(obj, 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);
+        }
+
+    }
+
+    public static Method getStaticMethod(Class obj, String methodName, Class[] classes) throws NoSuchMethodException {
+        Method m = null;
+        try {
+            m = obj.getDeclaredMethod(methodName, classes);
+        } catch (NoSuchMethodException e) {
+            m = obj.getMethod(methodName, classes);
+        }
+        return m;
+    }
+
+    /**
+     * convenience method which makes the code a little bit more readable
+     * use it in conjunction with static imports
+     *
+     * @param clazz the cast target for the method call
+     * @param value the value object to be used as param
+     * @return a Cast object of the parameters
+     */
+    public static Cast cast(Class clazz, Object value) {
+        return new Cast(clazz, value);
+    }
+
+    /**
+     * convenience method which makes the code a little bit more readable
+     * use it in conjunction with static imports
+     *
+     * @param clazz the cast target for the method call
+     * @return a null value Cast object of the parameters
+     */
+    public static Null nullCast(Class clazz) {
+        return new Null(clazz);
+    }
+}

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java?rev=813347&r1=813346&r2=813347&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ApplicationProxy.java Thu Sep 10 10:08:42 2009
@@ -369,6 +369,7 @@
         return _delegate.getConverterIds();
     }
 
+
     public Iterator<Class> getConverterTypes() {
         weaveDelegate();
         return _delegate.getConverterTypes();

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=813347&r1=813346&r2=813347&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 Thu Sep 10 10:08:42 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.util.ClassUtils;
+import org.apache.myfaces.scripting.core.util.ReflectUtil;
 //import org.apache.myfaces.scripting.loaders.java.jsr199.ReflectCompilerFacade;
 
 import javax.servlet.ServletContext;
@@ -111,7 +111,7 @@
         try {
             //we initialize the compiler lazy
             //because the facade itself is lazy
-            DynamicCompiler compiler = (DynamicCompiler) ClassUtils.instantiate(getScriptingFacadeClass());//new ReflectCompilerFacade();
+            DynamicCompiler compiler = (DynamicCompiler) ReflectUtil.instantiate(getScriptingFacadeClass());//new ReflectCompilerFacade();
             retVal = compiler.compileFile(sourceRoot, classPath, file);
         } catch (ClassNotFoundException e) {
             //can be safely ignored

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java?rev=813347&r1=813346&r2=813347&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java Thu Sep 10 10:08:42 2009
@@ -18,22 +18,20 @@
  */
 package org.apache.myfaces.scripting.loaders.java.jci;
 
-import org.apache.myfaces.scripting.api.DynamicCompiler;
-import org.apache.myfaces.scripting.core.util.FileUtils;
-import org.apache.myfaces.shared_impl.util.ClassUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.commons.jci.compilers.CompilationResult;
 import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.compilers.JavaCompilerFactory;
-import org.apache.commons.jci.compilers.CompilationResult;
-
-import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.readers.FileResourceReader;
-import org.apache.commons.jci.stores.MemoryResourceStore;
+import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.stores.FileResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.jci.stores.ResourceStoreClassLoader;
-import org.apache.commons.jci.stores.FileResourceStore;
-import org.apache.commons.jci.problems.CompilationProblem;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.scripting.api.DynamicCompiler;
+import org.apache.myfaces.scripting.core.util.ClassUtils;
+import org.apache.myfaces.scripting.core.util.FileUtils;
 
 import java.io.File;
 
@@ -61,12 +59,12 @@
         CompilationResult result = null;
         String[] toCompile = new String[]{filePath};
         String className = filePath.replaceAll(File.separator, ".");
-        className = org.apache.myfaces.scripting.core.util.ClassUtils.relativeFileToClassName(className);
+        className = ClassUtils.relativeFileToClassName(className);
 
         result = compiler.compile(toCompile, reader, target);
 
         if (result.getErrors().length == 0) {
-            org.apache.myfaces.scripting.core.util.ClassUtils.markAsDynamicJava(tempDir.getAbsolutePath(), className);
+            ClassUtils.markAsDynamicJava(tempDir.getAbsolutePath(), className);
 
             ResourceStore[] stores = {target};
             ResourceStoreClassLoader loader = new ResourceStoreClassLoader(ClassUtils.getContextClassLoader(), stores);

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/StartupServletContextPluginChainLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/StartupServletContextPluginChainLoader.java?rev=813347&r1=813346&r2=813347&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/StartupServletContextPluginChainLoader.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/StartupServletContextPluginChainLoader.java Thu Sep 10 10:08:42 2009
@@ -21,8 +21,9 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.shared_impl.util.ClassUtils;
+
 import org.apache.myfaces.webapp.StartupListener;
+import org.apache.myfaces.scripting.core.util.ClassUtils;
 
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContext;