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) {
+