You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2009/09/22 12:45:07 UTC

svn commit: r817588 - in /myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation: BaseAnnotationScanListener.java BeanImplementationListener.java ComponentImplementationListener.java

Author: werpu
Date: Tue Sep 22 10:45:06 2009
New Revision: 817588

URL: http://svn.apache.org/viewvc?rev=817588&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-18
extracting shared code

Modified:
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BaseAnnotationScanListener.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java
    myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ComponentImplementationListener.java

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BaseAnnotationScanListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BaseAnnotationScanListener.java?rev=817588&r1=817587&r2=817588&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BaseAnnotationScanListener.java (original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BaseAnnotationScanListener.java Tue Sep 22 10:45:06 2009
@@ -18,10 +18,64 @@
  */
 package org.apache.myfaces.scripting.jsf2.annotation;
 
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.config.impl.digester.elements.ManagedBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.context.FacesContext;
+import javax.faces.application.Application;
+import java.util.Map;
+import java.util.HashMap;
+
+import com.thoughtworks.qdox.model.annotation.AnnotationConstant;
+import com.thoughtworks.qdox.model.JavaClass;
+
 /**
  * @author Werner Punz (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
 
 public class BaseAnnotationScanListener {
+    Log log = LogFactory.getLog(this.getClass());
+    static Map<String, ManagedBean> _alreadyRegistered = new HashMap<String, ManagedBean>();
+
+    protected RuntimeConfig getRuntimeConfig() {
+        final FacesContext facesContext = FacesContext.getCurrentInstance();
+        return RuntimeConfig.getCurrentInstance(facesContext.getExternalContext());
+    }
+
+    protected Application getApplication() {
+        return FacesContext.getCurrentInstance().getApplication();
+    }
+
+    protected String getAnnotatedStringParam(Map<String, Object> propMap, String key) {
+        AnnotationConstant propVal = (AnnotationConstant) propMap.get(key);
+        String name = (String) propVal.getParameterValue();
+        name = name.replaceAll("\"", "");
+        return name;
+    }
+
+    protected boolean hasToReregister(String name, Class clazz) {
+        ManagedBean mbean = _alreadyRegistered.get(name);
+        return mbean == null || !mbean.getManagedBeanClassName().equals(clazz.getName());
+    }
+
+    /**
+     * simple check we do not check for the contents of the managed property here
+     * This is somewhat a simplification does not drag down the managed property handling
+     * speed too much
+     * <p/>
+     * TODO we have to find a way to enable the checking on managed property level
+     * so that we can replace the meta data on the fly (probably by extending the interface)
+     * for first registration this is enough
+     *
+     * @param name
+     * @param clazz
+     * @return
+     */
+    protected boolean hasToReregister(String name, JavaClass clazz) {
+        ManagedBean mbean = _alreadyRegistered.get(name);
+        return mbean == null || !mbean.getManagedBeanClassName().equals(clazz.getFullyQualifiedName());
+    }
 }

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java?rev=817588&r1=817587&r2=817588&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java (original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/BeanImplementationListener.java Tue Sep 22 10:45:06 2009
@@ -45,10 +45,6 @@
 
 public class BeanImplementationListener extends BaseAnnotationScanListener implements AnnotationScanListener {
 
-    Log log = LogFactory.getLog(this.getClass());
-
-    static Map<String, ManagedBean> _alreadyRegistered = new HashMap<String, ManagedBean>();
-
     public boolean supportsAnnotation(String annotation) {
         return annotation.equals(javax.faces.bean.ManagedBean.class.getName());
     }
@@ -103,12 +99,6 @@
     }
 
 
-    protected RuntimeConfig getRuntimeConfig() {
-        final FacesContext facesContext = FacesContext.getCurrentInstance();
-        return RuntimeConfig.getCurrentInstance(facesContext.getExternalContext());
-    }
-
-
     private void handleManagedpropertiesCompiled(ManagedBean mbean, Field[] fields) {
         for (Field field : fields) {
             if (log.isTraceEnabled()) {
@@ -167,38 +157,6 @@
         }
     }
 
-    private String getAnnotatedStringParam(Map<String, Object> propMap, String key) {
-        AnnotationConstant propVal = (AnnotationConstant) propMap.get(key);
-        String name = (String) propVal.getParameterValue();
-        name = name.replaceAll("\"", "");
-        return name;
-    }
-
-
-    private boolean hasToReregister(String name, Class clazz) {
-        ManagedBean mbean = _alreadyRegistered.get(name);
-        return mbean == null || !mbean.getManagedBeanClassName().equals(clazz.getName());
-    }
-
-
-    /**
-     * simple check we do not check for the contents of the managed property here
-     * This is somewhat a simplification does not drag down the managed property handling
-     * speed too much
-     * <p/>
-     * TODO we have to find a way to enable the checking on managed property level
-     * so that we can replace the meta data on the fly (probably by extending the interface)
-     * for first registration this is enough
-     *
-     * @param name
-     * @param clazz
-     * @return
-     */
-    private boolean hasToReregister(String name, JavaClass clazz) {
-        ManagedBean mbean = _alreadyRegistered.get(name);
-        return mbean == null || !mbean.getManagedBeanClassName().equals(clazz.getFullyQualifiedName());
-    }
-
 
     /**
      * <p>Return an array of all <code>Field</code>s reflecting declared

Modified: myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ComponentImplementationListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ComponentImplementationListener.java?rev=817588&r1=817587&r2=817588&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ComponentImplementationListener.java (original)
+++ myfaces/extensions/scripting/trunk/core/myfaces2-extensions/src/main/java/org/apache/myfaces/scripting/jsf2/annotation/ComponentImplementationListener.java Tue Sep 22 10:45:06 2009
@@ -20,11 +20,8 @@
 
 import com.thoughtworks.qdox.model.JavaClass;
 import org.apache.myfaces.scripting.api.AnnotationScanListener;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.Log;
 
 import javax.faces.component.FacesComponent;
-import javax.faces.context.FacesContext;
 import java.util.Map;
 
 /**
@@ -34,7 +31,6 @@
 
 public class ComponentImplementationListener extends BaseAnnotationScanListener implements AnnotationScanListener {
 
-    Log log = LogFactory.getLog(this.getClass());
 
     public boolean supportsAnnotation(String annotation) {
         return annotation.equals(FacesComponent.class.getName());  //To change body of implemented methods use File | Settings | File Templates.
@@ -59,7 +55,7 @@
                           + clazz.getName() + ")");
             }
 
-            FacesContext.getCurrentInstance().getApplication().addComponent(comp.value(), clazz.getName());
+            getApplication().addComponent(comp.value(), clazz.getName());
         }
     }