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/12/09 00:58:13 UTC
svn commit: r888644 - in
/myfaces/extensions/scripting/trunk/core/core/src/main:
groovy/org/apache/myfaces/groovyloader/core/
java/org/apache/myfaces/scripting/api/
java/org/apache/myfaces/scripting/loaders/java/
Author: werpu
Date: Tue Dec 8 23:58:13 2009
New Revision: 888644
URL: http://svn.apache.org/viewvc?rev=888644&view=rev
Log:
code cleanup moved some shared code (bean tainting) into the weaver base class
to handle it shared over all scripting engine instances.
Modified:
myfaces/extensions/scripting/trunk/core/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy
myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java
myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
Modified: myfaces/extensions/scripting/trunk/core/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy?rev=888644&r1=888643&r2=888644&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/groovy/org/apache/myfaces/groovyloader/core/GroovyWeaver.groovy Tue Dec 8 23:58:13 2009
@@ -56,36 +56,11 @@
_reloadingStrategy = new GlobalReloadingStrategy(this)
}
-
-
/**
- * central algorithm which determines which property values are overwritten and which are not
+ * central point for the
+ * loading, loads a class from a given sourceroot
+ * and file
*/
- protected void mapProperties(Object target, Object src) {
- src.properties.each {property ->
- //ok here is the algorithm, basic datatypes usually are not copied but read in anew and then overwritten
- //later on
- //all others can be manually overwritten by adding an attribute <attributename>_changed
-
- try {
- if (target.properties.containsKey(property.key)
- && !property.key.equals("metaClass") //the class information and meta class information cannot be changed
- && !property.key.equals("class") //otherwise we will get following error
- // java.lang.IllegalArgumentException: object is not an instance of declaring class
- && !(
- target.properties.containsKey(property.key + "_changed") //||
- //nothing further needed the phases take care of that
- )) {
- target.setProperty(property.key, property.value)
- }
- } catch (Exception e) {
-
- }
- }
- }
-
-
-
protected Class loadScriptingClassFromFile(String sourceRoot, String file) {
File currentClassFile = new File(sourceRoot + File.separator + file)
@@ -156,11 +131,11 @@
}
public void fullRecompile() {
- //TODO implement this
- }
+ //TODO probably not needed because the groovy classloader takes care of everything itself
+ //the tainting does the rest but we have to check it for the annotations
- public void requestRefresh() {
+ FileChangedDaemon.getInstance().getSystemRecompileMap().put(getScriptingEngine(), Boolean.FALSE);
}
}
Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java?rev=888644&r1=888643&r2=888644&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java Tue Dec 8 23:58:13 2009
@@ -6,12 +6,15 @@
import org.apache.myfaces.scripting.refresh.FileChangedDaemon;
import org.apache.myfaces.scripting.core.reloading.SimpleReloadingStrategy;
import org.apache.myfaces.scripting.core.reloading.GlobalReloadingStrategy;
+import org.apache.myfaces.scripting.core.util.WeavingContext;
+import org.apache.myfaces.scripting.core.util.ReflectUtil;
+import org.apache.myfaces.config.element.ManagedBean;
+import org.apache.myfaces.config.RuntimeConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.List;
-import java.util.LinkedList;
-import java.util.Map;
+import javax.faces.context.FacesContext;
+import java.util.*;
import java.io.File;
/**
@@ -228,4 +231,87 @@
public void fullAnnotationScan() {
}
+
+
+ public void requestRefresh() {
+ if ( //startup or full recompile conditionr reached
+ FileChangedDaemon.getInstance().getSystemRecompileMap().get(getScriptingEngine()) == null ||
+ FileChangedDaemon.getInstance().getSystemRecompileMap().get(getScriptingEngine())
+ ) {
+ fullRecompile();
+ //TODO if managed beans are tainted we have to do a full drop
+
+ refreshManagedBeans();
+ }
+ }
+
+ protected void refreshManagedBeans() {
+ if (FacesContext.getCurrentInstance() == null) {
+ return;//no npe allowed
+ }
+ Set<String> tainted = new HashSet<String>();
+ for (Map.Entry<String, ReloadingMetadata> it : FileChangedDaemon.getInstance().getClassMap().entrySet()) {
+ if (it.getValue().getScriptingEngine() == getScriptingEngine() && it.getValue().isTainted()) {
+ tainted.add(it.getKey());
+ }
+ }
+ if (tainted.size() > 0) {
+ boolean managedBeanTainted = false;
+ //We now have to check if the tainted classes belong to the managed beans
+ Set<String> managedBeanClasses = new HashSet<String>();
+ Map<String, ManagedBean> mbeans = RuntimeConfig.getCurrentInstance(FacesContext.getCurrentInstance().getExternalContext()).getManagedBeans();
+ for (Map.Entry<String, ManagedBean> entry : mbeans.entrySet()) {
+ managedBeanClasses.add(entry.getValue().getManagedBeanClassName());
+ }
+ for (String taintedClass : tainted) {
+ if (managedBeanClasses.contains(taintedClass)) {
+ managedBeanTainted = true;
+ break;
+ }
+ }
+
+ getLog().info("Tainting all beans to avoid classcast exceptions");
+ if (managedBeanTainted) {
+ for (Map.Entry<String, ManagedBean> entry : mbeans.entrySet()) {
+ Class managedBeanClass = entry.getValue().getManagedBeanClass();
+ if (WeavingContext.isDynamic(managedBeanClass)) {
+ //managed bean class found we drop the class from our session
+ removeBeanReferences(entry.getValue());
+ }
+ //one bean tainted we have to taint all dynamic beans otherwise we will get classcast
+ //exceptions
+ getLog().info("Tainting ");
+ ReloadingMetadata metaData = FileChangedDaemon.getInstance().getClassMap().get(managedBeanClass.getName());
+ metaData.setTainted(true);
+ }
+
+ }
+ }
+ }
+
+ /**
+ * removes the references from out static scope
+ * for jsf2 we probably have some kind of notification mechanism
+ * which notifies custom scopes
+ *
+ * @param bean
+ */
+ private void removeBeanReferences(ManagedBean bean) {
+ getLog().info("JavaScriptingWeaver.removeBeanReferences(" + bean.getManagedBeanName() + ")");
+
+ String scope = bean.getManagedBeanScope();
+
+ if (scope != null && scope.equalsIgnoreCase("session")) {
+ FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(bean.getManagedBeanName());
+ } else if (scope != null && scope.equalsIgnoreCase("application")) {
+ FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().remove(bean.getManagedBeanName());
+ } else if (scope != null) {
+ Object scopeImpl = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(scope);
+ if (scopeImpl == null) return; //scope not implemented
+ //we now have to revert to introspection here because scopes are a pure jsf2 construct
+ //so we use a messaging pattern here to cope with it
+ ReflectUtil.executeMethod(scopeImpl, "remove", bean.getManagedBeanName());
+ }
+ }
+
}
Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java?rev=888644&r1=888643&r2=888644&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java Tue Dec 8 23:58:13 2009
@@ -220,87 +220,8 @@
markAsFullyRecompiled();
}
- public void requestRefresh() {
- if (
- FileChangedDaemon.getInstance().getSystemRecompileMap().get(ScriptingConst.ENGINE_TYPE_JAVA) == null ||
- FileChangedDaemon.getInstance().getSystemRecompileMap().get(ScriptingConst.ENGINE_TYPE_JAVA)
- ) {
- fullRecompile();
- //TODO if managed beans are tainted we have to do a full drop
- refreshManagedBeans();
- }
- }
-
- private void refreshManagedBeans() {
- if(FacesContext.getCurrentInstance() == null) {
- return;//no npe allowed
- }
- Set<String> tainted = new HashSet<String>();
- for (Map.Entry<String, ReloadingMetadata> it : FileChangedDaemon.getInstance().getClassMap().entrySet()) {
- if (it.getValue().getScriptingEngine() == ScriptingConst.ENGINE_TYPE_JAVA && it.getValue().isTainted()) {
- tainted.add(it.getKey());
- }
- }
- if (tainted.size() > 0) {
- boolean managedBeanTainted = false;
- //We now have to check if the tainted classes belong to the managed beans
- Set<String> managedBeanClasses = new HashSet<String>();
- Map<String, ManagedBean> mbeans = RuntimeConfig.getCurrentInstance(FacesContext.getCurrentInstance().getExternalContext()).getManagedBeans();
- for (Map.Entry<String, ManagedBean> entry : mbeans.entrySet()) {
- managedBeanClasses.add(entry.getValue().getManagedBeanClassName());
- }
- for (String taintedClass : tainted) {
- if (managedBeanClasses.contains(taintedClass)) {
- managedBeanTainted = true;
- break;
- }
- }
-
- log.info("Tainting all beans to avoid classcast exceptions");
- if (managedBeanTainted) {
- for (Map.Entry<String, ManagedBean> entry : mbeans.entrySet()) {
- Class managedBeanClass = entry.getValue().getManagedBeanClass();
- if (WeavingContext.isDynamic(managedBeanClass)) {
- //managed bean class found we drop the class from our session
- removeBeanReferences(entry.getValue());
- }
- //one bean tainted we have to taint all dynamic beans otherwise we will get classcast
- //exceptions
- log.info("Tainting ");
- ReloadingMetadata metaData = FileChangedDaemon.getInstance().getClassMap().get(managedBeanClass.getName());
- metaData.setTainted(true);
- }
-
- }
- }
- }
-
- /**
- * removes the references from out static scope
- * for jsf2 we probably have some kind of notification mechanism
- * which notifies custom scopes
- *
- * @param bean
- */
- private void removeBeanReferences(ManagedBean bean) {
- getLog().info("JavaScriptingWeaver.removeBeanReferences(" + bean.getManagedBeanName() + ")");
-
- String scope = bean.getManagedBeanScope();
-
- if (scope != null && scope.equalsIgnoreCase("session")) {
- FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(bean.getManagedBeanName());
- } else if (scope != null && scope.equalsIgnoreCase("application")) {
- FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().remove(bean.getManagedBeanName());
- } else if (scope != null) {
- Object scopeImpl = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(scope);
- if (scopeImpl == null) return; //scope not implemented
- //we now have to revert to introspection here because scopes are a pure jsf2 construct
- //so we use a messaging pattern here to cope with it
- ReflectUtil.executeMethod(scopeImpl, "remove", bean.getManagedBeanName());
- }
- }
-
+
private void markAsFullyRecompiled() {
FacesContext context = FacesContext.getCurrentInstance();