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 2010/04/12 21:43:37 UTC

svn commit: r933379 [4/15] - in /myfaces/extensions/scripting/trunk: extscript-core-root/extscript-core-java6/src/main/java/org/apache/myfaces/extensions/ extscript-core-root/extscript-core-java6/src/main/java/org/apache/myfaces/extensions/scripting/ e...

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/StandardNamespaceFilter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/StandardNamespaceFilter.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/StandardNamespaceFilter.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/StandardNamespaceFilter.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,21 @@
+package org.apache.myfaces.extensions.scripting.core.dependencyScan.filter;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.core.ClassScanUtils;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.ClassFilter;
+
+/**
+ * Filter facade for our standard namespace check
+ */
+public class StandardNamespaceFilter implements ClassFilter {
+
+    /**
+     * is allowed implementation for our standard namespace filter
+     *
+     * @param engineType integer value of the engine type of the class
+     * @param clazz      the class itself to be processed by the filter
+     * @return true if it is not in the standard namespaces false otherwise
+     */
+    public final boolean isAllowed(Integer engineType, String clazz) {
+        return !ClassScanUtils.isStandardNamespace(clazz);
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/WhitelistFilter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/WhitelistFilter.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/WhitelistFilter.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/WhitelistFilter.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,128 @@
+/*
+ * 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.extensions.scripting.core.dependencyScan.filter;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.ClassFilter;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Filter class which depends upon a list of whitelisted packages
+ * wildcards in this filter are implicit which means
+ * <p/>
+ * org.apache.myfaces includes all files
+ * under org.apache.myfaces
+ */
+public class WhitelistFilter implements ClassFilter {
+
+    WhiteListNode _whiteList = new WhiteListNode();
+
+    /*we use a package tree here to make the whitelist check as performant as possible*/
+
+    class WhiteListNode {
+        Map<String, WhiteListNode> _value = new ConcurrentHashMap<String, WhiteListNode>();
+
+        public WhiteListNode addEntry(String key) {
+            if (_value.containsKey(key)) {
+                return _value.get(key);
+            }
+            WhiteListNode retVal = new WhiteListNode();
+            _value.put(key, retVal);
+            return retVal;
+        }
+
+        public boolean hasChildren() {
+            return !_value.isEmpty();
+        }
+
+        public Map<String, WhiteListNode> getValue() {
+            return _value;
+        }
+
+        public void setValue(Map<String, WhiteListNode> value) {
+            this._value = value;
+        }
+
+        public WhiteListNode get(String key) {
+            return _value.get(key);
+        }
+    }
+
+    public WhitelistFilter(String... whiteList) {
+        for (String singlePackage : whiteList) {
+            addEntry(singlePackage);
+        }
+    }
+
+    public WhitelistFilter(Collection<String> whiteList) {
+        for (String singlePackage : whiteList) {
+            addEntry(singlePackage);
+        }
+    }
+
+    /**
+     * whitespace is allowed implementation
+     *
+     * @param engineType integer value of the engine type of the class
+     * @param clazz      the class itself to be processed by the filter
+     * @return true if it is white-spaced, false otherwise
+     */
+    public final boolean isAllowed(Integer engineType, String clazz) {
+        String[] subParts = clazz.split("\\.");
+        WhiteListNode currPackage = _whiteList;
+        WhiteListNode parentPackage = null;
+        for (String subPart : subParts) {
+            currPackage = currPackage.get(subPart);
+            if (isRootPackageMismatch(currPackage, parentPackage)) {
+                return false;
+            } else if (isSubpackage(currPackage, parentPackage)) {
+                return true;
+            } else if (isMismatch(currPackage)) {
+                return false;
+            }
+
+            parentPackage = currPackage;
+        }
+        return true;
+    }
+
+    private void addEntry(String singlePackage) {
+        String[] subPackages = singlePackage.split("\\.");
+        WhiteListNode currPackage = _whiteList;
+        for (String subPackage : subPackages) {
+            currPackage = currPackage.addEntry(subPackage);
+        }
+    }
+
+    //special conditions extracted for readability reasons in the core
+    //algorithm
+
+    private boolean isMismatch(WhiteListNode currPackage) {
+        return currPackage == null;
+    }
+
+    private boolean isSubpackage(WhiteListNode currPackage, WhiteListNode parentPackage) {
+        return currPackage == null && parentPackage != null && !parentPackage.hasChildren();
+    }
+
+    private boolean isRootPackageMismatch(WhiteListNode currPackage, WhiteListNode parentPackage) {
+        return currPackage == null && parentPackage == null;
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/DependencyRegistryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/DependencyRegistryImpl.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/DependencyRegistryImpl.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/DependencyRegistryImpl.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,117 @@
+package org.apache.myfaces.extensions.scripting.core.dependencyScan.registry;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.ClassFilter;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.core.ClassDependencies;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.filter.ScanIdentifierFilter;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.filter.StandardNamespaceFilter;
+import org.apache.myfaces.extensions.scripting.core.util.StringUtils;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * registry facade which is used to track our dependencies
+ */
+public class DependencyRegistryImpl implements ExternalFilterDependencyRegistry {
+    List<ClassFilter> _filters = new LinkedList<ClassFilter>();
+
+    ClassDependencies _dependencMap;
+
+    //private volatile Strategy _registrationStrategy;
+    final Integer _engineType;
+
+    /**
+     * constructor for our facade
+     *
+     * @param engineType    the engine type this registry should support
+     * @param dependencyMap the dependency map which stores the dependencies
+     */
+    public DependencyRegistryImpl(Integer engineType, ClassDependencies dependencyMap) {
+        _dependencMap = dependencyMap;
+        _engineType = engineType;
+
+        _filters.add(new ScanIdentifierFilter(_engineType, ScriptingConst.ENGINE_TYPE_JSF_ALL, ScriptingConst.ENGINE_TYPE_JSF_NO_ENGINE));
+        _filters.add(new StandardNamespaceFilter());
+    }
+
+    /**
+     * Clears the entire filter map
+     */
+    public void clearFilters() {
+        _filters.clear();
+        _filters.add(new ScanIdentifierFilter(_engineType, ScriptingConst.ENGINE_TYPE_JSF_ALL, ScriptingConst.ENGINE_TYPE_JSF_NO_ENGINE));
+        _filters.add(new StandardNamespaceFilter());
+    }
+
+    /**
+     * adds a new filter
+     *
+     * @param filter the filter to be added
+     */
+    public void addFilter(ClassFilter filter) {
+        _filters.add(filter);
+    }
+
+    /**
+     * checks if the className is allowed in the current filter chain
+     *
+     * @param engineType an identifier for the current scan type (jsf java scan for instance)
+     * @param className  the classname to be checked
+     * @return true if a filter triggers false if not
+     */
+    public boolean isAllowed(Integer engineType, String className) {
+        for (ClassFilter filter : _filters) {
+            if (!filter.isAllowed(_engineType, className)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * adds a dependency to our dependency map (usually rootclass -> dependency and currentClass -> dependency)
+     *
+     * @param engineType            the engine type for this dependency
+     * @param rootClass             the root class of this scan which all dependencies are referenced from
+     * @param currentlyVisitedClass the source which includes or casts the dependencies
+     * @param dependency            the dependency to be added
+     */
+    public void addDependency(Integer engineType, String rootClass, String currentlyVisitedClass, String dependency) {
+
+        if (StringUtils.isBlank(dependency)) {
+            return;
+        }
+
+        if (currentlyVisitedClass != null && currentlyVisitedClass.equals(dependency)) {
+            return;
+        }
+
+
+
+        if (!isAllowed(engineType, dependency)) {
+            return;
+        }
+
+        //not needed
+        //if(!StringUtils.isBlank(currentlyVisitedClass)) {
+        //    _dependencMap.addDependency(currentlyVisitedClass, dependency);
+        //}
+
+        //for now we code it into a list like we used to do before
+        //but in the long run we have to directly register
+        //to save one step
+        //getDependencySet(source).add(dependency);
+        if(!StringUtils.isBlank(rootClass)) {
+            _dependencMap.addDependency(rootClass, dependency);
+        }
+    }
+
+    /**
+     * flush to flush down our stored dependencies into our final map
+     */
+    public void flush(Integer engineType) {
+        //_registrationStrategy.apply(_dependencies);
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/ExternalFilterDependencyRegistry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/ExternalFilterDependencyRegistry.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/ExternalFilterDependencyRegistry.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/ExternalFilterDependencyRegistry.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,49 @@
+package org.apache.myfaces.extensions.scripting.core.dependencyScan.registry;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyRegistry;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.ClassFilter;
+
+/**
+ * General contractual interface for a dependency registry with external filters
+ * being settable
+ * <p/>
+ * The dependency registry is a class which stores dependencies
+ * according to an internal whitelisting system.
+ * <p/>
+ * Only classes which pass the whitelisting check will be processed
+ */
+public interface ExternalFilterDependencyRegistry extends DependencyRegistry {
+
+    /**
+     * Clears the internal filters
+     * for the registry
+     */
+    void clearFilters();
+
+    /**
+     * adds another filter to the internal filter list
+     *
+     * @param filter the filter to be added
+     */
+    void addFilter(ClassFilter filter);
+
+    /**
+     * Allowance check for external shortcutting
+     * This check triggers into the internal filters
+     * to pre-check if a class is allowed to pass or not
+     *
+     * @param className      the classname to be checked
+     * @param engineType an identifier for the current scan type (jsf java scan for instance)
+     * @return true if it is false otherwise
+     */
+    public boolean isAllowed(Integer engineType, String className);
+
+    /**
+     * Flush operation to batch sync
+     * the current dependencies against a storage
+     * <p/>
+     * (will be removed later once we have all the code transitioned
+     * to the registry system)
+     */
+    void flush(Integer engineType);
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/MasterDependencyRegistry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/MasterDependencyRegistry.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/MasterDependencyRegistry.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/registry/MasterDependencyRegistry.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.extensions.scripting.core.dependencyScan.registry;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyRegistry;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A master dependency registry which keeps track of various
+ * sub-registries in our dependency scanning system
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class MasterDependencyRegistry implements DependencyRegistry {
+
+    /**
+     * We keep our central registry in a map
+     * with the engineType as key value to detect which
+     * registry needs to be triggered
+     */
+    private Map<Integer, DependencyRegistry> _subRegistries = new ConcurrentHashMap<Integer, DependencyRegistry>();
+
+    /**
+     * adds a new dependency to all registered registries
+     *
+     * @param engineType   the engine type which holds the registry
+     * @param rootClass    the root class of this scan which all dependencies are referenced from
+     * @param currentClass the current class scanned
+     * @param dependency   the dependency to be added relative to the current class
+     */
+    public void addDependency(Integer engineType, String rootClass, String currentClass, String dependency) {
+        for (Map.Entry<Integer, DependencyRegistry> entry : _subRegistries.entrySet()) {
+            entry.getValue().addDependency(engineType, rootClass, currentClass, dependency);
+        }
+    }
+
+    /**
+     * Flush which is issued at the end of processing to flush
+     * any content which has not been yet processed into our content holding
+     * data structures
+     *
+     * @param engineType the engine type which has issued the flush operation
+     */
+    public void flush(Integer engineType) {
+        for (Map.Entry<Integer, DependencyRegistry> entry : _subRegistries.entrySet()) {
+            entry.getValue().flush(engineType);
+        }
+    }
+
+    /**
+     * adds a subregistry to our current master registry
+     *
+     * @param engineType the engine type which is the key to our subregistry
+     * @param registry   the subregistry which has to be added
+     */
+    public void addSubregistry(Integer engineType, DependencyRegistry registry) {
+        _subRegistries.put(engineType, registry);
+    }
+
+    /**
+     * Getter for getting a subregistry from our given registry
+     *
+     * @param engineType the engine type to search for
+     * @return the subregistry according to the engine type, or null if none is found
+     */
+    public DependencyRegistry getSubregistry(Integer engineType) {
+        return _subRegistries.get(engineType);
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/GlobalReloadingStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/GlobalReloadingStrategy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/GlobalReloadingStrategy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/GlobalReloadingStrategy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,153 @@
+/*
+ * 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.extensions.scripting.core.reloading;
+
+import org.apache.myfaces.extensions.scripting.api.ReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.core.util.Cast;
+import org.apache.myfaces.extensions.scripting.core.util.ClassUtils;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          A reloading strategy chain of responsibility which switches
+ *          depending on the artifact type to the correct
+ *          strategy
+ *          <p/>
+ *          TODO make the reloading strategy pluggable from outside (1.1)!
+ */
+
+public class GlobalReloadingStrategy implements ReloadingStrategy {
+
+    final Logger _logger = Logger.getLogger(GlobalReloadingStrategy.class.getName());
+
+    protected ScriptingWeaver _weaver = null;
+
+    protected ReloadingStrategy _beanStrategy;
+    protected ReloadingStrategy _noMappingStrategy;
+    protected ReloadingStrategy _allOthers;
+
+    /*loaded dynamically for myfaces 2+*/
+    protected ReloadingStrategy _componentHandlerStrategy;
+    protected ReloadingStrategy _validatorHandlerStrategy;
+    protected ReloadingStrategy _converterHandlerStrategy;
+    protected ReloadingStrategy _behaviorHandlerStrategy;
+
+    public GlobalReloadingStrategy(ScriptingWeaver weaver) {
+        setWeaver(weaver);
+    }
+
+    public GlobalReloadingStrategy() {
+
+    }
+
+    /**
+     * the strategy callback which switches between various strategies
+     * we have in our system
+     *
+     * @param toReload     the object which has to be reloaded
+     * @param artifactType the artifact type for which the reloading strategy has to be applied to
+     * @return either the same or a reloading object depending on the current state of the object
+     */
+    public Object reload(Object toReload, int artifactType) {
+
+        switch (artifactType) {
+            case ScriptingConst.ARTIFACT_TYPE_MANAGEDBEAN:
+                return _beanStrategy.reload(toReload, artifactType);
+
+            case ScriptingConst.ARTIFACT_TYPE_RENDERER:
+                return _noMappingStrategy.reload(toReload, artifactType);
+            case ScriptingConst.ARTIFACT_TYPE_BEHAVIOR:
+                return _noMappingStrategy.reload(toReload, artifactType);
+            case ScriptingConst.ARTIFACT_TYPE_CLIENTBEHAVIORRENDERER:
+                return _noMappingStrategy.reload(toReload, artifactType);
+            case ScriptingConst.ARTIFACT_TYPE_COMPONENT:
+                return _noMappingStrategy.reload(toReload, artifactType);
+            case ScriptingConst.ARTIFACT_TYPE_VALIDATOR:
+                return _noMappingStrategy.reload(toReload, artifactType);
+
+            case ScriptingConst.ARTIFACT_TYPE_COMPONENT_HANDLER:
+                return dynaReload(toReload, _componentHandlerStrategy, artifactType);
+            case ScriptingConst.ARTIFACT_TYPE_CONVERTER_HANDLER:
+                return dynaReload(toReload, _converterHandlerStrategy, artifactType);
+            case ScriptingConst.ARTIFACT_TYPE_VALIDATOR_HANDLER:
+                return dynaReload(toReload, _validatorHandlerStrategy, artifactType);
+            case ScriptingConst.ARTIFACT_TYPE_BEHAVIOR_HANDLER:
+                return dynaReload(toReload, _behaviorHandlerStrategy, artifactType);
+
+            default:
+                return _allOthers.reload(toReload, artifactType);
+        }
+    }
+
+    public void setWeaver(ScriptingWeaver weaver) {
+        _weaver = weaver;
+        _beanStrategy = new ManagedBeanReloadingStrategy(weaver);
+        _noMappingStrategy = new NoMappingReloadingStrategy(weaver);
+        _allOthers = new SimpleReloadingStrategy(weaver);
+
+        /*
+         * external handlers coming from various submodules
+         */
+        _componentHandlerStrategy = dynaload(weaver, "org.apache.myfaces.extensions.scripting.facelet.ComponentHandlerReloadingStrategy");
+        _validatorHandlerStrategy = dynaload(weaver, "org.apache.myfaces.extensions.scripting.facelet.ValidatorHandlerReloadingStrategy");
+        _converterHandlerStrategy = dynaload(weaver, "org.apache.myfaces.extensions.scripting.facelet.ConverterHandlerReloadingStrategy");
+        _behaviorHandlerStrategy = dynaload(weaver, "org.apache.myfaces.extensions.scripting.facelet.BehaviorHandlerReloadingStrategy");
+    }
+
+    public Object dynaReload(Object toReload, ReloadingStrategy strategy, int artifactType) {
+        if (strategy == null) {
+            //no strategy no reload
+            return toReload;
+        } else {
+            return strategy.reload(toReload, artifactType);
+        }
+    }
+
+    /**
+     * load dynamically the given strategy class
+     *
+     * @param weaver        the weaver which the new strategy class is applied to
+     * @param strategyClass the strategy class which has to be loaded and instantiated
+     * @return an instance of the strategy class if found otherwise null
+     */
+    private ReloadingStrategy dynaload(ScriptingWeaver weaver, String strategyClass) {
+        try {
+            Class componentStrategyClass = ClassUtils.forName(strategyClass);
+            return (ReloadingStrategy) ReflectUtil.instantiate(componentStrategyClass, new Cast(ScriptingWeaver.class, weaver));
+        } catch (RuntimeException ex) {
+            //in this case swallowing the exception is expected
+            if (_logger.isLoggable(Level.FINEST)) {
+                _logger.log(Level.FINEST, "Expected Exception: ", ex);
+            }
+        }
+        return null;
+    }
+
+    public ScriptingWeaver getWeaver() {
+        return _weaver;
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/ManagedBeanReloadingStrategy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.extensions.scripting.core.reloading;
+
+import org.apache.myfaces.extensions.scripting.api.ReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+
+/**
+ * The managed beans have a different reloading
+ * strategy. The dependencies of a managed bean
+ * are managed by the IOC container and
+ * not transferred over the reloading strategy
+ * like for all other artifacts.
+ * Hence the bean handler removes the bean and its
+ * referring backward dependencies, and the runtime system
+ * rebuilds the tree anew.
+ *
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ManagedBeanReloadingStrategy implements ReloadingStrategy {
+
+    ScriptingWeaver _weaver;
+
+    public ManagedBeanReloadingStrategy(ScriptingWeaver weaver) {
+        _weaver = weaver;
+    }
+
+    public ManagedBeanReloadingStrategy() {
+    }
+
+    /**
+     * In our case the dropping already has happened at request time
+     * no need for another reloading here
+     *
+     * @param scriptingInstance the instance which has to be reloaded
+     * @param artifactType      the type of artifact
+     * @return does nothing in this case and returns only the original instance, the reloading is handled
+     *         for managed beans on another level
+     */
+    public Object reload(Object scriptingInstance, int artifactType) {
+        return scriptingInstance;
+    }
+
+    public ScriptingWeaver getWeaver() {
+        return _weaver;
+    }
+
+    public void setWeaver(ScriptingWeaver weaver) {
+        _weaver = weaver;
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/NoMappingReloadingStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/NoMappingReloadingStrategy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/NoMappingReloadingStrategy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/NoMappingReloadingStrategy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.extensions.scripting.core.reloading;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          <p/>
+ *          The renderer is a stateless flyweight pattern the reloading strategy is
+ *          to do nothing, this should give optimal results
+ *          <p/>
+ *          <p/>
+ *          The components are a similar case they are not flyweight
+ *          but the properties usually are preserved by the lifecycle if possible
+ *          or assigned by the tag handlers
+ *          <p/>
+ *          <p/>
+ *          The same also applies to other flyweight patterned classes
+ *          like converters or validators
+ *          <p/>
+ *          <p/>
+ *          The only ones which need to keep some state are the ones
+ *          which keep delegates, like the NavHandler
+ */
+public class NoMappingReloadingStrategy extends SimpleReloadingStrategy {
+
+    public NoMappingReloadingStrategy(ScriptingWeaver weaver) {
+        super(weaver);
+    }
+
+    @Override
+    protected void mapProperties(Object target, Object src) {
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,126 @@
+/*
+ * 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.extensions.scripting.core.reloading;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.myfaces.extensions.scripting.api.ReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A simple implementation of our reloading strategy
+ * pattern this is the most basic implementation
+ * covering our reloading.
+ * <p/>
+ * Applicable for most artifacts except for now managed beans
+ * <p/> *
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class SimpleReloadingStrategy implements ReloadingStrategy {
+
+    protected ScriptingWeaver _weaver;
+
+    public SimpleReloadingStrategy(ScriptingWeaver weaver) {
+        _weaver = weaver;
+    }
+
+    public SimpleReloadingStrategy() {
+
+    }
+
+    /**
+     * <p>
+     * the central callback for our strategy here
+     * it has to handle the reload of the scriptingInstance
+     * if possible, otherwise it has to return the
+     * original object if no reload was necessary or possible
+     * </p>
+     *
+     * @param scriptingInstance the instance to be reloaded by the system
+     * @return either the same object or a new instance utilizing the changed code
+     */
+    public Object reload(Object scriptingInstance, int artefactType) {
+
+        //reload the class to get new static content if needed
+        Class aclass = _weaver.reloadScriptingClass(scriptingInstance.getClass());
+        if (aclass.hashCode() == scriptingInstance.getClass().hashCode()) {
+            //class of this object has not changed although
+            // reload is enabled we can skip the rest now
+            return scriptingInstance;
+        }
+        getLog().info("[EXT-SCRIPTING] possible reload for " + scriptingInstance.getClass().getName());
+        /*only recreation of empty constructor classes is possible*/
+        try {
+            //reload the object by instantiating a new class and
+            // assigning the attributes properly
+            Object newObject = aclass.newInstance();
+
+            /*now we shuffle the properties between the objects*/
+            mapProperties(newObject, scriptingInstance);
+
+            return newObject;
+        } catch (Exception e) {
+            getLog().log(Level.SEVERE, "reload ", e);
+        }
+        return null;
+
+    }
+
+    /**
+     * helper to map the properties wherever possible
+     * <p/>
+     * This is the simplest solution for now,
+     * we apply only a copy properties here, which should be enough
+     * for all artifacts except the managed beans and the ones
+     * which have to preserve some kind of delegate before instantiation.
+     *
+     * @param target the target which has to receive the properties
+     * @param src    the source which has the original properties
+     */
+    protected void mapProperties(Object target, Object src) {
+        try {
+            BeanUtils.copyProperties(target, src);
+        } catch (IllegalAccessException e) {
+            getLog().log(Level.FINEST, e.toString());
+            //this is wanted
+        } catch (InvocationTargetException e) {
+            getLog().log(Level.FINEST, e.toString());
+            //this is wanted
+        }
+    }
+
+    protected Logger getLog() {
+        return Logger.getLogger(this.getClass().getName());
+    }
+
+    public ScriptingWeaver getWeaver() {
+        return _weaver;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void setWeaver(ScriptingWeaver weaver) {
+        _weaver = weaver;
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Array.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Array.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Array.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Array.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("unused")
+public class Array extends Cast {
+    public Array(Class clazz, Object... value) {
+
+        super(java.lang.reflect.Array.newInstance(clazz, 0).getClass(), value);
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Cast.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Cast.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Cast.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Cast.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+/**
+ * Simple casting representation for introspection
+ * calls
+ */
+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/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassLoaderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassLoaderUtils.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassLoaderUtils.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassLoaderUtils.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,167 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * <p>Utility class for class loading purposes, e.g. to determine the classpath of a
+ * class loader hierarchy.</p>
+ */
+public class ClassLoaderUtils {
+
+
+    // ------------------------------------------ Public methods
+
+    /**
+     * CompilationResult
+     * <p>Returns the default class loader to use.</p>
+     *
+     * @return the default class loader to use
+     */
+    public static ClassLoader getDefaultClassLoader() {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        if (classLoader != null) {
+            return classLoader;
+        } else {
+            return ClassLoaderUtils.class.getClassLoader();
+        }
+    }
+
+    /**
+     * <p>Determines whether the given class is loadable by the given class loader.</p>
+     *
+     * @param className   the class you want to check
+     * @param classLoader the class loader to use for that check
+     * @return <code>true</code>, if the given class is loadable by the given class loader
+     */
+    public static boolean isClassAvailable(String className, ClassLoader classLoader) {
+        try {
+            classLoader.loadClass(className);
+            return true;
+        }
+        catch (Throwable ex) {
+            return false;
+        }
+    }
+
+    /**
+     * <p>Resolves the classpath by walking up the hierachy of class loaders. Assuming
+     * that we're only dealing with URLClassLoaders it's possible to determine the
+     * classpath. This method, however, returns the classpath as a String, where each
+     * classpath entry is separated by a ';', i.e. it returns the classpath in a format
+     * that Java tools usually expect it to be.</p>
+     * <p/>
+     * it also adds the additional classpaths issued by our configuration to the list
+     *
+     * @param classLoader the class loader which you want to resolve the class path for
+     * @return the final classpath
+     */
+    public static String buildClasspath(ClassLoader classLoader) {
+        StringBuffer classpath = new StringBuffer();
+
+        URL[] urls = resolveClasspath(classLoader);
+        for (URL url : urls) {
+            classpath.append(url.getPath());
+
+            // Note that the classpath separator character is platform
+            // dependent. On Windows systems it's ";" whereas on other
+            // UNIX systems it's ":".
+            classpath.append(File.pathSeparatorChar);
+        }
+
+        String retVal = classpath.toString();
+        if (retVal.endsWith(File.pathSeparator)) {
+            retVal = retVal.substring(0, retVal.length() - 1);
+        }
+        return retVal;
+    }
+
+    /**
+     * <p>Resolves the classpath by walking up the hierarchy of class loaders. Assuming
+     * that we're only dealing with URLClassLoaders it's possible to determine the
+     * classpath.</p>
+     *
+     * @param parent the class loader which you want to resolve the class path for
+     * @return the final classpath
+     */
+    public static URL[] resolveClasspath(ClassLoader parent) {
+        List<URL> classpath = new ArrayList<URL>();
+
+        ClassLoader classLoader = parent;
+        // Walk up the hierachy of class loaders in order to determine the current classpath.
+        File target = WeavingContext.getConfiguration().getCompileTarget();
+        if (target != null) {
+            addFile(classpath, target);
+        }
+
+        while (classLoader != null) {
+            if (classLoader instanceof URLClassLoader) {
+                URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
+
+                URL[] urls = urlClassLoader.getURLs();
+                if (urls != null) {
+                    classpath.addAll(Arrays.asList(urls));
+                }
+            } /*else {
+                if (logger.isWarnEnabled()) {
+                    logger.warn("Resolving the classpath of the classloader '" + parent + "' - One of its parent class"
+                            + " loaders is no URLClassLoader '" + classLoader + "', which means it's possible that"
+                            + " some classpath entries aren't in the final outcome of this method call.");
+                }
+            } */
+
+            //we disable this warning entirely for now because our own url classloader
+            //can deal with this properly, due to extra startup context classpath determination
+
+            // Inspect the parent class loader next.
+            classLoader = classLoader.getParent();
+        }
+
+        List<String> additionalClassPaths = WeavingContext.getConfiguration().getAdditionalClassPath();
+        if (!(additionalClassPaths == null || additionalClassPaths.isEmpty())) {
+            for (String additionalClassPath : additionalClassPaths) {
+                File additionalPath = new File(additionalClassPath);
+                addFile(classpath, additionalPath);
+            }
+        }
+
+        return classpath.toArray(new URL[classpath.size()]);
+    }
+
+    private static void addFile(List<URL> classpath, File additionalPath) {
+        if (additionalPath.exists()) {
+            try {
+                classpath.add(additionalPath.toURI().toURL());
+            } catch (MalformedURLException e) {
+                Logger log = Logger.getLogger(ClassLoaderUtils.class.getName());
+                log.log(Level.SEVERE, "Additionalclasspath wrong url", e);
+            }
+        }
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassUtils.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassUtils.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ClassUtils.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+import org.apache.myfaces.shared_impl.util.ClassLoaderExtension;
+
+import java.io.File;
+
+/**
+ * A generic utils class dealing with different aspects
+ * (naming and reflection) of java classes
+ *
+ * @author werpu
+ *         <p/>
+ */
+public class ClassUtils {
+
+    public static Class forName(String name) {
+        try {
+            return Class.forName(name);
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static boolean isPresent(String clazz) {
+        try {
+            getContextClassLoader().loadClass(clazz);
+        } catch (ClassNotFoundException e) {
+            return false;
+        }
+        return true;
+    }
+
+    public static File classNameToFile(String classPath, String className) {
+        String classFileName = classNameToRelativeFileName(className);
+        return new File(classPath + File.separator + classFileName);
+    }
+
+    private static String classNameToRelativeFileName(String className) {
+        String separator = FileUtils.getFileSeparatorForRegex();
+
+        return className.replaceAll("\\.", separator) + ".class";
+    }
+
+    public static String relativeFileToClassName(String relativeFileName) {
+        String className = relativeFileName.replaceAll("\\\\", ".").replaceAll("\\/", ".");
+        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);
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/DirStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/DirStrategy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/DirStrategy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/DirStrategy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,50 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+import org.apache.myfaces.extensions.scripting.core.util.Strategy;
+
+import java.io.File;
+import java.util.List;
+import java.util.LinkedList;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class DirStrategy implements Strategy {
+    List<File> _foundFiles = new LinkedList<File>();
+
+    public void apply(Object element) {
+        File foundFile = (File) element;
+        if (foundFile.isDirectory()) {
+            _foundFiles.add(foundFile);
+        }
+    }
+
+    public List<File> getFoundFiles() {
+        return _foundFiles;
+    }
+
+    public void setFoundFiles(List<File> foundFiles) {
+        _foundFiles = foundFiles;
+    }
+}
+

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileStrategy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileStrategy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileStrategy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+import java.io.File;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          Java file strategy pattern to filter out all java files which are possible sources
+ *          so that we can recompile them
+ */
+
+public class FileStrategy implements Strategy {
+    Pattern _rePattern;
+
+    public FileStrategy(String pattern) {
+        pattern = pattern.trim().replaceAll("\\.", "\\\\.");
+        pattern = "." + pattern;
+
+        _rePattern = Pattern.compile(pattern);
+
+    }
+
+    List<File> _foundFiles = new LinkedList<File>();
+
+    public void apply(Object element) {
+        File foundFile = (File) element;
+        String fileName = foundFile.getName().toLowerCase(Locale.getDefault());
+        Matcher matcher = _rePattern.matcher(fileName);
+
+        if (!matcher.matches()) return;
+        _foundFiles.add(foundFile);
+    }
+
+    public List<File> getFoundFiles() {
+        return _foundFiles;
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileUtils.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileUtils.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/FileUtils.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,186 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class FileUtils {
+    static double _tempMarker = Math.random();
+
+    /**
+     * Get the file separator for this platform.
+     *
+     * @return The file separator.
+     */
+    public static String getFileSeparator() {
+        return File.separator;
+    }
+
+    /**
+     * Get the file separator for this platform, properly escaped for usage in a regular expression.
+     * workaround for http://bugs.sun.com/view_bug.do?bug_id=4626653 another workaround would be
+     * to use the Matcher.quoteReplacement as of http://bugs.sun.com/view_bug.do?bug_id=5024613  instead
+     * of using String.replaceAll
+     *
+     * @return The file separator, escaped for in a regex.
+     */
+    public static String getFileSeparatorForRegex() {
+        String sep = getFileSeparator();
+
+        if ("\\".equals(sep)) {
+            sep = "\\\\";
+        }
+
+        return sep;
+    }
+
+    public static File getTempDir() {
+        File tempDir;
+
+        String baseTempPath = System.getProperty("java.io.tmpdir");
+        String tempDirName = "myfaces_compilation_" + _tempMarker;
+
+        tempDir = new File(baseTempPath + File.separator + tempDirName);
+        while (tempDir.exists()) {
+            tempDirName = "myfaces_compilation_" + System.currentTimeMillis() + Math.random();
+            tempDir = new File(baseTempPath + File.separator + tempDirName);
+        }
+
+        synchronized (FileUtils.class) {
+            if (tempDir.exists()) {
+                return tempDir;
+            }
+            if (tempDir.mkdirs()) {
+                tempDir.deleteOnExit();
+            }
+        }
+        return tempDir;
+    }
+
+    /**
+     * we roll our own tree walker here
+     * to avoid a dependency into commons fileutils
+     * and to apply an easier pattern than
+     * commons fileutils uses
+     *
+     * @param rootDir  the root dir for our walking
+     * @param strategy the strategy to apply to for our walking
+     */
+    public static void listFiles(File rootDir, Strategy strategy) {
+        if (!rootDir.isDirectory()) {
+            strategy.apply(rootDir);
+            return;
+        }
+
+        File[] files = rootDir.listFiles();
+        for (File file : files) {
+            boolean isDirectory = file.isDirectory();
+            if (isDirectory && !file.getName().endsWith(".")) {
+                listFiles(file, strategy);
+                strategy.apply(file);
+            } else if (!isDirectory) {
+                strategy.apply(file);
+            }
+        }
+    }
+
+    /**
+     * <p>
+     * target path check to check if the targetPath is valid or can be created
+     * </p>
+     *
+     * @param path the path to be investigated
+     */
+    public static void assertPath(File path) {
+        // The destination directory must already exist as javac will not create the destination directory.
+        if (!path.exists()) {
+            if (!path.mkdirs()) {
+                throw new IllegalStateException("It wasn't possible to create the target " +
+                        "directory for the compiler ['" + path.getAbsolutePath() + "'].");
+            }
+
+            // If we've created the destination directory, we'll delete it as well once the application exits
+            path.deleteOnExit();
+        }
+    }
+
+    /**
+     * fetches recursively the files under the current root
+     *
+     * @param sourcePath the source path from which the walker should start from
+     * @param fileType   the pattern upon which the file has to be matched to aka *.java etc...
+     * @return a list of source files
+     */
+    public static List<File> fetchSourceFiles(File sourcePath, String fileType) {
+        FileStrategy strategy = new FileStrategy(fileType);
+        listFiles(sourcePath, strategy);
+
+        return strategy.getFoundFiles();
+    }
+
+    /**
+     * fetches the source files from a list of source paths
+     *
+     * @param sourcePaths the collection of paths to be searched for
+     * @param fileType    the filetype to be searched for
+     * @return a list of files found
+     */
+    public static List<File> fetchSourceFiles(Collection<String> sourcePaths, String fileType) {
+        FileStrategy strategy = new FileStrategy(fileType);
+
+        for (String sourcePath : sourcePaths) {
+            File fSourcePath = new File(sourcePath);
+            if (fSourcePath.exists()) {
+                listFiles(fSourcePath, strategy);
+            }
+        }
+
+        return strategy.getFoundFiles();
+    }
+
+    /**
+     * fetches the source paths from a given root directory in the format
+     * <path>/<appendix>;...
+     *
+     * @param sourcePath the sourcePath from which the directory traversal should happen from
+     * @param appendix   the appendix which has to be appended to every path found
+     * @return a string builder of the paths found
+     */
+    @SuppressWarnings("unused")
+    public static StringBuilder fetchSourcePaths(File sourcePath, String appendix) {
+        DirStrategy dirStrategy = new DirStrategy();
+        StringBuilder sourcesList = new StringBuilder(512);
+
+        listFiles(sourcePath, dirStrategy);
+        for (File foundDir : dirStrategy.getFoundFiles()) {
+            String dirName = foundDir.getAbsolutePath();
+            sourcesList.append(dirName);
+            sourcesList.append(File.separator);
+            sourcesList.append(appendix);
+        }
+        return sourcesList;
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Null.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Null.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Null.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Null.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+/**
+ * @Author Werner Punz
+ * Null representation for easier introspection calls
+ */
+public class Null extends Cast {
+
+    public Null(Class clazz) {
+        super(clazz, null);
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ReflectUtil.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ReflectUtil.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ReflectUtil.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/ReflectUtil.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,429 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ReflectUtil {
+
+    static final Logger _logger = Logger.getLogger(ReflectUtil.class.getName());
+
+    public static Object instantiate(String clazz, Object... varargs) {
+        return instantiate(ClassUtils.forName(clazz), varargs);
+    }
+
+    /**
+     * A simplified instantiation over reflection
+     *
+     * @param clazz   the class to be instantiated
+     * @param varargs the instantiation parameters
+     * @return the instantiated object
+     */
+    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();
+            }
+        }
+
+        try {
+            Constructor constr = clazz.getConstructor(classes);
+            return 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 environment. Groovy throws a classcast
+   * exception wrongly, delegating the instantiation code to java
+   * fixes that
+   * */
+
+    public static Object newObject(Class clazz) throws IllegalAccessException, InstantiationException {
+        return clazz.newInstance();
+    }
+
+    /**
+     * Generic execute method which simplifies the reflection api
+     * down to a usable system
+     *
+     * @param obj        the target object the method has to be executed upon
+     * @param methodName the method name
+     * @param varargs    the arguments which have to be passed to the method
+     * @return the return value of the method
+     */
+    public static Object executeStaticMethod(Class obj, String methodName, Object... varargs) {
+
+        Collection<Method> methods = getMethods(obj, methodName, varargs.length);
+
+        Object retVal = handleStaticMethod(obj, methodName, methods, varargs);
+        if (!methodNotFound(retVal)) {
+            return retVal;
+        }
+
+        methods = getAllMethods(obj, methodName, varargs.length);
+        retVal = handleStaticMethod(obj, methodName, methods, varargs);
+        if (!methodNotFound(retVal)) {
+            return retVal;
+        }
+
+        throw new RuntimeException("Static Method of :" + methodName + " from class " + obj.getClass().getName() + " not found");
+
+    }
+
+    public static Collection<Method> getAllMethods(Class clazz, String methodName, int varargLength) {
+        ArrayList<Method> retVal = new ArrayList<Method>(30);
+        while (clazz != null) {
+            for (Method m : clazz.getDeclaredMethods()) {
+                if (m.getParameterTypes().length == varargLength && m.getName().equals(methodName)) {
+                    retVal.add(m);
+                }
+            }
+            clazz = clazz.getSuperclass();
+        }
+
+        return retVal;
+    }
+
+    public static Collection<Method> getMethods(Class clazz, String methodName, int varargLength) {
+        ArrayList<Method> retVal = new ArrayList<Method>(30);
+        for (Method m : clazz.getDeclaredMethods()) {
+            if (m.getParameterTypes().length == varargLength && m.getName().equals(methodName)) {
+                retVal.add(m);
+            }
+        }
+
+        return retVal;
+    }
+
+    /**
+     * Generic execute method which simplifies the reflection api
+     * down to a usable system
+     *
+     * @param obj        the target object the method has to be executed upon
+     * @param methodName the method name
+     * @param varargs    the arguments which have to be passed to the method
+     * @return the return value of the method
+     * @throws RuntimeException a generic runtime exception in case of a failure
+     *                          we use unmanaged exceptions here to get a behavior similar to scripting
+     *                          language execution where failures can happen but method executions
+     *                          should not enforce exception handling
+     */
+    public static Object executeMethod(Object obj, String methodName, Object... varargs) {
+
+        Collection<Method> methods;
+        //if we have an invocationHandler here we
+        //can work over the generic invoke interface
+        //That way we can cover more dynamic stuff
+        //our reload invocation handler is treated differently here
+
+        if (obj instanceof InvocationHandler) {
+            InvocationHandler objToInvoke = (InvocationHandler) obj;
+
+            Object realTarget = WeavingContext.getDelegateFromProxy(objToInvoke);
+
+            //first we try only the public because they are the most likely ones
+            //to be accessed
+            methods = getMethods(realTarget.getClass(), methodName, varargs.length);
+            Object retVal = handleInvHandlerMethod(objToInvoke, methodName, methods, varargs);
+            if (!methodNotFound(retVal)) {
+                return retVal;
+            }
+            //if not we try all of them until we have a match
+            methods = getAllMethods(realTarget.getClass(), methodName, varargs.length);
+            retVal = handleInvHandlerMethod(objToInvoke, methodName, methods, varargs);
+            if (!(methodNotFound(retVal))) {
+                return retVal;
+            }
+
+            throw new RuntimeException("Method of :" + methodName + " from class " + obj.getClass().getName() + " not found");
+        }
+
+        Class clazz = obj.getClass();
+
+        //first we try only the public because they are the most likely ones
+        //to be accessed
+        methods = getMethods(clazz, methodName, varargs.length);
+        Object retVal = handleObjMethod(obj, methodName, methods, varargs);
+        if (!methodNotFound(retVal)) {
+            return retVal;
+        }
+
+        //if not we try all of them until we have a match
+        methods = getAllMethods(clazz, methodName, varargs.length);
+        retVal = handleObjMethod(obj, methodName, methods, varargs);
+        if (!methodNotFound(retVal)) {
+            return retVal;
+        }
+
+        throw new RuntimeException("Method of :" + methodName + " from class " + obj.getClass().getName() + " not found");
+    }
+
+    /**
+     * special marker class which is a special return value indicating
+     * that not method has been found which can be executed
+     */
+    static class _MethodNotFound {
+    }
+
+    /**
+     * check if the return value is a method not found return val which
+     * indicates we have to follow the next workflow step
+     *
+     * @param retVal the retVal which has to be investigated
+     * @return true if the retVal is instance of _MethodNotFound false otherwise
+     */
+    private static boolean methodNotFound(Object retVal) {
+        return retVal instanceof _MethodNotFound;
+    }
+
+    /**
+     * executes a method in an invocation handler with a set of
+     * methods which are canidates for execution
+     *
+     * @param objToInvoke the invokee object
+     * @param methodName  the method name
+     * @param methods     the methods which are under investigation for invoking
+     * @param varargs     the list of varargs to be passed to the method
+     * @return the result of the invocation, or an object of type _MethodNotFound otherwise
+     */
+    static private Object handleInvHandlerMethod(InvocationHandler objToInvoke, String methodName, Collection<Method> methods, Object... varargs) {
+        for (Method m : methods) {
+            if (!m.getName().equals(methodName) || m.getParameterTypes().length != varargs.length) {
+                continue;
+            }
+            try {
+                return objToInvoke.invoke(objToInvoke, m, varargs);
+            } catch (Throwable e) {
+                handleException(e);
+            }
+        }
+        return new _MethodNotFound();
+    }
+
+    /**
+     * executes a method on an object
+     *
+     * @param objToInvoke the invokee object
+     * @param methodName  the method name
+     * @param methods     the methods which are under investigation for invoking
+     * @param varargs     the list of varargs to be passed to the method
+     * @return the result of the invocation, or an object of type _MethodNotFound otherwise
+     */
+    static private Object handleObjMethod(Object objToInvoke, String methodName, Collection<Method> methods, Object... varargs) {
+        for (Method m : methods) {
+            if (!m.getName().equals(methodName) || m.getParameterTypes().length != varargs.length) {
+                continue;
+            }
+            try {
+                return m.invoke(objToInvoke, varargs);
+            } catch (Throwable e) {
+                handleException(e);
+            }
+        }
+        return new _MethodNotFound();
+    }
+
+    /**
+     * executes a static method on a class
+     *
+     * @param objToInvoke the invokee object
+     * @param methodName  the method name
+     * @param methods     the methods which are under investigation for invoking
+     * @param varargs     the list of varargs to be passed to the method
+     * @return the result of the invocation, or an object of type _MethodNotFound otherwise
+     */
+    static private Object handleStaticMethod(Class objToInvoke, String methodName, Collection<Method> methods, Object... varargs) {
+        for (Method m : methods) {
+            if (!m.getName().equals(methodName) || m.getParameterTypes().length != varargs.length) {
+                continue;
+            }
+            try {
+                return m.invoke(objToInvoke, varargs);
+            } catch (Throwable e) {
+                handleException(e);
+            }
+        }
+        return new _MethodNotFound();
+    }
+
+    private static void handleException(Throwable e) {
+        if (e instanceof IllegalAccessException) {
+            if (_logger.isLoggable(Level.FINEST)) {
+                _logger.log(Level.FINEST, "", e);
+            }
+        } else if (e instanceof IllegalArgumentException) {
+            if (_logger.isLoggable(Level.FINEST)) {
+                _logger.log(Level.FINEST, "", e);
+            }
+        } else {
+            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 Method(method) call
+     * @throws RuntimeException an unmanaged runtime exception in case of an introspection error
+     */
+    public static Object fastExecuteMethod(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 = fastGetMethod(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);
+        }
+
+    }
+
+    /**
+     * faster reflection call
+     * if we know the data types exactly we can
+     * trigger a direct call instead of walking through all methods
+     * note this method only allows to trigger against directly declared methods
+     * it ignores the inheritance hierarchy for faster access
+     *
+     * @param obj        the invokee object
+     * @param methodName the metod name
+     * @param classes    the parameter type classes
+     * @return the method if found
+     * @throws NoSuchMethodException in case it could not be found
+     */
+    public static Method fastGetMethod(Object obj, String methodName, Class[] classes) throws NoSuchMethodException {
+        Method m;
+        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 Method(method) call
+     * @throws RuntimeException an unmanaged runtime exception in case of an introspection error
+     */
+    public static Object fastExecuteStaticMethod(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 = fastGetStaticMethod(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 fastGetStaticMethod(Class obj, String methodName, Class[] classes) throws NoSuchMethodException {
+        Method m;
+        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);
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Strategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Strategy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Strategy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/util/Strategy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.extensions.scripting.core.util;
+
+/**
+ * Applied strategy class for iteration walkers
+ * to make the handling of iterated objects
+ * more scripting language like (aka a pattern similar to closures)
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public interface Strategy {
+
+    public void apply(Object element);
+
+}