Author: lukaszlenart
Date: Tue Nov 19 17:56:18 2013
New Revision: 1543527

URL: http://svn.apache.org/r1543527
Log:
WW-4243 Extracts BeanSelectionProvider interface

Added:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
      - copied, changed from r1535515, 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/DefaultBeanSelectionProviderTest.java
      - copied, changed from r1535515, 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java
Removed:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java
Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
    struts/struts2/trunk/core/src/main/resources/struts-default.xml
    
struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java

Added: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java?rev=1543527&view=auto
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java
 (added)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java
 Tue Nov 19 17:56:18 2013
@@ -0,0 +1,114 @@
+package org.apache.struts2.config;
+
+import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.config.BeanSelectionProvider;
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.inject.ContainerBuilder;
+import com.opensymphony.xwork2.inject.Context;
+import com.opensymphony.xwork2.inject.Factory;
+import com.opensymphony.xwork2.inject.Scope;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+
+import java.util.Properties;
+
+/**
+ * TODO lukaszlenart: write a JavaDoc
+ */
+public abstract class AbstractBeanSelectionProvider implements 
BeanSelectionProvider {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(AbstractBeanSelectionProvider.class);
+
+    public static final String DEFAULT_BEAN_NAME = "struts";
+
+    public void destroy() {
+        // NO-OP
+    }
+
+    public void loadPackages() throws ConfigurationException {
+        // NO-OP
+    }
+
+    public void init(Configuration configuration) throws 
ConfigurationException {
+        // NO-OP
+    }
+
+    public boolean needsReload() {
+        return false;
+    }
+
+    protected void alias(Class type, String key, ContainerBuilder builder, 
Properties props) {
+        alias(type, key, builder, props, Scope.SINGLETON);
+    }
+
+    protected void alias(Class type, String key, ContainerBuilder builder, 
Properties props, Scope scope) {
+        if (!builder.contains(type)) {
+            String foundName = props.getProperty(key, DEFAULT_BEAN_NAME);
+            if (builder.contains(type, foundName)) {
+                if (LOG.isInfoEnabled()) {
+                    LOG.info("Choosing bean (#0) for (#1)", foundName, 
type.getName());
+                }
+                builder.alias(type, foundName, Container.DEFAULT_NAME);
+            } else {
+                try {
+                    Class cls = ClassLoaderUtil.loadClass(foundName, 
this.getClass());
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Choosing bean (#0) for (#1)", 
cls.getName(), type.getName());
+                    }
+                    builder.factory(type, cls, scope);
+                } catch (ClassNotFoundException ex) {
+                    // Perhaps a spring bean id, so we'll delegate to the 
object factory at runtime
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Choosing bean (#0) for (#1) to be loaded 
from the ObjectFactory", foundName, type.getName());
+                    }
+                    if (DEFAULT_BEAN_NAME.equals(foundName)) {
+                        // Probably an optional bean, will ignore
+                    } else {
+                        if (ObjectFactory.class != type) {
+                            builder.factory(type, new 
ObjectFactoryDelegateFactory(foundName, type), scope);
+                        } else {
+                            throw new ConfigurationException("Cannot locate 
the chosen ObjectFactory implementation: " + foundName);
+                        }
+                    }
+                }
+            }
+        } else {
+            if (LOG.isWarnEnabled()) {
+                LOG.warn("Unable to alias bean type (#0), default mapping 
already assigned.", type.getName());
+            }
+        }
+    }
+
+    protected void convertIfExist(LocatableProperties props, String fromKey, 
String toKey) {
+        if (props.containsKey(fromKey)) {
+            props.setProperty(toKey, props.getProperty(fromKey));
+        }
+    }
+
+
+
+    static class ObjectFactoryDelegateFactory implements Factory {
+
+        String name;
+        Class type;
+
+        ObjectFactoryDelegateFactory(String name, Class type) {
+            this.name = name;
+            this.type = type;
+        }
+
+        public Object create(Context context) throws Exception {
+            ObjectFactory objFactory = 
context.getContainer().getInstance(ObjectFactory.class);
+            try {
+                return objFactory.buildBean(name, null, true);
+            } catch (ClassNotFoundException ex) {
+                throw new ConfigurationException("Unable to load bean 
"+type.getName()+" ("+name+")");
+            }
+        }
+
+    }
+}

Copied: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
 (from r1535515, 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java)
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java?p2=struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java&p1=struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java&r1=1535515&r2=1543527&rev=1543527&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
 Tue Nov 19 17:56:18 2013
@@ -29,9 +29,6 @@ import com.opensymphony.xwork2.ObjectFac
 import com.opensymphony.xwork2.TextProvider;
 import com.opensymphony.xwork2.UnknownHandlerManager;
 import com.opensymphony.xwork2.XWorkConstants;
-import com.opensymphony.xwork2.config.Configuration;
-import com.opensymphony.xwork2.config.ConfigurationException;
-import com.opensymphony.xwork2.config.ConfigurationProvider;
 import com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor;
 import com.opensymphony.xwork2.conversion.ConversionFileProcessor;
 import com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor;
@@ -49,12 +46,8 @@ import com.opensymphony.xwork2.factory.C
 import com.opensymphony.xwork2.factory.InterceptorFactory;
 import com.opensymphony.xwork2.factory.ResultFactory;
 import com.opensymphony.xwork2.factory.ValidatorFactory;
-import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.ContainerBuilder;
-import com.opensymphony.xwork2.inject.Context;
-import com.opensymphony.xwork2.inject.Factory;
 import com.opensymphony.xwork2.inject.Scope;
-import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.util.LocalizedTextUtil;
 import com.opensymphony.xwork2.util.PatternMatcher;
 import com.opensymphony.xwork2.util.TextParser;
@@ -75,7 +68,6 @@ import org.apache.struts2.views.freemark
 import org.apache.struts2.views.util.UrlHelper;
 import org.apache.struts2.views.velocity.VelocityManager;
 
-import java.util.Properties;
 import java.util.StringTokenizer;
 
 /**
@@ -341,27 +333,9 @@ import java.util.StringTokenizer;
  *   <li><code>struts.configuration.xml.reload = true</code></li>
  * </ul>
  */
-public class BeanSelectionProvider implements ConfigurationProvider {
+public class DefaultBeanSelectionProvider extends 
AbstractBeanSelectionProvider {
 
-    public static final String DEFAULT_BEAN_NAME = "struts";
-
-    private static final Logger LOG = 
LoggerFactory.getLogger(BeanSelectionProvider.class);
-
-    public void destroy() {
-        // NO-OP
-    }
-
-    public void loadPackages() throws ConfigurationException {
-        // NO-OP
-    }
-
-    public void init(Configuration configuration) throws 
ConfigurationException {
-        // NO-OP
-    }
-
-    public boolean needsReload() {
-        return false;
-    }
+    private static final Logger LOG = 
LoggerFactory.getLogger(DefaultBeanSelectionProvider.class);
 
     public void register(ContainerBuilder builder, LocatableProperties props) {
         alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, 
builder, props);
@@ -448,12 +422,6 @@ public class BeanSelectionProvider imple
         }
     }
 
-    private void convertIfExist(LocatableProperties props, String fromKey, 
String toKey) {
-        if (props.containsKey(fromKey)) {
-            props.setProperty(toKey, props.getProperty(fromKey));
-        }
-    }
-
     private void loadCustomResourceBundles(LocatableProperties props) {
         String bundles = 
props.getProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES);
         if (bundles != null && bundles.length() > 0) {
@@ -473,67 +441,4 @@ public class BeanSelectionProvider imple
         }
     }
 
-    void alias(Class type, String key, ContainerBuilder builder, Properties 
props) {
-        alias(type, key, builder, props, Scope.SINGLETON);
-    }
-
-    void alias(Class type, String key, ContainerBuilder builder, Properties 
props, Scope scope) {
-        if (!builder.contains(type)) {
-            String foundName = props.getProperty(key, DEFAULT_BEAN_NAME);
-            if (builder.contains(type, foundName)) {
-                if (LOG.isInfoEnabled()) {
-                    LOG.info("Choosing bean (#0) for (#1)", foundName, 
type.getName());
-                }
-                builder.alias(type, foundName, Container.DEFAULT_NAME);
-            } else {
-                try {
-                    Class cls = ClassLoaderUtil.loadClass(foundName, 
this.getClass());
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Choosing bean (#0) for (#1)", 
cls.getName(), type.getName());
-                    }
-                    builder.factory(type, cls, scope);
-                } catch (ClassNotFoundException ex) {
-                    // Perhaps a spring bean id, so we'll delegate to the 
object factory at runtime
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Choosing bean (#0) for (#1) to be loaded 
from the ObjectFactory", foundName, type.getName());
-                    }
-                    if (DEFAULT_BEAN_NAME.equals(foundName)) {
-                        // Probably an optional bean, will ignore
-                    } else {
-                        if (ObjectFactory.class != type) {
-                            builder.factory(type, new 
ObjectFactoryDelegateFactory(foundName, type), scope);
-                        } else {
-                            throw new ConfigurationException("Cannot locate 
the chosen ObjectFactory implementation: " + foundName);
-                        }
-                    }
-                }
-            }
-        } else {
-            if (LOG.isWarnEnabled()) {
-                   LOG.warn("Unable to alias bean type (#0), default mapping 
already assigned.", type.getName());
-            }
-        }
-    }
-
-    static class ObjectFactoryDelegateFactory implements Factory {
-
-        String name;
-        Class type;
-
-        ObjectFactoryDelegateFactory(String name, Class type) {
-            this.name = name;
-            this.type = type;
-        }
-
-        public Object create(Context context) throws Exception {
-            ObjectFactory objFactory = 
context.getContainer().getInstance(ObjectFactory.class);
-            try {
-                return objFactory.buildBean(name, null, true);
-            } catch (ClassNotFoundException ex) {
-                throw new ConfigurationException("Unable to load bean 
"+type.getName()+" ("+name+")");
-            }
-        }
-
-    }
-
 }

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?rev=1543527&r1=1543526&r2=1543527&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
 Tue Nov 19 17:56:18 2013
@@ -58,7 +58,7 @@ import org.apache.struts2.ServletActionC
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.StrutsException;
 import org.apache.struts2.StrutsStatics;
-import org.apache.struts2.config.BeanSelectionProvider;
+import org.apache.struts2.config.DefaultBeanSelectionProvider;
 import org.apache.struts2.config.DefaultPropertiesProvider;
 import org.apache.struts2.config.PropertiesConfigurationProvider;
 import org.apache.struts2.config.StrutsXmlConfigurationProvider;
@@ -446,7 +446,7 @@ public class Dispatcher {
     }
 
     private void init_AliasStandardObjects() {
-        configurationManager.addContainerProvider(new BeanSelectionProvider());
+        configurationManager.addContainerProvider(new 
DefaultBeanSelectionProvider());
     }
 
     private Container init_PreloadConfiguration() {
@@ -482,7 +482,7 @@ public class Dispatcher {
     public void init() {
 
        if (configurationManager == null) {
-               configurationManager = 
createConfigurationManager(BeanSelectionProvider.DEFAULT_BEAN_NAME);
+               configurationManager = 
createConfigurationManager(DefaultBeanSelectionProvider.DEFAULT_BEAN_NAME);
        }
 
         try {

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java?rev=1543527&r1=1543526&r2=1543527&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
 Tue Nov 19 17:56:18 2013
@@ -33,7 +33,7 @@ import java.io.IOException;
  * &lt;bean name="myContentLoader" type="org.apache.struts2.dispatcher" 
class="com.company.struts.MyContentLoader"/&gt;
  * &lt;constant name="struts.staticContentLoader" value="myContentLoader"/&gt;
  *
- * Check {@link org.apache.struts2.config.BeanSelectionProvider} for more 
details.
+ * Check {@link org.apache.struts2.config.DefaultBeanSelectionProvider} for 
more details.
  */
 public interface StaticContentLoader {
 

Modified: struts/struts2/trunk/core/src/main/resources/struts-default.xml
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/struts-default.xml?rev=1543527&r1=1543526&r2=1543527&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/struts-default.xml (original)
+++ struts/struts2/trunk/core/src/main/resources/struts-default.xml Tue Nov 19 
17:56:18 2013
@@ -25,8 +25,8 @@
 <!--
     When declaring beans in this file you must either use name="struts" or 
don't name the bean at all.
 
-    The name="struts" must be used when alias was defined in {@link 
org.apache.struts2.config.BeanSelectionProvider} -
-    it is then the default bean's name and {@link 
org.apache.struts2.config.BeanSelectionProvider} links name "struts"
+    The name="struts" must be used when alias was defined in {@link 
org.apache.struts2.config.DefaultBeanSelectionProvider} -
+    it is then the default bean's name and {@link 
org.apache.struts2.config.DefaultBeanSelectionProvider} links name "struts"
     with "default" (aliasing it)
 
     If name won't be defined then the "default" value will be used {@link 
com.opensymphony.xwork2.inject.Container#DEFAULT_NAME}

Copied: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/DefaultBeanSelectionProviderTest.java
 (from r1535515, 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java)
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/DefaultBeanSelectionProviderTest.java?p2=struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/DefaultBeanSelectionProviderTest.java&p1=struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java&r1=1535515&r2=1543527&rev=1543527&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/BeanSelectionProviderTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/DefaultBeanSelectionProviderTest.java
 Tue Nov 19 17:56:18 2013
@@ -31,7 +31,7 @@ import com.opensymphony.xwork2.util.loca
 
 import junit.framework.TestCase;
 
-public class BeanSelectionProviderTest extends TestCase {
+public class DefaultBeanSelectionProviderTest extends TestCase {
 
     public void testRegister() {
         Locale.setDefault(Locale.US); // force to US locale as we also have 
_de and _da properties
@@ -43,7 +43,7 @@ public class BeanSelectionProviderTest e
         LocatableProperties props = new LocatableProperties();
         props.setProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES, 
"testmessages,testmessages2");
         
-        new BeanSelectionProvider().register(new ContainerBuilder(), props);
+        new DefaultBeanSelectionProvider().register(new ContainerBuilder(), 
props);
 
         assertEquals("Replaced message for token tag", 
LocalizedTextUtil.findDefaultText("struts.messages.invalid.token", 
Locale.getDefault()));
     }

Modified: 
struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java?rev=1543527&r1=1543526&r2=1543527&view=diff
==============================================================================
--- 
struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java
 (original)
+++ 
struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java
 Tue Nov 19 17:56:18 2013
@@ -27,7 +27,7 @@ import com.opensymphony.xwork2.config.en
 import com.opensymphony.xwork2.config.entities.ResultConfig;
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
-import org.apache.struts2.config.BeanSelectionProvider;
+import org.apache.struts2.config.DefaultBeanSelectionProvider;
 import org.apache.struts2.config.DefaultPropertiesProvider;
 import org.apache.struts2.config.PropertiesConfigurationProvider;
 import org.apache.struts2.config.StrutsXmlConfigurationProvider;
@@ -76,7 +76,7 @@ public class StrutsConfigRetriever {
             cm.addContainerProvider(new 
StrutsXmlConfigurationProvider("struts-default.xml", false, null));
             cm.addContainerProvider(configProvider);
             cm.addContainerProvider(new PropertiesConfigurationProvider());
-            cm.addContainerProvider(new BeanSelectionProvider());
+            cm.addContainerProvider(new DefaultBeanSelectionProvider());
             isXWorkStarted = true;
         } catch (IOException e) {
             LOG.error("IOException", e);


Reply via email to