Repository: struts
Updated Branches:
  refs/heads/master e47a1127f -> decf48eb7


Minor code improvement's in the struts spring plugin

- Use Java 7 features like diamond operator
- Improve some logging message
- Remove out commented code
- Use BooleanUtils.toBoolean(string) instead of "true".isEquals to be more 
robust


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/decf48eb
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/decf48eb
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/decf48eb

Branch: refs/heads/master
Commit: decf48eb7198f7cda9d38c3391d9a3b0f5c05c81
Parents: e47a112
Author: Johannes Geppert <p...@jgeppert.com>
Authored: Mon Jun 8 19:51:09 2015 +0200
Committer: Johannes Geppert <p...@jgeppert.com>
Committed: Mon Jun 8 19:51:09 2015 +0200

----------------------------------------------------------------------
 .../spring/ClassReloadingBeanFactory.java       | 20 ++-----------
 .../ClassReloadingXMLWebApplicationContext.java | 30 ++++++++++----------
 .../spring/StrutsSpringObjectFactory.java       | 13 ++-------
 3 files changed, 21 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/decf48eb/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
----------------------------------------------------------------------
diff --git 
a/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
 
b/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
index 1dec9cd..c577645 100644
--- 
a/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
+++ 
b/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
@@ -43,22 +43,12 @@ public class ClassReloadingBeanFactory extends 
DefaultListableBeanFactory {
             return instantiateUsingFactoryMethod(beanName, mbd, args);
         }
 
-        //commented to cached constructor is not used
-        /* // Shortcut when re-creating the same bean...
-        if (mbd.resolvedConstructorOrFactoryMethod != null) {
-            if (mbd.constructorArgumentsResolved) {
-                return autowireConstructor(beanName, mbd, null, args);
-            } else {
-                return instantiateBean(beanName, mbd);
-            }
-        }*/
-
         // Need to determine the constructor...
-        Constructor[] ctors = 
determineConstructorsFromBeanPostProcessors(beanClass, beanName);
-        if (ctors != null ||
+        Constructor[] constructors = 
determineConstructorsFromBeanPostProcessors(beanClass, beanName);
+        if (constructors != null ||
                 mbd.getResolvedAutowireMode() == 
RootBeanDefinition.AUTOWIRE_CONSTRUCTOR ||
                 mbd.hasConstructorArgumentValues() || 
!ObjectUtils.isEmpty(args)) {
-            return autowireConstructor(beanName, mbd, ctors, args);
+            return autowireConstructor(beanName, mbd, constructors, args);
         }
 
         // No special handling: simply use no-arg constructor.
@@ -67,10 +57,6 @@ public class ClassReloadingBeanFactory extends 
DefaultListableBeanFactory {
 
     protected Class resolveBeanClass(RootBeanDefinition mbd, String beanName, 
Class[] typesToMatch) {
         try {
-             //commented to cached class is not used
-            /* if (mbd.hasBeanClass()) {
-                return mbd.getBeanClass();
-            }*/
             if (typesToMatch != null) {
                 ClassLoader tempClassLoader = getTempClassLoader();
                 if (tempClassLoader != null) {

http://git-wip-us.apache.org/repos/asf/struts/blob/decf48eb/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
----------------------------------------------------------------------
diff --git 
a/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
 
b/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
index 5aa7e79..87c39b8 100644
--- 
a/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
+++ 
b/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
@@ -74,7 +74,7 @@ public class ClassReloadingXMLWebApplicationContext extends 
XmlWebApplicationCon
     private static final Logger LOG = 
LogManager.getLogger(ClassReloadingXMLWebApplicationContext.class);
 
     protected ReloadingClassLoader classLoader;
-    protected FilesystemAlterationMonitor fam;
+    protected FilesystemAlterationMonitor filesystemAlterationMonitor;
 
     protected ClassReloadingBeanFactory beanFactory;
     //reload the runtime configuration when a change is detected
@@ -88,14 +88,14 @@ public class ClassReloadingXMLWebApplicationContext extends 
XmlWebApplicationCon
         //make a list of accepted classes
         if (StringUtils.isNotBlank(acceptClasses)) {
             String[] splitted = acceptClasses.split(",");
-            Set<Pattern> patterns = new HashSet<Pattern>(splitted.length);
+            Set<Pattern> patterns = new HashSet<>(splitted.length);
             for (String pattern : splitted)
                 patterns.add(Pattern.compile(pattern));
 
             classLoader.setAccepClasses(patterns);
         }
 
-        fam = new FilesystemAlterationMonitor();
+        filesystemAlterationMonitor = new FilesystemAlterationMonitor();
 
         //setup stores
         for (String watch : watchList) {
@@ -107,19 +107,19 @@ public class ClassReloadingXMLWebApplicationContext 
extends XmlWebApplicationCon
 
             if (watch.endsWith(".jar")) {
                 classLoader.addResourceStore(new JarResourceStore(file));
-                //register with the fam
-                fam.addListener(file, this);
+                //register with the filesystemAlterationMonitor
+                filesystemAlterationMonitor.addListener(file, this);
                 LOG.debug("Watching [{}] for changes", file.getAbsolutePath());
             } else {
                 //get all subdirs
-                List<File> dirs = new ArrayList<File>();
+                List<File> dirs = new ArrayList<>();
                 getAllPaths(file, dirs);
 
                 classLoader.addResourceStore(new FileResourceStore(file));
 
                 for (File dir : dirs) {
-                    //register with the fam
-                    fam.addListener(dir, this);
+                    //register with the filesystemAlterationMonitor
+                    filesystemAlterationMonitor.addListener(dir, this);
                        LOG.debug("Watching [{}] for changes", 
dir.getAbsolutePath());
                 }
             }
@@ -130,11 +130,11 @@ public class ClassReloadingXMLWebApplicationContext 
extends XmlWebApplicationCon
         beanFactory.setBeanClassLoader(classLoader);
 
         //start watch thread
-        fam.start();
+        filesystemAlterationMonitor.start();
     }
 
     /**
-     * If root is a dir, find al the subdir paths
+     * If root is a dir, find all the subdir paths
      */
     private void getAllPaths(File root, List<File> dirs) {
         dirs.add(root);
@@ -154,9 +154,9 @@ public class ClassReloadingXMLWebApplicationContext extends 
XmlWebApplicationCon
     public void close() {
         super.close();
 
-        if (fam != null) {
-            fam.removeListener(this);
-            fam.stop();
+        if (filesystemAlterationMonitor != null) {
+            filesystemAlterationMonitor.removeListener(this);
+            filesystemAlterationMonitor.stop();
         }
     }
 
@@ -176,8 +176,9 @@ public class ClassReloadingXMLWebApplicationContext extends 
XmlWebApplicationCon
         super.prepareBeanFactory(beanFactory);
 
         //overwrite the class loader in the bean factory
-        if (classLoader != null)
+        if (classLoader != null) {
             beanFactory.setBeanClassLoader(classLoader);
+        }
     }
 
     public void onDirectoryChange(File file) {
@@ -201,7 +202,6 @@ public class ClassReloadingXMLWebApplicationContext extends 
XmlWebApplicationCon
 
     private void reload(File file) {
         if (classLoader != null) {
-            final boolean debugEnabled = LOG.isDebugEnabled();
             LOG.debug("Change detected in file [{}], reloading class loader", 
file.getAbsolutePath());
             classLoader.reload();
             if (reloadConfig && Dispatcher.getInstance() != null) {

http://git-wip-us.apache.org/repos/asf/struts/blob/decf48eb/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
----------------------------------------------------------------------
diff --git 
a/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
 
b/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
index f4a6f31..7f7f985 100644
--- 
a/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
+++ 
b/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
@@ -24,6 +24,7 @@ package org.apache.struts2.spring;
 import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.spring.SpringObjectFactory;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -46,14 +47,6 @@ import javax.servlet.ServletContext;
 public class StrutsSpringObjectFactory extends SpringObjectFactory {
     private static final Logger LOG = 
LogManager.getLogger(StrutsSpringObjectFactory.class);
 
-    //@Inject
-    //public StrutsSpringObjectFactory(
-    //        
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE,required=false)
 String autoWire,
-    //        
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE,required=false)
 String useClassCacheStr,
-    //        @Inject ServletContext servletContext) {
-    //    this(autoWire, "false", useClassCacheStr, servletContext);
-    //}
-
     /**
      * Constructs the spring object factory
      * @param autoWire The type of autowiring to use
@@ -73,7 +66,7 @@ public class StrutsSpringObjectFactory extends 
SpringObjectFactory {
             @Inject Container container) {
           
         super();
-        boolean useClassCache = "true".equals(useClassCacheStr);
+        boolean useClassCache = BooleanUtils.toBoolean(useClassCacheStr);
         LOG.info("Initializing Struts-Spring integration...");
 
         Object rootWebApplicationContext =  
servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
@@ -136,7 +129,7 @@ public class StrutsSpringObjectFactory extends 
SpringObjectFactory {
 
         this.setUseClassCache(useClassCache);
 
-        
this.setAlwaysRespectAutowireStrategy("true".equalsIgnoreCase(alwaysAutoWire));
+        
this.setAlwaysRespectAutowireStrategy(BooleanUtils.toBoolean(alwaysAutoWire));
 
         this.setEnableAopSupport(enableAopSupport);
 

Reply via email to