Skip to content

Commit

Permalink
Reverts changes introduced with WW-4827 and adds default constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Sep 26, 2017
1 parent fe31a24 commit 2acf0ab
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 47 deletions.
7 changes: 5 additions & 2 deletions core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@ public class ObjectFactory implements Serializable {
private static final Logger LOG = LogManager.getLogger(ObjectFactory.class);

private transient ClassLoader ccl;
private final Container container;

private Container container;
private ActionFactory actionFactory;
private ResultFactory resultFactory;
private InterceptorFactory interceptorFactory;
private ValidatorFactory validatorFactory;
private ConverterFactory converterFactory;
private UnknownHandlerFactory unknownHandlerFactory;

public ObjectFactory() {
}

@Inject
public ObjectFactory(Container container) {
public void setContainer(Container container) {
this.container = container;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
@Deprecated
private boolean enableAopSupport = false;

public SpringObjectFactory() {
}

@Inject(value="applicationContextPath",required=false)
public void setApplicationContextPath(String ctx) {
if (ctx != null) {
Expand All @@ -73,11 +76,6 @@ public void setEnableAopSupport(String enableAopSupport) {
this.enableAopSupport = BooleanUtils.toBoolean(enableAopSupport);
}

@Inject
public SpringObjectFactory(Container container) {
super(container);
}

/**
* Set the Spring ApplicationContext that should be used to look beans up with.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;

import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -41,9 +38,7 @@ public class SpringProxyableObjectFactory extends SpringObjectFactory {

private List<String> skipBeanNames = new ArrayList<>();

@Inject
public SpringProxyableObjectFactory(Container container) {
super(container);
public SpringProxyableObjectFactory() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public void setAutowireStrategy(Integer autowireStrategy) {
LOG.warn("ApplicationContext could not be found. Action classes will not be autowired.");
} else {
setApplicationContext(applicationContext);
factory = new SpringObjectFactory(ActionContext.getContext().getContainer());
factory = new SpringObjectFactory();
factory.setContainer(ActionContext.getContext().getContainer());
factory.setApplicationContext(getApplicationContext());
if (autowireStrategy != null) {
factory.setAutowireStrategy(autowireStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
import java.lang.reflect.Proxy;
import java.util.Map;

import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;

/**
* ObjectFactory that returns a FooProxy in the buildBean if the clazz is FooAction
*/
public class ProxyObjectFactory extends ObjectFactory {

@Inject
public ProxyObjectFactory(Container container) {
super(container);
public ProxyObjectFactory() {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class ScopedModelDrivenInterceptorTest extends XWorkTestCase {
public void setUp() throws Exception {
super.setUp();
inter = new ScopedModelDrivenInterceptor();
inter.setObjectFactory(new ProxyObjectFactory(container));
ProxyObjectFactory factory = new ProxyObjectFactory();
factory.setContainer(container);
inter.setObjectFactory(factory);
}

public void testResolveModel() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ public void testObjectFactoryDestroy() throws Exception {
String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
reloadConfigs);
final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory((Container) mockContainer.proxy());
final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
destroyedObjectFactory.setContainer((Container) mockContainer.proxy());
mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);

mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
Expand Down Expand Up @@ -261,7 +262,7 @@ public void testInterceptorDestroy() throws Exception {
packageConfigs.put("test", packageConfig);

Mock mockContainer = new Mock(Container.class);
mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory((Container) mockContainer.proxy()));
mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory());
String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
reloadConfigs);
Expand Down Expand Up @@ -316,8 +317,7 @@ class DispatcherListenerState {
public static class InnerDestroyableObjectFactory extends ObjectFactory implements ObjectFactoryDestroyable {
public boolean destroyed = false;

public InnerDestroyableObjectFactory(Container container) {
super(container);
public InnerDestroyableObjectFactory() {
}

public void destroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.apache.struts2.cdi;

import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -74,9 +73,7 @@ public void setJndiKey( String jndiKey ) {

Map<Class<?>, InjectionTarget<?>> injectionTargetCache = new ConcurrentHashMap<Class<?>, InjectionTarget<?>>();

@Inject
public CdiObjectFactory(Container container) {
super(container);
public CdiObjectFactory() {
LOG.info("Initializing Struts2 CDI integration...");
this.beanManager = findBeanManager();
if (beanManager != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public void setUp() throws Exception {

@Test
public void testFindBeanManager() throws Exception {
assertNotNull(new CdiObjectFactory(null).findBeanManager());
assertNotNull(new CdiObjectFactory().findBeanManager());
}

@Test
public void testGetBean() throws Exception {
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory(null);
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory();
FooConsumer fooConsumer = (FooConsumer) cdiObjectFactory.buildBean(FooConsumer.class.getCanonicalName(), null, false);
assertNotNull(fooConsumer);
assertNotNull(fooConsumer.fooService);
}

@Test public void testGetInjectionTarget() throws Exception {
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory(null);
final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory();
final InjectionTarget<?> injectionTarget = cdiObjectFactory.getInjectionTarget(FooConsumer.class);
assertNotNull(injectionTarget);
assertTrue(cdiObjectFactory.injectionTargetCache.containsKey(FooConsumer.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ public Container getContainer() {
configuration.addPackageConfig("class-level", classLevelParentPkg);

ActionNameBuilder actionNameBuilder = new SEOActionNameBuilder("true", "-");
ObjectFactory of = new ObjectFactory(mockContainer);
ObjectFactory of = new ObjectFactory();
of.setContainer(mockContainer);
DefaultInterceptorMapBuilder interceptorBuilder = new DefaultInterceptorMapBuilder();
interceptorBuilder.setConfiguration(configuration);

Expand Down Expand Up @@ -780,7 +781,9 @@ public <T> T getInstance(Class<T> type) {
}
T obj;
if (type == ObjectFactory.class) {
obj = type.getConstructor(Container.class).newInstance(this);
obj = type.getConstructor().newInstance();
((ObjectFactory)obj).setContainer(this);

OgnlReflectionProvider rp = new OgnlReflectionProvider() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public class DelegatingObjectFactory extends ObjectFactory implements ObjectFact
private BundleAccessor bundleResourceLoader;
private OsgiConfigurationProvider osgiConfigurationProvider;

@Inject
public DelegatingObjectFactory(Container container) {
super(container);
public DelegatingObjectFactory() {
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import org.osgi.framework.ServiceReference;

Expand All @@ -39,9 +38,7 @@ public class SpringOsgiObjectFactory extends ObjectFactory {

private BundleAccessor bundleAccessor;

@Inject
public SpringOsgiObjectFactory(Container container) {
super(container);
public SpringOsgiObjectFactory() {
}

public Object buildBean(String className, Map<String, Object> extraContext, boolean injectInternal) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.InterceptorConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -81,9 +80,7 @@ public class PlexusObjectFactory extends ObjectFactory {
private PlexusContainer base;
private ReflectionProvider reflectionProvider;

@Inject
public PlexusObjectFactory(Container container) {
super(container);
public PlexusObjectFactory() {
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@
* </p>
*/
public class StrutsSpringObjectFactory extends SpringObjectFactory {

private static final Logger LOG = LogManager.getLogger(StrutsSpringObjectFactory.class);

public StrutsSpringObjectFactory() {
}

/**
* Constructs the spring object factory
* @param autoWire The type of autowiring to use
Expand All @@ -58,7 +62,6 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
* @param enableAopSupport enable AOP support
* @param servletContext The servlet context
* @param devMode development mode
* @param container container
* @since 2.1.3
*/
@Inject
Expand All @@ -71,7 +74,6 @@ public StrutsSpringObjectFactory(
@Inject(StrutsConstants.STRUTS_DEVMODE) String devMode,
@Inject Container container) {

super(container);
boolean useClassCache = BooleanUtils.toBoolean(useClassCacheStr);
LOG.info("Initializing Struts-Spring integration...");

Expand Down

0 comments on commit 2acf0ab

Please sign in to comment.