mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
Minor code improvements's in the xwork-core module
- Use Java 7 features like diamond operator and multi catch - Improve some logging message and don't check LOG.isXxx if not necessary - Fix some typos - Use BooleanUtils.toBoolean(string) instead of "true".isEquals to be more robust
This commit is contained in:
@@ -186,7 +186,7 @@ public class ActionChainResult implements Result {
|
||||
LinkedList<String> chainHistory = (LinkedList<String>) ActionContext.getContext().get(CHAIN_HISTORY);
|
||||
// Add if not exists
|
||||
if (chainHistory == null) {
|
||||
chainHistory = new LinkedList<String>();
|
||||
chainHistory = new LinkedList<>();
|
||||
ActionContext.getContext().put(CHAIN_HISTORY, chainHistory);
|
||||
}
|
||||
|
||||
@@ -211,8 +211,7 @@ public class ActionChainResult implements Result {
|
||||
|
||||
if (isInChainHistory(finalNamespace, finalActionName, finalMethodName)) {
|
||||
addToHistory(finalNamespace, finalActionName, finalMethodName);
|
||||
throw new XWorkException("Infinite recursion detected: "
|
||||
+ ActionChainResult.getChainHistory().toString());
|
||||
throw new XWorkException("Infinite recursion detected: " + ActionChainResult.getChainHistory().toString());
|
||||
}
|
||||
|
||||
if (ActionChainResult.getChainHistory().isEmpty() && invocation != null && invocation.getProxy() != null) {
|
||||
@@ -220,14 +219,12 @@ public class ActionChainResult implements Result {
|
||||
}
|
||||
addToHistory(finalNamespace, finalActionName, finalMethodName);
|
||||
|
||||
HashMap<String, Object> extraContext = new HashMap<String, Object>();
|
||||
HashMap<String, Object> extraContext = new HashMap<>();
|
||||
extraContext.put(ActionContext.VALUE_STACK, ActionContext.getContext().getValueStack());
|
||||
extraContext.put(ActionContext.PARAMETERS, ActionContext.getContext().getParameters());
|
||||
extraContext.put(CHAIN_HISTORY, ActionChainResult.getChainHistory());
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Chaining to action " + finalActionName);
|
||||
}
|
||||
LOG.debug("Chaining to action {}", finalActionName);
|
||||
|
||||
proxy = actionProxyFactory.createActionProxy(finalNamespace, finalActionName, finalMethodName, extraContext);
|
||||
proxy.execute();
|
||||
@@ -261,7 +258,7 @@ public class ActionChainResult implements Result {
|
||||
return false;
|
||||
} else {
|
||||
// Actions to skip
|
||||
Set<String> skipActionsList = new HashSet<String>();
|
||||
Set<String> skipActionsList = new HashSet<>();
|
||||
if (skipActions != null && skipActions.length() > 0) {
|
||||
ValueStack stack = ActionContext.getContext().getValueStack();
|
||||
String finalSkipActions = TextParseUtil.translateVariables(this.skipActions, stack);
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class ActionContext implements Serializable {
|
||||
|
||||
static ThreadLocal<ActionContext> actionContext = new ThreadLocal<ActionContext>();
|
||||
static ThreadLocal<ActionContext> actionContext = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* Constant for the name of the action being executed.
|
||||
@@ -197,7 +197,7 @@ public class ActionContext implements Serializable {
|
||||
Map<String, Object> errors = (Map) get(CONVERSION_ERRORS);
|
||||
|
||||
if (errors == null) {
|
||||
errors = new HashMap<String, Object>();
|
||||
errors = new HashMap<>();
|
||||
setConversionErrors(errors);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,9 +83,7 @@ public class ActionSupport implements Action, Validateable, ValidationAware, Tex
|
||||
if (ctx != null) {
|
||||
return ctx.getLocale();
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Action context not initialized");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(CompositeTextProvider.class);
|
||||
|
||||
private List<TextProvider> textProviders = new ArrayList<TextProvider>();
|
||||
private List<TextProvider> textProviders = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Instantiates a {@link CompositeTextProvider} with some predefined <code>textProviders</code>.
|
||||
@@ -60,7 +60,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
* It will consult each {@link TextProvider}s and return the first valid message for this
|
||||
* <code>key</code>
|
||||
*
|
||||
* @param key The key to lookup in ressource bundles.
|
||||
* @param key The key to lookup in resource bundles.
|
||||
* @return The i18n text for the requested key.
|
||||
* @see {@link com.opensymphony.xwork2.TextProvider#getText(String)}
|
||||
*/
|
||||
@@ -83,7 +83,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
|
||||
/**
|
||||
* It will consult each {@link TextProvider}s and return the first valid message for this
|
||||
* <code>key</code>, before returining <code>defaultValue</code>
|
||||
* <code>key</code>, before returning <code>defaultValue</code>
|
||||
* if every else fails.
|
||||
*
|
||||
* @param key
|
||||
@@ -97,8 +97,6 @@ public class CompositeTextProvider implements TextProvider {
|
||||
{
|
||||
add(obj);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,7 +129,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
|
||||
/**
|
||||
* It will consult each {@link TextProvider}s and return the first valid message for this
|
||||
* <code>key</code>, before returining <code>defaultValue</code>
|
||||
* <code>key</code>, before returning <code>defaultValue</code>
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
@@ -155,7 +153,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
|
||||
/**
|
||||
* It will consult each {@link TextProvider}s and return the first valid message for this
|
||||
* <code>key</code>, before returining <code>defaultValue</code>.
|
||||
* <code>key</code>, before returning <code>defaultValue</code>.
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
@@ -179,7 +177,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
|
||||
/**
|
||||
* It will consult each {@link TextProvider}s and return the first valid message for this
|
||||
* <code>key</code>, before returining <code>defaultValue</code>
|
||||
* <code>key</code>, before returning <code>defaultValue</code>
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
@@ -203,7 +201,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
|
||||
/**
|
||||
* It will consult each {@link TextProvider}s and return the first valid message for this
|
||||
* <code>key</code>, before returining <code>defaultValue</code>
|
||||
* <code>key</code>, before returning <code>defaultValue</code>
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
@@ -234,7 +232,7 @@ public class CompositeTextProvider implements TextProvider {
|
||||
* @see {@link TextProvider#getTexts(String)}
|
||||
*/
|
||||
public ResourceBundle getTexts(String bundleName) {
|
||||
// if there's one text provider that gives us a non-null resource bunlde for this bundleName, we are ok, else try the next
|
||||
// if there's one text provider that gives us a non-null resource bundle for this bundleName, we are ok, else try the next
|
||||
// text provider
|
||||
for (TextProvider textProvider : textProviders) {
|
||||
ResourceBundle bundle = textProvider.getTexts(bundleName);
|
||||
|
||||
@@ -156,9 +156,9 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
}
|
||||
|
||||
public void setResultCode(String resultCode) {
|
||||
if (isExecuted())
|
||||
if (isExecuted()) {
|
||||
throw new IllegalStateException("Result has already been executed.");
|
||||
|
||||
}
|
||||
this.resultCode = resultCode;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
*/
|
||||
public void addPreResultListener(PreResultListener listener) {
|
||||
if (preResultListeners == null) {
|
||||
preResultListeners = new ArrayList<PreResultListener>(1);
|
||||
preResultListeners = new ArrayList<>(1);
|
||||
}
|
||||
|
||||
preResultListeners.add(listener);
|
||||
@@ -236,9 +236,8 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
String interceptorMsg = "interceptor: " + interceptor.getName();
|
||||
UtilTimerStack.push(interceptorMsg);
|
||||
try {
|
||||
resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);
|
||||
}
|
||||
finally {
|
||||
resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);
|
||||
} finally {
|
||||
UtilTimerStack.pop(interceptorMsg);
|
||||
}
|
||||
} else {
|
||||
@@ -289,7 +288,7 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
UtilTimerStack.push(timerKey);
|
||||
action = objectFactory.buildAction(proxy.getActionName(), proxy.getNamespace(), proxy.getConfig(), contextMap);
|
||||
} catch (InstantiationException e) {
|
||||
throw new XWorkException("Unable to intantiate Action!", e, proxy.getConfig());
|
||||
throw new XWorkException("Unable to instantiate Action!", e, proxy.getConfig());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new XWorkException("Illegal access to constructor, is it public?", e, proxy.getConfig());
|
||||
} catch (Exception e) {
|
||||
@@ -367,7 +366,7 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
+ " and result " + getResultCode(), proxy.getConfig());
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("No result returned for action " + getAction().getClass().getName() + " at " + proxy.getConfig().getLocation());
|
||||
LOG.debug("No result returned for action {} at {}", getAction().getClass().getName(), proxy.getConfig().getLocation());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -398,7 +397,7 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
invocationContext.setName(proxy.getActionName());
|
||||
|
||||
// get a new List so we don't get problems with the iterator if someone changes the list
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<InterceptorMapping>(proxy.getConfig().getInterceptors());
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<>(proxy.getConfig().getInterceptors());
|
||||
interceptors = interceptorList.iterator();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@ public class DefaultLocaleProvider implements LocaleProvider {
|
||||
if (ctx != null) {
|
||||
return ctx.getLocale();
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Action context not initialized");
|
||||
}
|
||||
LOG.debug("Action context not initialized");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class DefaultTextProvider implements TextProvider, Serializable, Unchaina
|
||||
|
||||
|
||||
public String getText(String key, String defaultValue, String obj) {
|
||||
List<Object> args = new ArrayList<Object>(1);
|
||||
List<Object> args = new ArrayList<>(1);
|
||||
args.add(obj);
|
||||
return getText(key, defaultValue, args);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class DefaultUnknownHandlerManager implements UnknownHandlerManager {
|
||||
|
||||
if (configuration != null && container != null) {
|
||||
List<UnknownHandlerConfig> unkownHandlerStack = configuration.getUnknownHandlerStack();
|
||||
unknownHandlers = new ArrayList<UnknownHandler>();
|
||||
unknownHandlers = new ArrayList<>();
|
||||
|
||||
if (unkownHandlerStack != null && !unkownHandlerStack.isEmpty()) {
|
||||
//get UnknownHandlers in the specified order
|
||||
@@ -68,9 +68,9 @@ public class DefaultUnknownHandlerManager implements UnknownHandlerManager {
|
||||
}
|
||||
} else {
|
||||
//add all available UnknownHandlers
|
||||
Set<String> unknowHandlerNames = container.getInstanceNames(UnknownHandler.class);
|
||||
for (String unknowHandlerName : unknowHandlerNames) {
|
||||
UnknownHandler uh = container.getInstance(UnknownHandler.class, unknowHandlerName);
|
||||
Set<String> unknownHandlerNames = container.getInstanceNames(UnknownHandler.class);
|
||||
for (String unknownHandlerName : unknownHandlerNames) {
|
||||
UnknownHandler uh = container.getInstance(UnknownHandler.class, unknownHandlerName);
|
||||
unknownHandlers.add(uh);
|
||||
}
|
||||
}
|
||||
@@ -83,8 +83,9 @@ public class DefaultUnknownHandlerManager implements UnknownHandlerManager {
|
||||
public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig actionConfig, String resultCode) {
|
||||
for (UnknownHandler unknownHandler : unknownHandlers) {
|
||||
Result result = unknownHandler.handleUnknownResult(actionContext, actionName, actionConfig, resultCode);
|
||||
if (result != null)
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -98,8 +99,9 @@ public class DefaultUnknownHandlerManager implements UnknownHandlerManager {
|
||||
public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
|
||||
for (UnknownHandler unknownHandler : unknownHandlers) {
|
||||
Object result = unknownHandler.handleUnknownActionMethod(action, methodName);
|
||||
if (result != null)
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -111,8 +113,9 @@ public class DefaultUnknownHandlerManager implements UnknownHandlerManager {
|
||||
public ActionConfig handleUnknownAction(String namespace, String actionName) {
|
||||
for (UnknownHandler unknownHandler : unknownHandlers) {
|
||||
ActionConfig result = unknownHandler.handleUnknownAction(namespace, actionName);
|
||||
if (result != null)
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -148,7 +148,7 @@ public class TextProviderSupport implements ResourceBundleTextProvider {
|
||||
* @return value of named text or the provided defaultValue if no value is found
|
||||
*/
|
||||
public String getText(String key, String defaultValue, String arg) {
|
||||
List<Object> args = new ArrayList<Object>();
|
||||
List<Object> args = new ArrayList<>();
|
||||
args.add(arg);
|
||||
return getText(key, defaultValue, args);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ValidationAwareSupport implements ValidationAware, Serializable {
|
||||
}
|
||||
|
||||
public synchronized Collection<String> getActionErrors() {
|
||||
return new LinkedList<String>(internalGetActionErrors());
|
||||
return new LinkedList<>(internalGetActionErrors());
|
||||
}
|
||||
|
||||
public synchronized void setActionMessages(Collection<String> messages) {
|
||||
@@ -46,7 +46,7 @@ public class ValidationAwareSupport implements ValidationAware, Serializable {
|
||||
}
|
||||
|
||||
public synchronized Collection<String> getActionMessages() {
|
||||
return new LinkedList<String>(internalGetActionMessages());
|
||||
return new LinkedList<>(internalGetActionMessages());
|
||||
}
|
||||
|
||||
public synchronized void setFieldErrors(Map<String, List<String>> errorMap) {
|
||||
@@ -54,7 +54,7 @@ public class ValidationAwareSupport implements ValidationAware, Serializable {
|
||||
}
|
||||
|
||||
public synchronized Map<String, List<String>> getFieldErrors() {
|
||||
return new LinkedHashMap<String, List<String>>(internalGetFieldErrors());
|
||||
return new LinkedHashMap<>(internalGetFieldErrors());
|
||||
}
|
||||
|
||||
public synchronized void addActionError(String anErrorMessage) {
|
||||
@@ -70,7 +70,7 @@ public class ValidationAwareSupport implements ValidationAware, Serializable {
|
||||
List<String> thisFieldErrors = errors.get(fieldName);
|
||||
|
||||
if (thisFieldErrors == null) {
|
||||
thisFieldErrors = new ArrayList<String>();
|
||||
thisFieldErrors = new ArrayList<>();
|
||||
errors.put(fieldName, thisFieldErrors);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ValidationAwareSupport implements ValidationAware, Serializable {
|
||||
|
||||
private Collection<String> internalGetActionErrors() {
|
||||
if (actionErrors == null) {
|
||||
actionErrors = new ArrayList<String>();
|
||||
actionErrors = new ArrayList<>();
|
||||
}
|
||||
|
||||
return actionErrors;
|
||||
@@ -103,7 +103,7 @@ public class ValidationAwareSupport implements ValidationAware, Serializable {
|
||||
|
||||
private Collection<String> internalGetActionMessages() {
|
||||
if (actionMessages == null) {
|
||||
actionMessages = new ArrayList<String>();
|
||||
actionMessages = new ArrayList<>();
|
||||
}
|
||||
|
||||
return actionMessages;
|
||||
@@ -111,7 +111,7 @@ public class ValidationAwareSupport implements ValidationAware, Serializable {
|
||||
|
||||
private Map<String, List<String>> internalGetFieldErrors() {
|
||||
if (fieldErrors == null) {
|
||||
fieldErrors = new LinkedHashMap<String, List<String>>();
|
||||
fieldErrors = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
return fieldErrors;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class XWorkException extends RuntimeException implements Locatable {
|
||||
* @param target the target of the exception.
|
||||
*/
|
||||
public XWorkException(String s, Object target) {
|
||||
this(s, (Throwable) null, target);
|
||||
this(s, null, target);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.opensymphony.xwork2.XWorkConstants;
|
||||
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
|
||||
import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
|
||||
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -41,8 +41,8 @@ public class ConfigurationManager {
|
||||
protected static final Logger LOG = LogManager.getLogger(ConfigurationManager.class);
|
||||
protected Configuration configuration;
|
||||
protected Lock providerLock = new ReentrantLock();
|
||||
private List<ContainerProvider> containerProviders = new CopyOnWriteArrayList<ContainerProvider>();
|
||||
private List<PackageProvider> packageProviders = new CopyOnWriteArrayList<PackageProvider>();
|
||||
private List<ContainerProvider> containerProviders = new CopyOnWriteArrayList<>();
|
||||
private List<PackageProvider> packageProviders = new CopyOnWriteArrayList<>();
|
||||
protected String defaultFrameworkBeanName;
|
||||
private boolean providersChanged = false;
|
||||
private boolean reloadConfigs = true; // for the first time
|
||||
@@ -117,7 +117,7 @@ public class ConfigurationManager {
|
||||
public void setContainerProviders(List<ContainerProvider> containerProviders) {
|
||||
providerLock.lock();
|
||||
try {
|
||||
this.containerProviders = new CopyOnWriteArrayList<ContainerProvider>(containerProviders);
|
||||
this.containerProviders = new CopyOnWriteArrayList<>(containerProviders);
|
||||
providersChanged = true;
|
||||
} finally {
|
||||
providerLock.unlock();
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
package com.opensymphony.xwork2.config;
|
||||
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -44,7 +45,7 @@ public class ConfigurationUtil {
|
||||
*/
|
||||
public static List<PackageConfig> buildParentsFromString(Configuration configuration, String parent) {
|
||||
List<String> parentPackageNames = buildParentListFromString(parent);
|
||||
List<PackageConfig> parentPackageConfigs = new ArrayList<PackageConfig>();
|
||||
List<PackageConfig> parentPackageConfigs = new ArrayList<>();
|
||||
for (String parentPackageName : parentPackageNames) {
|
||||
PackageConfig parentPackageContext = configuration.getPackageConfig(parentPackageName);
|
||||
|
||||
@@ -62,17 +63,17 @@ public class ConfigurationUtil {
|
||||
* @return A list of tokens from the specified string.
|
||||
*/
|
||||
public static List<String> buildParentListFromString(String parent) {
|
||||
if ((parent == null) || ("".equals(parent))) {
|
||||
if (StringUtils.isEmpty(parent)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
StringTokenizer tokenizer = new StringTokenizer(parent, ",");
|
||||
List<String> parents = new ArrayList<String>();
|
||||
List<String> parents = new ArrayList<>();
|
||||
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String parentName = tokenizer.nextToken().trim();
|
||||
|
||||
if (!"".equals(parentName)) {
|
||||
if (StringUtils.isNotEmpty(parentName)) {
|
||||
parents.add(parentName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,7 @@ import com.opensymphony.xwork2.util.location.Location;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -82,11 +75,11 @@ public class ActionConfig extends Located implements Serializable {
|
||||
this.className = orig.className;
|
||||
this.methodName = orig.methodName;
|
||||
this.packageName = orig.packageName;
|
||||
this.params = new LinkedHashMap<String,String>(orig.params);
|
||||
this.interceptors = new ArrayList<InterceptorMapping>(orig.interceptors);
|
||||
this.results = new LinkedHashMap<String,ResultConfig>(orig.results);
|
||||
this.exceptionMappings = new ArrayList<ExceptionMappingConfig>(orig.exceptionMappings);
|
||||
this.allowedMethods = new HashSet<String>(orig.allowedMethods);
|
||||
this.params = new LinkedHashMap<>(orig.params);
|
||||
this.interceptors = new ArrayList<>(orig.interceptors);
|
||||
this.results = new LinkedHashMap<>(orig.results);
|
||||
this.exceptionMappings = new ArrayList<>(orig.exceptionMappings);
|
||||
this.allowedMethods = new HashSet<>(orig.allowedMethods);
|
||||
this.location = orig.location;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -41,14 +41,14 @@ public class ExceptionMappingConfig extends Located implements Serializable {
|
||||
this.name = name;
|
||||
this.exceptionClassName = exceptionClassName;
|
||||
this.result = result;
|
||||
this.params = new LinkedHashMap<String,String>();
|
||||
this.params = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
protected ExceptionMappingConfig(ExceptionMappingConfig target) {
|
||||
this.name = target.name;
|
||||
this.exceptionClassName = target.exceptionClassName;
|
||||
this.result = target.result;
|
||||
this.params = new LinkedHashMap<String,String>(target.params);
|
||||
this.params = new LinkedHashMap<>(target.params);
|
||||
this.location = target.location;
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -37,7 +37,7 @@ public class InterceptorConfig extends Located implements Serializable {
|
||||
protected String name;
|
||||
|
||||
protected InterceptorConfig(String name, String className) {
|
||||
this.params = new LinkedHashMap<String,String>();
|
||||
this.params = new LinkedHashMap<>();
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class InterceptorConfig extends Located implements Serializable {
|
||||
protected InterceptorConfig(InterceptorConfig orig) {
|
||||
this.name = orig.name;
|
||||
this.className = orig.className;
|
||||
this.params = new LinkedHashMap<String,String>(orig.params);
|
||||
this.params = new LinkedHashMap<>(orig.params);
|
||||
this.location = orig.location;
|
||||
}
|
||||
|
||||
@@ -73,8 +73,7 @@ public class InterceptorConfig extends Located implements Serializable {
|
||||
|
||||
final InterceptorConfig interceptorConfig = (InterceptorConfig) o;
|
||||
|
||||
if ((className != null) ? (!className.equals(interceptorConfig.className)) : (interceptorConfig.className != null))
|
||||
{
|
||||
if ((className != null) ? (!className.equals(interceptorConfig.className)) : (interceptorConfig.className != null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class InterceptorStackConfig extends Located implements Serializable {
|
||||
*/
|
||||
protected InterceptorStackConfig(InterceptorStackConfig orig) {
|
||||
this.name = orig.name;
|
||||
this.interceptors = new ArrayList<InterceptorMapping>(orig.interceptors);
|
||||
this.interceptors = new ArrayList<>(orig.interceptors);
|
||||
this.location = orig.location;
|
||||
}
|
||||
|
||||
|
||||
+20
-24
@@ -17,15 +17,11 @@ package com.opensymphony.xwork2.config.entities;
|
||||
|
||||
import com.opensymphony.xwork2.util.location.Located;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,12 +53,12 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
|
||||
protected PackageConfig(String name) {
|
||||
this.name = name;
|
||||
actionConfigs = new LinkedHashMap<String, ActionConfig>();
|
||||
globalResultConfigs = new LinkedHashMap<String, ResultConfig>();
|
||||
interceptorConfigs = new LinkedHashMap<String, Object>();
|
||||
resultTypeConfigs = new LinkedHashMap<String, ResultTypeConfig>();
|
||||
globalExceptionMappingConfigs = new ArrayList<ExceptionMappingConfig>();
|
||||
parents = new ArrayList<PackageConfig>();
|
||||
actionConfigs = new LinkedHashMap<>();
|
||||
globalResultConfigs = new LinkedHashMap<>();
|
||||
interceptorConfigs = new LinkedHashMap<>();
|
||||
resultTypeConfigs = new LinkedHashMap<>();
|
||||
globalExceptionMappingConfigs = new ArrayList<>();
|
||||
parents = new ArrayList<>();
|
||||
}
|
||||
|
||||
protected PackageConfig(PackageConfig orig) {
|
||||
@@ -74,12 +70,12 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
this.namespace = orig.namespace;
|
||||
this.isAbstract = orig.isAbstract;
|
||||
this.needsRefresh = orig.needsRefresh;
|
||||
this.actionConfigs = new LinkedHashMap<String, ActionConfig>(orig.actionConfigs);
|
||||
this.globalResultConfigs = new LinkedHashMap<String, ResultConfig>(orig.globalResultConfigs);
|
||||
this.interceptorConfigs = new LinkedHashMap<String, Object>(orig.interceptorConfigs);
|
||||
this.resultTypeConfigs = new LinkedHashMap<String, ResultTypeConfig>(orig.resultTypeConfigs);
|
||||
this.globalExceptionMappingConfigs = new ArrayList<ExceptionMappingConfig>(orig.globalExceptionMappingConfigs);
|
||||
this.parents = new ArrayList<PackageConfig>(orig.parents);
|
||||
this.actionConfigs = new LinkedHashMap<>(orig.actionConfigs);
|
||||
this.globalResultConfigs = new LinkedHashMap<>(orig.globalResultConfigs);
|
||||
this.interceptorConfigs = new LinkedHashMap<>(orig.interceptorConfigs);
|
||||
this.resultTypeConfigs = new LinkedHashMap<>(orig.resultTypeConfigs);
|
||||
this.globalExceptionMappingConfigs = new ArrayList<>(orig.globalExceptionMappingConfigs);
|
||||
this.parents = new ArrayList<>(orig.parents);
|
||||
this.location = orig.location;
|
||||
}
|
||||
|
||||
@@ -99,7 +95,7 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
* @see ActionConfig
|
||||
*/
|
||||
public Map<String, ActionConfig> getAllActionConfigs() {
|
||||
Map<String, ActionConfig> retMap = new LinkedHashMap<String, ActionConfig>();
|
||||
Map<String, ActionConfig> retMap = new LinkedHashMap<>();
|
||||
|
||||
if (!parents.isEmpty()) {
|
||||
for (PackageConfig parent : parents) {
|
||||
@@ -120,7 +116,7 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
* @see ResultConfig
|
||||
*/
|
||||
public Map<String, ResultConfig> getAllGlobalResults() {
|
||||
Map<String, ResultConfig> retMap = new LinkedHashMap<String, ResultConfig>();
|
||||
Map<String, ResultConfig> retMap = new LinkedHashMap<>();
|
||||
|
||||
if (!parents.isEmpty()) {
|
||||
for (PackageConfig parentConfig : parents) {
|
||||
@@ -142,7 +138,7 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
* @see InterceptorStackConfig
|
||||
*/
|
||||
public Map<String, Object> getAllInterceptorConfigs() {
|
||||
Map<String, Object> retMap = new LinkedHashMap<String, Object>();
|
||||
Map<String, Object> retMap = new LinkedHashMap<>();
|
||||
|
||||
if (!parents.isEmpty()) {
|
||||
for (PackageConfig parentContext : parents) {
|
||||
@@ -163,7 +159,7 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
* @see ResultTypeConfig
|
||||
*/
|
||||
public Map<String, ResultTypeConfig> getAllResultTypeConfigs() {
|
||||
Map<String, ResultTypeConfig> retMap = new LinkedHashMap<String, ResultTypeConfig>();
|
||||
Map<String, ResultTypeConfig> retMap = new LinkedHashMap<>();
|
||||
|
||||
if (!parents.isEmpty()) {
|
||||
for (PackageConfig parentContext : parents) {
|
||||
@@ -184,7 +180,7 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
* @see ExceptionMappingConfig
|
||||
*/
|
||||
public List<ExceptionMappingConfig> getAllExceptionMappingConfigs() {
|
||||
List<ExceptionMappingConfig> allExceptionMappings = new ArrayList<ExceptionMappingConfig>();
|
||||
List<ExceptionMappingConfig> allExceptionMappings = new ArrayList<>();
|
||||
|
||||
if (!parents.isEmpty()) {
|
||||
for (PackageConfig parentContext : parents) {
|
||||
@@ -310,7 +306,7 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
}
|
||||
|
||||
public List<PackageConfig> getParents() {
|
||||
return new ArrayList<PackageConfig>(parents);
|
||||
return new ArrayList<>(parents);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ResultConfig extends Located implements Serializable {
|
||||
protected ResultConfig(String name, String className) {
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
params = new LinkedHashMap<String, String>();
|
||||
params = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
protected ResultConfig(ResultConfig orig) {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class ResultTypeConfig extends Located implements Serializable {
|
||||
protected ResultTypeConfig(String name, String className) {
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
params = new LinkedHashMap<String,String>();
|
||||
params = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
protected ResultTypeConfig(ResultTypeConfig orig) {
|
||||
|
||||
@@ -18,16 +18,12 @@
|
||||
package com.opensymphony.xwork2.config.impl;
|
||||
|
||||
import com.opensymphony.xwork2.util.PatternMatcher;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p> Matches patterns against pre-compiled wildcard expressions pulled from
|
||||
@@ -52,7 +48,8 @@ public abstract class AbstractMatcher<E> implements Serializable {
|
||||
/**
|
||||
* <p> The compiled patterns and their associated target objects </p>
|
||||
*/
|
||||
List<Mapping<E>> compiledPatterns = new ArrayList<Mapping<E>>();;
|
||||
List<Mapping<E>> compiledPatterns = new ArrayList<>();
|
||||
;
|
||||
|
||||
public AbstractMatcher(PatternMatcher<?> helper) {
|
||||
this.wildcard = (PatternMatcher<Object>) helper;
|
||||
@@ -86,9 +83,7 @@ public abstract class AbstractMatcher<E> implements Serializable {
|
||||
name = name.substring(1);
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Compiling pattern '" + name + "'");
|
||||
}
|
||||
log.debug("Compiling pattern '{}'", name);
|
||||
|
||||
pattern = wildcard.compilePattern(name);
|
||||
compiledPatterns.add(new Mapping<E>(name, pattern, target));
|
||||
@@ -119,22 +114,13 @@ public abstract class AbstractMatcher<E> implements Serializable {
|
||||
E config = null;
|
||||
|
||||
if (compiledPatterns.size() > 0) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Attempting to match '" + potentialMatch
|
||||
+ "' to a wildcard pattern, "+ compiledPatterns.size()
|
||||
+ " available");
|
||||
}
|
||||
log.debug("Attempting to match '{}' to a wildcard pattern, {} available", potentialMatch, compiledPatterns.size());
|
||||
|
||||
Map<String,String> vars = new LinkedHashMap<String,String>();
|
||||
for (Mapping<E> m : compiledPatterns) {
|
||||
if (wildcard.match(vars, potentialMatch, m.getPattern())) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Value matches pattern '"
|
||||
+ m.getOriginalPattern() + "'");
|
||||
}
|
||||
|
||||
config =
|
||||
convert(potentialMatch, m.getTarget(), vars);
|
||||
log.debug("Value matches pattern '{}'", m.getOriginalPattern());
|
||||
config = convert(potentialMatch, m.getTarget(), vars);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -159,11 +145,11 @@ public abstract class AbstractMatcher<E> implements Serializable {
|
||||
* <p> Replaces parameter values
|
||||
* </p>
|
||||
*
|
||||
* @param orig The original parameters with placehold values
|
||||
* @param orig The original parameters with placeholder values
|
||||
* @param vars A Map of wildcard-matched strings
|
||||
*/
|
||||
protected Map<String,String> replaceParameters(Map<String, String> orig, Map<String,String> vars) {
|
||||
Map<String,String> map = new LinkedHashMap<String,String>();
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
|
||||
//this will set the group index references, like {1}
|
||||
for (String key : orig.keySet()) {
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ public class ActionConfigMatcher extends AbstractMatcher<ActionConfig> implement
|
||||
|
||||
Map<String,String> params = replaceParameters(orig.getParams(), vars);
|
||||
|
||||
Map<String,ResultConfig> results = new LinkedHashMap<String,ResultConfig>();
|
||||
Map<String, ResultConfig> results = new LinkedHashMap<>();
|
||||
for (String name : orig.getResults().keySet()) {
|
||||
ResultConfig result = orig.getResults().get(name);
|
||||
name = convertParam(name, vars);
|
||||
|
||||
+28
-94
@@ -15,91 +15,29 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.config.impl;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.DefaultLocaleProvider;
|
||||
import com.opensymphony.xwork2.DefaultTextProvider;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.LocaleProvider;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.TextProvider;
|
||||
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.config.ContainerProvider;
|
||||
import com.opensymphony.xwork2.config.FileManagerFactoryProvider;
|
||||
import com.opensymphony.xwork2.config.FileManagerProvider;
|
||||
import com.opensymphony.xwork2.config.PackageProvider;
|
||||
import com.opensymphony.xwork2.config.RuntimeConfiguration;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.config.entities.UnknownHandlerConfig;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.*;
|
||||
import com.opensymphony.xwork2.config.entities.*;
|
||||
import com.opensymphony.xwork2.config.providers.InterceptorBuilder;
|
||||
import com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor;
|
||||
import com.opensymphony.xwork2.conversion.ConversionFileProcessor;
|
||||
import com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor;
|
||||
import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverter;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverterCreator;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverterHolder;
|
||||
import com.opensymphony.xwork2.conversion.impl.ArrayConverter;
|
||||
import com.opensymphony.xwork2.conversion.impl.CollectionConverter;
|
||||
import com.opensymphony.xwork2.conversion.impl.DateConverter;
|
||||
import com.opensymphony.xwork2.conversion.impl.DefaultConversionAnnotationProcessor;
|
||||
import com.opensymphony.xwork2.conversion.impl.DefaultConversionFileProcessor;
|
||||
import com.opensymphony.xwork2.conversion.impl.DefaultConversionPropertiesProcessor;
|
||||
import com.opensymphony.xwork2.conversion.impl.DefaultObjectTypeDeterminer;
|
||||
import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverterCreator;
|
||||
import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverterHolder;
|
||||
import com.opensymphony.xwork2.conversion.impl.NumberConverter;
|
||||
import com.opensymphony.xwork2.conversion.impl.StringConverter;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import com.opensymphony.xwork2.factory.ActionFactory;
|
||||
import com.opensymphony.xwork2.factory.ConverterFactory;
|
||||
import com.opensymphony.xwork2.factory.DefaultActionFactory;
|
||||
import com.opensymphony.xwork2.factory.DefaultConverterFactory;
|
||||
import com.opensymphony.xwork2.factory.DefaultInterceptorFactory;
|
||||
import com.opensymphony.xwork2.factory.DefaultResultFactory;
|
||||
import com.opensymphony.xwork2.factory.DefaultUnknownHandlerFactory;
|
||||
import com.opensymphony.xwork2.factory.InterceptorFactory;
|
||||
import com.opensymphony.xwork2.factory.ResultFactory;
|
||||
import com.opensymphony.xwork2.factory.UnknownHandlerFactory;
|
||||
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.conversion.*;
|
||||
import com.opensymphony.xwork2.conversion.impl.*;
|
||||
import com.opensymphony.xwork2.factory.*;
|
||||
import com.opensymphony.xwork2.inject.*;
|
||||
import com.opensymphony.xwork2.ognl.OgnlReflectionProvider;
|
||||
import com.opensymphony.xwork2.ognl.OgnlUtil;
|
||||
import com.opensymphony.xwork2.ognl.OgnlValueStackFactory;
|
||||
import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
|
||||
import com.opensymphony.xwork2.util.CompoundRoot;
|
||||
import com.opensymphony.xwork2.util.OgnlTextParser;
|
||||
import com.opensymphony.xwork2.util.PatternMatcher;
|
||||
import com.opensymphony.xwork2.util.TextParser;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import com.opensymphony.xwork2.util.*;
|
||||
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
|
||||
import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -114,11 +52,11 @@ public class DefaultConfiguration implements Configuration {
|
||||
|
||||
|
||||
// Programmatic Action Configurations
|
||||
protected Map<String, PackageConfig> packageContexts = new LinkedHashMap<String, PackageConfig>();
|
||||
protected Map<String, PackageConfig> packageContexts = new LinkedHashMap<>();
|
||||
protected RuntimeConfiguration runtimeConfiguration;
|
||||
protected Container container;
|
||||
protected String defaultFrameworkBeanName;
|
||||
protected Set<String> loadedFileNames = new TreeSet<String>();
|
||||
protected Set<String> loadedFileNames = new TreeSet<>();
|
||||
protected List<UnknownHandlerConfig> unknownHandlerStack;
|
||||
|
||||
|
||||
@@ -173,11 +111,8 @@ public class DefaultConfiguration implements Configuration {
|
||||
if (check != null) {
|
||||
if (check.getLocation() != null && packageContext.getLocation() != null
|
||||
&& check.getLocation().equals(packageContext.getLocation())) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("The package name '" + name
|
||||
+ "' is already been loaded by the same location and could be removed: "
|
||||
+ packageContext.getLocation());
|
||||
}
|
||||
LOG.debug("The package name '{}' is already been loaded by the same location and could be removed: {}",
|
||||
name, packageContext.getLocation());
|
||||
} else {
|
||||
throw new ConfigurationException("The package name '" + name
|
||||
+ "' at location "+packageContext.getLocation()
|
||||
@@ -213,7 +148,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
public synchronized void reload(List<ConfigurationProvider> providers) throws ConfigurationException {
|
||||
|
||||
// Silly copy necessary due to lack of ability to cast generic lists
|
||||
List<ContainerProvider> contProviders = new ArrayList<ContainerProvider>();
|
||||
List<ContainerProvider> contProviders = new ArrayList<>();
|
||||
contProviders.addAll(providers);
|
||||
|
||||
reloadContainer(contProviders);
|
||||
@@ -228,7 +163,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
public synchronized List<PackageProvider> reloadContainer(List<ContainerProvider> providers) throws ConfigurationException {
|
||||
packageContexts.clear();
|
||||
loadedFileNames.clear();
|
||||
List<PackageProvider> packageProviders = new ArrayList<PackageProvider>();
|
||||
List<PackageProvider> packageProviders = new ArrayList<>();
|
||||
|
||||
ContainerProperties props = new ContainerProperties();
|
||||
ContainerBuilder builder = new ContainerBuilder();
|
||||
@@ -362,8 +297,8 @@ public class DefaultConfiguration implements Configuration {
|
||||
* will have two results.
|
||||
*/
|
||||
protected synchronized RuntimeConfiguration buildRuntimeConfiguration() throws ConfigurationException {
|
||||
Map<String, Map<String, ActionConfig>> namespaceActionConfigs = new LinkedHashMap<String, Map<String, ActionConfig>>();
|
||||
Map<String, String> namespaceConfigs = new LinkedHashMap<String, String>();
|
||||
Map<String, Map<String, ActionConfig>> namespaceActionConfigs = new LinkedHashMap<>();
|
||||
Map<String, String> namespaceConfigs = new LinkedHashMap<>();
|
||||
|
||||
for (PackageConfig packageConfig : packageContexts.values()) {
|
||||
|
||||
@@ -372,7 +307,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
Map<String, ActionConfig> configs = namespaceActionConfigs.get(namespace);
|
||||
|
||||
if (configs == null) {
|
||||
configs = new LinkedHashMap<String, ActionConfig>();
|
||||
configs = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
Map<String, ActionConfig> actionConfigs = packageConfig.getAllActionConfigs();
|
||||
@@ -418,8 +353,8 @@ public class DefaultConfiguration implements Configuration {
|
||||
*
|
||||
*/
|
||||
private ActionConfig buildFullActionConfig(PackageConfig packageContext, ActionConfig baseConfig) throws ConfigurationException {
|
||||
Map<String, String> params = new TreeMap<String, String>(baseConfig.getParams());
|
||||
Map<String, ResultConfig> results = new TreeMap<String, ResultConfig>();
|
||||
Map<String, String> params = new TreeMap<>(baseConfig.getParams());
|
||||
Map<String, ResultConfig> results = new TreeMap<>();
|
||||
|
||||
if (!baseConfig.getPackageName().equals(packageContext.getName()) && packageContexts.containsKey(baseConfig.getPackageName())) {
|
||||
results.putAll(packageContexts.get(baseConfig.getPackageName()).getAllGlobalResults());
|
||||
@@ -431,7 +366,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
|
||||
setDefaultResults(results, packageContext);
|
||||
|
||||
List<InterceptorMapping> interceptors = new ArrayList<InterceptorMapping>(baseConfig.getInterceptors());
|
||||
List<InterceptorMapping> interceptors = new ArrayList<>(baseConfig.getInterceptors());
|
||||
|
||||
if (interceptors.size() <= 0) {
|
||||
String defaultInterceptorRefName = packageContext.getFullDefaultInterceptorRef();
|
||||
@@ -465,7 +400,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
this.namespaceActionConfigs = namespaceActionConfigs;
|
||||
this.namespaceConfigs = namespaceConfigs;
|
||||
|
||||
this.namespaceActionConfigMatchers = new LinkedHashMap<String, ActionConfigMatcher>();
|
||||
this.namespaceActionConfigMatchers = new LinkedHashMap<>();
|
||||
this.namespaceMatcher = new NamespaceMatcher(matcher, namespaceActionConfigs.keySet());
|
||||
|
||||
for (String ns : namespaceActionConfigs.keySet()) {
|
||||
@@ -501,7 +436,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
}
|
||||
|
||||
// fail over to empty namespace
|
||||
if ((config == null) && (namespace != null) && (!"".equals(namespace.trim()))) {
|
||||
if (config == null && StringUtils.isNotBlank(namespace)) {
|
||||
config = findActionConfigInNamespace("", name);
|
||||
}
|
||||
|
||||
@@ -564,7 +499,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
public Object setProperty(String key, String value) {
|
||||
String oldValue = getProperty(key);
|
||||
if (LOG.isInfoEnabled() && oldValue != null && !oldValue.equals(value) && !defaultFrameworkBeanName.equals(oldValue)) {
|
||||
LOG.info("Overriding property "+key+" - old value: "+oldValue+" new value: "+value);
|
||||
LOG.info("Overriding property {} - old value: {} new value: {}", key, oldValue, value);
|
||||
}
|
||||
return super.setProperty(key, value);
|
||||
}
|
||||
@@ -572,8 +507,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
public void setConstants(ContainerBuilder builder) {
|
||||
for (Object keyobj : keySet()) {
|
||||
String key = (String)keyobj;
|
||||
builder.factory(String.class, key,
|
||||
new LocatableConstantFactory<String>(getProperty(key), getPropertyLocation(key)));
|
||||
builder.factory(String.class, key, new LocatableConstantFactory<>(getProperty(key), getPropertyLocation(key)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-13
@@ -16,12 +16,7 @@
|
||||
package com.opensymphony.xwork2.config.impl;
|
||||
|
||||
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.config.ContainerProvider;
|
||||
import com.opensymphony.xwork2.config.PackageProvider;
|
||||
import com.opensymphony.xwork2.config.RuntimeConfiguration;
|
||||
import com.opensymphony.xwork2.config.*;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.UnknownHandlerConfig;
|
||||
import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
|
||||
@@ -30,11 +25,7 @@ import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Scope;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,8 +33,8 @@ import java.util.Set;
|
||||
*/
|
||||
public class MockConfiguration implements Configuration {
|
||||
|
||||
private Map<String, PackageConfig> packages = new HashMap<String, PackageConfig>();
|
||||
private Set<String> loadedFiles = new HashSet<String>();
|
||||
private Map<String, PackageConfig> packages = new HashMap<>();
|
||||
private Set<String> loadedFiles = new HashSet<>();
|
||||
private Container container;
|
||||
protected List<UnknownHandlerConfig> unknownHandlerStack;
|
||||
private ContainerBuilder builder;
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ public class CycleDetector<T> {
|
||||
|
||||
public CycleDetector(DirectedGraph<T> graph) {
|
||||
this.graph = graph;
|
||||
marks = new HashMap<T, String>();
|
||||
verticesInCycles = new ArrayList<T>();
|
||||
marks = new HashMap<>();
|
||||
verticesInCycles = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean containsCycle() {
|
||||
|
||||
+7
-7
@@ -23,8 +23,8 @@ import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorStackConfig;
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -57,14 +57,14 @@ public class InterceptorBuilder {
|
||||
public static List<InterceptorMapping> constructInterceptorReference(InterceptorLocator interceptorLocator,
|
||||
String refName, Map<String,String> refParams, Location location, ObjectFactory objectFactory) throws ConfigurationException {
|
||||
Object referencedConfig = interceptorLocator.getInterceptorConfig(refName);
|
||||
List<InterceptorMapping> result = new ArrayList<InterceptorMapping>();
|
||||
List<InterceptorMapping> result = new ArrayList<>();
|
||||
|
||||
if (referencedConfig == null) {
|
||||
throw new ConfigurationException("Unable to find interceptor class referenced by ref-name " + refName, location);
|
||||
} else {
|
||||
if (referencedConfig instanceof InterceptorConfig) {
|
||||
InterceptorConfig config = (InterceptorConfig) referencedConfig;
|
||||
Interceptor inter = null;
|
||||
Interceptor inter;
|
||||
try {
|
||||
|
||||
inter = objectFactory.buildInterceptor(config, refParams);
|
||||
@@ -105,7 +105,7 @@ public class InterceptorBuilder {
|
||||
InterceptorLocator interceptorLocator, InterceptorStackConfig stackConfig, Map<String,String> refParams,
|
||||
ObjectFactory objectFactory) {
|
||||
List<InterceptorMapping> result;
|
||||
Map<String, Map<String, String>> params = new LinkedHashMap<String, Map<String, String>>();
|
||||
Map<String, Map<String, String>> params = new LinkedHashMap<>();
|
||||
|
||||
/*
|
||||
* We strip
|
||||
@@ -139,7 +139,7 @@ public class InterceptorBuilder {
|
||||
if (params.containsKey(name)) {
|
||||
map = params.get(name);
|
||||
} else {
|
||||
map = new LinkedHashMap<String, String>();
|
||||
map = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
map.put(key, value);
|
||||
@@ -150,7 +150,7 @@ public class InterceptorBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
result = new ArrayList<InterceptorMapping>(stackConfig.getInterceptors());
|
||||
result = new ArrayList<>(stackConfig.getInterceptors());
|
||||
|
||||
for (String key : params.keySet()) {
|
||||
|
||||
@@ -192,7 +192,7 @@ public class InterceptorBuilder {
|
||||
} else
|
||||
if (interceptorCfgObj instanceof InterceptorStackConfig) { // interceptor-ref param refer to an interceptor stack
|
||||
|
||||
// If its an interceptor-stack, we call this method recursively untill,
|
||||
// If its an interceptor-stack, we call this method recursively until,
|
||||
// all the params (eg. interceptorStack1.interceptor1.param etc.)
|
||||
// are resolved down to a specific interceptor.
|
||||
|
||||
|
||||
+53
-80
@@ -15,36 +15,33 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.config.providers;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.config.ConfigurationUtil;
|
||||
import com.opensymphony.xwork2.config.entities.*;
|
||||
import com.opensymphony.xwork2.config.entities.UnknownHandlerConfig;
|
||||
import com.opensymphony.xwork2.config.impl.LocatableFactory;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.inject.Scope;
|
||||
import com.opensymphony.xwork2.util.*;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.ClassPathFinder;
|
||||
import com.opensymphony.xwork2.util.DomHelper;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import com.opensymphony.xwork2.util.location.LocationUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -71,12 +68,12 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
private String configFileName;
|
||||
private ObjectFactory objectFactory;
|
||||
|
||||
private Set<String> loadedFileUrls = new HashSet<String>();
|
||||
private Set<String> loadedFileUrls = new HashSet<>();
|
||||
private boolean errorIfMissing;
|
||||
private Map<String, String> dtdMappings;
|
||||
private Configuration configuration;
|
||||
private boolean throwExceptionOnDuplicateBeans = true;
|
||||
private Map<String, Element> declaredPackages = new HashMap<String, Element>();
|
||||
private Map<String, Element> declaredPackages = new HashMap<>();
|
||||
|
||||
private FileManager fileManager;
|
||||
|
||||
@@ -92,7 +89,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
this.configFileName = filename;
|
||||
this.errorIfMissing = errorIfMissing;
|
||||
|
||||
Map<String, String> mappings = new HashMap<String, String>();
|
||||
Map<String, String> mappings = new HashMap<>();
|
||||
mappings.put("-//Apache Struts//XWork 2.3//EN", "xwork-2.3.dtd");
|
||||
mappings.put("-//Apache Struts//XWork 2.1.3//EN", "xwork-2.1.3.dtd");
|
||||
mappings.put("-//Apache Struts//XWork 2.1//EN", "xwork-2.1.dtd");
|
||||
@@ -173,10 +170,8 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
}
|
||||
|
||||
public void register(ContainerBuilder containerBuilder, LocatableProperties props) throws ConfigurationException {
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("Parsing configuration file [" + configFileName + "]");
|
||||
}
|
||||
Map<String, Node> loadedBeans = new HashMap<String, Node>();
|
||||
LOG.info("Parsing configuration file [{}]", configFileName);
|
||||
Map<String, Node> loadedBeans = new HashMap<>();
|
||||
for (Document doc : documents) {
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
NodeList children = rootElement.getChildNodes();
|
||||
@@ -215,33 +210,31 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
}
|
||||
|
||||
try {
|
||||
Class cimpl = ClassLoaderUtil.loadClass(impl, getClass());
|
||||
Class ctype = cimpl;
|
||||
Class classImpl = ClassLoaderUtil.loadClass(impl, getClass());
|
||||
Class classType = classImpl;
|
||||
if (StringUtils.isNotEmpty(type)) {
|
||||
ctype = ClassLoaderUtil.loadClass(type, getClass());
|
||||
classType = ClassLoaderUtil.loadClass(type, getClass());
|
||||
}
|
||||
if ("true".equals(onlyStatic)) {
|
||||
// Force loading of class to detect no class def found exceptions
|
||||
cimpl.getDeclaredClasses();
|
||||
containerBuilder.injectStatics(cimpl);
|
||||
classImpl.getDeclaredClasses();
|
||||
containerBuilder.injectStatics(classImpl);
|
||||
} else {
|
||||
if (containerBuilder.contains(ctype, name)) {
|
||||
Location loc = LocationUtils.getLocation(loadedBeans.get(ctype.getName() + name));
|
||||
if (containerBuilder.contains(classType, name)) {
|
||||
Location loc = LocationUtils.getLocation(loadedBeans.get(classType.getName() + name));
|
||||
if (throwExceptionOnDuplicateBeans) {
|
||||
throw new ConfigurationException("Bean type " + ctype + " with the name " +
|
||||
throw new ConfigurationException("Bean type " + classType + " with the name " +
|
||||
name + " has already been loaded by " + loc, child);
|
||||
}
|
||||
}
|
||||
|
||||
// Force loading of class to detect no class def found exceptions
|
||||
cimpl.getDeclaredConstructors();
|
||||
classImpl.getDeclaredConstructors();
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Loaded type:" + type + " name:" + name + " impl:" + impl);
|
||||
}
|
||||
containerBuilder.factory(ctype, name, new LocatableFactory(name, ctype, cimpl, scope, childNode), scope);
|
||||
LOG.debug("Loaded type: {} name: {} impl: {}", type, name, impl);
|
||||
containerBuilder.factory(classType, name, new LocatableFactory(name, classType, classImpl, scope, childNode), scope);
|
||||
}
|
||||
loadedBeans.put(ctype.getName() + name, child);
|
||||
loadedBeans.put(classType.getName() + name, child);
|
||||
} catch (Throwable ex) {
|
||||
if (!optional) {
|
||||
throw new ConfigurationException("Unable to load bean: type:" + type + " class:" + impl, ex, childNode);
|
||||
@@ -314,7 +307,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
}
|
||||
|
||||
private void verifyPackageStructure() {
|
||||
DirectedGraph<String> graph = new DirectedGraph<String>();
|
||||
DirectedGraph<String> graph = new DirectedGraph<>();
|
||||
|
||||
for (Document doc : documents) {
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
@@ -343,7 +336,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
CycleDetector<String> detector = new CycleDetector<String>(graph);
|
||||
CycleDetector<String> detector = new CycleDetector<>(graph);
|
||||
if (detector.containsCycle()) {
|
||||
StringBuilder builder = new StringBuilder("The following packages participate in cycles:");
|
||||
for (String packageName : detector.getVerticesInCycles()) {
|
||||
@@ -356,7 +349,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
|
||||
private void reloadRequiredPackages(List<Element> reloads) {
|
||||
if (reloads.size() > 0) {
|
||||
List<Element> result = new ArrayList<Element>();
|
||||
List<Element> result = new ArrayList<>();
|
||||
for (Element pkg : reloads) {
|
||||
PackageConfig cfg = addPackage(pkg);
|
||||
if (cfg.isNeedsRefresh()) {
|
||||
@@ -368,14 +361,14 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
// Print out error messages for all misconfigured inheritence packages
|
||||
// Print out error messages for all misconfigured inheritance packages
|
||||
if (result.size() > 0) {
|
||||
for (Element rp : result) {
|
||||
String parent = rp.getAttribute("extends");
|
||||
if (parent != null) {
|
||||
List<PackageConfig> parents = ConfigurationUtil.buildParentsFromString(configuration, parent);
|
||||
if (parents != null && parents.size() <= 0) {
|
||||
LOG.error("Unable to find parent packages " + parent);
|
||||
LOG.error("Unable to find parent packages {}", parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,18 +395,15 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
protected void addAction(Element actionElement, PackageConfig.Builder packageContext) throws ConfigurationException {
|
||||
String name = actionElement.getAttribute("name");
|
||||
String className = actionElement.getAttribute("class");
|
||||
String methodName = actionElement.getAttribute("method");
|
||||
//methodName should be null if it's not set
|
||||
String methodName = StringUtils.trimToNull(actionElement.getAttribute("method"));
|
||||
Location location = DomHelper.getLocationObject(actionElement);
|
||||
|
||||
if (location == null) {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("location null for " + className);
|
||||
}
|
||||
LOG.warn("Location null for {}", className);
|
||||
}
|
||||
//methodName should be null if it's not set
|
||||
methodName = (methodName.trim().length() > 0) ? methodName.trim() : null;
|
||||
|
||||
// if there isnt a class name specified for an <action/> then try to
|
||||
// if there isn't a class name specified for an <action/> then try to
|
||||
// use the default-class-ref from the <package/>
|
||||
if (StringUtils.isEmpty(className)) {
|
||||
// if there is a package default-class-ref use that, otherwise use action support
|
||||
@@ -455,12 +445,14 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
packageContext.addActionConfig(name, actionConfig);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Loaded " + (StringUtils.isNotEmpty(packageContext.getNamespace()) ? (packageContext.getNamespace() + "/") : "") + name + " in '" + packageContext.getName() + "' package:" + actionConfig);
|
||||
LOG.debug("Loaded {}{} in '{}' package: {}",
|
||||
StringUtils.isNotEmpty(packageContext.getNamespace()) ? (packageContext.getNamespace() + "/") : "",
|
||||
name, packageContext.getName(), actionConfig);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean verifyAction(String className, String name, Location loc) {
|
||||
if (className.indexOf('{') > -1) {
|
||||
if (className.contains("{")) {
|
||||
LOG.debug("Action class [{}] contains a wildcard replacement value, so it can't be verified", className);
|
||||
return true;
|
||||
}
|
||||
@@ -479,7 +471,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
LOG.debug("No constructor found for action [{}]", className, e);
|
||||
throw new ConfigurationException("Action class [" + className + "] does not have a public no-arg constructor", e, loc);
|
||||
} catch (RuntimeException ex) {
|
||||
// Probably not a big deal, like request or session-scoped Spring 2 beans that need a real request
|
||||
// Probably not a big deal, like request or session-scoped Spring beans that need a real request
|
||||
LOG.info("Unable to verify action class [{}] exists at initialization", className);
|
||||
LOG.debug("Action verification cause", ex);
|
||||
} catch (Exception ex) {
|
||||
@@ -573,7 +565,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
packageContext.addResultTypeConfig(resultType.build());
|
||||
|
||||
// set the default result type
|
||||
if ("true".equals(def)) {
|
||||
if (BooleanUtils.toBoolean(def)) {
|
||||
packageContext.defaultResultType(name);
|
||||
}
|
||||
}
|
||||
@@ -583,17 +575,15 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
protected Class verifyResultType(String className, Location loc) {
|
||||
try {
|
||||
return objectFactory.getClassInstance(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.warn("Result class [{}] doesn't exist (ClassNotFoundException) at {}, ignoring", className, loc, e);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
LOG.warn("Result class [{}] doesn't exist (NoClassDefFoundError) at {}, ignoring", className, loc, e);
|
||||
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
||||
LOG.warn("Result class [{}] doesn't exist ({}) at {}, ignoring", className, e.getClass().getSimpleName(), loc, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List<InterceptorMapping> buildInterceptorList(Element element, PackageConfig.Builder context) throws ConfigurationException {
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<InterceptorMapping>();
|
||||
List<InterceptorMapping> interceptorList = new ArrayList<>();
|
||||
NodeList interceptorRefList = element.getElementsByTagName("interceptor-ref");
|
||||
|
||||
for (int i = 0; i < interceptorRefList.getLength(); i++) {
|
||||
@@ -634,7 +624,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
.location(DomHelper.getLocationObject(packageElement));
|
||||
|
||||
if (StringUtils.isNotEmpty(StringUtils.defaultString(parent))) { // has parents, let's look it up
|
||||
List<PackageConfig> parents = new ArrayList<PackageConfig>();
|
||||
List<PackageConfig> parents = new ArrayList<>();
|
||||
for (String parentPackageName : ConfigurationUtil.buildParentListFromString(parent)) {
|
||||
if (configuration.getPackageConfigNames().contains(parentPackageName)) {
|
||||
parents.add(configuration.getPackageConfig(parentPackageName));
|
||||
@@ -665,7 +655,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
protected Map<String, ResultConfig> buildResults(Element element, PackageConfig.Builder packageContext) {
|
||||
NodeList resultEls = element.getElementsByTagName("result");
|
||||
|
||||
Map<String, ResultConfig> results = new LinkedHashMap<String, ResultConfig>();
|
||||
Map<String, ResultConfig> results = new LinkedHashMap<>();
|
||||
|
||||
for (int i = 0; i < resultEls.getLength(); i++) {
|
||||
Element resultElement = (Element) resultEls.item(i);
|
||||
@@ -781,7 +771,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
protected List<ExceptionMappingConfig> buildExceptionMappings(Element element, PackageConfig.Builder packageContext) {
|
||||
NodeList exceptionMappingEls = element.getElementsByTagName("exception-mapping");
|
||||
|
||||
List<ExceptionMappingConfig> exceptionMappings = new ArrayList<ExceptionMappingConfig>();
|
||||
List<ExceptionMappingConfig> exceptionMappings = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < exceptionMappingEls.getLength(); i++) {
|
||||
Element ehElement = (Element) exceptionMappingEls.item(i);
|
||||
@@ -814,7 +804,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
Set<String> allowedMethods = null;
|
||||
|
||||
if (allowedMethodsEls.getLength() > 0) {
|
||||
allowedMethods = new HashSet<String>();
|
||||
allowedMethods = new HashSet<>();
|
||||
Node n = allowedMethodsEls.item(0).getFirstChild();
|
||||
if (n != null) {
|
||||
String s = n.getNodeValue().trim();
|
||||
@@ -823,7 +813,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
}
|
||||
}
|
||||
} else if (packageContext.isStrictMethodInvocation()) {
|
||||
allowedMethods = new HashSet<String>();
|
||||
allowedMethods = new HashSet<>();
|
||||
}
|
||||
|
||||
return allowedMethods;
|
||||
@@ -881,16 +871,6 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// protected void loadIncludes(Element rootElement, DocumentBuilder db) throws Exception {
|
||||
// NodeList includeList = rootElement.getElementsByTagName("include");
|
||||
//
|
||||
// for (int i = 0; i < includeList.getLength(); i++) {
|
||||
// Element includeElement = (Element) includeList.item(i);
|
||||
// String fileName = includeElement.getAttribute("file");
|
||||
// includedFileNames.add(fileName);
|
||||
// loadConfigurationFile(fileName, db);
|
||||
// }
|
||||
// }
|
||||
protected InterceptorStackConfig loadInterceptorStack(Element element, PackageConfig.Builder context) throws ConfigurationException {
|
||||
String name = element.getAttribute("name");
|
||||
|
||||
@@ -948,12 +928,10 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
// }
|
||||
// }
|
||||
private List<Document> loadConfigurationFiles(String fileName, Element includeElement) {
|
||||
List<Document> docs = new ArrayList<Document>();
|
||||
List<Document> finalDocs = new ArrayList<Document>();
|
||||
List<Document> docs = new ArrayList<>();
|
||||
List<Document> finalDocs = new ArrayList<>();
|
||||
if (!includedFileNames.contains(fileName)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Loading action configurations from: " + fileName);
|
||||
}
|
||||
LOG.debug("Loading action configurations from: {}", fileName);
|
||||
|
||||
includedFileNames.add(fileName);
|
||||
|
||||
@@ -971,10 +949,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
if (errorIfMissing) {
|
||||
throw new ConfigurationException("Could not open files of the name " + fileName, ioException);
|
||||
} else {
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("Unable to locate configuration files of the name "
|
||||
+ fileName + ", skipping");
|
||||
}
|
||||
LOG.info("Unable to locate configuration files of the name {}, skipping", fileName);
|
||||
return docs;
|
||||
}
|
||||
}
|
||||
@@ -1049,9 +1024,7 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
finalDocs.add(doc);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Loaded action configuration from: " + fileName);
|
||||
}
|
||||
LOG.debug("Loaded action configuration from: {}", fileName);
|
||||
}
|
||||
return finalDocs;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.config.providers;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Document;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -54,7 +54,7 @@ public class XmlHelper {
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> getParams(Element paramsElement) {
|
||||
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
||||
LinkedHashMap<String, String> params = new LinkedHashMap<>();
|
||||
|
||||
if (paramsElement == null) {
|
||||
return params;
|
||||
@@ -97,8 +97,7 @@ public class XmlHelper {
|
||||
NodeList childNodes = element.getChildNodes();
|
||||
for (int j = 0; j < childNodes.getLength(); j++) {
|
||||
Node currentNode = childNodes.item(j);
|
||||
if (currentNode != null &&
|
||||
currentNode.getNodeType() == Node.TEXT_NODE) {
|
||||
if (currentNode != null && currentNode.getNodeType() == Node.TEXT_NODE) {
|
||||
String val = currentNode.getNodeValue();
|
||||
if (val != null) {
|
||||
paramValue.append(val.trim());
|
||||
|
||||
+3
-7
@@ -8,8 +8,8 @@ import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
|
||||
import com.opensymphony.xwork2.conversion.annotations.ConversionType;
|
||||
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -34,9 +34,7 @@ public class DefaultConversionAnnotationProcessor implements ConversionAnnotatio
|
||||
}
|
||||
|
||||
public void process(Map<String, Object> mapping, TypeConversion tc, String key) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("TypeConversion [{}] with key: [{}]", tc.converter(), key);
|
||||
}
|
||||
LOG.debug("TypeConversion [{}] with key: [{}]", tc.converter(), key);
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
@@ -62,9 +60,7 @@ public class DefaultConversionAnnotationProcessor implements ConversionAnnotatio
|
||||
mapping.put(key, converterCreator.createTypeConverter(tc.converter()));
|
||||
} else {
|
||||
mapping.put(key, converterClass);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Object placed in mapping for key [{}] is [{}]", key, mapping.get(key));
|
||||
}
|
||||
LOG.debug("Object placed in mapping for key [{}] is [{}]", key, mapping.get(key));
|
||||
}
|
||||
}
|
||||
//elements(values) of maps / lists
|
||||
|
||||
+2
-4
@@ -7,8 +7,8 @@ import com.opensymphony.xwork2.conversion.TypeConverter;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverterCreator;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
@@ -39,9 +39,7 @@ public class DefaultConversionFileProcessor implements ConversionFileProcessor {
|
||||
InputStream is = fileManager.loadFile(ClassLoaderUtil.getResource(converterFilename, clazz));
|
||||
|
||||
if (is != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Processing conversion file [{}] for class [{}]", converterFilename, clazz);
|
||||
}
|
||||
LOG.debug("Processing conversion file [{}] for class [{}]", converterFilename, clazz);
|
||||
|
||||
Properties prop = new Properties();
|
||||
prop.load(is);
|
||||
|
||||
+12
-24
@@ -21,10 +21,11 @@ import com.opensymphony.xwork2.util.CreateIfNull;
|
||||
import com.opensymphony.xwork2.util.Element;
|
||||
import com.opensymphony.xwork2.util.Key;
|
||||
import com.opensymphony.xwork2.util.KeyProperty;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionException;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.annotation.Annotation;
|
||||
@@ -64,9 +65,9 @@ public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer {
|
||||
private XWorkConverter xworkConverter;
|
||||
|
||||
@Inject
|
||||
public DefaultObjectTypeDeterminer(@Inject XWorkConverter conv, @Inject ReflectionProvider prov) {
|
||||
this.reflectionProvider = prov;
|
||||
this.xworkConverter = conv;
|
||||
public DefaultObjectTypeDeterminer(@Inject XWorkConverter converter, @Inject ReflectionProvider provider) {
|
||||
this.reflectionProvider = provider;
|
||||
this.xworkConverter = converter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +117,7 @@ public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer {
|
||||
clazz = (Class) xworkConverter.getConverter(parentClass, ELEMENT_PREFIX + property);
|
||||
if (clazz == null) {
|
||||
clazz = (Class) xworkConverter.getConverter(parentClass, DEPRECATED_ELEMENT_PREFIX + property);
|
||||
if (LOG.isInfoEnabled() && clazz != null) {
|
||||
if (clazz != null) {
|
||||
LOG.info("The Collection_xxx pattern for collection type conversion is deprecated. Please use Element_xxx!");
|
||||
}
|
||||
}
|
||||
@@ -163,12 +164,7 @@ public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer {
|
||||
String configValue = (String) xworkConverter.getConverter(parentClass, CREATE_IF_NULL_PREFIX + property);
|
||||
//check if a value is in the config
|
||||
if (configValue != null) {
|
||||
if ("true".equalsIgnoreCase(configValue)) {
|
||||
return true;
|
||||
}
|
||||
if ("false".equalsIgnoreCase(configValue)) {
|
||||
return false;
|
||||
}
|
||||
return BooleanUtils.toBoolean(configValue);
|
||||
}
|
||||
|
||||
//default values depend on target type
|
||||
@@ -218,9 +214,7 @@ public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer {
|
||||
if (getter != null) {
|
||||
return getter.getAnnotation(annotationClass);
|
||||
}
|
||||
} catch (ReflectionException ognle) {
|
||||
// ignore
|
||||
} catch (IntrospectionException ie) {
|
||||
} catch (ReflectionException | IntrospectionException e) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
@@ -241,9 +235,7 @@ public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer {
|
||||
if (setter != null) {
|
||||
return setter.getAnnotation(annotationClass);
|
||||
}
|
||||
} catch (ReflectionException ognle) {
|
||||
// ignore
|
||||
} catch (IntrospectionException ie) {
|
||||
} catch (ReflectionException | IntrospectionException e) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
@@ -270,9 +262,7 @@ public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer {
|
||||
try {
|
||||
Method setter = reflectionProvider.getSetMethod(parentClass, property);
|
||||
genericType = setter != null ? setter.getGenericParameterTypes()[0] : null;
|
||||
} catch (ReflectionException ognle) {
|
||||
// ignore
|
||||
} catch (IntrospectionException ie) {
|
||||
} catch (ReflectionException | IntrospectionException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@@ -282,9 +272,7 @@ public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer {
|
||||
try {
|
||||
Method getter = reflectionProvider.getGetMethod(parentClass, property);
|
||||
genericType = getter.getGenericReturnType();
|
||||
} catch (ReflectionException ognle) {
|
||||
// ignore
|
||||
} catch (IntrospectionException ie) {
|
||||
} catch (ReflectionException | IntrospectionException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -64,7 +64,7 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
private Container container;
|
||||
|
||||
static {
|
||||
Map<Class, Object> map = new HashMap<Class, Object>();
|
||||
Map<Class, Object> map = new HashMap<>();
|
||||
map.put(Boolean.TYPE, Boolean.FALSE);
|
||||
map.put(Byte.TYPE, Byte.valueOf((byte) 0));
|
||||
map.put(Short.TYPE, Short.valueOf((short) 0));
|
||||
@@ -134,19 +134,19 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
}
|
||||
} else {
|
||||
if ((toType == Integer.class) || (toType == Integer.TYPE))
|
||||
result = Integer.valueOf((int) longValue(value));
|
||||
result = (int) longValue(value);
|
||||
if ((toType == Double.class) || (toType == Double.TYPE))
|
||||
result = new Double(doubleValue(value));
|
||||
result = doubleValue(value);
|
||||
if ((toType == Boolean.class) || (toType == Boolean.TYPE))
|
||||
result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE;
|
||||
if ((toType == Byte.class) || (toType == Byte.TYPE))
|
||||
result = Byte.valueOf((byte) longValue(value));
|
||||
result = (byte) longValue(value);
|
||||
if ((toType == Character.class) || (toType == Character.TYPE))
|
||||
result = new Character((char) longValue(value));
|
||||
result = (char) longValue(value);
|
||||
if ((toType == Short.class) || (toType == Short.TYPE))
|
||||
result = Short.valueOf((short) longValue(value));
|
||||
result = (short) longValue(value);
|
||||
if ((toType == Long.class) || (toType == Long.TYPE))
|
||||
result = Long.valueOf(longValue(value));
|
||||
result = longValue(value);
|
||||
if ((toType == Float.class) || (toType == Float.TYPE))
|
||||
result = new Float(doubleValue(value));
|
||||
if (toType == BigInteger.class)
|
||||
@@ -156,7 +156,7 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
if (toType == String.class)
|
||||
result = stringValue(value);
|
||||
if (Enum.class.isAssignableFrom(toType))
|
||||
result = enumValue((Class<Enum>)toType, value);
|
||||
result = enumValue(toType, value);
|
||||
}
|
||||
} else {
|
||||
if (toType.isPrimitive()) {
|
||||
@@ -180,11 +180,11 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
return false;
|
||||
Class c = value.getClass();
|
||||
if (c == Boolean.class)
|
||||
return ((Boolean) value).booleanValue();
|
||||
return (Boolean) value;
|
||||
// if ( c == String.class )
|
||||
// return ((String)value).length() > 0;
|
||||
if (c == Character.class)
|
||||
return ((Character) value).charValue() != 0;
|
||||
return (Character) value != 0;
|
||||
if (value instanceof Number)
|
||||
return ((Number) value).doubleValue() != 0;
|
||||
return true; // non-null
|
||||
@@ -218,9 +218,9 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
if (c.getSuperclass() == Number.class)
|
||||
return ((Number) value).longValue();
|
||||
if (c == Boolean.class)
|
||||
return ((Boolean) value).booleanValue() ? 1 : 0;
|
||||
return (Boolean) value ? 1 : 0;
|
||||
if (c == Character.class)
|
||||
return ((Character) value).charValue();
|
||||
return (Character) value;
|
||||
return Long.parseLong(stringValue(value, true));
|
||||
}
|
||||
|
||||
@@ -240,9 +240,9 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
if (c.getSuperclass() == Number.class)
|
||||
return ((Number) value).doubleValue();
|
||||
if (c == Boolean.class)
|
||||
return ((Boolean) value).booleanValue() ? 1 : 0;
|
||||
return (Boolean) value ? 1 : 0;
|
||||
if (c == Character.class)
|
||||
return ((Character) value).charValue();
|
||||
return (Character) value;
|
||||
String s = stringValue(value, true);
|
||||
|
||||
return (s.length() == 0) ? 0.0 : Double.parseDouble(s);
|
||||
@@ -273,7 +273,7 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
if (c.getSuperclass() == Number.class)
|
||||
return BigInteger.valueOf(((Number) value).longValue());
|
||||
if (c == Boolean.class)
|
||||
return BigInteger.valueOf(((Boolean) value).booleanValue() ? 1 : 0);
|
||||
return BigInteger.valueOf((Boolean) value ? 1 : 0);
|
||||
if (c == Character.class)
|
||||
return BigInteger.valueOf(((Character) value).charValue());
|
||||
return new BigInteger(stringValue(value, true));
|
||||
@@ -300,7 +300,7 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
if (c.getSuperclass() == Number.class)
|
||||
return new BigDecimal(((Number) value).doubleValue());
|
||||
if (c == Boolean.class)
|
||||
return BigDecimal.valueOf(((Boolean) value).booleanValue() ? 1 : 0);
|
||||
return BigDecimal.valueOf((Boolean) value ? 1 : 0);
|
||||
if (c == Character.class)
|
||||
return BigDecimal.valueOf(((Character) value).charValue());
|
||||
return new BigDecimal(stringValue(value, true));
|
||||
|
||||
+4
-4
@@ -19,7 +19,7 @@ public class DefaultTypeConverterHolder implements TypeConverterHolder {
|
||||
* - TypeConverter - instance of TypeConverter
|
||||
* </pre>
|
||||
*/
|
||||
private HashMap<String, TypeConverter> defaultMappings = new HashMap<String, TypeConverter>(); // non-action (eg. returned value)
|
||||
private HashMap<String, TypeConverter> defaultMappings = new HashMap<>(); // non-action (eg. returned value)
|
||||
|
||||
/**
|
||||
* Target class conversion Mappings.
|
||||
@@ -40,12 +40,12 @@ public class DefaultTypeConverterHolder implements TypeConverterHolder {
|
||||
* Element_property=foo.bar.MyObject
|
||||
* </pre>
|
||||
*/
|
||||
private HashMap<Class, Map<String, Object>> mappings = new HashMap<Class, Map<String, Object>>(); // action
|
||||
private HashMap<Class, Map<String, Object>> mappings = new HashMap<>(); // action
|
||||
|
||||
/**
|
||||
* Unavailable target class conversion mappings, serves as a simple cache.
|
||||
*/
|
||||
private HashSet<Class> noMapping = new HashSet<Class>(); // action
|
||||
private HashSet<Class> noMapping = new HashSet<>(); // action
|
||||
|
||||
/**
|
||||
* Record classes that doesn't have conversion mapping defined.
|
||||
@@ -53,7 +53,7 @@ public class DefaultTypeConverterHolder implements TypeConverterHolder {
|
||||
* - String -> classname as String
|
||||
* </pre>
|
||||
*/
|
||||
protected HashSet<String> unknownMappings = new HashSet<String>(); // non-action (eg. returned value)
|
||||
protected HashSet<String> unknownMappings = new HashSet<>(); // non-action (eg. returned value)
|
||||
|
||||
public void addDefaultMapping(String className, TypeConverter typeConverter) {
|
||||
defaultMappings.put(className, typeConverter);
|
||||
|
||||
+5
-13
@@ -19,10 +19,10 @@ import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.conversion.NullHandler;
|
||||
import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.*;
|
||||
@@ -93,18 +93,12 @@ public class InstantiatingNullHandler implements NullHandler {
|
||||
}
|
||||
|
||||
public Object nullMethodResult(Map<String, Object> context, Object target, String methodName, Object[] args) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering nullMethodResult ");
|
||||
}
|
||||
|
||||
LOG.debug("Entering nullMethodResult");
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object nullPropertyValue(Map<String, Object> context, Object target, Object property) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering nullPropertyValue [target="+target+", property="+property+"]");
|
||||
}
|
||||
|
||||
LOG.debug("Entering nullPropertyValue [target={}, property={}]", target, property);
|
||||
boolean c = ReflectionContextState.isCreatingNullObjects(context);
|
||||
|
||||
if (!c) {
|
||||
@@ -140,9 +134,7 @@ public class InstantiatingNullHandler implements NullHandler {
|
||||
|
||||
return param;
|
||||
} catch (Exception e) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("Could not create and/or set value back on to object", e);
|
||||
}
|
||||
LOG.error("Could not create and/or set value back on to object", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ public class StringConverter extends DefaultTypeConverter {
|
||||
|
||||
if (value instanceof int[]) {
|
||||
int[] x = (int[]) value;
|
||||
List<Integer> intArray = new ArrayList<Integer>(x.length);
|
||||
List<Integer> intArray = new ArrayList<>(x.length);
|
||||
|
||||
for (int aX : x) {
|
||||
intArray.add(Integer.valueOf(aX));
|
||||
@@ -27,7 +27,7 @@ public class StringConverter extends DefaultTypeConverter {
|
||||
result = StringUtils.join(intArray, ", ");
|
||||
} else if (value instanceof long[]) {
|
||||
long[] x = (long[]) value;
|
||||
List<Long> longArray = new ArrayList<Long>(x.length);
|
||||
List<Long> longArray = new ArrayList<>(x.length);
|
||||
|
||||
for (long aX : x) {
|
||||
longArray.add(Long.valueOf(aX));
|
||||
@@ -36,7 +36,7 @@ public class StringConverter extends DefaultTypeConverter {
|
||||
result = StringUtils.join(longArray, ", ");
|
||||
} else if (value instanceof double[]) {
|
||||
double[] x = (double[]) value;
|
||||
List<Double> doubleArray = new ArrayList<Double>(x.length);
|
||||
List<Double> doubleArray = new ArrayList<>(x.length);
|
||||
|
||||
for (double aX : x) {
|
||||
doubleArray.add(new Double(aX));
|
||||
@@ -45,7 +45,7 @@ public class StringConverter extends DefaultTypeConverter {
|
||||
result = StringUtils.join(doubleArray, ", ");
|
||||
} else if (value instanceof boolean[]) {
|
||||
boolean[] x = (boolean[]) value;
|
||||
List<Boolean> booleanArray = new ArrayList<Boolean>(x.length);
|
||||
List<Boolean> booleanArray = new ArrayList<>(x.length);
|
||||
|
||||
for (boolean aX : x) {
|
||||
booleanArray.add(new Boolean(aX));
|
||||
|
||||
+14
-28
@@ -15,28 +15,16 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.conversion.impl;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.XWorkConstants;
|
||||
import com.opensymphony.xwork2.XWorkMessages;
|
||||
import com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor;
|
||||
import com.opensymphony.xwork2.conversion.ConversionFileProcessor;
|
||||
import com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverter;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverterHolder;
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.conversion.*;
|
||||
import com.opensymphony.xwork2.conversion.annotations.Conversion;
|
||||
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.AnnotationUtils;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.CompoundRoot;
|
||||
import com.opensymphony.xwork2.util.LocalizedTextUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.*;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Member;
|
||||
@@ -158,8 +146,8 @@ public class XWorkConverter extends DefaultTypeConverter {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDefaultTypeConverter(XWorkBasicConverter conv) {
|
||||
this.defaultTypeConverter = conv;
|
||||
public void setDefaultTypeConverter(XWorkBasicConverter converter) {
|
||||
this.defaultTypeConverter = converter;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -203,7 +191,7 @@ public class XWorkConverter extends DefaultTypeConverter {
|
||||
|
||||
List<String> indexValues = getIndexValues(propertyName);
|
||||
|
||||
propertyName = removeAllIndexesInProperytName(propertyName);
|
||||
propertyName = removeAllIndexesInPropertyName(propertyName);
|
||||
|
||||
String getTextExpression = "getText('" + CONVERSION_ERROR_PROPERTY_PREFIX + propertyName + "','" + defaultMessage + "')";
|
||||
String message = (String) stack.findValue(getTextExpression);
|
||||
@@ -217,13 +205,13 @@ public class XWorkConverter extends DefaultTypeConverter {
|
||||
return message;
|
||||
}
|
||||
|
||||
private static String removeAllIndexesInProperytName(String propertyName) {
|
||||
private static String removeAllIndexesInPropertyName(String propertyName) {
|
||||
return propertyName.replaceAll(MESSAGE_INDEX_PATTERN, PERIOD);
|
||||
}
|
||||
|
||||
private static List<String> getIndexValues(String propertyName) {
|
||||
Matcher matcher = messageIndexPattern.matcher(propertyName);
|
||||
List<String> indexes = new ArrayList<String>();
|
||||
List<String> indexes = new ArrayList<>();
|
||||
while (matcher.find()) {
|
||||
Integer index = new Integer(matcher.group().replaceAll(MESSAGE_INDEX_BRACKET_PATTERN, "")) + 1;
|
||||
indexes.add(Integer.toString(index));
|
||||
@@ -280,9 +268,7 @@ public class XWorkConverter extends DefaultTypeConverter {
|
||||
}
|
||||
|
||||
tc = (TypeConverter) getConverter(clazz, property);
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("field-level type converter for property [" + property + "] = " + (tc == null ? "none found" : tc));
|
||||
LOG.debug("field-level type converter for property [{}] = {}", property, (tc == null ? "none found" : tc));
|
||||
}
|
||||
|
||||
if (tc == null && context != null) {
|
||||
@@ -305,7 +291,7 @@ public class XWorkConverter extends DefaultTypeConverter {
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("global-level type converter for property [" + property + "] = " + (tc == null ? "none found" : tc));
|
||||
LOG.debug("global-level type converter for property [{}] = {} ", property, (tc == null ? "none found" : tc));
|
||||
}
|
||||
|
||||
|
||||
@@ -443,7 +429,7 @@ public class XWorkConverter extends DefaultTypeConverter {
|
||||
Map<String, Object> conversionErrors = (Map<String, Object>) context.get(ActionContext.CONVERSION_ERRORS);
|
||||
|
||||
if (conversionErrors == null) {
|
||||
conversionErrors = new HashMap<String, Object>();
|
||||
conversionErrors = new HashMap<>();
|
||||
context.put(ActionContext.CONVERSION_ERRORS, conversionErrors);
|
||||
}
|
||||
|
||||
@@ -530,7 +516,7 @@ public class XWorkConverter extends DefaultTypeConverter {
|
||||
* @return the converter mappings
|
||||
*/
|
||||
protected Map<String, Object> buildConverterMapping(Class clazz) throws Exception {
|
||||
Map<String, Object> mapping = new HashMap<String, Object>();
|
||||
Map<String, Object> mapping = new HashMap<>();
|
||||
|
||||
// check for conversion mapping associated with super classes and any implemented interfaces
|
||||
Class curClazz = clazz;
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class DefaultInterceptorFactory implements InterceptorFactory {
|
||||
public Interceptor buildInterceptor(InterceptorConfig interceptorConfig, Map<String, String> interceptorRefParams) throws ConfigurationException {
|
||||
String interceptorClassName = interceptorConfig.getClassName();
|
||||
Map<String, String> thisInterceptorClassParams = interceptorConfig.getParams();
|
||||
Map<String, String> params = (thisInterceptorClassParams == null) ? new HashMap<String, String>() : new HashMap<String, String>(thisInterceptorClassParams);
|
||||
Map<String, String> params = (thisInterceptorClassParams == null) ? new HashMap<String, String>() : new HashMap<>(thisInterceptorClassParams);
|
||||
params.putAll(interceptorRefParams);
|
||||
|
||||
String message;
|
||||
|
||||
@@ -66,16 +66,14 @@ class ConstructionContext<T> {
|
||||
// instance (as opposed to one per caller).
|
||||
|
||||
if (!expectedType.isInterface()) {
|
||||
throw new DependencyException(
|
||||
expectedType.getName() + " is not an interface.");
|
||||
throw new DependencyException(expectedType.getName() + " is not an interface.");
|
||||
}
|
||||
|
||||
if (invocationHandlers == null) {
|
||||
invocationHandlers = new ArrayList<DelegatingInvocationHandler<T>>();
|
||||
}
|
||||
|
||||
DelegatingInvocationHandler<T> invocationHandler =
|
||||
new DelegatingInvocationHandler<T>();
|
||||
DelegatingInvocationHandler<T> invocationHandler = new DelegatingInvocationHandler<>();
|
||||
invocationHandlers.add(invocationHandler);
|
||||
|
||||
return Proxy.newProxyInstance(
|
||||
@@ -87,8 +85,7 @@ class ConstructionContext<T> {
|
||||
|
||||
void setProxyDelegates(T delegate) {
|
||||
if (invocationHandlers != null) {
|
||||
for (DelegatingInvocationHandler<T> invocationHandler
|
||||
: invocationHandlers) {
|
||||
for (DelegatingInvocationHandler<T> invocationHandler : invocationHandlers) {
|
||||
invocationHandler.setDelegate(delegate);
|
||||
}
|
||||
}
|
||||
@@ -108,9 +105,7 @@ class ConstructionContext<T> {
|
||||
|
||||
try {
|
||||
return method.invoke(delegate, args);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException | IllegalArgumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw e.getTargetException();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2006 Google Inc.
|
||||
*
|
||||
* <p/>
|
||||
* 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
|
||||
*
|
||||
* <p/>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p/>
|
||||
* 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.
|
||||
@@ -36,492 +36,475 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public final class ContainerBuilder {
|
||||
|
||||
final Map<Key<?>, InternalFactory<?>> factories =
|
||||
new HashMap<Key<?>, InternalFactory<?>>();
|
||||
final List<InternalFactory<?>> singletonFactories =
|
||||
new ArrayList<InternalFactory<?>>();
|
||||
final List<Class<?>> staticInjections = new ArrayList<Class<?>>();
|
||||
boolean created;
|
||||
boolean allowDuplicates = false;
|
||||
final Map<Key<?>, InternalFactory<?>> factories = new HashMap<>();
|
||||
final List<InternalFactory<?>> singletonFactories = new ArrayList<>();
|
||||
final List<Class<?>> staticInjections = new ArrayList<>();
|
||||
boolean created;
|
||||
boolean allowDuplicates = false;
|
||||
|
||||
private static final InternalFactory<Container> CONTAINER_FACTORY =
|
||||
new InternalFactory<Container>() {
|
||||
public Container create(InternalContext context) {
|
||||
return context.getContainer();
|
||||
}
|
||||
};
|
||||
private static final InternalFactory<Container> CONTAINER_FACTORY =
|
||||
new InternalFactory<Container>() {
|
||||
public Container create(InternalContext context) {
|
||||
return context.getContainer();
|
||||
}
|
||||
};
|
||||
|
||||
private static final InternalFactory<Logger> LOGGER_FACTORY =
|
||||
new InternalFactory<Logger>() {
|
||||
public Logger create(InternalContext context) {
|
||||
Member member = context.getExternalContext().getMember();
|
||||
return member == null ? Logger.getAnonymousLogger()
|
||||
: Logger.getLogger(member.getDeclaringClass().getName());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a new builder.
|
||||
*/
|
||||
public ContainerBuilder() {
|
||||
// In the current container as the default Container implementation.
|
||||
factories.put(Key.newInstance(Container.class, Container.DEFAULT_NAME),
|
||||
CONTAINER_FACTORY);
|
||||
|
||||
// Inject the logger for the injected member's declaring class.
|
||||
factories.put(Key.newInstance(Logger.class, Container.DEFAULT_NAME),
|
||||
LOGGER_FACTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a dependency. All methods in this class ultimately funnel through
|
||||
* here.
|
||||
*/
|
||||
private <T> ContainerBuilder factory(final Key<T> key,
|
||||
InternalFactory<? extends T> factory, Scope scope) {
|
||||
ensureNotCreated();
|
||||
checkKey(key);
|
||||
final InternalFactory<? extends T> scopedFactory =
|
||||
scope.scopeFactory(key.getType(), key.getName(), factory);
|
||||
factories.put(key, scopedFactory);
|
||||
if (scope == Scope.SINGLETON) {
|
||||
singletonFactories.add(new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
try {
|
||||
context.setExternalContext(ExternalContext.newInstance(
|
||||
null, key, context.getContainerImpl()));
|
||||
return scopedFactory.create(context);
|
||||
} finally {
|
||||
context.setExternalContext(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures a key isn't already mapped.
|
||||
*/
|
||||
private void checkKey(Key<?> key) {
|
||||
if (factories.containsKey(key) && !allowDuplicates) {
|
||||
throw new DependencyException(
|
||||
"Dependency mapping for " + key + " already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a factory to a given dependency type and name.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param factory creates objects to inject
|
||||
* @param scope scope of injected instances
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder factory(final Class<T> type, final String name,
|
||||
final Factory<? extends T> factory, Scope scope) {
|
||||
InternalFactory<T> internalFactory =
|
||||
new InternalFactory<T>() {
|
||||
|
||||
public T create(InternalContext context) {
|
||||
try {
|
||||
Context externalContext = context.getExternalContext();
|
||||
return factory.create(externalContext);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new LinkedHashMap<String, Object>() {{
|
||||
put("type", type);
|
||||
put("name", name);
|
||||
put("factory", factory);
|
||||
}}.toString();
|
||||
}
|
||||
};
|
||||
|
||||
return factory(Key.newInstance(type, name), internalFactory, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, factory, scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Factory, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type,
|
||||
Factory<? extends T> factory, Scope scope) {
|
||||
return factory(type, Container.DEFAULT_NAME, factory, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type, name, factory,
|
||||
* Scope.DEFAULT)}.
|
||||
*
|
||||
* @see #factory(Class, String, Factory, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, String name,
|
||||
Factory<? extends T> factory) {
|
||||
return factory(type, name, factory, Scope.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, factory, Scope.DEFAULT)}.
|
||||
*
|
||||
* @see #factory(Class, String, Factory, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type,
|
||||
Factory<? extends T> factory) {
|
||||
return factory(type, Container.DEFAULT_NAME, factory, Scope.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an implementation class to a given dependency type and name. Creates
|
||||
* instances using the container, recursively injecting dependencies.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param implementation class
|
||||
* @param scope scope of injected instances
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder factory(final Class<T> type, final String name,
|
||||
final Class<? extends T> implementation, final Scope scope) {
|
||||
// This factory creates new instances of the given implementation.
|
||||
// We have to lazy load the constructor because the Container
|
||||
// hasn't been created yet.
|
||||
InternalFactory<? extends T> factory = new InternalFactory<T>() {
|
||||
|
||||
volatile ContainerImpl.ConstructorInjector<? extends T> constructor;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T create(InternalContext context) {
|
||||
if (constructor == null) {
|
||||
this.constructor =
|
||||
context.getContainerImpl().getConstructor(implementation);
|
||||
}
|
||||
return (T) constructor.construct(context, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new LinkedHashMap<String, Object>() {{
|
||||
put("type", type);
|
||||
put("name", name);
|
||||
put("implementation", implementation);
|
||||
put("scope", scope);
|
||||
}}.toString();
|
||||
}
|
||||
};
|
||||
|
||||
return factory(Key.newInstance(type, name), factory, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an implementation class to a given dependency type and name. Creates
|
||||
* instances using the container, recursively injecting dependencies.
|
||||
*
|
||||
* <p>Sets scope to value from {@link Scoped} annotation on the
|
||||
* implementation class. Defaults to {@link Scope#DEFAULT} if no annotation
|
||||
* is found.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param implementation class
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder factory(final Class<T> type, String name,
|
||||
final Class<? extends T> implementation) {
|
||||
Scoped scoped = implementation.getAnnotation(Scoped.class);
|
||||
Scope scope = scoped == null ? Scope.DEFAULT : scoped.value();
|
||||
return factory(type, name, implementation, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, implementation)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type,
|
||||
Class<? extends T> implementation) {
|
||||
return factory(type, Container.DEFAULT_NAME, implementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, type)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type) {
|
||||
return factory(type, Container.DEFAULT_NAME, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type, name, type)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, String name) {
|
||||
return factory(type, name, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, implementation, scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type,
|
||||
Class<? extends T> implementation, Scope scope) {
|
||||
return factory(type, Container.DEFAULT_NAME, implementation, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, type, scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, Scope scope) {
|
||||
return factory(type, Container.DEFAULT_NAME, type, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type, name, type,
|
||||
* scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, String name, Scope scope) {
|
||||
return factory(type, name, type, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code alias(type, Container.DEFAULT_NAME,
|
||||
* type)}.
|
||||
*
|
||||
* @see #alias(Class, String, String)
|
||||
*/
|
||||
public <T> ContainerBuilder alias(Class<T> type, String alias) {
|
||||
return alias(type, Container.DEFAULT_NAME, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an existing factory to a new name.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param alias of to the dependency
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder alias(Class<T> type, String name, String alias) {
|
||||
return alias(Key.newInstance(type, name), Key.newInstance(type, alias));
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an existing dependency. All methods in this class ultimately funnel through
|
||||
* here.
|
||||
*/
|
||||
private <T> ContainerBuilder alias(final Key<T> key,
|
||||
final Key<T> aliasKey) {
|
||||
ensureNotCreated();
|
||||
checkKey(aliasKey);
|
||||
|
||||
final InternalFactory<? extends T> scopedFactory =
|
||||
(InternalFactory<? extends T>)factories.get(key);
|
||||
if (scopedFactory == null) {
|
||||
throw new DependencyException(
|
||||
"Dependency mapping for " + key + " doesn't exists.");
|
||||
}
|
||||
factories.put(aliasKey, scopedFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, String value) {
|
||||
return constant(String.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, int value) {
|
||||
return constant(int.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, long value) {
|
||||
return constant(long.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, boolean value) {
|
||||
return constant(boolean.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, double value) {
|
||||
return constant(double.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, float value) {
|
||||
return constant(float.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, short value) {
|
||||
return constant(short.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, char value) {
|
||||
return constant(char.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a class to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, Class value) {
|
||||
return constant(Class.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an enum to the given name.
|
||||
*/
|
||||
public <E extends Enum<E>> ContainerBuilder constant(String name, E value) {
|
||||
return constant(value.getDeclaringClass(), name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given type and name.
|
||||
*/
|
||||
private <T> ContainerBuilder constant(final Class<T> type, final String name,
|
||||
final T value) {
|
||||
InternalFactory<T> factory = new InternalFactory<T>() {
|
||||
public T create(InternalContext ignored) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("type", type);
|
||||
put("name", name);
|
||||
put("value", value);
|
||||
}
|
||||
}.toString();
|
||||
}
|
||||
};
|
||||
|
||||
return factory(Key.newInstance(type, name), factory, Scope.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upon creation, the {@link Container} will inject static fields and methods
|
||||
* into the given classes.
|
||||
*
|
||||
* @param types for which static members will be injected
|
||||
*/
|
||||
public ContainerBuilder injectStatics(Class<?>... types) {
|
||||
staticInjections.addAll(Arrays.asList(types));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this builder contains a mapping for the given type and
|
||||
* name.
|
||||
*/
|
||||
public boolean contains(Class<?> type, String name) {
|
||||
return factories.containsKey(Key.newInstance(type, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code contains(type,
|
||||
* Container.DEFAULT_NAME)}.
|
||||
*/
|
||||
public boolean contains(Class<?> type) {
|
||||
return contains(type, Container.DEFAULT_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Container} instance. Injects static members for classes
|
||||
* which were registered using {@link #injectStatics(Class...)}.
|
||||
*
|
||||
* @param loadSingletons If true, the container will load all singletons
|
||||
* now. If false, the container will lazily load singletons. Eager loading
|
||||
* is appropriate for production use while lazy loading can speed
|
||||
* development.
|
||||
* @throws IllegalStateException if called more than once
|
||||
*/
|
||||
public Container create(boolean loadSingletons) {
|
||||
ensureNotCreated();
|
||||
created = true;
|
||||
final ContainerImpl container = new ContainerImpl(
|
||||
new HashMap<Key<?>, InternalFactory<?>>(factories));
|
||||
if (loadSingletons) {
|
||||
container.callInContext(new ContainerImpl.ContextualCallable<Void>() {
|
||||
public Void call(InternalContext context) {
|
||||
for (InternalFactory<?> factory : singletonFactories) {
|
||||
factory.create(context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
container.injectStatics(staticInjections);
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently we only support creating one Container instance per builder.
|
||||
* If we want to support creating more than one container per builder,
|
||||
* we should move to a "factory factory" model where we create a factory
|
||||
* instance per Container. Right now, one factory instance would be
|
||||
* shared across all the containers, singletons synchronize on the
|
||||
* container when lazy loading, etc.
|
||||
*/
|
||||
private void ensureNotCreated() {
|
||||
if (created) {
|
||||
throw new IllegalStateException("Container already created.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllowDuplicates(boolean val) {
|
||||
allowDuplicates = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented by classes which participate in building a container.
|
||||
*/
|
||||
public interface Command {
|
||||
private static final InternalFactory<Logger> LOGGER_FACTORY =
|
||||
new InternalFactory<Logger>() {
|
||||
public Logger create(InternalContext context) {
|
||||
Member member = context.getExternalContext().getMember();
|
||||
return member == null ? Logger.getAnonymousLogger()
|
||||
: Logger.getLogger(member.getDeclaringClass().getName());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Contributes factories to the given builder.
|
||||
*
|
||||
* @param builder
|
||||
* Constructs a new builder.
|
||||
*/
|
||||
void build(ContainerBuilder builder);
|
||||
}
|
||||
public ContainerBuilder() {
|
||||
// In the current container as the default Container implementation.
|
||||
factories.put(Key.newInstance(Container.class, Container.DEFAULT_NAME), CONTAINER_FACTORY);
|
||||
|
||||
// Inject the logger for the injected member's declaring class.
|
||||
factories.put(Key.newInstance(Logger.class, Container.DEFAULT_NAME), LOGGER_FACTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a dependency. All methods in this class ultimately funnel through
|
||||
* here.
|
||||
*/
|
||||
private <T> ContainerBuilder factory(final Key<T> key,
|
||||
InternalFactory<? extends T> factory, Scope scope) {
|
||||
ensureNotCreated();
|
||||
checkKey(key);
|
||||
final InternalFactory<? extends T> scopedFactory = scope.scopeFactory(key.getType(), key.getName(), factory);
|
||||
factories.put(key, scopedFactory);
|
||||
if (scope == Scope.SINGLETON) {
|
||||
singletonFactories.add(new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
try {
|
||||
context.setExternalContext(ExternalContext.newInstance(null, key, context.getContainerImpl()));
|
||||
return scopedFactory.create(context);
|
||||
} finally {
|
||||
context.setExternalContext(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures a key isn't already mapped.
|
||||
*/
|
||||
private void checkKey(Key<?> key) {
|
||||
if (factories.containsKey(key) && !allowDuplicates) {
|
||||
throw new DependencyException("Dependency mapping for " + key + " already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a factory to a given dependency type and name.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param factory creates objects to inject
|
||||
* @param scope scope of injected instances
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder factory(final Class<T> type, final String name,
|
||||
final Factory<? extends T> factory, Scope scope) {
|
||||
InternalFactory<T> internalFactory = new InternalFactory<T>() {
|
||||
|
||||
public T create(InternalContext context) {
|
||||
try {
|
||||
Context externalContext = context.getExternalContext();
|
||||
return factory.create(externalContext);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new LinkedHashMap<String, Object>() {{
|
||||
put("type", type);
|
||||
put("name", name);
|
||||
put("factory", factory);
|
||||
}}.toString();
|
||||
}
|
||||
};
|
||||
|
||||
return factory(Key.newInstance(type, name), internalFactory, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, factory, scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Factory, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, Factory<? extends T> factory, Scope scope) {
|
||||
return factory(type, Container.DEFAULT_NAME, factory, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type, name, factory,
|
||||
* Scope.DEFAULT)}.
|
||||
*
|
||||
* @see #factory(Class, String, Factory, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, String name, Factory<? extends T> factory) {
|
||||
return factory(type, name, factory, Scope.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, factory, Scope.DEFAULT)}.
|
||||
*
|
||||
* @see #factory(Class, String, Factory, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, Factory<? extends T> factory) {
|
||||
return factory(type, Container.DEFAULT_NAME, factory, Scope.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an implementation class to a given dependency type and name. Creates
|
||||
* instances using the container, recursively injecting dependencies.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param implementation class
|
||||
* @param scope scope of injected instances
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder factory(final Class<T> type, final String name,
|
||||
final Class<? extends T> implementation, final Scope scope) {
|
||||
// This factory creates new instances of the given implementation.
|
||||
// We have to lazy load the constructor because the Container
|
||||
// hasn't been created yet.
|
||||
InternalFactory<? extends T> factory = new InternalFactory<T>() {
|
||||
|
||||
volatile ContainerImpl.ConstructorInjector<? extends T> constructor;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T create(InternalContext context) {
|
||||
if (constructor == null) {
|
||||
this.constructor =
|
||||
context.getContainerImpl().getConstructor(implementation);
|
||||
}
|
||||
return (T) constructor.construct(context, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new LinkedHashMap<String, Object>() {{
|
||||
put("type", type);
|
||||
put("name", name);
|
||||
put("implementation", implementation);
|
||||
put("scope", scope);
|
||||
}}.toString();
|
||||
}
|
||||
};
|
||||
|
||||
return factory(Key.newInstance(type, name), factory, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an implementation class to a given dependency type and name. Creates
|
||||
* instances using the container, recursively injecting dependencies.
|
||||
* <p/>
|
||||
* <p>Sets scope to value from {@link Scoped} annotation on the
|
||||
* implementation class. Defaults to {@link Scope#DEFAULT} if no annotation
|
||||
* is found.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param implementation class
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder factory(final Class<T> type, String name,
|
||||
final Class<? extends T> implementation) {
|
||||
Scoped scoped = implementation.getAnnotation(Scoped.class);
|
||||
Scope scope = scoped == null ? Scope.DEFAULT : scoped.value();
|
||||
return factory(type, name, implementation, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, implementation)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, Class<? extends T> implementation) {
|
||||
return factory(type, Container.DEFAULT_NAME, implementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, type)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type) {
|
||||
return factory(type, Container.DEFAULT_NAME, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type, name, type)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, String name) {
|
||||
return factory(type, name, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, implementation, scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, Class<? extends T> implementation, Scope scope) {
|
||||
return factory(type, Container.DEFAULT_NAME, implementation, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type,
|
||||
* Container.DEFAULT_NAME, type, scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, Scope scope) {
|
||||
return factory(type, Container.DEFAULT_NAME, type, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code factory(type, name, type,
|
||||
* scope)}.
|
||||
*
|
||||
* @see #factory(Class, String, Class, Scope)
|
||||
*/
|
||||
public <T> ContainerBuilder factory(Class<T> type, String name, Scope scope) {
|
||||
return factory(type, name, type, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code alias(type, Container.DEFAULT_NAME,
|
||||
* type)}.
|
||||
*
|
||||
* @see #alias(Class, String, String)
|
||||
*/
|
||||
public <T> ContainerBuilder alias(Class<T> type, String alias) {
|
||||
return alias(type, Container.DEFAULT_NAME, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an existing factory to a new name.
|
||||
*
|
||||
* @param type of dependency
|
||||
* @param name of dependency
|
||||
* @param alias of to the dependency
|
||||
* @return this builder
|
||||
*/
|
||||
public <T> ContainerBuilder alias(Class<T> type, String name, String alias) {
|
||||
return alias(Key.newInstance(type, name), Key.newInstance(type, alias));
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an existing dependency. All methods in this class ultimately funnel through
|
||||
* here.
|
||||
*/
|
||||
private <T> ContainerBuilder alias(final Key<T> key,
|
||||
final Key<T> aliasKey) {
|
||||
ensureNotCreated();
|
||||
checkKey(aliasKey);
|
||||
|
||||
final InternalFactory<? extends T> scopedFactory = (InternalFactory<? extends T>) factories.get(key);
|
||||
if (scopedFactory == null) {
|
||||
throw new DependencyException("Dependency mapping for " + key + " doesn't exists.");
|
||||
}
|
||||
factories.put(aliasKey, scopedFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, String value) {
|
||||
return constant(String.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, int value) {
|
||||
return constant(int.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, long value) {
|
||||
return constant(long.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, boolean value) {
|
||||
return constant(boolean.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, double value) {
|
||||
return constant(double.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, float value) {
|
||||
return constant(float.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, short value) {
|
||||
return constant(short.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, char value) {
|
||||
return constant(char.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a class to the given name.
|
||||
*/
|
||||
public ContainerBuilder constant(String name, Class value) {
|
||||
return constant(Class.class, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an enum to the given name.
|
||||
*/
|
||||
public <E extends Enum<E>> ContainerBuilder constant(String name, E value) {
|
||||
return constant(value.getDeclaringClass(), name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a constant value to the given type and name.
|
||||
*/
|
||||
private <T> ContainerBuilder constant(final Class<T> type, final String name, final T value) {
|
||||
InternalFactory<T> factory = new InternalFactory<T>() {
|
||||
public T create(InternalContext ignored) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("type", type);
|
||||
put("name", name);
|
||||
put("value", value);
|
||||
}
|
||||
}.toString();
|
||||
}
|
||||
};
|
||||
|
||||
return factory(Key.newInstance(type, name), factory, Scope.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upon creation, the {@link Container} will inject static fields and methods
|
||||
* into the given classes.
|
||||
*
|
||||
* @param types for which static members will be injected
|
||||
*/
|
||||
public ContainerBuilder injectStatics(Class<?>... types) {
|
||||
staticInjections.addAll(Arrays.asList(types));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this builder contains a mapping for the given type and
|
||||
* name.
|
||||
*/
|
||||
public boolean contains(Class<?> type, String name) {
|
||||
return factories.containsKey(Key.newInstance(type, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Equivalent to {@code contains(type,
|
||||
* Container.DEFAULT_NAME)}.
|
||||
*/
|
||||
public boolean contains(Class<?> type) {
|
||||
return contains(type, Container.DEFAULT_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Container} instance. Injects static members for classes
|
||||
* which were registered using {@link #injectStatics(Class...)}.
|
||||
*
|
||||
* @param loadSingletons If true, the container will load all singletons
|
||||
* now. If false, the container will lazily load singletons. Eager loading
|
||||
* is appropriate for production use while lazy loading can speed
|
||||
* development.
|
||||
* @throws IllegalStateException if called more than once
|
||||
*/
|
||||
public Container create(boolean loadSingletons) {
|
||||
ensureNotCreated();
|
||||
created = true;
|
||||
final ContainerImpl container = new ContainerImpl(new HashMap<>(factories));
|
||||
if (loadSingletons) {
|
||||
container.callInContext(new ContainerImpl.ContextualCallable<Void>() {
|
||||
public Void call(InternalContext context) {
|
||||
for (InternalFactory<?> factory : singletonFactories) {
|
||||
factory.create(context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
container.injectStatics(staticInjections);
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently we only support creating one Container instance per builder.
|
||||
* If we want to support creating more than one container per builder,
|
||||
* we should move to a "factory factory" model where we create a factory
|
||||
* instance per Container. Right now, one factory instance would be
|
||||
* shared across all the containers, singletons synchronize on the
|
||||
* container when lazy loading, etc.
|
||||
*/
|
||||
private void ensureNotCreated() {
|
||||
if (created) {
|
||||
throw new IllegalStateException("Container already created.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllowDuplicates(boolean val) {
|
||||
allowDuplicates = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented by classes which participate in building a container.
|
||||
*/
|
||||
public interface Command {
|
||||
|
||||
/**
|
||||
* Contributes factories to the given builder.
|
||||
*
|
||||
* @param builder
|
||||
*/
|
||||
void build(ContainerBuilder builder);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2006 Google Inc.
|
||||
*
|
||||
* <p/>
|
||||
* 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
|
||||
*
|
||||
* <p/>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p/>
|
||||
* 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.
|
||||
@@ -27,48 +27,47 @@ import java.util.LinkedHashMap;
|
||||
*/
|
||||
class ExternalContext<T> implements Context {
|
||||
|
||||
final Member member;
|
||||
final Key<T> key;
|
||||
final ContainerImpl container;
|
||||
final Member member;
|
||||
final Key<T> key;
|
||||
final ContainerImpl container;
|
||||
|
||||
public ExternalContext(Member member, Key<T> key, ContainerImpl container) {
|
||||
this.member = member;
|
||||
this.key = key;
|
||||
this.container = container;
|
||||
}
|
||||
public ExternalContext(Member member, Key<T> key, ContainerImpl container) {
|
||||
this.member = member;
|
||||
this.key = key;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public Class<T> getType() {
|
||||
return key.getType();
|
||||
}
|
||||
public Class<T> getType() {
|
||||
return key.getType();
|
||||
}
|
||||
|
||||
public Scope.Strategy getScopeStrategy() {
|
||||
return (Scope.Strategy) container.localScopeStrategy.get();
|
||||
}
|
||||
public Scope.Strategy getScopeStrategy() {
|
||||
return (Scope.Strategy) container.localScopeStrategy.get();
|
||||
}
|
||||
|
||||
public Container getContainer() {
|
||||
return container;
|
||||
}
|
||||
public Container getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
public Member getMember() {
|
||||
return member;
|
||||
}
|
||||
public Member getMember() {
|
||||
return member;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return key.getName();
|
||||
}
|
||||
public String getName() {
|
||||
return key.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Context" + new LinkedHashMap<String, Object>() {{
|
||||
put("member", member);
|
||||
put("type", getType());
|
||||
put("name", getName());
|
||||
put("container", container);
|
||||
}}.toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Context" + new LinkedHashMap<String, Object>() {{
|
||||
put("member", member);
|
||||
put("type", getType());
|
||||
put("name", getName());
|
||||
put("container", container);
|
||||
}}.toString();
|
||||
}
|
||||
|
||||
static <T> ExternalContext<T> newInstance(Member member, Key<T> key,
|
||||
ContainerImpl container) {
|
||||
return new ExternalContext<T>(member, key, container);
|
||||
}
|
||||
static <T> ExternalContext<T> newInstance(Member member, Key<T> key, ContainerImpl container) {
|
||||
return new ExternalContext<T>(member, key, container);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import java.util.Map;
|
||||
class InternalContext {
|
||||
|
||||
final ContainerImpl container;
|
||||
final Map<Object, ConstructionContext<?>> constructionContexts =
|
||||
new HashMap<Object, ConstructionContext<?>>();
|
||||
final Map<Object, ConstructionContext<?>> constructionContexts = new HashMap<Object, ConstructionContext<?>>();
|
||||
Scope.Strategy scopeStrategy;
|
||||
ExternalContext<?> externalContext;
|
||||
|
||||
@@ -50,8 +49,7 @@ class InternalContext {
|
||||
scopeStrategy = (Scope.Strategy) container.localScopeStrategy.get();
|
||||
|
||||
if (scopeStrategy == null) {
|
||||
throw new IllegalStateException("Scope strategy not set. "
|
||||
+ "Please call Container.setScopeStrategy().");
|
||||
throw new IllegalStateException("Scope strategy not set. Please call Container.setScopeStrategy().");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +58,7 @@ class InternalContext {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T> ConstructionContext<T> getConstructionContext(Object key) {
|
||||
ConstructionContext<T> constructionContext =
|
||||
(ConstructionContext<T>) constructionContexts.get(key);
|
||||
ConstructionContext<T> constructionContext = (ConstructionContext<T>) constructionContexts.get(key);
|
||||
if (constructionContext == null) {
|
||||
constructionContext = new ConstructionContext<T>();
|
||||
constructionContexts.put(key, constructionContext);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2006 Google Inc.
|
||||
*
|
||||
* <p/>
|
||||
* 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
|
||||
*
|
||||
* <p/>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p/>
|
||||
* 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.
|
||||
@@ -23,55 +23,55 @@ package com.opensymphony.xwork2.inject;
|
||||
*/
|
||||
class Key<T> {
|
||||
|
||||
final Class<T> type;
|
||||
final String name;
|
||||
final int hashCode;
|
||||
final Class<T> type;
|
||||
final String name;
|
||||
final int hashCode;
|
||||
|
||||
private Key(Class<T> type, String name) {
|
||||
if (type == null) {
|
||||
throw new NullPointerException("Type is null.");
|
||||
}
|
||||
if (name == null) {
|
||||
throw new NullPointerException("Name is null.");
|
||||
private Key(Class<T> type, String name) {
|
||||
if (type == null) {
|
||||
throw new NullPointerException("Type is null.");
|
||||
}
|
||||
if (name == null) {
|
||||
throw new NullPointerException("Name is null.");
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
|
||||
hashCode = type.hashCode() * 31 + name.hashCode();
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
|
||||
hashCode = type.hashCode() * 31 + name.hashCode();
|
||||
}
|
||||
|
||||
Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Key)) {
|
||||
return false;
|
||||
Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
if (o == this) {
|
||||
return true;
|
||||
|
||||
String getName() {
|
||||
return name;
|
||||
}
|
||||
Key other = (Key) o;
|
||||
return name.equals(other.name) && type.equals(other.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[type=" + type.getName() + ", name='" + name + "']";
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
static <T> Key<T> newInstance(Class<T> type, String name) {
|
||||
return new Key<T>(type, name);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Key)) {
|
||||
return false;
|
||||
}
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
Key other = (Key) o;
|
||||
return name.equals(other.name) && type.equals(other.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[type=" + type.getName() + ", name='" + name + "']";
|
||||
}
|
||||
|
||||
static <T> Key<T> newInstance(Class<T> type, String name) {
|
||||
return new Key<T>(type, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2006 Google Inc.
|
||||
*
|
||||
* <p/>
|
||||
* 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
|
||||
*
|
||||
* <p/>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p/>
|
||||
* 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.
|
||||
@@ -25,193 +25,190 @@ import java.util.concurrent.Callable;
|
||||
*/
|
||||
public enum Scope {
|
||||
|
||||
/**
|
||||
* One instance per injection.
|
||||
*/
|
||||
DEFAULT {
|
||||
@Override
|
||||
<T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name,
|
||||
InternalFactory<? extends T> factory) {
|
||||
return factory;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* One instance per container.
|
||||
*/
|
||||
SINGLETON {
|
||||
@Override
|
||||
<T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name,
|
||||
final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
T instance;
|
||||
public T create(InternalContext context) {
|
||||
synchronized (context.getContainer()) {
|
||||
if (instance == null) {
|
||||
instance = factory.create(context);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One instance per injection.
|
||||
*/
|
||||
DEFAULT {
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* One instance per thread.
|
||||
*
|
||||
* <p><b>Note:</b> if a thread local object strongly references its {@link
|
||||
* Container}, neither the {@code Container} nor the object will be
|
||||
* eligible for garbage collection, i.e. memory leak.
|
||||
*/
|
||||
THREAD {
|
||||
@Override
|
||||
<T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name,
|
||||
final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
final ThreadLocal<T> threadLocal = new ThreadLocal<T>();
|
||||
public T create(final InternalContext context) {
|
||||
T t = threadLocal.get();
|
||||
if (t == null) {
|
||||
t = factory.create(context);
|
||||
threadLocal.set(t);
|
||||
}
|
||||
return t;
|
||||
<T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name,
|
||||
InternalFactory<? extends T> factory) {
|
||||
return factory;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* One instance per container.
|
||||
*/
|
||||
SINGLETON {
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
<T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
T instance;
|
||||
|
||||
/**
|
||||
* One instance per request.
|
||||
*/
|
||||
REQUEST {
|
||||
@Override
|
||||
<T> InternalFactory<? extends T> scopeFactory(final Class<T> type,
|
||||
final String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
Strategy strategy = context.getScopeStrategy();
|
||||
try {
|
||||
return strategy.findInRequest(
|
||||
type, name, toCallable(context, factory));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public T create(InternalContext context) {
|
||||
synchronized (context.getContainer()) {
|
||||
if (instance == null) {
|
||||
instance = factory.create(context);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* One instance per thread.
|
||||
* <p/>
|
||||
* <p><b>Note:</b> if a thread local object strongly references its {@link
|
||||
* Container}, neither the {@code Container} nor the object will be
|
||||
* eligible for garbage collection, i.e. memory leak.
|
||||
*/
|
||||
THREAD {
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
<T> InternalFactory<? extends T> scopeFactory(Class<T> type, String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
final ThreadLocal<T> threadLocal = new ThreadLocal<T>();
|
||||
|
||||
/**
|
||||
* One instance per session.
|
||||
*/
|
||||
SESSION {
|
||||
@Override
|
||||
<T> InternalFactory<? extends T> scopeFactory(final Class<T> type,
|
||||
final String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
Strategy strategy = context.getScopeStrategy();
|
||||
try {
|
||||
return strategy.findInSession(
|
||||
type, name, toCallable(context, factory));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public T create(final InternalContext context) {
|
||||
T t = threadLocal.get();
|
||||
if (t == null) {
|
||||
t = factory.create(context);
|
||||
threadLocal.set(t);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* One instance per request.
|
||||
*/
|
||||
REQUEST {
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
<T> InternalFactory<? extends T> scopeFactory(final Class<T> type, final String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
Strategy strategy = context.getScopeStrategy();
|
||||
try {
|
||||
return strategy.findInRequest(
|
||||
type, name, toCallable(context, factory));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One instance per wizard.
|
||||
*/
|
||||
WIZARD {
|
||||
@Override
|
||||
<T> InternalFactory<? extends T> scopeFactory(final Class<T> type,
|
||||
final String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
Strategy strategy = context.getScopeStrategy();
|
||||
try {
|
||||
return strategy.findInWizard(
|
||||
type, name, toCallable(context, factory));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* One instance per session.
|
||||
*/
|
||||
SESSION {
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
<T> InternalFactory<? extends T> scopeFactory(final Class<T> type, final String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
Strategy strategy = context.getScopeStrategy();
|
||||
try {
|
||||
return strategy.findInSession(
|
||||
type, name, toCallable(context, factory));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
<T> Callable<? extends T> toCallable(final InternalContext context,
|
||||
final InternalFactory<? extends T> factory) {
|
||||
return new Callable<T>() {
|
||||
public T call() throws Exception {
|
||||
return factory.create(context);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* One instance per wizard.
|
||||
*/
|
||||
WIZARD {
|
||||
@Override
|
||||
<T> InternalFactory<? extends T> scopeFactory(final Class<T> type, final String name, final InternalFactory<? extends T> factory) {
|
||||
return new InternalFactory<T>() {
|
||||
public T create(InternalContext context) {
|
||||
Strategy strategy = context.getScopeStrategy();
|
||||
try {
|
||||
return strategy.findInWizard(
|
||||
type, name, toCallable(context, factory));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return factory.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps factory with scoping logic.
|
||||
*/
|
||||
abstract <T> InternalFactory<? extends T> scopeFactory(
|
||||
Class<T> type, String name, InternalFactory<? extends T> factory);
|
||||
|
||||
/**
|
||||
* Pluggable scoping strategy. Enables users to provide custom
|
||||
* implementations of request, session, and wizard scopes. Implement and
|
||||
* pass to {@link
|
||||
* Container#setScopeStrategy(com.opensymphony.xwork2.inject.Scope.Strategy)}.
|
||||
*/
|
||||
public interface Strategy {
|
||||
<T> Callable<? extends T> toCallable(final InternalContext context,
|
||||
final InternalFactory<? extends T> factory) {
|
||||
return new Callable<T>() {
|
||||
public T call() throws Exception {
|
||||
return factory.create(context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an object for the given type and name in the request scope.
|
||||
* Creates a new object if necessary using the given factory.
|
||||
* Wraps factory with scoping logic.
|
||||
*/
|
||||
<T> T findInRequest(Class<T> type, String name,
|
||||
Callable<? extends T> factory) throws Exception;
|
||||
abstract <T> InternalFactory<? extends T> scopeFactory(
|
||||
Class<T> type, String name, InternalFactory<? extends T> factory);
|
||||
|
||||
/**
|
||||
* Finds an object for the given type and name in the session scope.
|
||||
* Creates a new object if necessary using the given factory.
|
||||
* Pluggable scoping strategy. Enables users to provide custom
|
||||
* implementations of request, session, and wizard scopes. Implement and
|
||||
* pass to {@link
|
||||
* Container#setScopeStrategy(com.opensymphony.xwork2.inject.Scope.Strategy)}.
|
||||
*/
|
||||
<T> T findInSession(Class<T> type, String name,
|
||||
Callable<? extends T> factory) throws Exception;
|
||||
public interface Strategy {
|
||||
|
||||
/**
|
||||
* Finds an object for the given type and name in the wizard scope.
|
||||
* Creates a new object if necessary using the given factory.
|
||||
*/
|
||||
<T> T findInWizard(Class<T> type, String name,
|
||||
Callable<? extends T> factory) throws Exception;
|
||||
}
|
||||
/**
|
||||
* Finds an object for the given type and name in the request scope.
|
||||
* Creates a new object if necessary using the given factory.
|
||||
*/
|
||||
<T> T findInRequest(Class<T> type, String name,
|
||||
Callable<? extends T> factory) throws Exception;
|
||||
|
||||
/**
|
||||
* Finds an object for the given type and name in the session scope.
|
||||
* Creates a new object if necessary using the given factory.
|
||||
*/
|
||||
<T> T findInSession(Class<T> type, String name,
|
||||
Callable<? extends T> factory) throws Exception;
|
||||
|
||||
/**
|
||||
* Finds an object for the given type and name in the wizard scope.
|
||||
* Creates a new object if necessary using the given factory.
|
||||
*/
|
||||
<T> T findInWizard(Class<T> type, String name,
|
||||
Callable<? extends T> factory) throws Exception;
|
||||
}
|
||||
}
|
||||
|
||||
+136
-143
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2006 Google Inc.
|
||||
*
|
||||
* <p/>
|
||||
* 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
|
||||
*
|
||||
* <p/>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p/>
|
||||
* 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.
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.opensymphony.xwork2.inject.util;
|
||||
|
||||
import static com.opensymphony.xwork2.inject.util.ReferenceType.STRONG;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static com.opensymphony.xwork2.inject.util.ReferenceType.STRONG;
|
||||
|
||||
/**
|
||||
* Extends {@link ReferenceMap} to support lazy loading values by overriding
|
||||
* {@link #create(Object)}.
|
||||
@@ -30,155 +30,148 @@ import java.util.concurrent.*;
|
||||
*/
|
||||
public abstract class ReferenceCache<K, V> extends ReferenceMap<K, V> {
|
||||
|
||||
private static final long serialVersionUID = 0;
|
||||
private static final long serialVersionUID = 0;
|
||||
|
||||
transient ConcurrentMap<Object, Future<V>> futures =
|
||||
new ConcurrentHashMap<Object, Future<V>>();
|
||||
transient ConcurrentMap<Object, Future<V>> futures = new ConcurrentHashMap<>();
|
||||
transient ThreadLocal<Future<V>> localFuture = new ThreadLocal<>();
|
||||
|
||||
transient ThreadLocal<Future<V>> localFuture = new ThreadLocal<Future<V>>();
|
||||
public ReferenceCache(ReferenceType keyReferenceType, ReferenceType valueReferenceType) {
|
||||
super(keyReferenceType, valueReferenceType);
|
||||
}
|
||||
|
||||
public ReferenceCache(ReferenceType keyReferenceType,
|
||||
ReferenceType valueReferenceType) {
|
||||
super(keyReferenceType, valueReferenceType);
|
||||
}
|
||||
/**
|
||||
* Equivalent to {@code new ReferenceCache(STRONG, STRONG)}.
|
||||
*/
|
||||
public ReferenceCache() {
|
||||
super(STRONG, STRONG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent to {@code new ReferenceCache(STRONG, STRONG)}.
|
||||
*/
|
||||
public ReferenceCache() {
|
||||
super(STRONG, STRONG);
|
||||
}
|
||||
/**
|
||||
* Override to lazy load values. Use as an alternative to {@link
|
||||
* #put(Object, Object)}. Invoked by getter if value isn't already cached.
|
||||
* Must not return {@code null}. This method will not be called again until
|
||||
* the garbage collector reclaims the returned value.
|
||||
*/
|
||||
protected abstract V create(K key);
|
||||
|
||||
/**
|
||||
* Override to lazy load values. Use as an alternative to {@link
|
||||
* #put(Object,Object)}. Invoked by getter if value isn't already cached.
|
||||
* Must not return {@code null}. This method will not be called again until
|
||||
* the garbage collector reclaims the returned value.
|
||||
*/
|
||||
protected abstract V create(K key);
|
||||
|
||||
V internalCreate(K key) {
|
||||
try {
|
||||
FutureTask<V> futureTask = new FutureTask<V>(
|
||||
new CallableCreate(key));
|
||||
|
||||
// use a reference so we get the same equality semantics.
|
||||
Object keyReference = referenceKey(key);
|
||||
Future<V> future = futures.putIfAbsent(keyReference, futureTask);
|
||||
if (future == null) {
|
||||
// winning thread.
|
||||
V internalCreate(K key) {
|
||||
try {
|
||||
if (localFuture.get() != null) {
|
||||
throw new IllegalStateException(
|
||||
"Nested creations within the same cache are not allowed.");
|
||||
}
|
||||
localFuture.set(futureTask);
|
||||
futureTask.run();
|
||||
V value = futureTask.get();
|
||||
putStrategy().execute(this,
|
||||
keyReference, referenceValue(keyReference, value));
|
||||
return value;
|
||||
} finally {
|
||||
localFuture.remove();
|
||||
futures.remove(keyReference);
|
||||
FutureTask<V> futureTask = new FutureTask<>(new CallableCreate(key));
|
||||
|
||||
// use a reference so we get the same equality semantics.
|
||||
Object keyReference = referenceKey(key);
|
||||
Future<V> future = futures.putIfAbsent(keyReference, futureTask);
|
||||
if (future == null) {
|
||||
// winning thread.
|
||||
try {
|
||||
if (localFuture.get() != null) {
|
||||
throw new IllegalStateException("Nested creations within the same cache are not allowed.");
|
||||
}
|
||||
localFuture.set(futureTask);
|
||||
futureTask.run();
|
||||
V value = futureTask.get();
|
||||
putStrategy().execute(this, keyReference, referenceValue(keyReference, value));
|
||||
return value;
|
||||
} finally {
|
||||
localFuture.remove();
|
||||
futures.remove(keyReference);
|
||||
}
|
||||
} else {
|
||||
// wait for winning thread.
|
||||
return future.get();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
} else if (cause instanceof Error) {
|
||||
throw (Error) cause;
|
||||
}
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
} else {
|
||||
// wait for winning thread.
|
||||
return future.get();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
} else if (cause instanceof Error) {
|
||||
throw (Error) cause;
|
||||
}
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* If this map does not contain an entry for the given key and {@link
|
||||
* #create(Object)} has been overridden, this method will create a new
|
||||
* value, put it in the map, and return it.
|
||||
*
|
||||
* @throws NullPointerException if {@link #create(Object)} returns null.
|
||||
* @throws java.util.concurrent.CancellationException if the creation is
|
||||
* cancelled. See {@link #cancel()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override public V get(final Object key) {
|
||||
V value = super.get(key);
|
||||
return (value == null)
|
||||
? internalCreate((K) key)
|
||||
: value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the current {@link #create(Object)}. Throws {@link
|
||||
* java.util.concurrent.CancellationException} to all clients currently
|
||||
* blocked on {@link #get(Object)}.
|
||||
*/
|
||||
protected void cancel() {
|
||||
Future<V> future = localFuture.get();
|
||||
if (future == null) {
|
||||
throw new IllegalStateException("Not in create().");
|
||||
}
|
||||
future.cancel(false);
|
||||
}
|
||||
|
||||
class CallableCreate implements Callable<V> {
|
||||
|
||||
K key;
|
||||
|
||||
public CallableCreate(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public V call() {
|
||||
// try one more time (a previous future could have come and gone.)
|
||||
V value = internalGet(key);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// create value.
|
||||
value = create(key);
|
||||
if (value == null) {
|
||||
throw new NullPointerException(
|
||||
"create(K) returned null for: " + key);
|
||||
}
|
||||
return value;
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p/>
|
||||
* If this map does not contain an entry for the given key and {@link
|
||||
* #create(Object)} has been overridden, this method will create a new
|
||||
* value, put it in the map, and return it.
|
||||
*
|
||||
* @throws NullPointerException if {@link #create(Object)} returns null.
|
||||
* @throws java.util.concurrent.CancellationException if the creation is
|
||||
* cancelled. See {@link #cancel()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public V get(final Object key) {
|
||||
V value = super.get(key);
|
||||
return (value == null) ? internalCreate((K) key) : value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code ReferenceCache} delegating to the specified {@code
|
||||
* function}. The specified function must not return {@code null}.
|
||||
*/
|
||||
public static <K, V> ReferenceCache<K, V> of(
|
||||
ReferenceType keyReferenceType,
|
||||
ReferenceType valueReferenceType,
|
||||
final Function<? super K, ? extends V> function) {
|
||||
ensureNotNull(function);
|
||||
return new ReferenceCache<K, V>(keyReferenceType, valueReferenceType) {
|
||||
@Override
|
||||
protected V create(K key) {
|
||||
return function.apply(key);
|
||||
}
|
||||
private static final long serialVersionUID = 0;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Cancels the current {@link #create(Object)}. Throws {@link
|
||||
* java.util.concurrent.CancellationException} to all clients currently
|
||||
* blocked on {@link #get(Object)}.
|
||||
*/
|
||||
protected void cancel() {
|
||||
Future<V> future = localFuture.get();
|
||||
if (future == null) {
|
||||
throw new IllegalStateException("Not in create().");
|
||||
}
|
||||
future.cancel(false);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
this.futures = new ConcurrentHashMap<Object, Future<V>>();
|
||||
this.localFuture = new ThreadLocal<Future<V>>();
|
||||
}
|
||||
class CallableCreate implements Callable<V> {
|
||||
|
||||
K key;
|
||||
|
||||
public CallableCreate(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public V call() {
|
||||
// try one more time (a previous future could have come and gone.)
|
||||
V value = internalGet(key);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// create value.
|
||||
value = create(key);
|
||||
if (value == null) {
|
||||
throw new NullPointerException("create(K) returned null for: " + key);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code ReferenceCache} delegating to the specified {@code
|
||||
* function}. The specified function must not return {@code null}.
|
||||
*/
|
||||
public static <K, V> ReferenceCache<K, V> of(
|
||||
ReferenceType keyReferenceType,
|
||||
ReferenceType valueReferenceType,
|
||||
final Function<? super K, ? extends V> function) {
|
||||
ensureNotNull(function);
|
||||
return new ReferenceCache<K, V>(keyReferenceType, valueReferenceType) {
|
||||
@Override
|
||||
protected V create(K key) {
|
||||
return function.apply(key);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0;
|
||||
};
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
this.futures = new ConcurrentHashMap<>();
|
||||
this.localFuture = new ThreadLocal<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,15 +20,15 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ValidationAware;
|
||||
import com.opensymphony.xwork2.XWorkConstants;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClearableValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import com.opensymphony.xwork2.util.LocalizedTextUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -184,9 +184,7 @@ public class AliasInterceptor extends AbstractInterceptor {
|
||||
if (clearableStack && (stack.getContext() != null) && (newStack.getContext() != null))
|
||||
stack.getContext().put(ActionContext.CONVERSION_ERRORS, newStack.getContext().get(ActionContext.CONVERSION_ERRORS));
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("invalid alias expression:" + aliasesKey);
|
||||
}
|
||||
LOG.debug("invalid alias expression: {}", aliasesKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ public class ConversionErrorInterceptor extends AbstractInterceptor {
|
||||
}
|
||||
|
||||
if (fakie == null) {
|
||||
fakie = new HashMap<Object, Object>();
|
||||
fakie = new HashMap<>();
|
||||
}
|
||||
|
||||
fakie.put(propertyName, getOverrideExpr(invocation, value));
|
||||
|
||||
+3
-2
@@ -19,8 +19,9 @@ import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ValidationAware;
|
||||
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -185,7 +186,7 @@ public class DefaultWorkflowInterceptor extends MethodFilterInterceptor {
|
||||
String resultName = currentResultName;
|
||||
InputConfig annotation = action.getClass().getMethod(method, EMPTY_CLASS_ARRAY).getAnnotation(InputConfig.class);
|
||||
if (annotation != null) {
|
||||
if (!annotation.methodName().equals("")) {
|
||||
if (StringUtils.isNotEmpty(annotation.methodName())) {
|
||||
Method m = action.getClass().getMethod(annotation.methodName());
|
||||
resultName = (String) m.invoke(action);
|
||||
} else {
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.LocalizedTextUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -103,9 +103,7 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
protected enum Storage { SESSION, NONE }
|
||||
|
||||
public I18nInterceptor() {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("new I18nInterceptor()");
|
||||
}
|
||||
LOG.debug("new I18nInterceptor()");
|
||||
}
|
||||
|
||||
public void setParameterName(String parameterName) {
|
||||
@@ -123,8 +121,7 @@ public class I18nInterceptor extends AbstractInterceptor {
|
||||
@Override
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Intercept '{}/{}' {",
|
||||
invocation.getProxy().getNamespace(), invocation.getProxy().getActionName());
|
||||
LOG.debug("Intercept '{}/{}' {", invocation.getProxy().getNamespace(), invocation.getProxy().getActionName());
|
||||
}
|
||||
|
||||
LocaleFinder localeFinder = new LocaleFinder(invocation);
|
||||
|
||||
+1
-3
@@ -16,8 +16,8 @@
|
||||
package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
/**
|
||||
@@ -79,9 +79,7 @@ public class LoggingInterceptor extends AbstractInterceptor {
|
||||
}
|
||||
|
||||
message.append(invocation.getProxy().getActionName());
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info(message.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -18,8 +18,8 @@ package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
@@ -104,10 +104,8 @@ public abstract class MethodFilterInterceptor extends AbstractInterceptor {
|
||||
String method = invocation.getProxy().getMethod();
|
||||
// ValidationInterceptor
|
||||
boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);
|
||||
if (log.isDebugEnabled()) {
|
||||
if (!applyMethod) {
|
||||
log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list.");
|
||||
}
|
||||
if (!applyMethod) {
|
||||
log.debug("Skipping Interceptor... Method [{}] found in exclude list.", method);
|
||||
}
|
||||
return applyMethod;
|
||||
}
|
||||
|
||||
+2
-2
@@ -86,7 +86,7 @@ public class MethodFilterInterceptorUtil {
|
||||
for (String pattern : includeMethods) {
|
||||
if (pattern.contains("*")) {
|
||||
int[] compiledPattern = wildcard.compilePattern(pattern);
|
||||
HashMap<String,String> matchedPatterns = new HashMap<String, String>();
|
||||
HashMap<String, String> matchedPatterns = new HashMap<>();
|
||||
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
|
||||
if (matches) {
|
||||
return true; // run it, includeMethods takes precedence
|
||||
@@ -106,7 +106,7 @@ public class MethodFilterInterceptorUtil {
|
||||
for ( String pattern : excludeMethods) {
|
||||
if (pattern.contains("*")) {
|
||||
int[] compiledPattern = wildcard.compilePattern(pattern);
|
||||
HashMap<String,String> matchedPatterns = new HashMap<String, String>();
|
||||
HashMap<String, String> matchedPatterns = new HashMap<>();
|
||||
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
|
||||
if (matches) {
|
||||
// if found, and wasn't included earlier, don't run it
|
||||
|
||||
+9
-10
@@ -17,8 +17,9 @@ package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -106,7 +107,7 @@ public class ParameterFilterInterceptor extends AbstractInterceptor {
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
|
||||
Map<String, Object> parameters = invocation.getInvocationContext().getParameters();
|
||||
HashSet<String> paramsToRemove = new HashSet<String>();
|
||||
HashSet<String> paramsToRemove = new HashSet<>();
|
||||
|
||||
Map<String, Boolean> includesExcludesMap = getIncludesExcludesMap();
|
||||
|
||||
@@ -116,7 +117,7 @@ public class ParameterFilterInterceptor extends AbstractInterceptor {
|
||||
for (String currRule : includesExcludesMap.keySet()) {
|
||||
if (param.startsWith(currRule)
|
||||
&& (param.length() == currRule.length()
|
||||
|| isPropSeperator(param.charAt(currRule.length())))) {
|
||||
|| isPropertySeparator(param.charAt(currRule.length())))) {
|
||||
currentAllowed = includesExcludesMap.get(currRule).booleanValue();
|
||||
}
|
||||
}
|
||||
@@ -125,9 +126,7 @@ public class ParameterFilterInterceptor extends AbstractInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Params to remove: " + paramsToRemove);
|
||||
}
|
||||
LOG.debug("Params to remove: {}", paramsToRemove);
|
||||
|
||||
for (Object aParamsToRemove : paramsToRemove) {
|
||||
parameters.remove(aParamsToRemove);
|
||||
@@ -137,18 +136,18 @@ public class ParameterFilterInterceptor extends AbstractInterceptor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the given char is a property seperator char <code>.([</code>.
|
||||
* Tests if the given char is a property separator char <code>.([</code>.
|
||||
*
|
||||
* @param c the char
|
||||
* @return <tt>true</tt>, if char is property separator, <tt>false</tt> otherwise.
|
||||
*/
|
||||
private static boolean isPropSeperator(char c) {
|
||||
private static boolean isPropertySeparator(char c) {
|
||||
return c == '.' || c == '(' || c == '[';
|
||||
}
|
||||
|
||||
private Map<String, Boolean> getIncludesExcludesMap() {
|
||||
if (this.includesExcludesMap == null) {
|
||||
this.includesExcludesMap = new TreeMap<String, Boolean>();
|
||||
this.includesExcludesMap = new TreeMap<>();
|
||||
|
||||
if (getAllowedCollection() != null) {
|
||||
for (String e : getAllowedCollection()) {
|
||||
@@ -228,7 +227,7 @@ public class ParameterFilterInterceptor extends AbstractInterceptor {
|
||||
* @return A collection from the comma delimited String. Returns <tt>null</tt> if the string is empty.
|
||||
*/
|
||||
private Collection<String> asCollection(String commaDelim) {
|
||||
if (commaDelim == null || commaDelim.trim().length() == 0) {
|
||||
if (StringUtils.isBlank(commaDelim)) {
|
||||
return null;
|
||||
}
|
||||
return TextParseUtil.commaDelimitedStringToSet(commaDelim);
|
||||
|
||||
+7
-11
@@ -18,8 +18,8 @@ package com.opensymphony.xwork2.interceptor;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -84,7 +84,6 @@ public class ParameterRemoverInterceptor extends AbstractInterceptor {
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private Set<String> paramNames = Collections.emptySet();
|
||||
|
||||
private Set<String> paramValues = Collections.emptySet();
|
||||
|
||||
|
||||
@@ -107,18 +106,15 @@ public class ParameterRemoverInterceptor extends AbstractInterceptor {
|
||||
if (parameters.containsKey(removeName)) {
|
||||
|
||||
try {
|
||||
String[] values = (String[]) parameters
|
||||
.get(removeName);
|
||||
String value = values[0];
|
||||
if (null != value && this.paramValues.contains(value)) {
|
||||
String[] values = (String[]) parameters.get(removeName);
|
||||
String value = values[0];
|
||||
if (null != value && this.paramValues.contains(value)) {
|
||||
parameters.remove(removeName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("Failed to convert parameter to string", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.error("Failed to convert parameter to string", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-18
@@ -17,21 +17,18 @@ package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.security.AcceptedPatternsChecker;
|
||||
import com.opensymphony.xwork2.security.ExcludedPatternsChecker;
|
||||
import com.opensymphony.xwork2.ValidationAware;
|
||||
import com.opensymphony.xwork2.XWorkConstants;
|
||||
import com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClearableValueStack;
|
||||
import com.opensymphony.xwork2.util.LocalizedTextUtil;
|
||||
import com.opensymphony.xwork2.util.MemberAccessValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.security.AcceptedPatternsChecker;
|
||||
import com.opensymphony.xwork2.security.ExcludedPatternsChecker;
|
||||
import com.opensymphony.xwork2.util.*;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
@@ -155,7 +152,7 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
|
||||
|
||||
@Inject(XWorkConstants.DEV_MODE)
|
||||
public void setDevMode(String mode) {
|
||||
devMode = "true".equalsIgnoreCase(mode);
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -207,7 +204,7 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
|
||||
final Map<String, Object> parameters = retrieveParameters(ac);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Setting params " + getParameterLogMap(parameters));
|
||||
LOG.debug("Setting params {}", getParameterLogMap(parameters));
|
||||
}
|
||||
|
||||
if (parameters != null) {
|
||||
@@ -256,12 +253,12 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
|
||||
Map<String, Object> params;
|
||||
Map<String, Object> acceptableParameters;
|
||||
if (ordered) {
|
||||
params = new TreeMap<String, Object>(getOrderedComparator());
|
||||
acceptableParameters = new TreeMap<String, Object>(getOrderedComparator());
|
||||
params = new TreeMap<>(getOrderedComparator());
|
||||
acceptableParameters = new TreeMap<>(getOrderedComparator());
|
||||
params.putAll(parameters);
|
||||
} else {
|
||||
params = new TreeMap<String, Object>(parameters);
|
||||
acceptableParameters = new TreeMap<String, Object>();
|
||||
params = new TreeMap<>(parameters);
|
||||
acceptableParameters = new TreeMap<>();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
@@ -447,9 +444,7 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
|
||||
if (devMode) {
|
||||
LOG.warn(message, parameters);
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(message, parameters);
|
||||
}
|
||||
LOG.debug(message, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public class ScopedModelDrivenInterceptor extends AbstractInterceptor {
|
||||
}
|
||||
|
||||
protected Object resolveModel(ObjectFactory factory, ActionContext actionContext, String modelClassName, String modelScope, String modelName) throws Exception {
|
||||
Object model = null;
|
||||
Object model;
|
||||
Map<String, Object> scopeMap = actionContext.getContextMap();
|
||||
if ("session".equals(modelScope)) {
|
||||
scopeMap = actionContext.getSession();
|
||||
|
||||
+14
-16
@@ -19,13 +19,14 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ValidationAware;
|
||||
import com.opensymphony.xwork2.XWorkConstants;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.Parameterizable;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.*;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -84,8 +85,7 @@ public class StaticParametersInterceptor extends AbstractInterceptor {
|
||||
private boolean parse;
|
||||
private boolean overwrite;
|
||||
private boolean merge = true;
|
||||
|
||||
static boolean devMode = false;
|
||||
private boolean devMode = false;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(StaticParametersInterceptor.class);
|
||||
|
||||
@@ -97,16 +97,16 @@ public class StaticParametersInterceptor extends AbstractInterceptor {
|
||||
}
|
||||
|
||||
@Inject(XWorkConstants.DEV_MODE)
|
||||
public static void setDevMode(String mode) {
|
||||
devMode = "true".equals(mode);
|
||||
public void setDevMode(String mode) {
|
||||
devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
public void setParse(String value) {
|
||||
this.parse = Boolean.valueOf(value).booleanValue();
|
||||
this.parse = BooleanUtils.toBoolean(value);
|
||||
}
|
||||
|
||||
public void setMerge(String value) {
|
||||
this.merge = Boolean.valueOf(value).booleanValue();
|
||||
this.merge = BooleanUtils.toBoolean(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ public class StaticParametersInterceptor extends AbstractInterceptor {
|
||||
* @param value
|
||||
*/
|
||||
public void setOverwrite(String value) {
|
||||
this.overwrite = Boolean.valueOf(value).booleanValue();
|
||||
this.overwrite = BooleanUtils.toBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,9 +126,7 @@ public class StaticParametersInterceptor extends AbstractInterceptor {
|
||||
|
||||
final Map<String, String> parameters = config.getParams();
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Setting static parameters " + parameters);
|
||||
}
|
||||
LOG.debug("Setting static parameters: {}", parameters);
|
||||
|
||||
// for actions marked as Parameterizable, pass the static parameters directly
|
||||
if (action instanceof Parameterizable) {
|
||||
@@ -220,18 +218,18 @@ public class StaticParametersInterceptor extends AbstractInterceptor {
|
||||
Map<String, Object> combinedParams;
|
||||
if ( overwrite ) {
|
||||
if (previousParams != null) {
|
||||
combinedParams = new TreeMap<String, Object>(previousParams);
|
||||
combinedParams = new TreeMap<>(previousParams);
|
||||
} else {
|
||||
combinedParams = new TreeMap<String, Object>();
|
||||
combinedParams = new TreeMap<>();
|
||||
}
|
||||
if ( newParams != null) {
|
||||
combinedParams.putAll(newParams);
|
||||
}
|
||||
} else {
|
||||
if (newParams != null) {
|
||||
combinedParams = new TreeMap<String, Object>(newParams);
|
||||
combinedParams = new TreeMap<>(newParams);
|
||||
} else {
|
||||
combinedParams = new TreeMap<String, Object>();
|
||||
combinedParams = new TreeMap<>();
|
||||
}
|
||||
if ( previousParams != null) {
|
||||
combinedParams.putAll(previousParams);
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: description -->
|
||||
@@ -138,7 +139,7 @@ public class TimerInterceptor extends AbstractInterceptor {
|
||||
StringBuilder message = new StringBuilder(100);
|
||||
message.append("Executed action [");
|
||||
String namespace = invocation.getProxy().getNamespace();
|
||||
if ((namespace != null) && (namespace.trim().length() > 0)) {
|
||||
if (StringUtils.isNotBlank(namespace)) {
|
||||
message.append(namespace).append("/");
|
||||
}
|
||||
message.append(invocation.getProxy().getActionName());
|
||||
|
||||
+2
-3
@@ -43,8 +43,8 @@ public class AnnotationParameterFilterIntereptor extends AbstractInterceptor {
|
||||
}
|
||||
|
||||
boolean blockByDefault = action.getClass().isAnnotationPresent(BlockByDefault.class);
|
||||
List<Field> annotatedFields = new ArrayList<Field>();
|
||||
HashSet<String> paramsToRemove = new HashSet<String>();
|
||||
List<Field> annotatedFields = new ArrayList<>();
|
||||
HashSet<String> paramsToRemove = new HashSet<>();
|
||||
|
||||
if (blockByDefault) {
|
||||
AnnotationUtils.addAllFields(Allowed.class, action.getClass(), annotatedFields);
|
||||
@@ -75,7 +75,6 @@ public class AnnotationParameterFilterIntereptor extends AbstractInterceptor {
|
||||
}
|
||||
|
||||
for (String paramName : parameters.keySet()) {
|
||||
|
||||
for (Field field : annotatedFields) {
|
||||
//TODO only matches exact field names. need to change to it matches start of ognl expression
|
||||
//i.e take param name up to first . (period) and match against that
|
||||
|
||||
+2
-3
@@ -113,7 +113,7 @@ public class AnnotationWorkflowInterceptor extends AbstractInterceptor implement
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
final Object action = invocation.getAction();
|
||||
invocation.addPreResultListener(this);
|
||||
List<Method> methods = new ArrayList<Method>(AnnotationUtils.getAnnotatedMethods(action.getClass(), Before.class));
|
||||
List<Method> methods = new ArrayList<>(AnnotationUtils.getAnnotatedMethods(action.getClass(), Before.class));
|
||||
if (methods.size() > 0) {
|
||||
// methods are only sorted by priority
|
||||
Collections.sort(methods, new Comparator<Method>() {
|
||||
@@ -123,8 +123,7 @@ public class AnnotationWorkflowInterceptor extends AbstractInterceptor implement
|
||||
}
|
||||
});
|
||||
for (Method m : methods) {
|
||||
final String resultCode = (String) m
|
||||
.invoke(action, (Object[]) null);
|
||||
final String resultCode = (String) m.invoke(action, (Object[]) null);
|
||||
if (resultCode != null) {
|
||||
// shortcircuit execution
|
||||
return resultCode;
|
||||
|
||||
@@ -40,8 +40,8 @@ public class MockActionInvocation implements ActionInvocation {
|
||||
private Result result;
|
||||
private String resultCode;
|
||||
private ValueStack stack;
|
||||
|
||||
private List<PreResultListener> preResultListeners = new ArrayList<PreResultListener>();
|
||||
|
||||
private List<PreResultListener> preResultListeners = new ArrayList<>();
|
||||
|
||||
public Object getAction() {
|
||||
return action;
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Mock for an {@link ActionProxy}.
|
||||
@@ -110,7 +111,7 @@ public class MockActionProxy implements ActionProxy {
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
methodSpecified=method!=null && !"".equals(method);
|
||||
methodSpecified = StringUtils.isNotEmpty(method);
|
||||
}
|
||||
|
||||
public boolean isMethodSpecified()
|
||||
|
||||
@@ -34,11 +34,7 @@ public class MockResult implements Result {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof MockResult)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return o instanceof MockResult;
|
||||
}
|
||||
|
||||
public void execute(ActionInvocation invocation) throws Exception {
|
||||
|
||||
@@ -26,12 +26,12 @@ import java.util.Map;
|
||||
public class OgnlTypeConverterWrapper implements ognl.TypeConverter {
|
||||
|
||||
private TypeConverter typeConverter;
|
||||
|
||||
public OgnlTypeConverterWrapper(TypeConverter conv) {
|
||||
if (conv == null) {
|
||||
|
||||
public OgnlTypeConverterWrapper(TypeConverter converter) {
|
||||
if (converter == null) {
|
||||
throw new IllegalArgumentException("Wrapped type converter cannot be null");
|
||||
}
|
||||
this.typeConverter = conv;
|
||||
this.typeConverter = converter;
|
||||
}
|
||||
|
||||
public Object convertValue(Map context, Object target, Member member,
|
||||
|
||||
@@ -23,27 +23,18 @@ import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
|
||||
import com.opensymphony.xwork2.util.CompoundRoot;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionException;
|
||||
import ognl.ClassResolver;
|
||||
import ognl.Ognl;
|
||||
import ognl.OgnlContext;
|
||||
import ognl.OgnlException;
|
||||
import ognl.OgnlRuntime;
|
||||
import ognl.SimpleNode;
|
||||
import ognl.TypeConverter;
|
||||
import ognl.*;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -58,16 +49,16 @@ import java.util.regex.Pattern;
|
||||
public class OgnlUtil {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(OgnlUtil.class);
|
||||
private ConcurrentMap<String, Object> expressions = new ConcurrentHashMap<String, Object>();
|
||||
private final ConcurrentMap<Class, BeanInfo> beanInfoCache = new ConcurrentHashMap<Class, BeanInfo>();
|
||||
private ConcurrentMap<String, Object> expressions = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Class, BeanInfo> beanInfoCache = new ConcurrentHashMap<>();
|
||||
private TypeConverter defaultConverter;
|
||||
|
||||
private boolean devMode = false;
|
||||
private boolean enableExpressionCache = true;
|
||||
private boolean enableEvalExpression;
|
||||
|
||||
private Set<Class<?>> excludedClasses = new HashSet<Class<?>>();
|
||||
private Set<Pattern> excludedPackageNamePatterns = new HashSet<Pattern>();
|
||||
private Set<Class<?>> excludedClasses = new HashSet<>();
|
||||
private Set<Pattern> excludedPackageNamePatterns = new HashSet<>();
|
||||
|
||||
private Container container;
|
||||
private boolean allowStaticMethodAccess;
|
||||
@@ -79,12 +70,12 @@ public class OgnlUtil {
|
||||
|
||||
@Inject(XWorkConstants.DEV_MODE)
|
||||
public void setDevMode(String mode) {
|
||||
devMode = "true".equals(mode);
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
@Inject(XWorkConstants.ENABLE_OGNL_EXPRESSION_CACHE)
|
||||
public void setEnableExpressionCache(String cache) {
|
||||
enableExpressionCache = "true".equals(cache);
|
||||
enableExpressionCache = BooleanUtils.toBoolean(cache);
|
||||
}
|
||||
|
||||
@Inject(value = XWorkConstants.ENABLE_OGNL_EVAL_EXPRESSION, required = false)
|
||||
@@ -249,12 +240,9 @@ public class OgnlUtil {
|
||||
|
||||
try {
|
||||
for (Object target : cr) {
|
||||
if (
|
||||
OgnlRuntime.hasSetProperty((OgnlContext) context, target, property)
|
||||
||
|
||||
OgnlRuntime.hasGetProperty((OgnlContext) context, target, property)
|
||||
||
|
||||
OgnlRuntime.getIndexedPropertyType((OgnlContext) context, target.getClass(), property) != OgnlRuntime.INDEXED_PROPERTY_NONE
|
||||
if (OgnlRuntime.hasSetProperty((OgnlContext) context, target, property)
|
||||
|| OgnlRuntime.hasGetProperty((OgnlContext) context, target, property)
|
||||
|| OgnlRuntime.getIndexedPropertyType((OgnlContext) context, target.getClass(), property) != OgnlRuntime.INDEXED_PROPERTY_NONE
|
||||
) {
|
||||
return target;
|
||||
}
|
||||
@@ -269,7 +257,6 @@ public class OgnlUtil {
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper around Ognl.setValue() to handle type conversion for collection elements.
|
||||
* Ideally, this should be handled by OGNL directly.
|
||||
@@ -373,18 +360,15 @@ public class OgnlUtil {
|
||||
*/
|
||||
public void copy(final Object from, final Object to, final Map<String, Object> context, Collection<String> exclusions, Collection<String> inclusions) {
|
||||
if (from == null || to == null) {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("Attempting to copy from or to a null source. This is illegal and is bein skipped. This may be due to an error in an OGNL expression, action chaining, or some other event.");
|
||||
}
|
||||
|
||||
LOG.warn("Attempting to copy from or to a null source. This is illegal and is bein skipped. This may be due to an error in an OGNL expression, action chaining, or some other event.");
|
||||
return;
|
||||
}
|
||||
|
||||
TypeConverter conv = getTypeConverterFromContext(context);
|
||||
TypeConverter converter = getTypeConverterFromContext(context);
|
||||
final Map contextFrom = createDefaultContext(from, null);
|
||||
Ognl.setTypeConverter(contextFrom, conv);
|
||||
Ognl.setTypeConverter(contextFrom, converter);
|
||||
final Map contextTo = createDefaultContext(to, null);
|
||||
Ognl.setTypeConverter(contextTo, conv);
|
||||
Ognl.setTypeConverter(contextTo, converter);
|
||||
|
||||
PropertyDescriptor[] fromPds;
|
||||
PropertyDescriptor[] toPds;
|
||||
@@ -393,13 +377,11 @@ public class OgnlUtil {
|
||||
fromPds = getPropertyDescriptors(from);
|
||||
toPds = getPropertyDescriptors(to);
|
||||
} catch (IntrospectionException e) {
|
||||
if (LOG.isErrorEnabled()) {
|
||||
LOG.error("An error occured", e);
|
||||
}
|
||||
LOG.error("An error occurred", e);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, PropertyDescriptor> toPdHash = new HashMap<String, PropertyDescriptor>();
|
||||
Map<String, PropertyDescriptor> toPdHash = new HashMap<>();
|
||||
|
||||
for (PropertyDescriptor toPd : toPds) {
|
||||
toPdHash.put(toPd.getName(), toPd);
|
||||
@@ -427,9 +409,7 @@ public class OgnlUtil {
|
||||
});
|
||||
|
||||
} catch (OgnlException e) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Got OGNL exception", e);
|
||||
}
|
||||
LOG.debug("Got OGNL exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,7 +471,7 @@ public class OgnlUtil {
|
||||
* @throws OgnlException is thrown by OGNL if the property value could not be retrieved
|
||||
*/
|
||||
public Map<String, Object> getBeanMap(final Object source) throws IntrospectionException, OgnlException {
|
||||
Map<String, Object> beanMap = new HashMap<String, Object>();
|
||||
Map<String, Object> beanMap = new HashMap<>();
|
||||
final Map sourceMap = createDefaultContext(source, null);
|
||||
PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(source);
|
||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
|
||||
@@ -27,11 +27,11 @@ import com.opensymphony.xwork2.util.ClearableValueStack;
|
||||
import com.opensymphony.xwork2.util.CompoundRoot;
|
||||
import com.opensymphony.xwork2.util.MemberAccessValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerUtils;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import ognl.*;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
@@ -97,12 +97,12 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
|
||||
@Inject(XWorkConstants.DEV_MODE)
|
||||
public void setDevMode(String mode) {
|
||||
devMode = "true".equalsIgnoreCase(mode);
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
@Inject(value = "logMissingProperties", required = false)
|
||||
public void setLogMissingProperties(String logMissingProperties) {
|
||||
this.logMissingProperties = "true".equalsIgnoreCase(logMissingProperties);
|
||||
this.logMissingProperties = BooleanUtils.toBoolean(logMissingProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,11 +207,9 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
boolean shouldLog = shouldLogMissingPropertyWarning(e);
|
||||
String msg = null;
|
||||
if (throwExceptionOnFailure || shouldLog) {
|
||||
msg = ErrorMessageBuilder.create()
|
||||
.errorSettingExpressionWithValue(expr, value)
|
||||
.build();
|
||||
}
|
||||
if (shouldLog) {
|
||||
msg = ErrorMessageBuilder.create().errorSettingExpressionWithValue(expr, value).build();
|
||||
}
|
||||
if (shouldLog) {
|
||||
LOG.warn(msg, e);
|
||||
}
|
||||
|
||||
@@ -451,7 +449,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
XWorkConverter xworkConverter = cont.getInstance(XWorkConverter.class);
|
||||
CompoundRootAccessor accessor = (CompoundRootAccessor) cont.getInstance(PropertyAccessor.class, CompoundRoot.class.getName());
|
||||
TextProvider prov = cont.getInstance(TextProvider.class, "system");
|
||||
boolean allow = "true".equals(cont.getInstance(String.class, XWorkConstants.ALLOW_STATIC_METHOD_ACCESS));
|
||||
boolean allow = BooleanUtils.toBoolean(cont.getInstance(String.class, XWorkConstants.ALLOW_STATIC_METHOD_ACCESS));
|
||||
OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, prov, allow);
|
||||
aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class));
|
||||
aStack.setRoot(xworkConverter, accessor, this.root, allow);
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import ognl.MethodAccessor;
|
||||
import ognl.OgnlRuntime;
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -44,8 +45,8 @@ public class OgnlValueStackFactory implements ValueStackFactory {
|
||||
private boolean allowStaticMethodAccess;
|
||||
|
||||
@Inject
|
||||
public void setXWorkConverter(XWorkConverter conv) {
|
||||
this.xworkConverter = conv;
|
||||
public void setXWorkConverter(XWorkConverter converter) {
|
||||
this.xworkConverter = converter;
|
||||
}
|
||||
|
||||
@Inject("system")
|
||||
@@ -55,7 +56,7 @@ public class OgnlValueStackFactory implements ValueStackFactory {
|
||||
|
||||
@Inject(value="allowStaticMethodAccess", required=false)
|
||||
public void setAllowStaticMethodAccess(String allowStaticMethodAccess) {
|
||||
this.allowStaticMethodAccess = "true".equalsIgnoreCase(allowStaticMethodAccess);
|
||||
this.allowStaticMethodAccess = BooleanUtils.toBoolean(allowStaticMethodAccess);
|
||||
}
|
||||
|
||||
public ValueStack createValueStack() {
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.ognl;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import ognl.DefaultMemberAccess;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -53,7 +53,7 @@ public class SecurityMemberAccess extends DefaultMemberAccess {
|
||||
@Override
|
||||
public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
|
||||
if (checkEnumAccess(target, member)) {
|
||||
LOG.trace("Allowing access to enum {}", target);
|
||||
LOG.trace("Allowing access to enum: {}", target);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -89,12 +89,12 @@ public class SecurityMemberAccess extends DefaultMemberAccess {
|
||||
}
|
||||
|
||||
//failed static test
|
||||
if (!allow)
|
||||
if (!allow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now check for standard scope rules
|
||||
return super.isAccessible(context, target, member, propertyName)
|
||||
&& isAcceptableProperty(propertyName);
|
||||
return super.isAccessible(context, target, member, propertyName) && isAcceptableProperty(propertyName);
|
||||
}
|
||||
|
||||
protected boolean checkStaticMethodAccess(Member member) {
|
||||
@@ -109,8 +109,9 @@ public class SecurityMemberAccess extends DefaultMemberAccess {
|
||||
protected boolean checkEnumAccess(Object target, Member member) {
|
||||
if (target instanceof Class) {
|
||||
Class clazz = (Class) target;
|
||||
if (Enum.class.isAssignableFrom(clazz) && member.getName().equals("values"))
|
||||
if (Enum.class.isAssignableFrom(clazz) && member.getName().equals("values")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+9
-13
@@ -21,9 +21,10 @@ import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.ognl.OgnlValueStack;
|
||||
import com.opensymphony.xwork2.util.CompoundRoot;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import ognl.*;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
@@ -58,13 +59,12 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
||||
|
||||
private final static Logger LOG = LogManager.getLogger(CompoundRootAccessor.class);
|
||||
private final static Class[] EMPTY_CLASS_ARRAY = new Class[0];
|
||||
private static Map<MethodCall, Boolean> invalidMethods = new ConcurrentHashMap<MethodCall, Boolean>();
|
||||
|
||||
static boolean devMode = false;
|
||||
private static Map<MethodCall, Boolean> invalidMethods = new ConcurrentHashMap<>();
|
||||
private boolean devMode = false;
|
||||
|
||||
@Inject(XWorkConstants.DEV_MODE)
|
||||
public static void setDevMode(String mode) {
|
||||
devMode = "true".equals(mode);
|
||||
public void setDevMode(String mode) {
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
||||
@@ -121,7 +121,6 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
||||
|
||||
if (name instanceof Integer) {
|
||||
Integer index = (Integer) name;
|
||||
|
||||
return root.cutStack(index);
|
||||
} else if (name instanceof String) {
|
||||
if ("top".equals(name)) {
|
||||
@@ -187,7 +186,7 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
||||
}
|
||||
}
|
||||
|
||||
SortedSet<String> set = new TreeSet<String>();
|
||||
SortedSet<String> set = new TreeSet<>();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (PropertyDescriptor pd : descriptors.values()) {
|
||||
|
||||
@@ -209,12 +208,9 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} catch (IntrospectionException e) {
|
||||
LOG.debug("Got exception in callMethod", e);
|
||||
} catch (OgnlException e) {
|
||||
} catch (IntrospectionException | OgnlException e) {
|
||||
LOG.debug("Got exception in callMethod", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+16
-35
@@ -21,19 +21,17 @@ import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.ognl.OgnlUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
|
||||
import ognl.ObjectPropertyAccessor;
|
||||
import ognl.OgnlException;
|
||||
import ognl.OgnlRuntime;
|
||||
import ognl.SetPropertyAccessor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -42,7 +40,6 @@ import java.util.Map;
|
||||
public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(XWorkCollectionPropertyAccessor.class);
|
||||
private static final String CONTEXT_COLLECTION_MAP = "xworkCollectionPropertyAccessorContextSetMap";
|
||||
|
||||
public static final String KEY_PROPERTY_FOR_CREATION = "makeNew";
|
||||
|
||||
@@ -87,18 +84,13 @@ public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
|
||||
* @see ognl.PropertyAccessor#getProperty(java.util.Map, Object, Object)
|
||||
*/
|
||||
@Override
|
||||
public Object getProperty(Map context, Object target, Object key)
|
||||
throws OgnlException {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering getProperty()");
|
||||
}
|
||||
public Object getProperty(Map context, Object target, Object key) throws OgnlException {
|
||||
LOG.trace("Entering getProperty()");
|
||||
|
||||
//check if it is a generic type property.
|
||||
//if so, return the value from the
|
||||
//superclass which will determine this.
|
||||
if (!ReflectionContextState.isGettingByKeyProperty(context)
|
||||
&& !key.equals(KEY_PROPERTY_FOR_CREATION)) {
|
||||
if (!ReflectionContextState.isGettingByKeyProperty(context) && !key.equals(KEY_PROPERTY_FOR_CREATION)) {
|
||||
return super.getProperty(context, target, key);
|
||||
} else {
|
||||
//reset context property
|
||||
@@ -119,17 +111,15 @@ public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
|
||||
ReflectionContextState.updateCurrentPropertyPath(context, key);
|
||||
return super.getProperty(context, target, key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//get the key property to index the
|
||||
//collection with from the ObjectTypeDeterminer
|
||||
String keyProperty = objectTypeDeterminer
|
||||
.getKeyProperty(lastBeanClass, lastPropertyClass);
|
||||
String keyProperty = objectTypeDeterminer.getKeyProperty(lastBeanClass, lastPropertyClass);
|
||||
|
||||
//get the collection class of the
|
||||
Class collClass = objectTypeDeterminer.getElementClass(lastBeanClass, lastPropertyClass, key);
|
||||
|
||||
Class keyType = null;
|
||||
Class keyType;
|
||||
Class toGetTypeFrom = (collClass != null) ? collClass : c.iterator().next().getClass();
|
||||
try {
|
||||
keyType = OgnlRuntime.getPropertyDescriptor(toGetTypeFrom, keyProperty).getPropertyType();
|
||||
@@ -139,7 +129,7 @@ public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
|
||||
|
||||
|
||||
if (ReflectionContextState.isCreatingNullObjects(context)) {
|
||||
Map collMap = getSetMap(context, c, keyProperty, collClass);
|
||||
Map collMap = getSetMap(context, c, keyProperty);
|
||||
if (key.toString().equals(KEY_PROPERTY_FOR_CREATION)) {
|
||||
//this should return the XWorkList
|
||||
//for this set that contains new entries
|
||||
@@ -171,7 +161,6 @@ public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
|
||||
|
||||
} catch (Exception exc) {
|
||||
throw new OgnlException("Error adding new element to collection", exc);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -194,21 +183,15 @@ public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
|
||||
* Gets an indexed Map by a given key property with the key being
|
||||
* the value of the property and the value being the
|
||||
*/
|
||||
private Map getSetMap(Map context, Collection collection, String property, Class valueClass)
|
||||
throws OgnlException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("getting set Map");
|
||||
}
|
||||
|
||||
private Map getSetMap(Map context, Collection collection, String property) throws OgnlException {
|
||||
LOG.trace("getting set Map");
|
||||
|
||||
String path = ReflectionContextState.getCurrentPropertyPath(context);
|
||||
Map map = ReflectionContextState.getSetMap(context,
|
||||
path);
|
||||
Map map = ReflectionContextState.getSetMap(context, path);
|
||||
|
||||
if (map == null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("creating set Map");
|
||||
}
|
||||
|
||||
LOG.trace("creating set Map");
|
||||
|
||||
map = new HashMap();
|
||||
map.put(null, new SurrugateList(collection));
|
||||
for (Object currTest : collection) {
|
||||
@@ -238,9 +221,7 @@ public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(Map context, Object target, Object name, Object value)
|
||||
throws OgnlException {
|
||||
|
||||
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
||||
Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
|
||||
String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
|
||||
Class convertToClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, name);
|
||||
|
||||
-1
@@ -29,7 +29,6 @@ public class XWorkEnumerationAccessor extends EnumerationPropertyAccessor {
|
||||
|
||||
ObjectPropertyAccessor opa = new ObjectPropertyAccessor();
|
||||
|
||||
|
||||
@Override
|
||||
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
||||
opa.setProperty(context, target, name, value);
|
||||
|
||||
-1
@@ -29,7 +29,6 @@ public class XWorkIteratorPropertyAccessor extends IteratorPropertyAccessor {
|
||||
|
||||
ObjectPropertyAccessor opa = new ObjectPropertyAccessor();
|
||||
|
||||
|
||||
@Override
|
||||
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
||||
opa.setProperty(context, target, name, value);
|
||||
|
||||
+4
-9
@@ -72,17 +72,15 @@ public class XWorkListPropertyAccessor extends ListPropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProperty(Map context, Object target, Object name)
|
||||
throws OgnlException {
|
||||
public Object getProperty(Map context, Object target, Object name) throws OgnlException {
|
||||
|
||||
if (ReflectionContextState.isGettingByKeyProperty(context)
|
||||
|| name.equals(XWorkCollectionPropertyAccessor.KEY_PROPERTY_FOR_CREATION)) {
|
||||
return _sAcc.getProperty(context, target, name);
|
||||
} else if (name instanceof String) {
|
||||
} else if (name instanceof String) {
|
||||
return super.getProperty(context, target, name);
|
||||
}
|
||||
ReflectionContextState.updateCurrentPropertyPath(context, name);
|
||||
//System.out.println("Entering XWorkListPropertyAccessor. Name: " + name);
|
||||
Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
|
||||
String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
|
||||
|
||||
@@ -90,7 +88,6 @@ public class XWorkListPropertyAccessor extends ListPropertyAccessor {
|
||||
&& ReflectionContextState.isCreatingNullObjects(context)
|
||||
&& objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,true)) {
|
||||
|
||||
//System.out.println("Getting index from List");
|
||||
List list = (List) target;
|
||||
int index = ((Number) name).intValue();
|
||||
int listSize = list.size();
|
||||
@@ -100,12 +97,10 @@ public class XWorkListPropertyAccessor extends ListPropertyAccessor {
|
||||
}
|
||||
Class beanClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, name);
|
||||
if (listSize <= index) {
|
||||
Object result = null;
|
||||
Object result;
|
||||
|
||||
for (int i = listSize; i < index; i++) {
|
||||
|
||||
list.add(null);
|
||||
|
||||
}
|
||||
try {
|
||||
list.add(index, result = objectFactory.buildBean(beanClass, context));
|
||||
@@ -114,7 +109,7 @@ public class XWorkListPropertyAccessor extends ListPropertyAccessor {
|
||||
}
|
||||
return result;
|
||||
} else if (list.get(index) == null) {
|
||||
Object result = null;
|
||||
Object result;
|
||||
try {
|
||||
list.set(index, result = objectFactory.buildBean(beanClass, context));
|
||||
} catch (Exception exc) {
|
||||
|
||||
+9
-18
@@ -20,11 +20,11 @@ import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import ognl.MapPropertyAccessor;
|
||||
import ognl.OgnlException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -38,8 +38,7 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(XWorkMapPropertyAccessor.class);
|
||||
|
||||
private static final String[] INDEX_ACCESS_PROPS = new String[]
|
||||
{"size", "isEmpty", "keys", "values"};
|
||||
private static final String[] INDEX_ACCESS_PROPS = new String[]{"size", "isEmpty", "keys", "values"};
|
||||
|
||||
private XWorkConverter xworkConverter;
|
||||
private ObjectFactory objectFactory;
|
||||
@@ -62,10 +61,7 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
|
||||
|
||||
@Override
|
||||
public Object getProperty(Map context, Object target, Object name) throws OgnlException {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering getProperty ("+context+","+target+","+name+")");
|
||||
}
|
||||
LOG.trace("Entering getProperty ({},{},{})", context, target, name);
|
||||
|
||||
ReflectionContextState.updateCurrentPropertyPath(context, name);
|
||||
// if this is one of the regular index access
|
||||
@@ -79,7 +75,7 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
|
||||
|
||||
try{
|
||||
result = super.getProperty(context, target, name);
|
||||
} catch(ClassCastException ex){
|
||||
} catch (ClassCastException ex) {
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
@@ -103,9 +99,7 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
|
||||
result = objectFactory.buildBean(valueClass, context);
|
||||
map.put(key, result);
|
||||
} catch (Exception exc) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -127,16 +121,14 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
|
||||
|
||||
@Override
|
||||
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Entering setProperty("+context+","+target+","+name+","+value+")");
|
||||
}
|
||||
|
||||
LOG.trace("Entering setProperty({},{},{},{})", context, target, name, value);
|
||||
|
||||
Object key = getKey(context, name);
|
||||
Map map = (Map) target;
|
||||
map.put(key, getValue(context, value));
|
||||
}
|
||||
|
||||
private Object getValue(Map context, Object value) {
|
||||
private Object getValue(Map context, Object value) {
|
||||
Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
|
||||
String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
|
||||
if (lastClass == null || lastProperty == null) {
|
||||
@@ -147,7 +139,7 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
|
||||
return value; // nothing is specified, we assume it will be the value passed in.
|
||||
}
|
||||
return xworkConverter.convertValue(context, value, elementClass);
|
||||
}
|
||||
}
|
||||
|
||||
private Object getKey(Map context, Object name) {
|
||||
Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
|
||||
@@ -163,7 +155,6 @@ public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
|
||||
}
|
||||
|
||||
return xworkConverter.convertValue(context, name, keyClass);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-25
@@ -15,21 +15,16 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.ognl.accessor;
|
||||
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import ognl.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import ognl.MethodFailedException;
|
||||
import ognl.ObjectMethodAccessor;
|
||||
import ognl.OgnlContext;
|
||||
import ognl.OgnlRuntime;
|
||||
import ognl.PropertyAccessor;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
|
||||
|
||||
/**
|
||||
* Allows methods to be executed under normal cirumstances, except when {@link ReflectionContextState#DENY_METHOD_EXECUTION}
|
||||
@@ -59,9 +54,8 @@ public class XWorkMethodAccessor extends ObjectMethodAccessor {
|
||||
//this if statement ensures that ognl
|
||||
//statements of the form someBean.mySet('keyPropVal')
|
||||
//return the set element with value of the keyProp given
|
||||
|
||||
if (objects.length==1
|
||||
&& context instanceof OgnlContext) {
|
||||
|
||||
if (objects.length == 1 && context instanceof OgnlContext) {
|
||||
try {
|
||||
OgnlContext ogContext=(OgnlContext)context;
|
||||
if (OgnlRuntime.hasSetProperty(ogContext, object, string)) {
|
||||
@@ -90,11 +84,7 @@ public class XWorkMethodAccessor extends ObjectMethodAccessor {
|
||||
}
|
||||
|
||||
//HACK - we pass indexed method access i.e. setXXX(A,B) pattern
|
||||
if (
|
||||
(objects.length == 2 && string.startsWith("set"))
|
||||
||
|
||||
(objects.length == 1 && string.startsWith("get"))
|
||||
) {
|
||||
if ((objects.length == 2 && string.startsWith("set")) || (objects.length == 1 && string.startsWith("get"))) {
|
||||
Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_INDEXED_ACCESS_EXECUTION);
|
||||
boolean e = ((exec == null) ? false : exec.booleanValue());
|
||||
if (!e) {
|
||||
@@ -111,18 +101,17 @@ public class XWorkMethodAccessor extends ObjectMethodAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
private Object callMethodWithDebugInfo(Map context, Object object, String methodName,
|
||||
Object[] objects) throws MethodFailedException {
|
||||
try {
|
||||
return super.callMethod(context, object, methodName, objects);
|
||||
private Object callMethodWithDebugInfo(Map context, Object object, String methodName, Object[] objects) throws MethodFailedException {
|
||||
try {
|
||||
return super.callMethod(context, object, methodName, objects);
|
||||
}
|
||||
catch(MethodFailedException e) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
if (!(e.getReason() instanceof NoSuchMethodException)) {
|
||||
// the method exists on the target object, but something went wrong
|
||||
LOG.debug( "Error calling method through OGNL: object: [{}] method: [{}] args: [{}]", e.getReason(), object.toString(), methodName, Arrays.toString(objects));
|
||||
}
|
||||
}
|
||||
LOG.debug("Error calling method through OGNL: object: [{}] method: [{}] args: [{}]", e.getReason(), object.toString(), methodName, Arrays.toString(objects));
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -3,8 +3,8 @@ package com.opensymphony.xwork2.security;
|
||||
import com.opensymphony.xwork2.XWorkConstants;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -29,7 +29,7 @@ public class DefaultAcceptedPatternsChecker implements AcceptedPatternsChecker {
|
||||
public void setOverrideAcceptedPatterns(String acceptablePatterns) {
|
||||
LOG.warn("Overriding accepted patterns [{}] with [{}], be aware that this affects all instances and safety of your application!",
|
||||
XWorkConstants.OVERRIDE_ACCEPTED_PATTERNS, acceptablePatterns);
|
||||
acceptedPatterns = new HashSet<Pattern>();
|
||||
acceptedPatterns = new HashSet<>();
|
||||
for (String pattern : TextParseUtil.commaDelimitedStringToSet(acceptablePatterns)) {
|
||||
acceptedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
@@ -48,12 +48,12 @@ public class DefaultAcceptedPatternsChecker implements AcceptedPatternsChecker {
|
||||
}
|
||||
|
||||
public void setAcceptedPatterns(String[] additionalPatterns) {
|
||||
setAcceptedPatterns(new HashSet<String>(Arrays.asList(additionalPatterns)));
|
||||
setAcceptedPatterns(new HashSet<>(Arrays.asList(additionalPatterns)));
|
||||
}
|
||||
|
||||
public void setAcceptedPatterns(Set<String> patterns) {
|
||||
LOG.trace("Sets accepted patterns [{}]", patterns);
|
||||
acceptedPatterns = new HashSet<Pattern>(patterns.size());
|
||||
acceptedPatterns = new HashSet<>(patterns.size());
|
||||
for (String pattern : patterns) {
|
||||
acceptedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
package com.opensymphony.xwork2.security;
|
||||
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.XWorkConstants;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -49,12 +49,12 @@ public class DefaultExcludedPatternsChecker implements ExcludedPatternsChecker {
|
||||
}
|
||||
|
||||
public void setExcludedPatterns(String[] patterns) {
|
||||
setExcludedPatterns(new HashSet<String>(Arrays.asList(patterns)));
|
||||
setExcludedPatterns(new HashSet<>(Arrays.asList(patterns)));
|
||||
}
|
||||
|
||||
public void setExcludedPatterns(Set<String> patterns) {
|
||||
LOG.trace("Sets excluded patterns [{}]", patterns);
|
||||
excludedPatterns = new HashSet<Pattern>(patterns.size());
|
||||
excludedPatterns = new HashSet<>(patterns.size());
|
||||
for (String pattern : patterns) {
|
||||
excludedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.opensymphony.xwork2.spring;
|
||||
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -44,7 +45,7 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
|
||||
protected ApplicationContext appContext;
|
||||
protected AutowireCapableBeanFactory autoWiringFactory;
|
||||
protected int autowireStrategy = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;
|
||||
private final Map<String, Object> classes = new HashMap<String, Object>();
|
||||
private final Map<String, Object> classes = new HashMap<>();
|
||||
private boolean useClassCache = true;
|
||||
private boolean alwaysRespectAutowireStrategy = false;
|
||||
/**
|
||||
@@ -62,7 +63,7 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
|
||||
|
||||
@Inject(value = "enableAopSupport", required = false)
|
||||
public void setEnableAopSupport(String enableAopSupport) {
|
||||
this.enableAopSupport = Boolean.parseBoolean(enableAopSupport);
|
||||
this.enableAopSupport = BooleanUtils.toBoolean(enableAopSupport);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,8 +204,7 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
|
||||
*/
|
||||
public Object autoWireBean(Object bean, AutowireCapableBeanFactory autoWiringFactory) {
|
||||
if (autoWiringFactory != null) {
|
||||
autoWiringFactory.autowireBeanProperties(bean,
|
||||
autowireStrategy, false);
|
||||
autoWiringFactory.autowireBeanProperties(bean, autowireStrategy, false);
|
||||
}
|
||||
injectApplicationContext(bean);
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public class SpringProxyableObjectFactory extends SpringObjectFactory {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(SpringProxyableObjectFactory.class);
|
||||
|
||||
private List<String> skipBeanNames = new ArrayList<String>();
|
||||
private List<String> skipBeanNames = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Object buildBean(String beanName, Map<String, Object> extraContext) throws Exception {
|
||||
|
||||
+2
-4
@@ -20,8 +20,8 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
import com.opensymphony.xwork2.spring.SpringObjectFactory;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -97,9 +97,7 @@ public class ActionAutowiringInterceptor extends AbstractInterceptor implements
|
||||
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||
|
||||
if (applicationContext == null) {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("ApplicationContext could not be found. Action classes will not be autowired.");
|
||||
}
|
||||
LOG.warn("ApplicationContext could not be found. Action classes will not be autowired.");
|
||||
} else {
|
||||
setApplicationContext(applicationContext);
|
||||
factory = new SpringObjectFactory();
|
||||
|
||||
@@ -118,14 +118,14 @@ public class AnnotationUtils {
|
||||
* method {@link AnnotatedElement}s matching the specified {@link Annotation}s
|
||||
*/
|
||||
public static Collection<Method> getAnnotatedMethods(Class clazz, Class<? extends Annotation>... annotation){
|
||||
Collection<Method> toReturn = new HashSet<Method>();
|
||||
|
||||
for(Method m : clazz.getMethods()){
|
||||
if( ArrayUtils.isNotEmpty(annotation) && isAnnotatedBy(m, annotation) ){
|
||||
toReturn.add(m);
|
||||
}else if( ArrayUtils.isEmpty(annotation) && ArrayUtils.isNotEmpty(m.getAnnotations())){
|
||||
toReturn.add(m);
|
||||
}
|
||||
Collection<Method> toReturn = new HashSet<>();
|
||||
|
||||
for (Method m : clazz.getMethods()) {
|
||||
if (org.apache.commons.lang3.ArrayUtils.isNotEmpty(annotation) && isAnnotatedBy(m, annotation)) {
|
||||
toReturn.add(m);
|
||||
} else if (org.apache.commons.lang3.ArrayUtils.isEmpty(annotation) && org.apache.commons.lang3.ArrayUtils.isNotEmpty(m.getAnnotations())) {
|
||||
toReturn.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
@@ -136,7 +136,9 @@ public class AnnotationUtils {
|
||||
* @see AnnotatedElement
|
||||
*/
|
||||
public static boolean isAnnotatedBy(AnnotatedElement annotatedElement, Class<? extends Annotation>... annotation) {
|
||||
if(ArrayUtils.isEmpty(annotation)) return false;
|
||||
if (org.apache.commons.lang3.ArrayUtils.isEmpty(annotation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for( Class<? extends Annotation> c : annotation ){
|
||||
if( annotatedElement.isAnnotationPresent(c) ) return true;
|
||||
@@ -173,20 +175,21 @@ public class AnnotationUtils {
|
||||
* Returns the annotation on the given class or the package of the class. This searchs up the
|
||||
* class hierarchy and the package hierarchy for the closest match.
|
||||
*
|
||||
* @param klass The class to search for the annotation.
|
||||
* @param clazz The class to search for the annotation.
|
||||
* @param annotationClass The Class of the annotation.
|
||||
* @return The annotation or null.
|
||||
*/
|
||||
public static <T extends Annotation> T findAnnotation(Class<?> klass, Class<T> annotationClass) {
|
||||
T ann = klass.getAnnotation(annotationClass);
|
||||
while (ann == null && klass != null) {
|
||||
ann = klass.getAnnotation(annotationClass);
|
||||
if (ann == null)
|
||||
ann = klass.getPackage().getAnnotation(annotationClass);
|
||||
public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) {
|
||||
T ann = clazz.getAnnotation(annotationClass);
|
||||
while (ann == null && clazz != null) {
|
||||
ann = clazz.getAnnotation(annotationClass);
|
||||
if (ann == null) {
|
||||
klass = klass.getSuperclass();
|
||||
if (klass != null ) {
|
||||
ann = klass.getAnnotation(annotationClass);
|
||||
ann = clazz.getPackage().getAnnotation(annotationClass);
|
||||
}
|
||||
if (ann == null) {
|
||||
clazz = clazz.getSuperclass();
|
||||
if (clazz != null) {
|
||||
ann = clazz.getAnnotation(annotationClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Dan Oxlade, dan d0t oxlade at gmail d0t c0m
|
||||
* @deprecated Can be replaced eith ArrayUtils from lang3 package --> org.apache.commons.lang3.ArrayUtils
|
||||
*/
|
||||
@Deprecated
|
||||
public class ArrayUtils {
|
||||
|
||||
public static boolean isEmpty(Object[] array) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ClassLoaderUtil {
|
||||
*/
|
||||
public static Iterator<URL> getResources(String resourceName, Class callingClass, boolean aggregate) throws IOException {
|
||||
|
||||
AggregateIterator<URL> iterator = new AggregateIterator<URL>();
|
||||
AggregateIterator<URL> iterator = new AggregateIterator<>();
|
||||
|
||||
iterator.addEnumeration(Thread.currentThread().getContextClassLoader().getResources(resourceName));
|
||||
|
||||
@@ -182,7 +182,7 @@ public class ClassLoaderUtil {
|
||||
*/
|
||||
static class AggregateIterator<E> implements Iterator<E> {
|
||||
|
||||
LinkedList<Enumeration<E>> enums = new LinkedList<Enumeration<E>>();
|
||||
LinkedList<Enumeration<E>> enums = new LinkedList<>();
|
||||
Enumeration<E> cur = null;
|
||||
E next = null;
|
||||
Set<E> loaded = new HashSet<E>();
|
||||
|
||||
@@ -48,8 +48,8 @@ public class ClassPathFinder {
|
||||
* The PatternMatcher implementation to use
|
||||
*/
|
||||
private PatternMatcher<int[]> patternMatcher = new WildcardHelper();
|
||||
|
||||
private Vector<String> compared = new Vector<String>();
|
||||
|
||||
private Vector<String> compared = new Vector<>();
|
||||
|
||||
/**
|
||||
* retrieves the pattern in use
|
||||
@@ -74,13 +74,13 @@ public class ClassPathFinder {
|
||||
* @return Vector<String> containing matching filenames
|
||||
*/
|
||||
public Vector<String> findMatches() {
|
||||
Vector<String> matches = new Vector<String>();
|
||||
Vector<String> matches = new Vector<>();
|
||||
URLClassLoader cl = getURLClassLoader();
|
||||
if (cl == null ) {
|
||||
throw new XWorkException("unable to attain an URLClassLoader") ;
|
||||
}
|
||||
URL[] parentUrls = cl.getURLs();
|
||||
compiledPattern = (int[]) patternMatcher.compilePattern(pattern);
|
||||
compiledPattern = patternMatcher.compilePattern(pattern);
|
||||
for (URL url : parentUrls) {
|
||||
if (!"file".equals(url.getProtocol())) {
|
||||
continue ;
|
||||
@@ -105,8 +105,8 @@ public class ClassPathFinder {
|
||||
if (entries == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Vector<String> matches = new Vector<String>();
|
||||
|
||||
Vector<String> matches = new Vector<>();
|
||||
for (String listEntry : entries) {
|
||||
File tempFile ;
|
||||
if (!"".equals(prefix) ) {
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import com.opensymphony.xwork2.util.location.LocationAttributes;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -92,7 +92,7 @@ public class DomHelper {
|
||||
factory.setValidating((dtdMappings != null));
|
||||
factory.setNamespaceAware(true);
|
||||
|
||||
SAXParser parser = null;
|
||||
SAXParser parser;
|
||||
try {
|
||||
parser = factory.newSAXParser();
|
||||
} catch (Exception ex) {
|
||||
@@ -344,8 +344,7 @@ public class DomHelper {
|
||||
|
||||
@Override
|
||||
public void error(SAXParseException exception) throws SAXException {
|
||||
LOG.error(exception.getMessage() + " at (" + exception.getPublicId() + ":" +
|
||||
exception.getLineNumber() + ":" + exception.getColumnNumber() + ")", exception);
|
||||
LOG.error("{} at ({}:{}:{})", exception.getMessage(), exception.getPublicId(), exception.getLineNumber(), exception.getColumnNumber(), exception);
|
||||
throw exception;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ModelDriven;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionProviderFactory;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -90,14 +90,14 @@ public class LocalizedTextUtil {
|
||||
|
||||
private static final String TOMCAT_RESOURCE_ENTRIES_FIELD = "resourceEntries";
|
||||
|
||||
private static final ConcurrentMap<Integer, List<String>> classLoaderMap = new ConcurrentHashMap<Integer, List<String>>();
|
||||
private static final ConcurrentMap<Integer, List<String>> classLoaderMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static boolean reloadBundles = false;
|
||||
private static boolean devMode;
|
||||
|
||||
private static final ConcurrentMap<String, ResourceBundle> bundlesMap = new ConcurrentHashMap<String, ResourceBundle>();
|
||||
private static final ConcurrentMap<MessageFormatKey, MessageFormat> messageFormats = new ConcurrentHashMap<MessageFormatKey, MessageFormat>();
|
||||
private static final ConcurrentMap<Integer, ClassLoader> delegatedClassLoaderMap = new ConcurrentHashMap<Integer, ClassLoader>();
|
||||
private static final ConcurrentMap<String, ResourceBundle> bundlesMap = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentMap<MessageFormatKey, MessageFormat> messageFormats = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentMap<Integer, ClassLoader> delegatedClassLoaderMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static final String RELOADED = "com.opensymphony.xwork2.util.LocalizedTextUtil.reloaded";
|
||||
private static final String XWORK_MESSAGES_BUNDLE = "com/opensymphony/xwork2/xwork-messages";
|
||||
@@ -112,7 +112,7 @@ public class LocalizedTextUtil {
|
||||
*/
|
||||
public static void clearDefaultResourceBundles() {
|
||||
ClassLoader ccl = getCurrentThreadContextClassLoader();
|
||||
List<String> bundles = new ArrayList<String>();
|
||||
List<String> bundles = new ArrayList<>();
|
||||
classLoaderMap.put(ccl.hashCode(), bundles);
|
||||
bundles.add(0, XWORK_MESSAGES_BUNDLE);
|
||||
}
|
||||
@@ -417,9 +417,7 @@ public class LocalizedTextUtil {
|
||||
ValueStack valueStack) {
|
||||
String indexedTextName = null;
|
||||
if (aTextName == null) {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("Trying to find text with null key!");
|
||||
}
|
||||
aTextName = "";
|
||||
}
|
||||
// calculate indexedTextName (collection[*]) if applicable
|
||||
@@ -518,12 +516,13 @@ public class LocalizedTextUtil {
|
||||
Class clazz = propertyDescriptor.getPropertyType();
|
||||
|
||||
if (clazz != null) {
|
||||
if (obj != null)
|
||||
if (obj != null) {
|
||||
valueStack.push(obj);
|
||||
}
|
||||
msg = findText(clazz, newKey, locale, null, args);
|
||||
if (obj != null)
|
||||
if (obj != null) {
|
||||
valueStack.pop();
|
||||
|
||||
}
|
||||
if (msg != null) {
|
||||
return msg;
|
||||
}
|
||||
@@ -531,7 +530,7 @@ public class LocalizedTextUtil {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.debug("unable to find property " + prop, e);
|
||||
LOG.debug("unable to find property {}", prop, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class NamedVariablePatternMatcher implements PatternMatcher<NamedVariable
|
||||
public CompiledPattern compilePattern(String data) {
|
||||
StringBuilder regex = new StringBuilder();
|
||||
if (data != null && data.length() > 0) {
|
||||
List<String> varNames = new ArrayList<String>();
|
||||
List<String> varNames = new ArrayList<>();
|
||||
StringBuilder varName = null;
|
||||
for (int x=0; x<data.length(); x++) {
|
||||
char c = data.charAt(x);
|
||||
|
||||
@@ -25,37 +25,54 @@ import java.util.List;
|
||||
* not terminate with new-line chars but rather when there is no
|
||||
* backslash sign a the end of the line. This is used to
|
||||
* concatenate multiple lines for readability.
|
||||
*
|
||||
* <p/>
|
||||
* This class was pulled out of Jakarta Commons Configuration and
|
||||
* Jakarta Commons Lang trunk revision 476093
|
||||
*/
|
||||
public class PropertiesReader extends LineNumberReader
|
||||
{
|
||||
/** Stores the comment lines for the currently processed property.*/
|
||||
public class PropertiesReader extends LineNumberReader {
|
||||
/**
|
||||
* Stores the comment lines for the currently processed property.
|
||||
*/
|
||||
private List<String> commentLines;
|
||||
|
||||
/** Stores the name of the last read property.*/
|
||||
/**
|
||||
* Stores the name of the last read property.
|
||||
*/
|
||||
private String propertyName;
|
||||
|
||||
/** Stores the value of the last read property.*/
|
||||
/**
|
||||
* Stores the value of the last read property.
|
||||
*/
|
||||
private String propertyValue;
|
||||
|
||||
/** Stores the list delimiter character.*/
|
||||
/**
|
||||
* Stores the list delimiter character.
|
||||
*/
|
||||
private char delimiter;
|
||||
|
||||
/** Constant for the supported comment characters.*/
|
||||
|
||||
/**
|
||||
* Constant for the supported comment characters.
|
||||
*/
|
||||
static final String COMMENT_CHARS = "#!";
|
||||
|
||||
/** Constant for the radix of hex numbers.*/
|
||||
|
||||
/**
|
||||
* Constant for the radix of hex numbers.
|
||||
*/
|
||||
private static final int HEX_RADIX = 16;
|
||||
|
||||
/** Constant for the length of a unicode literal.*/
|
||||
/**
|
||||
* Constant for the length of a unicode literal.
|
||||
*/
|
||||
private static final int UNICODE_LEN = 4;
|
||||
|
||||
/** The list of possible key/value separators */
|
||||
private static final char[] SEPARATORS = new char[] {'=', ':'};
|
||||
|
||||
/** The white space characters used as key/value separators. */
|
||||
/**
|
||||
* The list of possible key/value separators
|
||||
*/
|
||||
private static final char[] SEPARATORS = new char[]{'=', ':'};
|
||||
|
||||
/**
|
||||
* The white space characters used as key/value separators.
|
||||
*/
|
||||
private static final char[] WHITE_SPACE = new char[]{' ', '\t', '\f'};
|
||||
|
||||
/**
|
||||
@@ -63,8 +80,7 @@ public class PropertiesReader extends LineNumberReader
|
||||
*
|
||||
* @param reader A Reader.
|
||||
*/
|
||||
public PropertiesReader(Reader reader)
|
||||
{
|
||||
public PropertiesReader(Reader reader) {
|
||||
this(reader, ',');
|
||||
}
|
||||
|
||||
@@ -72,17 +88,16 @@ public class PropertiesReader extends LineNumberReader
|
||||
* Creates a new instance of <code>PropertiesReader</code> and sets
|
||||
* the underlaying reader and the list delimiter.
|
||||
*
|
||||
* @param reader the reader
|
||||
* @param reader the reader
|
||||
* @param listDelimiter the list delimiter character
|
||||
* @since 1.3
|
||||
*/
|
||||
public PropertiesReader(Reader reader, char listDelimiter)
|
||||
{
|
||||
public PropertiesReader(Reader reader, char listDelimiter) {
|
||||
super(reader);
|
||||
commentLines = new ArrayList<String>();
|
||||
delimiter = listDelimiter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests whether a line is a comment, i.e. whether it starts with a comment
|
||||
* character.
|
||||
@@ -91,8 +106,7 @@ public class PropertiesReader extends LineNumberReader
|
||||
* @return a flag if this is a comment line
|
||||
* @since 1.3
|
||||
*/
|
||||
boolean isCommentLine(String line)
|
||||
{
|
||||
boolean isCommentLine(String line) {
|
||||
String s = line.trim();
|
||||
// blanc lines are also treated as comment lines
|
||||
return s.length() < 1 || COMMENT_CHARS.indexOf(s.charAt(0)) >= 0;
|
||||
@@ -106,38 +120,30 @@ public class PropertiesReader extends LineNumberReader
|
||||
* = <code><value></code>)
|
||||
*
|
||||
* @return A string containing a property value or null
|
||||
*
|
||||
* @throws IOException in case of an I/O error
|
||||
*/
|
||||
public String readProperty() throws IOException
|
||||
{
|
||||
public String readProperty() throws IOException {
|
||||
commentLines.clear();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
String line = readLine();
|
||||
if (line == null)
|
||||
{
|
||||
if (line == null) {
|
||||
// EOF
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isCommentLine(line))
|
||||
{
|
||||
if (isCommentLine(line)) {
|
||||
commentLines.add(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
line = line.trim();
|
||||
|
||||
if (checkCombineLines(line))
|
||||
{
|
||||
if (checkCombineLines(line)) {
|
||||
line = line.substring(0, line.length() - 1);
|
||||
buffer.append(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
buffer.append(line);
|
||||
break;
|
||||
}
|
||||
@@ -156,12 +162,10 @@ public class PropertiesReader extends LineNumberReader
|
||||
* @throws IOException if an error occurs
|
||||
* @since 1.3
|
||||
*/
|
||||
public boolean nextProperty() throws IOException
|
||||
{
|
||||
public boolean nextProperty() throws IOException {
|
||||
String line = readProperty();
|
||||
|
||||
if (line == null)
|
||||
{
|
||||
if (line == null) {
|
||||
return false; // EOF
|
||||
}
|
||||
|
||||
@@ -179,8 +183,7 @@ public class PropertiesReader extends LineNumberReader
|
||||
* <code>readProperty()</code>
|
||||
* @since 1.3
|
||||
*/
|
||||
public List<String> getCommentLines()
|
||||
{
|
||||
public List<String> getCommentLines() {
|
||||
return commentLines;
|
||||
}
|
||||
|
||||
@@ -192,8 +195,7 @@ public class PropertiesReader extends LineNumberReader
|
||||
* @return the name of the last read property
|
||||
* @since 1.3
|
||||
*/
|
||||
public String getPropertyName()
|
||||
{
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
@@ -205,8 +207,7 @@ public class PropertiesReader extends LineNumberReader
|
||||
* @return the value of the last read property
|
||||
* @since 1.3
|
||||
*/
|
||||
public String getPropertyValue()
|
||||
{
|
||||
public String getPropertyValue() {
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
@@ -217,11 +218,9 @@ public class PropertiesReader extends LineNumberReader
|
||||
* @param line the line
|
||||
* @return a flag if the lines should be combined
|
||||
*/
|
||||
private boolean checkCombineLines(String line)
|
||||
{
|
||||
private boolean checkCombineLines(String line) {
|
||||
int bsCount = 0;
|
||||
for (int idx = line.length() - 1; idx >= 0 && line.charAt(idx) == '\\'; idx--)
|
||||
{
|
||||
for (int idx = line.length() - 1; idx >= 0 && line.charAt(idx) == '\\'; idx--) {
|
||||
bsCount++;
|
||||
}
|
||||
|
||||
@@ -235,8 +234,7 @@ public class PropertiesReader extends LineNumberReader
|
||||
* @return an array with the property's key and value
|
||||
* @since 1.2
|
||||
*/
|
||||
private String[] parseProperty(String line)
|
||||
{
|
||||
private String[] parseProperty(String line) {
|
||||
// sorry for this spaghetti code, please replace it as soon as
|
||||
// possible with a regexp when the Java 1.3 requirement is dropped
|
||||
|
||||
@@ -251,42 +249,30 @@ public class PropertiesReader extends LineNumberReader
|
||||
// 3: value parsing
|
||||
int state = 0;
|
||||
|
||||
for (int pos = 0; pos < line.length(); pos++)
|
||||
{
|
||||
for (int pos = 0; pos < line.length(); pos++) {
|
||||
char c = line.charAt(pos);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (c == '\\')
|
||||
{
|
||||
if (c == '\\') {
|
||||
state = 1;
|
||||
}
|
||||
else if (contains(WHITE_SPACE, c))
|
||||
{
|
||||
} else if (contains(WHITE_SPACE, c)) {
|
||||
// switch to the separator crossing state
|
||||
state = 2;
|
||||
}
|
||||
else if (contains(SEPARATORS, c))
|
||||
{
|
||||
} else if (contains(SEPARATORS, c)) {
|
||||
// switch to the value parsing state
|
||||
state = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
key.append(c);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (contains(SEPARATORS, c) || contains(WHITE_SPACE, c))
|
||||
{
|
||||
if (contains(SEPARATORS, c) || contains(WHITE_SPACE, c)) {
|
||||
// this is an escaped separator or white space
|
||||
key.append(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// another escaped character, the '\' is preserved
|
||||
key.append('\\');
|
||||
key.append(c);
|
||||
@@ -298,18 +284,13 @@ public class PropertiesReader extends LineNumberReader
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (contains(WHITE_SPACE, c))
|
||||
{
|
||||
if (contains(WHITE_SPACE, c)) {
|
||||
// do nothing, eat all white spaces
|
||||
state = 2;
|
||||
}
|
||||
else if (contains(SEPARATORS, c))
|
||||
{
|
||||
} else if (contains(SEPARATORS, c)) {
|
||||
// switch to the value parsing state
|
||||
state = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// any other character indicates we encoutered the beginning of the value
|
||||
value.append(c);
|
||||
|
||||
@@ -330,22 +311,20 @@ public class PropertiesReader extends LineNumberReader
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Unescapes any Java literals found in the <code>String</code> to a
|
||||
* <code>Writer</code>.</p> This is a slightly modified version of the
|
||||
* StringEscapeUtils.unescapeJava() function in commons-lang that doesn't
|
||||
* drop escaped separators (i.e '\,').
|
||||
*
|
||||
* @param str the <code>String</code> to unescape, may be null
|
||||
* @param str the <code>String</code> to unescape, may be null
|
||||
* @param delimiter the delimiter for multi-valued properties
|
||||
* @return the processed string
|
||||
* @throws IllegalArgumentException if the Writer is <code>null</code>
|
||||
*/
|
||||
protected static String unescapeJava(String str, char delimiter)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
protected static String unescapeJava(String str, char delimiter) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
int sz = str.length();
|
||||
@@ -353,98 +332,67 @@ public class PropertiesReader extends LineNumberReader
|
||||
StringBuffer unicode = new StringBuffer(UNICODE_LEN);
|
||||
boolean hadSlash = false;
|
||||
boolean inUnicode = false;
|
||||
for (int i = 0; i < sz; i++)
|
||||
{
|
||||
for (int i = 0; i < sz; i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (inUnicode)
|
||||
{
|
||||
if (inUnicode) {
|
||||
// if in unicode, then we're reading unicode
|
||||
// values in somehow
|
||||
unicode.append(ch);
|
||||
if (unicode.length() == UNICODE_LEN)
|
||||
{
|
||||
if (unicode.length() == UNICODE_LEN) {
|
||||
// unicode now contains the four hex digits
|
||||
// which represents our unicode character
|
||||
try
|
||||
{
|
||||
try {
|
||||
int value = Integer.parseInt(unicode.toString(), HEX_RADIX);
|
||||
out.append((char) value);
|
||||
unicode.setLength(0);
|
||||
inUnicode = false;
|
||||
hadSlash = false;
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new RuntimeException("Unable to parse unicode value: " + unicode, nfe);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hadSlash)
|
||||
{
|
||||
if (hadSlash) {
|
||||
// handle an escaped value
|
||||
hadSlash = false;
|
||||
|
||||
if (ch == '\\')
|
||||
{
|
||||
if (ch == '\\') {
|
||||
out.append('\\');
|
||||
}
|
||||
else if (ch == '\'')
|
||||
{
|
||||
} else if (ch == '\'') {
|
||||
out.append('\'');
|
||||
}
|
||||
else if (ch == '\"')
|
||||
{
|
||||
} else if (ch == '\"') {
|
||||
out.append('"');
|
||||
}
|
||||
else if (ch == 'r')
|
||||
{
|
||||
} else if (ch == 'r') {
|
||||
out.append('\r');
|
||||
}
|
||||
else if (ch == 'f')
|
||||
{
|
||||
} else if (ch == 'f') {
|
||||
out.append('\f');
|
||||
}
|
||||
else if (ch == 't')
|
||||
{
|
||||
} else if (ch == 't') {
|
||||
out.append('\t');
|
||||
}
|
||||
else if (ch == 'n')
|
||||
{
|
||||
} else if (ch == 'n') {
|
||||
out.append('\n');
|
||||
}
|
||||
else if (ch == 'b')
|
||||
{
|
||||
} else if (ch == 'b') {
|
||||
out.append('\b');
|
||||
}
|
||||
else if (ch == delimiter)
|
||||
{
|
||||
} else if (ch == delimiter) {
|
||||
out.append('\\');
|
||||
out.append(delimiter);
|
||||
}
|
||||
else if (ch == 'u')
|
||||
{
|
||||
} else if (ch == 'u') {
|
||||
// uh-oh, we're in unicode country....
|
||||
inUnicode = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
out.append(ch);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
else if (ch == '\\')
|
||||
{
|
||||
} else if (ch == '\\') {
|
||||
hadSlash = true;
|
||||
continue;
|
||||
}
|
||||
out.append(ch);
|
||||
}
|
||||
|
||||
if (hadSlash)
|
||||
{
|
||||
if (hadSlash) {
|
||||
// then we're in the weird case of a \ at the end of the
|
||||
// string, let's output it anyway.
|
||||
out.append('\\');
|
||||
@@ -452,14 +400,14 @@ public class PropertiesReader extends LineNumberReader
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Checks if the object is in the given array.</p>
|
||||
*
|
||||
* <p/>
|
||||
* <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p>
|
||||
*
|
||||
* @param array the array to search through
|
||||
* @param objectToFind the object to find
|
||||
*
|
||||
* @param array the array to search through
|
||||
* @param objectToFind the object to find
|
||||
* @return <code>true</code> if the array contains the object
|
||||
*/
|
||||
public boolean contains(char[] array, char objectToFind) {
|
||||
@@ -473,14 +421,14 @@ public class PropertiesReader extends LineNumberReader
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Unescapes any Java literals found in the <code>String</code>.
|
||||
* For example, it will turn a sequence of <code>'\'</code> and
|
||||
* <code>'n'</code> into a newline character, unless the <code>'\'</code>
|
||||
* is preceded by another <code>'\'</code>.</p>
|
||||
*
|
||||
* @param str the <code>String</code> to unescape, may be null
|
||||
*
|
||||
* @param str the <code>String</code> to unescape, may be null
|
||||
* @return a new unescaped <code>String</code>, <code>null</code> if null string input
|
||||
*/
|
||||
public static String unescapeJava(String str) {
|
||||
@@ -501,17 +449,17 @@ public class PropertiesReader extends LineNumberReader
|
||||
/**
|
||||
* <p>Unescapes any Java literals found in the <code>String</code> to a
|
||||
* <code>Writer</code>.</p>
|
||||
*
|
||||
* <p/>
|
||||
* <p>For example, it will turn a sequence of <code>'\'</code> and
|
||||
* <code>'n'</code> into a newline character, unless the <code>'\'</code>
|
||||
* is preceded by another <code>'\'</code>.</p>
|
||||
*
|
||||
* <p/>
|
||||
* <p>A <code>null</code> string input has no effect.</p>
|
||||
*
|
||||
* @param out the <code>Writer</code> used to output unescaped characters
|
||||
* @param str the <code>String</code> to unescape, may be null
|
||||
*
|
||||
* @param out the <code>Writer</code> used to output unescaped characters
|
||||
* @param str the <code>String</code> to unescape, may be null
|
||||
* @throws IllegalArgumentException if the Writer is <code>null</code>
|
||||
* @throws IOException if error occurs on underlying Writer
|
||||
* @throws IOException if error occurs on underlying Writer
|
||||
*/
|
||||
public static void unescapeJava(Writer out, String str) throws IOException {
|
||||
if (out == null) {
|
||||
@@ -573,13 +521,12 @@ public class PropertiesReader extends LineNumberReader
|
||||
case 'b':
|
||||
out.write('\b');
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
// uh-oh, we're in unicode country....
|
||||
inUnicode = true;
|
||||
break;
|
||||
}
|
||||
default :
|
||||
case 'u': {
|
||||
// uh-oh, we're in unicode country....
|
||||
inUnicode = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
out.write(ch);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,7 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -119,7 +115,7 @@ public class TextParseUtil {
|
||||
/**
|
||||
* Converted object from variable translation.
|
||||
*
|
||||
* @param open
|
||||
* @param openChars
|
||||
* @param expression
|
||||
* @param stack
|
||||
* @param asType
|
||||
@@ -147,7 +143,7 @@ public class TextParseUtil {
|
||||
/**
|
||||
* Converted object from variable translation.
|
||||
*
|
||||
* @param open
|
||||
* @param openChars
|
||||
* @param expression
|
||||
* @param stack
|
||||
* @param asType
|
||||
@@ -216,7 +212,7 @@ public class TextParseUtil {
|
||||
if (result instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> casted = (Collection<Object>)result;
|
||||
resultCol = new ArrayList<String>();
|
||||
resultCol = new ArrayList<>();
|
||||
|
||||
XWorkConverter conv = ((Container)context.get(ActionContext.CONTAINER)).getInstance(XWorkConverter.class);
|
||||
|
||||
@@ -230,7 +226,7 @@ public class TextParseUtil {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resultCol = new ArrayList<String>();
|
||||
resultCol = new ArrayList<>();
|
||||
String resultStr = translateVariables(expression, stack, evaluator);
|
||||
if (shallBeIncluded(resultStr, excludeEmptyElements)) {
|
||||
resultCol.add(resultStr);
|
||||
@@ -258,7 +254,7 @@ public class TextParseUtil {
|
||||
* @return A set from comma delimted Strings.
|
||||
*/
|
||||
public static Set<String> commaDelimitedStringToSet(String s) {
|
||||
Set<String> set = new HashSet<String>();
|
||||
Set<String> set = new HashSet<>();
|
||||
String[] split = s.split(",");
|
||||
for (String aSplit : split) {
|
||||
String trimmed = aSplit.trim();
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.util;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
@@ -46,10 +48,14 @@ public class URLUtil {
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(url);
|
||||
|
||||
URL u = new URL(url);
|
||||
URI uri = u.toURI(); // perform a additional url syntax check
|
||||
if (uri.getHost() == null) {
|
||||
LOG.debug("Url [{}] does not contains a valid host: {}", url, uri);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (MalformedURLException e) {
|
||||
} catch (MalformedURLException | URISyntaxException e) {
|
||||
LOG.debug("Url [{}] is invalid: {}", url, e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverter;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -98,18 +98,18 @@ public class XWorkList extends ArrayList {
|
||||
* <p/>
|
||||
* This method performs any necessary type conversion.
|
||||
*
|
||||
* @param c the elements to be inserted into this list.
|
||||
* @param collection the elements to be inserted into this list.
|
||||
* @return <tt>true</tt> if this list changed as a result of the call.
|
||||
* @throws NullPointerException if the specified collection is null.
|
||||
*/
|
||||
@Override
|
||||
public boolean addAll(Collection c) {
|
||||
if (c == null) {
|
||||
public boolean addAll(Collection collection) {
|
||||
if (collection == null) {
|
||||
throw new NullPointerException("Collection to add is null");
|
||||
}
|
||||
|
||||
for (Object aC : c) {
|
||||
add(aC);
|
||||
for (Object nextElement : collection) {
|
||||
add(nextElement);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -126,12 +126,12 @@ public class XWorkList extends ArrayList {
|
||||
* also performs any necessary type conversion.
|
||||
*
|
||||
* @param index index at which to insert first element from the specified collection.
|
||||
* @param c elements to be inserted into this list.
|
||||
* @param collection elements to be inserted into this list.
|
||||
* @return <tt>true</tt> if this list changed as a result of the call.
|
||||
*/
|
||||
@Override
|
||||
public boolean addAll(int index, Collection c) {
|
||||
if (c == null) {
|
||||
public boolean addAll(int index, Collection collection) {
|
||||
if (collection == null) {
|
||||
throw new NullPointerException("Collection to add is null");
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class XWorkList extends ArrayList {
|
||||
trim = true;
|
||||
}
|
||||
|
||||
for (Iterator it = c.iterator(); it.hasNext(); index++) {
|
||||
for (Iterator it = collection.iterator(); it.hasNext(); index++) {
|
||||
add(index, it.next());
|
||||
}
|
||||
|
||||
@@ -203,12 +203,10 @@ public class XWorkList extends ArrayList {
|
||||
private Object convert(Object element) {
|
||||
if ((element != null) && !clazz.isAssignableFrom(element.getClass())) {
|
||||
// convert to correct type
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Converting from " + element.getClass().getName() + " to " + clazz.getName());
|
||||
}
|
||||
TypeConverter conv = getTypeConverter();
|
||||
LOG.debug("Converting from {} to {}", element.getClass().getName(), clazz.getName());
|
||||
TypeConverter converter = getTypeConverter();
|
||||
Map<String, Object> context = ActionContext.getContext().getContextMap();
|
||||
element = conv.convertValue(context, null, null, null, element, clazz);
|
||||
element = converter.convertValue(context, null, null, null, element, clazz);
|
||||
}
|
||||
|
||||
return element;
|
||||
@@ -221,7 +219,6 @@ public class XWorkList extends ArrayList {
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
element = convert(element);
|
||||
|
||||
return super.contains(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,7 @@ public class XWorkTestCaseHelper {
|
||||
public void init(Configuration configuration) throws ConfigurationException {}
|
||||
public boolean needsReload() { return false; }
|
||||
|
||||
public void register(ContainerBuilder builder,
|
||||
LocatableProperties props) throws ConfigurationException {
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
builder.setAllowDuplicates(true);
|
||||
}
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2002-2015 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.util.classloader;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
public abstract class AbstractResourceStore implements ResourceStore {
|
||||
private static final Logger log = LogManager.getLogger(JarResourceStore.class);
|
||||
protected final File file;
|
||||
|
||||
public AbstractResourceStore(final File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
protected void closeQuietly(InputStream is) {
|
||||
try {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Unable to close file input stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(String pResourceName, byte[] pResourceData) {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getName() + file.toString();
|
||||
}
|
||||
}
|
||||
+5
-25
@@ -15,25 +15,22 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.util.classloader;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
/**
|
||||
* Reads a class from disk
|
||||
* class taken from Apache JCI
|
||||
*/
|
||||
public final class FileResourceStore implements ResourceStore {
|
||||
public final class FileResourceStore extends AbstractResourceStore {
|
||||
private static final Logger LOG = LogManager.getLogger(FileResourceStore.class);
|
||||
private final File root;
|
||||
|
||||
public FileResourceStore(final File pFile) {
|
||||
root = pFile;
|
||||
public FileResourceStore(final File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
public byte[] read(final String pResourceName) {
|
||||
@@ -53,25 +50,8 @@ public final class FileResourceStore implements ResourceStore {
|
||||
}
|
||||
}
|
||||
|
||||
public void write(final String pResourceName, final byte[] pData) {
|
||||
|
||||
}
|
||||
|
||||
private void closeQuietly(InputStream is) {
|
||||
try {
|
||||
if (is != null)
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
LOG.error("Unable to close file input stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
private File getFile(final String pResourceName) {
|
||||
final String fileName = pResourceName.replace('/', File.separatorChar);
|
||||
return new File(root, fileName);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getName() + root.toString();
|
||||
return new File(file, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-19
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.opensymphony.xwork2.util.classloader;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -26,16 +26,11 @@ import java.util.zip.ZipFile;
|
||||
/**
|
||||
* Read resources from a jar file
|
||||
*/
|
||||
public class JarResourceStore implements ResourceStore {
|
||||
public class JarResourceStore extends AbstractResourceStore {
|
||||
private static final Logger LOG = LogManager.getLogger(JarResourceStore.class);
|
||||
|
||||
private final File file;
|
||||
|
||||
public JarResourceStore(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public void write(String pResourceName, byte[] pResourceData) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
public byte[] read(String pResourceName) {
|
||||
@@ -58,8 +53,7 @@ public class JarResourceStore implements ResourceStore {
|
||||
}
|
||||
}
|
||||
|
||||
public static long copy(InputStream input, OutputStream output)
|
||||
throws IOException {
|
||||
public static long copy(InputStream input, OutputStream output) throws IOException {
|
||||
byte[] buffer = new byte[1024 * 4];
|
||||
long count = 0;
|
||||
int n = 0;
|
||||
@@ -69,13 +63,4 @@ public class JarResourceStore implements ResourceStore {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private void closeQuietly(InputStream is) {
|
||||
try {
|
||||
if (is != null)
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
LOG.error("Unable to close input stream", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -19,9 +19,9 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
@@ -125,8 +125,7 @@ public class ReloadingClassLoader extends ClassLoader {
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
if (LOG.isTraceEnabled())
|
||||
LOG.trace("Reloading class loader");
|
||||
LOG.trace("Reloading class loader");
|
||||
delegate = new ResourceStoreClassLoader(parent, stores);
|
||||
}
|
||||
|
||||
|
||||
-6
@@ -15,16 +15,11 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.util.classloader;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
/**
|
||||
* class taken from Apache JCI
|
||||
*/
|
||||
public final class ResourceStoreClassLoader extends ClassLoader {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(ResourceStoreClassLoader.class);
|
||||
|
||||
private final ResourceStore[] stores;
|
||||
|
||||
public ResourceStoreClassLoader(final ClassLoader pParent, final ResourceStore[] pStores) {
|
||||
@@ -63,7 +58,6 @@ public final class ResourceStoreClassLoader extends ClassLoader {
|
||||
} else {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public interface ClassFinder {
|
||||
}
|
||||
|
||||
public class Annotatable {
|
||||
private final List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>();
|
||||
private final List<AnnotationInfo> annotations = new ArrayList<>();
|
||||
|
||||
public Annotatable(AnnotatedElement element) {
|
||||
for (Annotation annotation : element.getAnnotations()) {
|
||||
@@ -136,12 +136,12 @@ public interface ClassFinder {
|
||||
|
||||
public class ClassInfo extends Annotatable implements Info {
|
||||
private final String name;
|
||||
private final List<MethodInfo> methods = new ArrayList<MethodInfo>();
|
||||
private final List<MethodInfo> constructors = new ArrayList<MethodInfo>();
|
||||
private final List<MethodInfo> methods = new ArrayList<>();
|
||||
private final List<MethodInfo> constructors = new ArrayList<>();
|
||||
private final String superType;
|
||||
private final List<String> interfaces = new ArrayList<String>();
|
||||
private final List<String> superInterfaces = new ArrayList<String>();
|
||||
private final List<FieldInfo> fields = new ArrayList<FieldInfo>();
|
||||
private final List<String> interfaces = new ArrayList<>();
|
||||
private final List<String> superInterfaces = new ArrayList<>();
|
||||
private final List<FieldInfo> fields = new ArrayList<>();
|
||||
private Class<?> clazz;
|
||||
private ClassFinder classFinder;
|
||||
private ClassNotFoundException notFound;
|
||||
@@ -216,7 +216,7 @@ public interface ClassFinder {
|
||||
private final ClassInfo declaringClass;
|
||||
private final String returnType;
|
||||
private final String name;
|
||||
private final List<List<AnnotationInfo>> parameterAnnotations = new ArrayList<List<AnnotationInfo>>();
|
||||
private final List<List<AnnotationInfo>> parameterAnnotations = new ArrayList<>();
|
||||
|
||||
public MethodInfo(ClassInfo info, Constructor constructor){
|
||||
super(constructor);
|
||||
@@ -245,7 +245,7 @@ public interface ClassFinder {
|
||||
public List<AnnotationInfo> getParameterAnnotations(int index) {
|
||||
if (index >= parameterAnnotations.size()) {
|
||||
for (int i = parameterAnnotations.size(); i <= index; i++) {
|
||||
List<AnnotationInfo> annotationInfos = new ArrayList<AnnotationInfo>();
|
||||
List<AnnotationInfo> annotationInfos = new ArrayList<>();
|
||||
parameterAnnotations.add(i, annotationInfos);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-34
@@ -19,9 +19,9 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.XWorkException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.AnnotationVisitor;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
@@ -38,26 +38,17 @@ import java.lang.reflect.Method;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
public class DefaultClassFinder implements ClassFinder {
|
||||
private static final Logger LOG = LogManager.getLogger(DefaultClassFinder.class);
|
||||
|
||||
private final Map<String, List<Info>> annotated = new HashMap<String, List<Info>>();
|
||||
private final Map<String, ClassInfo> classInfos = new LinkedHashMap<String, ClassInfo>();
|
||||
private final Map<String, List<Info>> annotated = new HashMap<>();
|
||||
private final Map<String, ClassInfo> classInfos = new LinkedHashMap<>();
|
||||
|
||||
private final List<String> classesNotLoaded = new ArrayList<String>();
|
||||
private final List<String> classesNotLoaded = new ArrayList<>();
|
||||
|
||||
private boolean extractBaseInterfaces;
|
||||
private ClassLoaderInterface classLoaderInterface;
|
||||
@@ -68,7 +59,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
this.extractBaseInterfaces = extractBaseInterfaces;
|
||||
this.fileManager = ActionContext.getContext().getInstance(FileManagerFactory.class).getFileManager();
|
||||
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
List<String> classNames = new ArrayList<>();
|
||||
for (URL location : urls) {
|
||||
try {
|
||||
if (protocols.contains(location.getProtocol())) {
|
||||
@@ -105,8 +96,8 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public DefaultClassFinder(List<Class> classes){
|
||||
this.classLoaderInterface = null;
|
||||
List<Info> infos = new ArrayList<Info>();
|
||||
List<Package> packages = new ArrayList<Package>();
|
||||
List<Info> infos = new ArrayList<>();
|
||||
List<Package> packages = new ArrayList<>();
|
||||
for (Class clazz : classes) {
|
||||
|
||||
Package aPackage = clazz.getPackage();
|
||||
@@ -154,7 +145,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Package> findAnnotatedPackages(Class<? extends Annotation> annotation) {
|
||||
classesNotLoaded.clear();
|
||||
List<Package> packages = new ArrayList<Package>();
|
||||
List<Package> packages = new ArrayList<>();
|
||||
List<Info> infos = getAnnotationInfos(annotation.getName());
|
||||
for (Info info : infos) {
|
||||
if (info instanceof PackageInfo) {
|
||||
@@ -175,7 +166,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Class> findAnnotatedClasses(Class<? extends Annotation> annotation) {
|
||||
classesNotLoaded.clear();
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
List<Class> classes = new ArrayList<>();
|
||||
List<Info> infos = getAnnotationInfos(annotation.getName());
|
||||
for (Info info : infos) {
|
||||
if (info instanceof ClassInfo) {
|
||||
@@ -197,8 +188,8 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Method> findAnnotatedMethods(Class<? extends Annotation> annotation) {
|
||||
classesNotLoaded.clear();
|
||||
List<ClassInfo> seen = new ArrayList<ClassInfo>();
|
||||
List<Method> methods = new ArrayList<Method>();
|
||||
List<ClassInfo> seen = new ArrayList<>();
|
||||
List<Method> methods = new ArrayList<>();
|
||||
List<Info> infos = getAnnotationInfos(annotation.getName());
|
||||
for (Info info : infos) {
|
||||
if (info instanceof MethodInfo && !"<init>".equals(info.getName())) {
|
||||
@@ -227,8 +218,8 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Constructor> findAnnotatedConstructors(Class<? extends Annotation> annotation) {
|
||||
classesNotLoaded.clear();
|
||||
List<ClassInfo> seen = new ArrayList<ClassInfo>();
|
||||
List<Constructor> constructors = new ArrayList<Constructor>();
|
||||
List<ClassInfo> seen = new ArrayList<>();
|
||||
List<Constructor> constructors = new ArrayList<>();
|
||||
List<Info> infos = getAnnotationInfos(annotation.getName());
|
||||
for (Info info : infos) {
|
||||
if (info instanceof MethodInfo && "<init>".equals(info.getName())) {
|
||||
@@ -257,15 +248,17 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Field> findAnnotatedFields(Class<? extends Annotation> annotation) {
|
||||
classesNotLoaded.clear();
|
||||
List<ClassInfo> seen = new ArrayList<ClassInfo>();
|
||||
List<Field> fields = new ArrayList<Field>();
|
||||
List<ClassInfo> seen = new ArrayList<>();
|
||||
List<Field> fields = new ArrayList<>();
|
||||
List<Info> infos = getAnnotationInfos(annotation.getName());
|
||||
for (Info info : infos) {
|
||||
if (info instanceof FieldInfo) {
|
||||
FieldInfo fieldInfo = (FieldInfo) info;
|
||||
ClassInfo classInfo = fieldInfo.getDeclaringClass();
|
||||
|
||||
if (seen.contains(classInfo)) continue;
|
||||
if (seen.contains(classInfo)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
seen.add(classInfo);
|
||||
|
||||
@@ -287,7 +280,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Class> findClassesInPackage(String packageName, boolean recursive) {
|
||||
classesNotLoaded.clear();
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
List<Class> classes = new ArrayList<>();
|
||||
for (ClassInfo classInfo : classInfos.values()) {
|
||||
try {
|
||||
if (recursive && classInfo.getPackageName().startsWith(packageName)){
|
||||
@@ -305,7 +298,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Class> findClasses(Test<ClassInfo> test) {
|
||||
classesNotLoaded.clear();
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
List<Class> classes = new ArrayList<>();
|
||||
for (ClassInfo classInfo : classInfos.values()) {
|
||||
try {
|
||||
if (test.test(classInfo)) {
|
||||
@@ -321,7 +314,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
|
||||
public List<Class> findClasses() {
|
||||
classesNotLoaded.clear();
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
List<Class> classes = new ArrayList<>();
|
||||
for (ClassInfo classInfo : classInfos.values()) {
|
||||
try {
|
||||
classes.add(classInfo.get());
|
||||
@@ -334,7 +327,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
}
|
||||
|
||||
private static List<URL> getURLs(ClassLoaderInterface classLoader, String[] dirNames) {
|
||||
List<URL> urls = new ArrayList<URL>();
|
||||
List<URL> urls = new ArrayList<>();
|
||||
for (String dirName : dirNames) {
|
||||
try {
|
||||
Enumeration<URL> classLoaderURLs = classLoader.getResources(dirName);
|
||||
@@ -351,7 +344,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
}
|
||||
|
||||
private List<String> file(URL location) {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
List<String> classNames = new ArrayList<>();
|
||||
File dir = new File(URLDecoder.decode(location.getPath()));
|
||||
if ("META-INF".equals(dir.getName())) {
|
||||
dir = dir.getParentFile(); // Scrape "META-INF" off
|
||||
@@ -394,7 +387,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
}
|
||||
|
||||
private List<String> jar(JarInputStream jarStream) throws IOException {
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
List<String> classNames = new ArrayList<>();
|
||||
|
||||
JarEntry entry;
|
||||
while ((entry = jarStream.getNextJarEntry()) != null) {
|
||||
@@ -444,7 +437,7 @@ public class DefaultClassFinder implements ClassFinder {
|
||||
private List<Info> getAnnotationInfos(String name) {
|
||||
List<Info> infos = annotated.get(name);
|
||||
if (infos == null) {
|
||||
infos = new ArrayList<Info>();
|
||||
infos = new ArrayList<>();
|
||||
annotated.put(name, infos);
|
||||
}
|
||||
return infos;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user