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 [13/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/ ...

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/RenderkitProxy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,194 @@
+/*
+ * 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.jsf.dynamicdecorators.implemetations;
+
+import org.apache.myfaces.extensions.scripting.api.Decorated;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedRenderer;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedClientBehaviorRenderer;
+
+import javax.faces.context.FacesContext;
+import javax.faces.render.RenderKit;
+import javax.faces.render.Renderer;
+import javax.faces.render.ResponseStateManager;
+import javax.faces.render.ClientBehaviorRenderer;
+import javax.faces.context.ResponseWriter;
+import javax.faces.context.ResponseStream;
+import javax.faces.FacesException;
+import java.io.Writer;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Weaving renderkit which
+ * acts as a proxy factory for
+ * our internal reloading referers
+ *
+ * @author Werner Punz
+ */
+public class RenderkitProxy extends RenderKit implements Decorated {
+
+    RenderKit _delegate = null;
+
+    public RenderkitProxy(RenderKit delegate) {
+        _delegate = delegate;
+    }
+
+    public void addRenderer(String componentFamily, String rendererType, Renderer renderer) {
+        weaveDelegate();
+        //wo do it brute force here because we have sometimes casts and hence cannot rely on proxies
+        //renderers itself are flyweight patterns which means they are shared over objects
+        
+        renderer = (Renderer) reloadInstance(renderer, ScriptingConst.ARTIFACT_TYPE_RENDERER);
+
+        _delegate.addRenderer(componentFamily, rendererType, renderer);
+    }
+
+    public Renderer getRenderer(String componentFamily, String rendererType) {
+        weaveDelegate();
+        Renderer rendr = _delegate.getRenderer(componentFamily, rendererType);
+        Renderer rendr2 = (Renderer) reloadInstance(rendr, ScriptingConst.ARTIFACT_TYPE_RENDERER);
+        if (rendr != rendr2) {
+            Renderer tempRenderer = _delegate.getRenderer(componentFamily, rendererType);
+            if (tempRenderer instanceof PurgedRenderer) {
+                return handleAnnotationChange(componentFamily, rendererType);
+            }
+
+            _delegate.addRenderer(componentFamily, rendererType, rendr2);
+            return rendr2;
+        }
+        return rendr;
+    }
+
+
+    private ClientBehaviorRenderer handleAnnotationChangeBehaviorRenderer(String s) {
+        ClientBehaviorRenderer rendr2;
+
+        rendr2 = _delegate.getClientBehaviorRenderer(s);
+        if (rendr2 instanceof PurgedClientBehaviorRenderer) {
+            throw new FacesException("Renderer not found");
+        }
+        rendr2 = _delegate.getClientBehaviorRenderer(s);
+        return rendr2;
+    }
+
+    private Renderer handleAnnotationChange(String s, String s1) {
+        Renderer rendr2;
+
+        //WeavingContext.getWeaver().fullClassScan();
+        rendr2 = _delegate.getRenderer(s, s1);
+        if (rendr2 instanceof PurgedRenderer) {
+            throw new FacesException("Renderer not found");
+        }
+        rendr2 = _delegate.getRenderer(s, s1);
+        return rendr2;
+    }
+
+    public ResponseStateManager getResponseStateManager() {
+        weaveDelegate();
+        return _delegate.getResponseStateManager();
+    }
+
+    public ResponseWriter createResponseWriter(Writer writer, String s, String s1) {
+        weaveDelegate();
+        return (ResponseWriter) reloadInstance(_delegate.createResponseWriter(writer, s, s1), ScriptingConst.ARTIFACT_TYPE_RESPONSEWRITER);
+    }
+
+    public ResponseStream createResponseStream(OutputStream outputStream) {
+        weaveDelegate();
+        return (ResponseStream) reloadInstance(_delegate.createResponseStream(outputStream), ScriptingConst.ARTIFACT_TYPE_RESPONSESTREAM);
+    }
+
+
+    @Override
+    public void addClientBehaviorRenderer(String s, ClientBehaviorRenderer renderer) {
+
+        weaveDelegate();
+        renderer = (ClientBehaviorRenderer) reloadInstance(renderer, ScriptingConst.ARTIFACT_TYPE_CLIENTBEHAVIORRENDERER);
+        _delegate.addClientBehaviorRenderer(s, renderer);
+    }
+
+    @Override
+    public ClientBehaviorRenderer getClientBehaviorRenderer(String s) {
+        weaveDelegate();
+        ClientBehaviorRenderer rendr = _delegate.getClientBehaviorRenderer(s);
+        ClientBehaviorRenderer rendr2 = (ClientBehaviorRenderer) reloadInstance(rendr, ScriptingConst.ARTIFACT_TYPE_CLIENTBEHAVIORRENDERER);
+        if (rendr != rendr2) {
+
+            rendr2 = _delegate.getClientBehaviorRenderer(s);
+            if (rendr2 instanceof PurgedClientBehaviorRenderer) {
+                return handleAnnotationChangeBehaviorRenderer(s);
+            }
+            return rendr2;
+        }
+        return rendr;
+    }
+
+    @Override
+    public Iterator<String> getClientBehaviorRendererTypes() {
+        weaveDelegate();
+        return _delegate.getClientBehaviorRendererTypes();
+    }
+
+    @Override
+    public Iterator<String> getComponentFamilies() {
+        weaveDelegate();
+        return _delegate.getComponentFamilies();
+    }
+
+    @Override
+    public Iterator<String> getRendererTypes(String s) {
+        weaveDelegate();
+        return _delegate.getRendererTypes(s);
+    }
+
+    public Object getDelegate() {
+        return _delegate;
+    }
+
+    private void weaveDelegate() {
+        _delegate = (RenderKit) WeavingContext.getWeaver().reloadScriptingInstance(_delegate, ScriptingConst.ARTIFACT_TYPE_RENDERKIT);
+    }
+
+    private Object reloadInstance(Object instance, int artefactType) {
+        if (instance == null) {
+            return null;
+        }
+        if (WeavingContext.isDynamic(instance.getClass()) && !alreadyWovenInRequest(instance.getClass().getName())) {
+            alreadyWovenInRequest(instance.getClass().getName());
+            instance = WeavingContext.getWeaver().reloadScriptingInstance(instance, artefactType);
+
+            //now the add should be done properly if possible
+        }
+        return instance;
+    }
+
+    private boolean alreadyWovenInRequest(String clazz) {
+        //portlets now can be enabled thanks to the jsf2 indirections regarding the external context
+        Map<String, Object> req = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+        if (req.get(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz) == null) {
+            req.put(ScriptingConst.SCRIPTING_REQUSINGLETON + clazz, "");
+            return false;
+        }
+        return true;
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ResourceHandlerProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ResourceHandlerProxy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ResourceHandlerProxy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ResourceHandlerProxy.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.jsf.dynamicdecorators.implemetations;
+
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ResourceHandlerProxy extends ResourceHandler {
+    private ResourceHandler _delegate;
+
+    public ResourceHandlerProxy(ResourceHandler delegate) {
+        _delegate = delegate;
+    }
+
+    public Resource createResource(String resourceName) {
+        weaveDelegate();
+        return _delegate.createResource(resourceName);
+    }
+
+    public Resource createResource(String resourceName, String libraryName) {
+        weaveDelegate();
+        return _delegate.createResource(resourceName, libraryName);
+    }
+
+    public Resource createResource(String resourceName, String libraryName, String contentType) {
+        weaveDelegate();
+        return _delegate.createResource(resourceName, libraryName, contentType);
+    }
+
+    public String getRendererTypeForResourceName(String resourceName) {
+        weaveDelegate();
+        return _delegate.getRendererTypeForResourceName(resourceName);
+    }
+
+    public void handleResourceRequest(FacesContext context) throws java.io.IOException {
+        weaveDelegate();
+        _delegate.handleResourceRequest(context);
+    }
+
+    public boolean isResourceRequest(FacesContext context) {
+        return _delegate.isResourceRequest(context);
+    }
+
+    public boolean libraryExists(String libraryName) {
+        return _delegate.libraryExists(libraryName);
+    }
+
+    private final void weaveDelegate() {
+        _delegate = (ResourceHandler) WeavingContext.getWeaver().reloadScriptingInstance(_delegate, ScriptingConst.ARTIFACT_TYPE_RESOURCEHANDLER);
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/SystemEventListenerProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/SystemEventListenerProxy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/SystemEventListenerProxy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/SystemEventListenerProxy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.jsf.dynamicdecorators.implemetations;
+
+import org.apache.myfaces.extensions.scripting.api.Decorated;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+/**
+ * a method level reloading proxy class
+ * we do not use auto proxies here because
+ * this class needs special treatment
+ * over our decorated interface
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class SystemEventListenerProxy implements Decorated, SystemEventListener {
+
+    SystemEventListener _delegate;
+
+    public SystemEventListenerProxy(SystemEventListener delegate) {
+        _delegate = delegate;
+    }
+
+    public boolean isListenerForSource(Object source) {
+        weaveDelegate();
+        return _delegate.isListenerForSource(source);
+    }
+
+    public void processEvent(SystemEvent event) {
+        weaveDelegate();
+        _delegate.processEvent(event);
+    }
+
+    @Override
+    public Object getDelegate() {
+        return _delegate;
+    }
+
+    private void weaveDelegate() {
+        //TODO (1.1) add a speed optimization here by pushing something in the request map
+        if (_delegate != null) {
+            _delegate = (SystemEventListener) WeavingContext.getWeaver().reloadScriptingInstance(_delegate, ScriptingConst.ARTIFACT_TYPE_SYSTEMEVENTLISTENER);
+        }
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/VariableResolverProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/VariableResolverProxy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/VariableResolverProxy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/VariableResolverProxy.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.jsf.dynamicdecorators.implemetations;
+
+import org.apache.myfaces.extensions.scripting.api.Decorated;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.*;
+
+
+/**
+ * objects loaded must
+ * be checked if a reloading is needed
+ *
+ * @author Werner Punz
+ */
+@SuppressWarnings("deprecation") //we must suppress it here
+public class VariableResolverProxy extends VariableResolver implements Decorated {
+    VariableResolver _delegate;
+
+    public VariableResolverProxy(VariableResolver delegate) {
+        _delegate = delegate;
+    }
+
+    public Object resolveVariable(FacesContext facesContext, String s) throws EvaluationException {
+        Object variable = _delegate.resolveVariable(facesContext, s);
+        if (variable != null && WeavingContext.isDynamic(variable.getClass()))
+            variable = WeavingContext.getWeaver().reloadScriptingInstance(variable, ScriptingConst.ARTIFACT_TYPE_MANAGEDBEAN);
+        return variable;
+    }
+
+    public Object getDelegate() {
+        return _delegate;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,131 @@
+/*
+ * 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.jsf.dynamicdecorators.implemetations;
+
+import org.apache.myfaces.extensions.scripting.api.Decorated;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIViewRoot;
+import javax.faces.FacesException;
+import javax.faces.view.ViewDeclarationLanguage;
+import java.util.Locale;
+import java.util.Map;
+import java.util.List;
+import java.io.IOException;
+
+/**
+ * Scripting enabled View Handler
+ *
+ * @author Werner Punz
+ */
+public class ViewHandlerProxy extends ViewHandler implements Decorated {
+
+    ViewHandler _delegate = null;
+
+    private void weaveDelegate() {
+        if (_delegate != null) {
+            _delegate = (ViewHandler) WeavingContext.getWeaver().reloadScriptingInstance(_delegate, ScriptingConst.ARTIFACT_TYPE_VIEWHANDLER);
+        }
+    }
+
+    public ViewHandlerProxy(ViewHandler delegate) {
+        _delegate = delegate;
+    }
+
+    public String calculateCharacterEncoding(FacesContext facesContext) {
+        weaveDelegate();
+        return _delegate.calculateCharacterEncoding(facesContext);
+    }
+
+    public Locale calculateLocale(FacesContext facesContext) {
+        weaveDelegate();
+        return _delegate.calculateLocale(facesContext);
+    }
+
+    public String calculateRenderKitId(FacesContext facesContext) {
+        weaveDelegate();
+        return _delegate.calculateRenderKitId(facesContext);
+    }
+
+    public UIViewRoot createView(FacesContext facesContext, String s) {
+        weaveDelegate();
+        return _delegate.createView(facesContext, s);
+    }
+
+    public String getActionURL(FacesContext facesContext, String s) {
+        weaveDelegate();
+        return _delegate.getActionURL(facesContext, s);
+    }
+
+    public String getResourceURL(FacesContext facesContext, String s) {
+        weaveDelegate();
+        return _delegate.getResourceURL(facesContext, s);
+    }
+
+    public void initView(FacesContext facesContext) throws FacesException {
+        weaveDelegate();
+        _delegate.initView(facesContext);
+    }
+
+    public void renderView(FacesContext facesContext, UIViewRoot uiViewRoot) throws IOException, FacesException {
+        weaveDelegate();
+        _delegate.renderView(facesContext, uiViewRoot);
+    }
+
+    public UIViewRoot restoreView(FacesContext facesContext, String s) {
+        weaveDelegate();
+        return _delegate.restoreView(facesContext, s);
+    }
+
+    public void writeState(FacesContext facesContext) throws IOException {
+        weaveDelegate();
+        _delegate.writeState(facesContext);
+    }
+
+
+    @Override
+    public String deriveViewId(FacesContext facesContext, String s) {
+        weaveDelegate();
+        return _delegate.deriveViewId(facesContext, s);
+    }
+
+    @Override
+    public String getBookmarkableURL(FacesContext facesContext, String s, Map<String, List<String>> stringListMap, boolean b) {
+        return super.getBookmarkableURL(facesContext, s, stringListMap, b);
+    }
+
+    @Override
+    public ViewDeclarationLanguage getViewDeclarationLanguage(FacesContext facesContext, String s) {
+        weaveDelegate();
+        return _delegate.getViewDeclarationLanguage(facesContext, s);
+    }
+
+    @Override
+    public String getRedirectURL(FacesContext facesContext, String s, Map<String, List<String>> stringListMap, boolean b) {
+        weaveDelegate();
+        return _delegate.getRedirectURL(facesContext, s, stringListMap, b);
+    }
+
+    public Object getDelegate() {
+        return _delegate;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BaseAnnotationScanListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BaseAnnotationScanListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BaseAnnotationScanListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BaseAnnotationScanListener.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.config.RuntimeConfig;
+
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class BaseAnnotationScanListener {
+    Logger log = Logger.getLogger(this.getClass().getName());
+    static Map<String, Object> _alreadyRegistered = new ConcurrentHashMap<String, Object>(8, 0.75f, 1);
+
+    protected RuntimeConfig getRuntimeConfig() {
+        final FacesContext facesContext = FacesContext.getCurrentInstance();
+        //runtime config not started
+        if (facesContext == null) {
+            return null;
+        }
+        return RuntimeConfig.getCurrentInstance(facesContext.getExternalContext());
+    }
+
+    protected Application getApplication() {
+        return FacesContext.getCurrentInstance().getApplication();
+    }
+
+    /**
+     * unregisters this class in the central registry
+     * is triggered if the class itself has been registered previously
+     *
+     * @param className
+     * @return
+     */
+    public void purge(String className) {
+
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BeanImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BeanImplementationListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BeanImplementationListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BeanImplementationListener.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,204 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.config.element.NavigationRule;
+import org.apache.myfaces.config.impl.digester.elements.ManagedBean;
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.core.util.StringUtils;
+
+import javax.faces.bean.*;
+import java.lang.reflect.Field;
+import java.util.*;
+import java.util.logging.Level;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          bean implementation listener which registers new java sources
+ *          into the runtime config, note this class is not thread safe
+ *          it is only allowed to be called from a single thread
+ */
+
+public class BeanImplementationListener extends BaseAnnotationScanListener implements AnnotationScanListener {
+
+    public boolean supportsAnnotation(String annotation) {
+        return annotation.equals(javax.faces.bean.ManagedBean.class.getName());
+    }
+
+    public boolean supportsAnnotation(Class annotation) {
+        return annotation.equals(javax.faces.bean.ManagedBean.class);
+    }
+
+    public void register(Class clazz, java.lang.annotation.Annotation ann) {
+
+        RuntimeConfig config = getRuntimeConfig();
+
+        javax.faces.bean.ManagedBean annCasted = (javax.faces.bean.ManagedBean) ann;
+
+        String beanName = annCasted.name();
+        if (StringUtils.isBlank(beanName)) {
+            beanName = normalizeName(clazz.getName());
+        }
+
+        beanName = beanName.replaceAll("\"", "");
+        //we need to reregister for every bean due to possible managed prop
+        //and scope changes
+        ManagedBean mbean;
+        if (!hasToReregister(beanName, clazz)) {
+            mbean = (ManagedBean) _alreadyRegistered.get(beanName);
+            //return;
+        } else {
+            mbean = new ManagedBean();
+        }
+
+        mbean.setBeanClass(clazz.getName());
+        mbean.setName(beanName);
+        handleManagedpropertiesCompiled(mbean, fields(clazz));
+        resolveScope(clazz, mbean);
+
+        _alreadyRegistered.put(beanName, mbean);
+        config.addManagedBean(beanName, mbean);
+
+    }
+
+    private void resolveScope(Class clazz, ManagedBean mbean) {
+        //now lets resolve the scope
+        String scope = "none";
+        if (clazz.isAnnotationPresent(RequestScoped.class)) {
+            scope = "request";
+        } else if (clazz.isAnnotationPresent(SessionScoped.class)) {
+            scope = "session";
+        } else if (clazz.isAnnotationPresent(ApplicationScoped.class)) {
+            scope = "application";
+        } else if (clazz.isAnnotationPresent(NoneScoped.class)) {
+            scope = "none";
+        } else if (clazz.isAnnotationPresent(CustomScoped.class)) {
+            scope = "custom";
+        }
+        mbean.setScope(scope);
+    }
+
+    private void handleManagedpropertiesCompiled(ManagedBean mbean, Field[] fields) {
+        for (Field field : fields) {
+            if (log.isLoggable(Level.FINEST)) {
+                log.log(Level.FINEST, "  Scanning field '" + field.getName() + "'");
+            }
+            javax.faces.bean.ManagedProperty property = field
+                    .getAnnotation(ManagedProperty.class);
+            if (property != null) {
+                if (log.isLoggable(Level.FINE)) {
+                    log.log(Level.FINE, "  Field '" + field.getName()
+                            + "' has a @ManagedProperty annotation");
+                }
+
+                org.apache.myfaces.config.impl.digester.elements.ManagedProperty mpc =
+                        new org.apache.myfaces.config.impl.digester.elements.ManagedProperty();
+                String name = property.name();
+                if ((name == null) || "".equals(name)) {
+                    name = field.getName();
+                }
+                mpc.setPropertyName(name);
+                mpc.setPropertyClass(field.getType().getName()); // FIXME - primitives, arrays, etc.
+                mpc.setValue(property.value());
+                mbean.addProperty(mpc);
+            }
+        }
+    }
+
+    /**
+     * <p>Return an array of all <code>Field</code>s reflecting declared
+     * fields in this class, or in any superclass other than
+     * <code>java.lang.Object</code>.</p>
+     *
+     * @param clazz Class to be analyzed
+     * @return the array of fields
+     */
+    private Field[] fields(Class clazz) {
+
+        Map<String, Field> fields = new HashMap<String, Field>();
+        do {
+            for (Field field : clazz.getDeclaredFields()) {
+                if (!fields.containsKey(field.getName())) {
+                    fields.put(field.getName(), field);
+                }
+            }
+        } while ((clazz = clazz.getSuperclass()) != Object.class);
+        return fields.values().toArray(new Field[fields.size()]);
+    }
+
+    protected boolean hasToReregister(String name, Class clazz) {
+        ManagedBean mbean = (ManagedBean) _alreadyRegistered.get(name);
+        return mbean == null || !mbean.getManagedBeanClassName().equals(clazz.getName());
+    }
+
+    /**
+     * name normalizer for automated name mapping
+     * (aka if no name attribute is given in the annotation)
+     *
+     * @param className the classname to be mapped (can be with package=
+     * @return the normalized jsf bean name
+     */
+    private String normalizeName(String className) {
+        String name = className.substring(className.lastIndexOf(".") + 1);
+
+        return name.substring(0, 1).toLowerCase() + name.substring(1);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void purge(String className) {
+        RuntimeConfig config = getRuntimeConfig();
+        //We have to purge and readd our managed beans, unfortunatly the myfaces impl enforces
+        //us to do the same for the nav rules after purge
+        //we cannot purge the managed beans and nav rules separately
+        Collection<NavigationRule> navigationRules = new ArrayList<NavigationRule>();
+        Map<String, org.apache.myfaces.config.element.ManagedBean> managedBeans = new HashMap<String, org.apache.myfaces.config.element.ManagedBean>();
+
+        navigationRules.addAll(config.getNavigationRules());
+        managedBeans.putAll(config.getManagedBeans());
+
+        config.purge();
+
+        for (NavigationRule navRule : navigationRules) {
+            config.addNavigationRule(navRule);
+        }
+
+        //We refresh the managed beans, dead references still can cause
+        //runtime errors but in this case we cannot do anything
+        org.apache.myfaces.config.element.ManagedBean mbeanFound = null;
+        List<String> mbeanKey = new LinkedList<String>();
+
+        for (Map.Entry mbean : managedBeans.entrySet()) {
+            org.apache.myfaces.config.element.ManagedBean bean = (org.apache.myfaces.config.element.ManagedBean) mbean.getValue();
+            if (!bean.getManagedBeanClass().getName().equals(className)) {
+                config.addManagedBean((String) mbean.getKey(), (org.apache.myfaces.config.element.ManagedBean) mbean.getValue());
+            } else {
+                mbeanFound = (org.apache.myfaces.config.element.ManagedBean) mbean.getValue();
+                mbeanKey.add(mbeanFound.getManagedBeanName());
+            }
+        }
+        if (mbeanFound != null) {
+            for (String toRemove : mbeanKey) {
+                _alreadyRegistered.remove(toRemove);
+            }
+        }
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorImplementationListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorImplementationListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorImplementationListener.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedComponent;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedBehavior;
+
+import javax.faces.component.behavior.FacesBehavior;
+import java.util.logging.Level;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class BehaviorImplementationListener extends SingleEntityAnnotationListener implements AnnotationScanListener {
+
+    public BehaviorImplementationListener() {
+        super();
+        _entityParamValue = "value";
+    }
+
+    public boolean supportsAnnotation(String annotation) {
+        return annotation.equals(FacesBehavior.class.getName());  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public boolean supportsAnnotation(Class annotation) {
+        return annotation.equals(FacesBehavior.class);  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+
+    protected void addEntity(Class clazz, String val) {
+        if (log.isLoggable(Level.FINEST)) {
+            log.log(Level.FINEST, "addBehavior(" + val + ","
+                    + clazz.getName() + ")");
+        }
+        getApplication().addBehavior(val, clazz.getName());
+    }
+
+    @Override
+    public void purge(String className) {
+        super.purge(className);
+        if (!_alreadyRegistered.containsKey(className)) {
+            return;
+        }
+
+        String val = (String) _alreadyRegistered.remove(className);
+        if (val != null) {
+            getApplication().addBehavior(val, PurgedBehavior.class.getName());
+        }
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorRendererImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorRendererImplementationListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorRendererImplementationListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/BehaviorRendererImplementationListener.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,175 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedClientBehaviorRenderer;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedRenderer;
+
+import javax.faces.FactoryFinder;
+import javax.faces.context.FacesContext;
+import javax.faces.render.FacesBehaviorRenderer;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          Implementation listener for the FacesBehaviorRenderer annotation
+ */
+
+public class BehaviorRendererImplementationListener extends MapEntityAnnotationScanner {
+
+    private static final String PAR_RENDERERTYPE = "rendererType";
+    private static final String PAR_RENDERKITID = "renderKitId";
+
+    Map<AnnotationEntry, String> _inverseIndex = new HashMap<AnnotationEntry, String>();
+
+    class AnnotationEntry {
+        String rendererType;
+        String renderKitId;
+
+        AnnotationEntry(String rendererType, String renderKitId) {
+            this.rendererType = rendererType;
+            this.renderKitId = renderKitId;
+        }
+
+        public boolean equals(Object incoming) {
+            if (!(incoming instanceof AnnotationEntry)) {
+                return false;
+            }
+            AnnotationEntry toCompare = (AnnotationEntry) incoming;
+
+            if (incoming == null) {
+                return false;
+            }
+
+            boolean firstEquals = compareValuePair(rendererType, toCompare.getRendererType());
+            boolean secondEquals = compareValuePair(renderKitId, toCompare.getRenderKitId());
+
+            return firstEquals && secondEquals;
+        }
+
+        @Override
+        public int hashCode() {
+            return (checkForNull(rendererType) + "_" + checkForNull(renderKitId)).hashCode();    //To change body of overridden methods use File | Settings | File Templates.
+        }
+
+        private String checkForNull(String in) {
+            return (in == null) ? "" : in;
+        }
+
+        protected boolean compareValuePair(Object val1, Object val2) {
+            boolean retVal = false;
+            if (val1 == null) {
+                if (val2 != null) retVal = false;
+                if (val2 == null) {
+                    retVal = true;
+                }
+            } else {
+                retVal = val1.equals(val2);
+            }
+            return retVal;
+        }
+
+        public String getRendererType() {
+            return rendererType;
+        }
+
+        public String getRenderKitId() {
+            return renderKitId;
+        }
+    }
+
+    public BehaviorRendererImplementationListener() {
+        super();
+    }
+
+    @Override
+    protected void addEntity(Class clazz, Map<String, Object> params) {
+        String value = (String) params.get(PAR_RENDERERTYPE);
+        String renderKitId = (String) params.get(PAR_RENDERKITID);
+
+        AnnotationEntry entry = new AnnotationEntry(value, renderKitId);
+        _alreadyRegistered.put(clazz.getName(), entry);
+        _inverseIndex.put(entry, clazz.getName());
+
+        getApplication().addConverter(entry.getRendererType(), clazz.getName());
+    }
+
+    @Override
+    protected boolean hasToReregister(Map params, Class clazz) {
+        String value = (String) params.get(PAR_RENDERERTYPE);
+        String renderKitId = (String) params.get(PAR_RENDERKITID);
+
+        AnnotationEntry entry = new AnnotationEntry(value, renderKitId);
+
+        AnnotationEntry alreadyRegistered = (AnnotationEntry) _alreadyRegistered.get(clazz.getName());
+        if (alreadyRegistered == null) {
+            return true;
+        }
+
+        return alreadyRegistered.equals(entry);
+    }
+
+    public boolean supportsAnnotation(String annotation) {
+        return annotation.equals(FacesBehaviorRenderer.class.getName());
+    }
+
+    public boolean supportsAnnotation(Class annotation) {
+        return annotation.equals(FacesBehaviorRenderer.class);
+    }
+
+
+    private RenderKitFactory getRenderKitFactory() {
+        return (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+    }
+
+    private RenderKit getRenderkit(String renderKitId) {
+        RenderKitFactory factory = getRenderKitFactory();
+        RenderKit renderKit = factory.getRenderKit(FacesContext.getCurrentInstance(), renderKitId);
+        return renderKit;
+    }
+
+    @Override
+    public void purge(String className) {
+        super.purge(className);
+        AnnotationEntry entry = (AnnotationEntry) _alreadyRegistered.remove(className);
+        if (entry == null) {
+            return;
+        }
+
+        RenderKit renderKit = getRenderkit(entry.getRenderKitId());
+        try {
+            String rendererClass = _inverseIndex.get(entry);
+            if (rendererClass != null && rendererClass.equals(className)) {
+                _inverseIndex.put(entry, PurgedClientBehaviorRenderer.class.getName());
+                renderKit.addClientBehaviorRenderer(entry.getRendererType(), PurgedClientBehaviorRenderer.class.newInstance());
+            }
+        } catch (InstantiationException e) {
+            log.log(Level.SEVERE, "", e);
+        } catch (IllegalAccessException e) {
+            log.log(Level.SEVERE, "", e);
+        }
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ComponentImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ComponentImplementationListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ComponentImplementationListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ComponentImplementationListener.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedComponent;
+
+import javax.faces.component.FacesComponent;
+import java.util.logging.Level;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ComponentImplementationListener extends SingleEntityAnnotationListener implements AnnotationScanListener {
+
+    public ComponentImplementationListener() {
+        super();
+        _entityParamValue = "value";
+    }
+
+    public boolean supportsAnnotation(String annotation) {
+        return annotation.equals(FacesComponent.class.getName());  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public boolean supportsAnnotation(Class annotation) {
+        return annotation.equals(FacesComponent.class);  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+
+    protected void addEntity(Class clazz, String val) {
+        if (log.isLoggable(Level.FINEST)) {
+            log.log(Level.FINEST, "addComponent(" + val + "," + clazz.getName() + ")");
+        }
+        getApplication().addComponent(val, clazz.getName());
+        //register the renderer if not registered
+
+        _alreadyRegistered.put(clazz.getName(), val);
+    }
+
+    @Override
+    public void purge(String className) {
+        super.purge(className);
+        //no purge needed we already have a different class
+        //registered
+        if (!_alreadyRegistered.containsKey(className)) {
+            return;
+        }
+        String val = (String) _alreadyRegistered.remove(className);
+        if (val != null) {
+            getApplication().addComponent(val, PurgedComponent.class.getName());
+        }
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ConverterImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ConverterImplementationListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ConverterImplementationListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ConverterImplementationListener.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,152 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedConverter;
+
+import javax.faces.application.Application;
+import javax.faces.convert.FacesConverter;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ConverterImplementationListener extends MapEntityAnnotationScanner implements AnnotationScanListener {
+
+    private static final String PAR_VALUE = "value";
+    private static final String PAR_DEFAULT = "forClass";
+
+    Map<AnnotationEntry, String> _inverseIndex = new HashMap<AnnotationEntry, String>();
+
+    class AnnotationEntry {
+        String value;
+        Class forClass;
+
+        AnnotationEntry(String value, Class forClass) {
+
+            this.value = value;
+            this.forClass = forClass;
+        }
+
+        public boolean equals(Object incoming) {
+            if (incoming == null) {
+                return false;
+            }
+
+            if (!(incoming instanceof AnnotationEntry)) {
+                return false;
+            }
+            AnnotationEntry toCompare = (AnnotationEntry) incoming;
+
+            boolean firstEquals = compareValuePair(value, toCompare.getValue());
+            boolean secondEquals = compareValuePair(forClass, toCompare.getForClass());
+
+            return firstEquals && secondEquals;
+        }
+
+        @Override
+        public int hashCode() {
+            String retVal = checkForNull(value) + "_";
+            retVal += ((forClass != null) ? forClass.getName() : "");
+            return retVal.hashCode();
+        }
+
+        private String checkForNull(String in) {
+            return (in == null) ? "" : in;
+        }
+
+        protected boolean compareValuePair(Object val1, Object val2) {
+            boolean retVal = false;
+            if (val1 == null) {
+                if (val2 != null) retVal = false;
+                if (val2 == null) {
+                    retVal = true;
+                }
+            } else {
+                retVal = val1.equals(val2);
+            }
+            return retVal;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        public Class getForClass() {
+            return forClass;
+        }
+    }
+
+    public ConverterImplementationListener() {
+        super(PAR_VALUE, PAR_DEFAULT);
+    }
+
+    @Override
+    protected void addEntity(Class clazz, Map<String, Object> params) {
+        String value = (String) params.get(PAR_VALUE);
+        Class forClass = (Class) params.get(PAR_DEFAULT);
+
+        AnnotationEntry entry = new AnnotationEntry(value, forClass);
+        _alreadyRegistered.put(clazz.getName(), entry);
+        _inverseIndex.put(entry, clazz.getName());
+
+        getApplication().addConverter(entry.getValue(), clazz.getName());
+    }
+
+    @Override
+    protected boolean hasToReregister(Map params, Class clazz) {
+        String value = (String) params.get(PAR_VALUE);
+        Class forClass = (Class) params.get(PAR_DEFAULT);
+
+        AnnotationEntry entry = new AnnotationEntry(value, forClass);
+
+        AnnotationEntry alreadyRegistered = (AnnotationEntry) _alreadyRegistered.get(clazz.getName());
+
+        return (alreadyRegistered == null) || alreadyRegistered.equals(entry);
+    }
+
+    public boolean supportsAnnotation(String annotation) {
+        return annotation.equals(FacesConverter.class.getName());
+    }
+
+    public boolean supportsAnnotation(Class annotation) {
+        return annotation.equals(FacesConverter.class);
+    }
+
+
+    @Override
+    public void purge(String className) {
+        super.purge(className);
+        AnnotationEntry entry = (AnnotationEntry) _alreadyRegistered.remove(className);
+        if (entry == null) {
+            return;
+        }
+        String _oldConverterClass = _inverseIndex.get(entry);
+        if (_oldConverterClass.equals(className)) {
+            Application application = getApplication();
+            application.addConverter(entry.getValue(), PurgedConverter.class.getName());
+            _inverseIndex.put(entry, className);
+        }
+    }
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/GenericAnnotationScanner.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/GenericAnnotationScanner.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/GenericAnnotationScanner.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/GenericAnnotationScanner.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,204 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.api.ClassScanListener;
+import org.apache.myfaces.extensions.scripting.api.ClassScanner;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.loaders.java.ScannerClassloader;
+import org.apache.myfaces.extensions.scripting.refresh.ReloadingMetadata;
+
+import javax.faces.context.FacesContext;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          Source path annotation scanner for java it scans all sources in the specified source paths
+ *          recursively for additional information
+ *          and then adds the id/name -> class binding information to the correct factory locations,
+ *          wherever possible
+ */
+@SuppressWarnings("unused")
+public class GenericAnnotationScanner extends BaseAnnotationScanListener implements ClassScanner {
+
+    List<ClassScanListener> _listeners = new LinkedList<ClassScanListener>();
+
+    Map<String, String> _registeredAnnotations = new HashMap<String, String>();
+    LinkedList<String> _sourcePaths = new LinkedList<String>();
+    private static final String JAVAX_FACES = "javax.faces";
+
+    ScriptingWeaver _weaver = null;
+
+    public GenericAnnotationScanner() {
+        initDefaultListeners();
+    }
+
+    public GenericAnnotationScanner(ScriptingWeaver weaver) {
+        _weaver = weaver;
+        initDefaultListeners();
+    }
+
+    public void addScanPath(String sourcePath) {
+        _sourcePaths.addFirst(sourcePath);
+    }
+
+    Collection<java.lang.annotation.Annotation> filterAnnotations(java.lang.annotation.Annotation[] annotations) {
+        List<java.lang.annotation.Annotation> retVal = new ArrayList<java.lang.annotation.Annotation>(annotations.length);
+        
+        for (java.lang.annotation.Annotation annotation : annotations) {
+            if (annotation.annotationType().getName().startsWith(JAVAX_FACES)) {
+                retVal.add(annotation);
+            }
+
+        }
+        return retVal;
+    }
+
+    public void scanClass(Class clazz) {
+        java.lang.annotation.Annotation[] annotations = clazz.getAnnotations();
+
+        Collection<java.lang.annotation.Annotation> annCol = filterAnnotations(annotations);
+        if (!annCol.isEmpty()) {
+            addOrMoveAnnotations(clazz);
+        } else {
+            removeAnnotations(clazz);
+        }
+    }
+
+    private void initDefaultListeners() {
+        _listeners.add(new BeanImplementationListener());
+        _listeners.add(new BehaviorImplementationListener());
+        _listeners.add(new ComponentImplementationListener());
+        _listeners.add(new ConverterImplementationListener());
+        _listeners.add(new RendererImplementationListener());
+        _listeners.add(new ValidatorImplementationListener());
+    }
+
+    /**
+     * builds up the parsing chain and then notifies its observers
+     * on the found data
+     */
+    public void scanPaths() {
+        //https://issues.apache.org/jira/browse/EXTSCRIPT-33
+
+        //check if the faces config is already available otherwise we cannot scan yet
+        final FacesContext facesContext = FacesContext.getCurrentInstance();
+        //runtime config not started
+        //for now we only can reach the runtime config in the referenced BaseAnnotatonScanListener
+        //if we have a facesContext reachable.
+        if (facesContext == null) {
+            //TODO (1.1) decouple the scan in the BaseAnnotationScanListener from the facesConfig
+            //to get the runtime config
+            return;
+        }
+
+        for (String className : _weaver.loadPossibleDynamicClasses()) {
+            try {
+                ScannerClassloader loader = new ScannerClassloader(Thread.currentThread().getContextClassLoader(), -1, null, WeavingContext.getConfiguration().getCompileTarget());
+
+                Class clazz;
+                //in case the class does not exist we have to load it from our weavingcontext
+                //otherwise we do just a scan on the class to avoid side behavior
+                if (WeavingContext.getFileChangedDaemon().getClassMap().get(className) == null) {
+                    clazz = _weaver.loadScriptingClassFromName(className);
+                } else {
+                    clazz = loader.loadClass(className);
+                }
+
+                if (clazz != null) {
+                    java.lang.annotation.Annotation[] anns = clazz.getAnnotations();
+                    if (anns != null && anns.length > 0) {
+                        addOrMoveAnnotations(clazz);
+                    } else {
+                        removeAnnotations(clazz);
+                    }
+                }
+            } catch (ClassNotFoundException e) {
+                Logger _logger = Logger.getLogger(this.getClass().getName());
+                _logger.log(Level.WARNING, "", e);
+            }
+        }
+
+    }
+
+    /**
+     * add or moves a class level annotation
+     * to a new place
+     *
+     * @param clazz the class to have the annotation moved or added
+     */
+    private void addOrMoveAnnotations(Class clazz) {
+        java.lang.annotation.Annotation[] anns = clazz.getAnnotations();
+        for (java.lang.annotation.Annotation ann : anns) {
+            for (ClassScanListener cListener : _listeners) {
+                AnnotationScanListener listener = (AnnotationScanListener) cListener;
+                if (listener.supportsAnnotation(ann.annotationType())) {
+                    listener.register(clazz, ann);
+
+                    _registeredAnnotations.put(clazz.getName(), ann.annotationType().getName());
+
+                    ReloadingMetadata metaData = WeavingContext.getFileChangedDaemon().getClassMap().get(clazz.getName());
+                    if (metaData != null) {
+                        metaData.setAnnotated(true);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * use case annotation removed
+     * we have to entirely remove the annotation
+     * from our internal registry and the myfaces registry
+     *
+     * @param clazz the class to have the annotation removed
+     */
+    private void removeAnnotations(Class clazz) {
+        String registeredAnnotation = _registeredAnnotations.get(clazz.getName());
+        if (registeredAnnotation != null) {
+            for (ClassScanListener cListener : _listeners) {
+                AnnotationScanListener listener = (AnnotationScanListener) cListener;
+                if (listener.supportsAnnotation(registeredAnnotation)) {
+                    listener.purge(clazz.getName());
+                    _registeredAnnotations.remove(clazz.getName());
+                    WeavingContext.getFileChangedDaemon().getClassMap().remove(clazz.getName());
+                }
+            }
+        }
+    }
+
+    public void clearListeners() {
+        _listeners.clear();
+    }
+
+    public void addListener(ClassScanListener listener) {
+        _listeners.add(listener);
+    }
+
+    @Override
+    public void scanAndMarkChange() {
+        //do nothing here
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/IOCResolver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/IOCResolver.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/IOCResolver.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/IOCResolver.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.jsf2.annotation;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *          <p/>
+ *          parses an existing object
+ *          and resolves its ioc patterns
+ *          and triggers the reloading of its managed beans
+ *          wherever needed
+ *          <p/>
+ *          <p/>
+ *          TODO implement this
+ */
+
+public class IOCResolver {
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ListenerForAnnotationHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ListenerForAnnotationHandler.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ListenerForAnnotationHandler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/ListenerForAnnotationHandler.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.jsf2.annotation;
+
+/**
+ * A generic system event listener which makes the system event
+ * annotations dynamic
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ListenerForAnnotationHandler {
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/MapEntityAnnotationScanner.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/MapEntityAnnotationScanner.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/MapEntityAnnotationScanner.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/MapEntityAnnotationScanner.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,59 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+
+import javax.faces.component.behavior.FacesBehavior;
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public abstract class MapEntityAnnotationScanner extends BaseAnnotationScanListener implements AnnotationScanListener {
+
+    String[] _annotationParms = null;
+
+    public MapEntityAnnotationScanner(String... annotationParms) {
+        _annotationParms = annotationParms;
+    }
+
+    public void register(Class clazz, Annotation annotation) {
+
+        Map<String, Object> parms = new HashMap<String, Object>(_annotationParms.length);
+
+        for (String accessor : _annotationParms) {
+            parms.put(accessor, ReflectUtil.fastExecuteMethod(annotation, accessor, new Object[0]));
+        }
+
+        if (hasToReregister(parms, clazz)) {
+            addEntity(clazz, parms);
+        }
+    }
+
+    protected abstract void addEntity(Class clazz, Map<String, Object> params);
+
+    protected abstract boolean hasToReregister(Map params, Class clazz);
+
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/RendererImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/RendererImplementationListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/RendererImplementationListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/RendererImplementationListener.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,201 @@
+/*
+ * 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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.jsf2.annotation.purged.PurgedRenderer;
+
+import javax.faces.FactoryFinder;
+import javax.faces.context.FacesContext;
+import javax.faces.render.FacesRenderer;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.Renderer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.logging.Level;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RendererImplementationListener extends MapEntityAnnotationScanner implements AnnotationScanListener {
+    private static final String PAR_FAMILY = "componentFamily";
+    private static final String PAR_RENDERERTYPE = "rendererType";
+    private static final String PAR_RENDERKITID = "renderKitId";
+
+    Map<AnnotationEntry, String> _inverseIndex = new HashMap<AnnotationEntry, String>();
+
+    public RendererImplementationListener() {
+        super(PAR_FAMILY, PAR_RENDERERTYPE, PAR_RENDERKITID);
+    }
+
+    class AnnotationEntry {
+        String componentFamily;
+        String rendererType;
+        String renderKitId;
+
+        AnnotationEntry(String componentFamily, String rendererType, String renderKitId) {
+            this.componentFamily = componentFamily;
+            this.rendererType = rendererType;
+            this.renderKitId = renderKitId;
+        }
+
+        public boolean equals(Object incoming) {
+            if (!(incoming instanceof AnnotationEntry)) {
+                return false;
+            }
+            AnnotationEntry toCompare = (AnnotationEntry) incoming;
+            //handle null cases
+            if ((componentFamily == null && toCompare.getComponentFamily() != null) ||
+                    (componentFamily != null && toCompare.getComponentFamily() == null) ||
+                    (rendererType == null && toCompare.getRendererType() != null) ||
+                    (rendererType != null && toCompare.getRendererType() == null) ||
+                    (renderKitId == null && toCompare.getRenderKitId() != null) ||
+                    (renderKitId != null && toCompare.getRenderKitId() == null)) {
+
+                return false;
+            } else if (componentFamily == null && toCompare.getComponentFamily() == null &&
+                    rendererType == null && toCompare.getRendererType() == null &&
+                    renderKitId == null && toCompare.getRenderKitId() == null) {
+                return true;
+            }
+            //TODO a simple hash compare should be enough for almost if not all cases since the hashes have a very low propability to be the same
+            return componentFamily.equals(toCompare.getComponentFamily()) &&
+                    rendererType.equals(toCompare.getRendererType()) &&
+                    renderKitId.equals(toCompare.getRenderKitId());
+        }
+
+        @Override
+        public int hashCode() {
+            /*we calculate the hashcoide to avoid double entries*/
+            return (((componentFamily != null) ? componentFamily : "")
+                    + "_" +
+                    ((rendererType != null) ? rendererType : "")
+                    + "_" +
+                    ((renderKitId != null) ? renderKitId : "")
+
+            ).hashCode();
+        }
+
+        public String getComponentFamily() {
+            return componentFamily;
+        }
+
+        public String getRendererType() {
+            return rendererType;
+        }
+
+        public String getRenderKitId() {
+            return renderKitId;
+        }
+    }
+
+    public boolean supportsAnnotation(String annotation) {
+        return annotation.equals(FacesRenderer.class.getName());
+    }
+
+    public boolean supportsAnnotation(Class annotation) {
+        return annotation.equals(FacesRenderer.class);
+    }
+
+    @Override
+    protected void addEntity(Class clazz, Map<String, Object> params) {
+        String value = (String) params.get(PAR_FAMILY);
+        String theDefault = (String) params.get(PAR_RENDERERTYPE);
+
+        String renderKitId = getRenderKitId(params);
+        RenderKit renderKit = getRenderkit(renderKitId);
+
+        AnnotationEntry entry = new AnnotationEntry(value, theDefault, renderKitId);
+        _inverseIndex.put(entry, clazz.getName());
+        _alreadyRegistered.put(clazz.getName(), entry);
+
+        if (log.isLoggable(Level.FINEST)) {
+            log.log(Level.FINEST, "addRenderer(" + renderKitId + ", "
+                    + entry.getComponentFamily() + ", " + entry.getRendererType()
+                    + ", " + clazz.getName() + ")");
+        }
+
+        try {
+            renderKit.addRenderer(entry.getComponentFamily(), entry.getRendererType(), (Renderer) clazz.newInstance());
+        } catch (InstantiationException e) {
+            log.log(Level.SEVERE, "", e);
+        } catch (IllegalAccessException e) {
+            log.log(Level.SEVERE, "", e);
+        }
+    }
+
+    private RenderKitFactory getRenderKitFactory() {
+        return (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+    }
+
+    @Override
+    protected boolean hasToReregister(Map params, Class clazz) {
+        String value = (String) params.get(PAR_FAMILY);
+        String theDefault = (String) params.get(PAR_RENDERERTYPE);
+        String renderKitId = (String) params.get(PAR_RENDERKITID);
+
+        AnnotationEntry entry = new AnnotationEntry(value, theDefault, renderKitId);
+
+        AnnotationEntry alreadyRegistered = (AnnotationEntry) _alreadyRegistered.get(clazz.getName());
+        if (alreadyRegistered == null) {
+            return true;
+        }
+        //here the check if the new class is the same as the old one
+        return alreadyRegistered.equals(entry);
+    }
+
+    private String getRenderKitId(Map<String, Object> params) {
+        String renderKitId = (String) params.get(PAR_RENDERKITID);
+        renderKitId = (renderKitId == null) ? getApplication().getDefaultRenderKitId() : renderKitId;
+        return renderKitId;
+    }
+
+    private RenderKit getRenderkit(String renderKitId) {
+        RenderKitFactory factory = getRenderKitFactory();
+        RenderKit renderKit = factory.getRenderKit(FacesContext.getCurrentInstance(), renderKitId);
+        return renderKit;
+    }
+
+    @Override
+    public void purge(String className) {
+        super.purge(className);
+        AnnotationEntry entry = (AnnotationEntry) _alreadyRegistered.remove(className);
+        if (entry == null) {
+            return;
+        }
+
+        RenderKit renderKit = getRenderkit(entry.getRenderKitId());
+        try {
+            //by fetching the changed renderer we save a full rescan
+            String rendererClass = _inverseIndex.get(entry);
+            if (rendererClass != null && rendererClass.equals(className)) {
+                _inverseIndex.put(entry, PurgedRenderer.class.getName());
+                renderKit.addRenderer(entry.getComponentFamily(), entry.getRendererType(), PurgedRenderer.class.newInstance());
+            }
+        } catch (InstantiationException e) {
+            log.log(Level.SEVERE, "", e);
+        } catch (IllegalAccessException e) {
+            log.log(Level.SEVERE, "", e);
+        }
+    }
+}

Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/SingleEntityAnnotationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/SingleEntityAnnotationListener.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/SingleEntityAnnotationListener.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-myfaces2-extensions/src/main/java/org/apache/myfaces/extensions/scripting/jsf2/annotation/SingleEntityAnnotationListener.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.jsf2.annotation;
+
+import org.apache.myfaces.extensions.scripting.api.AnnotationScanListener;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+
+import java.util.Map;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public abstract class SingleEntityAnnotationListener extends BaseAnnotationScanListener implements AnnotationScanListener {
+    String _entityParamValue = null;
+
+    public void register(Class clazz, Annotation annotation) {
+
+        String val = (String) ReflectUtil.executeMethod(annotation, _entityParamValue);
+        if (hasToReregister(val, clazz)) {
+            addEntity(clazz, val);
+        }
+    }
+
+    protected abstract void addEntity(Class clazz, String val);
+
+    protected boolean hasToReregister(String name, Class clazz) {
+        String componentClass = (String) _alreadyRegistered.get(name);
+        return componentClass == null || !componentClass.equals(clazz.getName());
+    }
+
+}