Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.opensymphony.xwork2.conversion.TypeConverterCreator;
import com.opensymphony.xwork2.conversion.TypeConverterHolder;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.inject.PostInit;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand All @@ -31,7 +32,7 @@
import java.util.Map;
import java.util.Properties;

public class DefaultConversionPropertiesProcessor implements ConversionPropertiesProcessor {
public class DefaultConversionPropertiesProcessor implements ConversionPropertiesProcessor, PostInit {

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

Expand All @@ -48,6 +49,13 @@ public void setTypeConverterHolder(TypeConverterHolder converterHolder) {
this.converterHolder = converterHolder;
}

@Override
public void init() {
LOG.debug("Initialising beans after instantiation...");
processRequired("struts-default-conversion.properties");
process("xwork-conversion.properties");
}

public void process(String propsName) {
loadConversionProperties(propsName, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.opensymphony.xwork2.conversion.annotations.Conversion;
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.inject.PostInit;
import com.opensymphony.xwork2.util.*;
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -171,12 +172,6 @@ public void setReloadingConfigs(String reloadingConfigs) {
this.reloadingConfigs = Boolean.parseBoolean(reloadingConfigs);
}

@Inject
public void setConversionPropertiesProcessor(ConversionPropertiesProcessor propertiesProcessor) {
propertiesProcessor.processRequired("struts-default-conversion.properties");
propertiesProcessor.process("xwork-conversion.properties");
}

@Inject
public void setConversionFileProcessor(ConversionFileProcessor fileProcessor) {
this.fileProcessor = fileProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ public void inject(final Object o) {
callInContext(new ContextualCallable<Void>() {
public Void call(InternalContext context) {
inject(o, context);

if (o instanceof PostInit) {
((PostInit) o).init();
}

return null;
}
});
Expand All @@ -513,23 +518,41 @@ public Void call(InternalContext context) {
public <T> T inject(final Class<T> implementation) {
return callInContext(new ContextualCallable<T>() {
public T call(InternalContext context) {
return inject(implementation, context);
T o = inject(implementation, context);

if (o instanceof PostInit) {
((PostInit) o).init();
}

return o;
}
});
}

public <T> T getInstance(final Class<T> type, final String name) {
return callInContext(new ContextualCallable<T>() {
public T call(InternalContext context) {
return getInstance(type, name, context);
T o = getInstance(type, name, context);

if (o instanceof PostInit) {
((PostInit) o).init();
}

return o;
}
});
}

public <T> T getInstance(final Class<T> type) {
return callInContext(new ContextualCallable<T>() {
public T call(InternalContext context) {
return getInstance(type, context);
T o = getInstance(type, context);

if (o instanceof PostInit) {
((PostInit) o).init();
}

return o;
}
});
}
Expand Down
23 changes: 23 additions & 0 deletions core/src/main/java/com/opensymphony/xwork2/inject/PostInit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2002-2017 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.opensymphony.xwork2.inject;

public interface PostInit {

void init();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.opensymphony.xwork2.conversion.impl;

import com.opensymphony.xwork2.*;
import com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor;
import com.opensymphony.xwork2.ognl.OgnlValueStack;
import com.opensymphony.xwork2.test.ModelDrivenAction2;
import com.opensymphony.xwork2.test.User;
Expand Down Expand Up @@ -699,6 +700,7 @@ public static class Bar1Impl implements Bar1 {
protected void setUp() throws Exception {
super.setUp();

container.getInstance(ConversionPropertiesProcessor.class); // to init converters
converter = container.getInstance(XWorkConverter.class);

ActionContext ac = ActionContext.getContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public void testMethodInjector() throws Exception {
}
}

public void testPostInit() throws Exception {

PostInitCheck postInitCheck = new PostInitCheck();

try {
c.inject(postInitCheck);
assertTrue(postInitCheck.initialised);
} catch (DependencyException expected) {
fail("No exception expected!");
}
}

/**
* Inject values into field under SecurityManager
*/
Expand Down Expand Up @@ -116,4 +128,18 @@ public String getName() {

}

class PostInitCheck implements PostInit {

boolean initialised = false;

@Override
public void init() {
initialised = true;
}

public boolean isInitialised() {
return initialised;
}
}

}