You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2015/06/17 23:09:02 UTC
[02/57] [partial] struts git commit: Merges xwork packages into struts
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
deleted file mode 100644
index f1137d9..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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.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;
-import org.springframework.beans.factory.UnsatisfiedDependencyException;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Simple implementation of the ObjectFactory that makes use of Spring's application context if one has been configured,
- * before falling back on the default mechanism of instantiating a new class using the class name. <p/> In order to use
- * this class in your application, you will need to instantiate a copy of this class and set it as XWork's ObjectFactory
- * before the xwork.xml file is parsed. In a servlet environment, this could be done using a ServletContextListener.
- *
- * @author Simon Stewart (sms@lateral.net)
- */
-public class SpringObjectFactory extends ObjectFactory implements ApplicationContextAware {
- private static final Logger LOG = LogManager.getLogger(SpringObjectFactory.class);
-
- protected ApplicationContext appContext;
- protected AutowireCapableBeanFactory autoWiringFactory;
- protected int autowireStrategy = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;
- private final Map<String, Object> classes = new HashMap<>();
- private boolean useClassCache = true;
- private boolean alwaysRespectAutowireStrategy = false;
- /**
- * This is temporary solution, after validating can be removed
- * @since 2.3.18
- */
- private boolean enableAopSupport = false;
-
- @Inject(value="applicationContextPath",required=false)
- public void setApplicationContextPath(String ctx) {
- if (ctx != null) {
- setApplicationContext(new ClassPathXmlApplicationContext(ctx));
- }
- }
-
- @Inject(value = "enableAopSupport", required = false)
- public void setEnableAopSupport(String enableAopSupport) {
- this.enableAopSupport = BooleanUtils.toBoolean(enableAopSupport);
- }
-
- /**
- * Set the Spring ApplicationContext that should be used to look beans up with.
- *
- * @param appContext The Spring ApplicationContext that should be used to look beans up with.
- */
- public void setApplicationContext(ApplicationContext appContext) throws BeansException {
- this.appContext = appContext;
- autoWiringFactory = findAutoWiringBeanFactory(this.appContext);
- }
-
- /**
- * Sets the autowiring strategy
- *
- * @param autowireStrategy
- */
- public void setAutowireStrategy(int autowireStrategy) {
- switch (autowireStrategy) {
- case AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT:
- LOG.info("Setting autowire strategy to autodetect");
- this.autowireStrategy = autowireStrategy;
- break;
- case AutowireCapableBeanFactory.AUTOWIRE_BY_NAME:
- LOG.info("Setting autowire strategy to name");
- this.autowireStrategy = autowireStrategy;
- break;
- case AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE:
- LOG.info("Setting autowire strategy to type");
- this.autowireStrategy = autowireStrategy;
- break;
- case AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR:
- LOG.info("Setting autowire strategy to constructor");
- this.autowireStrategy = autowireStrategy;
- break;
- case AutowireCapableBeanFactory.AUTOWIRE_NO:
- LOG.info("Setting autowire strategy to none");
- this.autowireStrategy = autowireStrategy;
- break;
- default:
- throw new IllegalStateException("Invalid autowire type set");
- }
- }
-
- public int getAutowireStrategy() {
- return autowireStrategy;
- }
-
-
- /**
- * If the given context is assignable to AutowireCapbleBeanFactory or contains a parent or a factory that is, then
- * set the autoWiringFactory appropriately.
- *
- * @param context
- */
- protected AutowireCapableBeanFactory findAutoWiringBeanFactory(ApplicationContext context) {
- if (context instanceof AutowireCapableBeanFactory) {
- // Check the context
- return (AutowireCapableBeanFactory) context;
- } else if (context instanceof ConfigurableApplicationContext) {
- // Try and grab the beanFactory
- return ((ConfigurableApplicationContext) context).getBeanFactory();
- } else if (context.getParent() != null) {
- // And if all else fails, try again with the parent context
- return findAutoWiringBeanFactory(context.getParent());
- }
- return null;
- }
-
- /**
- * Looks up beans using Spring's application context before falling back to the method defined in the {@link
- * ObjectFactory}.
- *
- * @param beanName The name of the bean to look up in the application context
- * @param extraContext
- * @return A bean from Spring or the result of calling the overridden
- * method.
- * @throws Exception
- */
- @Override
- public Object buildBean(String beanName, Map<String, Object> extraContext, boolean injectInternal) throws Exception {
- Object o;
-
- if (appContext.containsBean(beanName)) {
- o = appContext.getBean(beanName);
- } else {
- Class beanClazz = getClassInstance(beanName);
- o = buildBean(beanClazz, extraContext);
- }
- if (injectInternal) {
- injectInternalBeans(o);
- }
- return o;
- }
-
- /**
- * @param clazz
- * @param extraContext
- * @throws Exception
- */
- @Override
- public Object buildBean(Class clazz, Map<String, Object> extraContext) throws Exception {
- Object bean;
-
- try {
- // Decide to follow autowire strategy or use the legacy approach which mixes injection strategies
- if (alwaysRespectAutowireStrategy) {
- // Leave the creation up to Spring
- bean = autoWiringFactory.createBean(clazz, autowireStrategy, false);
- injectApplicationContext(bean);
- return injectInternalBeans(bean);
- } else if (enableAopSupport) {
- bean = autoWiringFactory.createBean(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
- bean = autoWireBean(bean, autoWiringFactory);
- bean = autoWiringFactory.initializeBean(bean, bean.getClass().getName());
- return bean;
- } else {
- bean = autoWiringFactory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
- bean = autoWiringFactory.applyBeanPostProcessorsBeforeInitialization(bean, bean.getClass().getName());
- bean = autoWiringFactory.initializeBean(bean, bean.getClass().getName());
- bean = autoWiringFactory.applyBeanPostProcessorsAfterInitialization(bean, bean.getClass().getName());
- return autoWireBean(bean, autoWiringFactory);
- }
- } catch (UnsatisfiedDependencyException e) {
- LOG.error("Error building bean", e);
- // Fall back
- return autoWireBean(super.buildBean(clazz, extraContext), autoWiringFactory);
- }
- }
-
- public Object autoWireBean(Object bean) {
- return autoWireBean(bean, autoWiringFactory);
- }
-
- /**
- * @param bean
- * @param autoWiringFactory
- */
- public Object autoWireBean(Object bean, AutowireCapableBeanFactory autoWiringFactory) {
- if (autoWiringFactory != null) {
- autoWiringFactory.autowireBeanProperties(bean, autowireStrategy, false);
- }
- injectApplicationContext(bean);
-
- injectInternalBeans(bean);
-
- return bean;
- }
-
- private void injectApplicationContext(Object bean) {
- if (bean instanceof ApplicationContextAware) {
- ((ApplicationContextAware) bean).setApplicationContext(appContext);
- }
- }
-
- public Class getClassInstance(String className) throws ClassNotFoundException {
- Class clazz = null;
- if (useClassCache) {
- synchronized(classes) {
- // this cache of classes is needed because Spring sucks at dealing with situations where the
- // class instance changes
- clazz = (Class) classes.get(className);
- }
- }
-
- if (clazz == null) {
- if (appContext.containsBean(className)) {
- clazz = appContext.getBean(className).getClass();
- } else {
- clazz = super.getClassInstance(className);
- }
-
- if (useClassCache) {
- synchronized(classes) {
- classes.put(className, clazz);
- }
- }
- }
-
- return clazz;
- }
-
- /**
- * This method sets the ObjectFactory used by XWork to this object. It's best used as the "init-method" of a Spring
- * bean definition in order to hook Spring and XWork together properly (as an alternative to the
- * org.apache.struts2.spring.lifecycle.SpringObjectFactoryListener)
- * @deprecated Since 2.1 as it isn't necessary
- */
- @Deprecated public void initObjectFactory() {
- // not necessary anymore
- }
-
- /**
- * Allows for ObjectFactory implementations that support
- * Actions without no-arg constructors.
- *
- * @return false
- */
- @Override
- public boolean isNoArgConstructorRequired() {
- return false;
- }
-
- /**
- * Enable / disable caching of classes loaded by Spring.
- *
- * @param useClassCache
- */
- public void setUseClassCache(boolean useClassCache) {
- this.useClassCache = useClassCache;
- }
-
- /**
- * Determines if the autowire strategy is always followed when creating beans
- *
- * @param alwaysRespectAutowireStrategy True if the strategy is always used
- */
- public void setAlwaysRespectAutowireStrategy(boolean alwaysRespectAutowireStrategy) {
- this.alwaysRespectAutowireStrategy = alwaysRespectAutowireStrategy;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
deleted file mode 100644
index f249f5f..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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.spring;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.context.ApplicationContext;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * SpringProxyableObjectFactory.
- *
- * @author Jason Carreira
- */
-public class SpringProxyableObjectFactory extends SpringObjectFactory {
-
- private static final Logger LOG = LogManager.getLogger(SpringProxyableObjectFactory.class);
-
- private List<String> skipBeanNames = new ArrayList<>();
-
- @Override
- public Object buildBean(String beanName, Map<String, Object> extraContext) throws Exception {
- LOG.debug("Building bean for name {}", beanName);
- if (!skipBeanNames.contains(beanName)) {
- ApplicationContext anAppContext = getApplicationContext(extraContext);
- try {
- LOG.debug("Trying the application context... appContext = {},\n bean name = {}", anAppContext, beanName);
- return anAppContext.getBean(beanName);
- } catch (NoSuchBeanDefinitionException e) {
- LOG.debug("Did not find bean definition for bean named {}, creating a new one...", beanName);
- if (autoWiringFactory instanceof BeanDefinitionRegistry) {
- try {
- Class clazz = Class.forName(beanName);
- BeanDefinitionRegistry registry = (BeanDefinitionRegistry) autoWiringFactory;
- RootBeanDefinition def = new RootBeanDefinition(clazz, autowireStrategy, true);
- def.setScope(BeanDefinition.SCOPE_SINGLETON);
- LOG.debug("Registering a new bean definition for class {}", beanName);
- registry.registerBeanDefinition(beanName,def);
- try {
- return anAppContext.getBean(beanName);
- } catch (NoSuchBeanDefinitionException e2) {
- LOG.warn("Could not register new bean definition for bean {}", beanName);
- skipBeanNames.add(beanName);
- }
- } catch (ClassNotFoundException e1) {
- skipBeanNames.add(beanName);
- }
- }
- }
- }
- LOG.debug("Returning autowired instance created by default ObjectFactory");
- return autoWireBean(super.buildBean(beanName, extraContext), autoWiringFactory);
- }
-
- /**
- * Subclasses may override this to return a different application context.
- * Note that this application context should see any changes made to the
- * <code>autoWiringFactory</code>, so the application context should be either
- * the original or a child context of the original.
- *
- * @param context provided context.
- */
- protected ApplicationContext getApplicationContext(Map<String, Object> context) {
- return appContext;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
deleted file mode 100644
index fe02ca5..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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.spring.interceptor;
-
-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.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.web.context.WebApplicationContext;
-
-/**
- * <!-- START SNIPPET: description -->
- * TODO: Give a description of the Interceptor.
- * <!-- END SNIPPET: description -->
- *
- * <!-- START SNIPPET: parameters -->
- * TODO: Describe the paramters for this Interceptor.
- * <!-- END SNIPPET: parameters -->
- *
- * <!-- START SNIPPET: extending -->
- * TODO: Discuss some possible extension of the Interceptor.
- * <!-- END SNIPPET: extending -->
- *
- * <pre>
- * <!-- START SNIPPET: example -->
- * <!-- TODO: Describe how the Interceptor reference will effect execution -->
- * <action name="someAction" class="com.examples.SomeAction">
- * TODO: fill in the interceptor reference.
- * <interceptor-ref name=""/>
- * <result name="success">good_result.ftl</result>
- * </action>
- * <!-- END SNIPPET: example -->
- * </pre>
- *
- * Autowires action classes to Spring beans. The strategy for autowiring the beans can be configured
- * by setting the parameter on the interceptor. Actions that need access to the <code>ActionContext</code>
- * can implements the <code>ApplicationContextAware</code> interface. The context will also be placed on
- * the action context under the APPLICATION_CONTEXT attribute.
- *
- * @author Simon Stewart
- * @author Eric Hauser
- */
-public class ActionAutowiringInterceptor extends AbstractInterceptor implements ApplicationContextAware {
- private static final Logger LOG = LogManager.getLogger(ActionAutowiringInterceptor.class);
-
- public static final String APPLICATION_CONTEXT = "com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor.applicationContext";
-
- private boolean initialized = false;
- private ApplicationContext context;
- private SpringObjectFactory factory;
- private Integer autowireStrategy;
-
- /**
- * @param autowireStrategy
- */
- public void setAutowireStrategy(Integer autowireStrategy) {
- this.autowireStrategy = autowireStrategy;
- }
-
- /**
- * Looks for the <code>ApplicationContext</code> under the attribute that the Spring listener sets in
- * the servlet context. The configuration is done the first time here instead of in init() since the
- * <code>ActionContext</code> is not available during <code>Interceptor</code> initialization.
- * <p/>
- * Autowires the action to Spring beans and places the <code>ApplicationContext</code>
- * on the <code>ActionContext</code>
- * <p/>
- * TODO Should this check to see if the <code>SpringObjectFactory</code> has already been configured
- * instead of instantiating a new one? Or is there a good reason for the interceptor to have it's own
- * factory?
- *
- * @param invocation
- * @throws Exception
- */
- @Override public String intercept(ActionInvocation invocation) throws Exception {
- if (!initialized) {
- ApplicationContext applicationContext = (ApplicationContext) ActionContext.getContext().getApplication().get(
- WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
-
- if (applicationContext == null) {
- LOG.warn("ApplicationContext could not be found. Action classes will not be autowired.");
- } else {
- setApplicationContext(applicationContext);
- factory = new SpringObjectFactory();
- factory.setApplicationContext(getApplicationContext());
- if (autowireStrategy != null) {
- factory.setAutowireStrategy(autowireStrategy.intValue());
- }
- }
- initialized = true;
- }
-
- if (factory != null) {
- Object bean = invocation.getAction();
- factory.autoWireBean(bean);
-
- ActionContext.getContext().put(APPLICATION_CONTEXT, context);
- }
- return invocation.invoke();
- }
-
- /**
- * @param applicationContext
- * @throws BeansException
- */
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- context = applicationContext;
- }
-
- /**
- * @return context
- */
- protected ApplicationContext getApplicationContext() {
- return context;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/package.html
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/package.html
deleted file mode 100644
index 6579e80..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/interceptor/package.html
+++ /dev/null
@@ -1 +0,0 @@
-<body>Spring specific interceptor classes.</body>
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/spring/package.html
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/spring/package.html
deleted file mode 100644
index 91d2d95..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/spring/package.html
+++ /dev/null
@@ -1 +0,0 @@
-<body>Spring ObjectFactory classes.</body>
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java b/xwork-core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java
deleted file mode 100644
index 309db06..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/test/StubConfigurationProvider.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.opensymphony.xwork2.test;
-
-import com.opensymphony.xwork2.config.Configuration;
-import com.opensymphony.xwork2.config.ConfigurationException;
-import com.opensymphony.xwork2.config.ConfigurationProvider;
-import com.opensymphony.xwork2.inject.ContainerBuilder;
-import com.opensymphony.xwork2.util.location.LocatableProperties;
-
-public class StubConfigurationProvider implements ConfigurationProvider {
-
- public void destroy() {
- // TODO Auto-generated method stub
-
- }
-
- public void init(Configuration configuration) throws ConfigurationException {
- // TODO Auto-generated method stub
- }
-
- public void loadPackages() throws ConfigurationException {
- // TODO Auto-generated method stub
-
- }
-
- public boolean needsReload() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void register(ContainerBuilder builder, LocatableProperties props)
- throws ConfigurationException {
- // TODO Auto-generated method stub
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java
deleted file mode 100644
index 08cae03..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * <code>AnnotationUtils</code>
- *
- * Various utility methods dealing with annotations
- *
- * @author Rainer Hermanns
- * @author Zsolt Szasz, zsolt at lorecraft dot com
- * @author Dan Oxlade, dan d0t oxlade at gmail d0t c0m
- * @version $Id$
- */
-public class AnnotationUtils {
-
- private static final Pattern SETTER_PATTERN = Pattern.compile("set([A-Z][A-Za-z0-9]*)$");
- private static final Pattern GETTER_PATTERN = Pattern.compile("(get|is|has)([A-Z][A-Za-z0-9]*)$");
-
-
-
- /**
- * Adds all fields with the specified Annotation of class clazz and its superclasses to allFields
- *
- * @param annotationClass
- * @param clazz
- * @param allFields
- */
- public static void addAllFields(Class<? extends Annotation> annotationClass, Class clazz, List<Field> allFields) {
-
- if (clazz == null) {
- return;
- }
-
- Field[] fields = clazz.getDeclaredFields();
-
- for (Field field : fields) {
- Annotation ann = field.getAnnotation(annotationClass);
- if (ann!=null) {
- allFields.add(field);
- }
- }
- addAllFields(annotationClass, clazz.getSuperclass(), allFields);
- }
-
- /**
- * Adds all methods with the specified Annotation of class clazz and its superclasses to allFields
- *
- * @param annotationClass
- * @param clazz
- * @param allMethods
- */
- public static void addAllMethods(Class<? extends Annotation> annotationClass, Class clazz, List<Method> allMethods) {
-
- if (clazz == null) {
- return;
- }
-
- Method[] methods = clazz.getDeclaredMethods();
-
- for (Method method : methods) {
- Annotation ann = method.getAnnotation(annotationClass);
- if (ann!=null) {
- allMethods.add(method);
- }
- }
- addAllMethods(annotationClass, clazz.getSuperclass(), allMethods);
- }
-
- /**
- *
- * @param clazz
- * @param allInterfaces
- */
- public static void addAllInterfaces(Class clazz, List<Class> allInterfaces) {
- if (clazz == null) {
- return;
- }
-
- Class[] interfaces = clazz.getInterfaces();
- allInterfaces.addAll(Arrays.asList(interfaces));
- addAllInterfaces(clazz.getSuperclass(), allInterfaces);
- }
-
- /**
- * For the given <code>Class</code> get a collection of the the {@link AnnotatedElement}s
- * that match the given <code>annotation</code>s or if no <code>annotation</code>s are
- * specified then return all of the annotated elements of the given <code>Class</code>.
- * Includes only the method level annotations.
- *
- * @param clazz The {@link Class} to inspect
- * @param annotation the {@link Annotation}s to find
- * @return A {@link Collection}<{@link AnnotatedElement}> containing all of the
- * 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<>();
-
- 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;
- }
-
- /**
- * Varargs version of <code>AnnotatedElement.isAnnotationPresent()</code>
- * @see AnnotatedElement
- */
- public static boolean isAnnotatedBy(AnnotatedElement annotatedElement, Class<? extends Annotation>... annotation) {
- if (org.apache.commons.lang3.ArrayUtils.isEmpty(annotation)) {
- return false;
- }
-
- for( Class<? extends Annotation> c : annotation ){
- if( annotatedElement.isAnnotationPresent(c) ) return true;
- }
-
- return false;
- }
-
- /**
- * Returns the property name for a method.
- * This method is independent from property fields.
- *
- * @param method The method to get the property name for.
- * @return the property name for given method; null if non could be resolved.
- */
- public static String resolvePropertyName(Method method) {
-
- Matcher matcher = SETTER_PATTERN.matcher(method.getName());
- if (matcher.matches() && method.getParameterTypes().length == 1) {
- String raw = matcher.group(1);
- return raw.substring(0, 1).toLowerCase() + raw.substring(1);
- }
-
- matcher = GETTER_PATTERN.matcher(method.getName());
- if (matcher.matches() && method.getParameterTypes().length == 0) {
- String raw = matcher.group(2);
- return raw.substring(0, 1).toLowerCase() + raw.substring(1);
- }
-
- return null;
- }
-
- /**
- * 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 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<?> clazz, Class<T> annotationClass) {
- T ann = clazz.getAnnotation(annotationClass);
- while (ann == null && clazz != null) {
- ann = clazz.getAnnotation(annotationClass);
- if (ann == null) {
- ann = clazz.getPackage().getAnnotation(annotationClass);
- }
- if (ann == null) {
- clazz = clazz.getSuperclass();
- if (clazz != null) {
- ann = clazz.getAnnotation(annotationClass);
- }
- }
- }
-
- return ann;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/ArrayUtils.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ArrayUtils.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/ArrayUtils.java
deleted file mode 100644
index 99f4ab6..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ArrayUtils.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-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) {
- return null == array || array.length == 0;
- }
-
- public static boolean isNotEmpty(Object[] array) {
- return !isEmpty(array);
- }
-
- /**
- * Return a collection from the comma delimited String.
- *
- * @param commaDelim the comma delimited String.
- * @return A collection from the comma delimited String. Returns <tt>null</tt> if the string is empty.
- */
- public static Collection<String> asCollection(String commaDelim) {
- if (commaDelim == null || commaDelim.trim().length() == 0) {
- return null;
- }
- return TextParseUtil.commaDelimitedStringToSet(commaDelim);
- }
-
- public static <T> Set<T> asSet(T... element) {
- HashSet<T> elements = new HashSet<T>(element.length);
- Collections.addAll(elements, element);
- return elements;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
deleted file mode 100644
index 919f5af..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright 2002-2003,2009 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;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.*;
-
-
-/**
- * This class is extremely useful for loading resources and classes in a fault tolerant manner
- * that works across different applications servers.
- * <p/>
- * It has come out of many months of frustrating use of multiple application servers at Atlassian,
- * please don't change things unless you're sure they're not going to break in one server or another!
- *
- */
-public class ClassLoaderUtil {
-
- /**
- * Load all resources with a given name, potentially aggregating all results
- * from the searched classloaders. If no results are found, the resource name
- * is prepended by '/' and tried again.
- *
- * This method will try to load the resources using the following methods (in order):
- * <ul>
- * <li>From Thread.currentThread().getContextClassLoader()
- * <li>From ClassLoaderUtil.class.getClassLoader()
- * <li>callingClass.getClassLoader()
- * </ul>
- *
- * @param resourceName The name of the resources to load
- * @param callingClass The Class object of the calling object
- */
- public static Iterator<URL> getResources(String resourceName, Class callingClass, boolean aggregate) throws IOException {
-
- AggregateIterator<URL> iterator = new AggregateIterator<>();
-
- iterator.addEnumeration(Thread.currentThread().getContextClassLoader().getResources(resourceName));
-
- if (!iterator.hasNext() || aggregate) {
- iterator.addEnumeration(ClassLoaderUtil.class.getClassLoader().getResources(resourceName));
- }
-
- if (!iterator.hasNext() || aggregate) {
- ClassLoader cl = callingClass.getClassLoader();
-
- if (cl != null) {
- iterator.addEnumeration(cl.getResources(resourceName));
- }
- }
-
- if (!iterator.hasNext() && (resourceName != null) && ((resourceName.length() == 0) || (resourceName.charAt(0) != '/'))) {
- return getResources('/' + resourceName, callingClass, aggregate);
- }
-
- return iterator;
- }
-
- /**
- * Load a given resource.
- * <p/>
- * This method will try to load the resource using the following methods (in order):
- * <ul>
- * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()}
- * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()}
- * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() }
- * </ul>
- *
- * @param resourceName The name of the resource to load
- * @param callingClass The Class object of the calling object
- */
- public static URL getResource(String resourceName, Class callingClass) {
- URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
-
- if (url == null) {
- url = ClassLoaderUtil.class.getClassLoader().getResource(resourceName);
- }
-
- if (url == null) {
- ClassLoader cl = callingClass.getClassLoader();
-
- if (cl != null) {
- url = cl.getResource(resourceName);
- }
- }
-
- if ((url == null) && (resourceName != null) && ((resourceName.length() == 0) || (resourceName.charAt(0) != '/'))) {
- return getResource('/' + resourceName, callingClass);
- }
-
- return url;
- }
-
- /**
- * This is a convenience method to load a resource as a stream.
- *
- * The algorithm used to find the resource is given in getResource()
- *
- * @param resourceName The name of the resource to load
- * @param callingClass The Class object of the calling object
- */
- public static InputStream getResourceAsStream(String resourceName, Class callingClass) {
- URL url = getResource(resourceName, callingClass);
-
- try {
- return (url != null) ? url.openStream() : null;
- } catch (IOException e) {
- return null;
- }
- }
-
- /**
- * Load a class with a given name.
- * <p/>
- * It will try to load the class in the following order:
- * <ul>
- * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()}
- * <li>Using the basic {@link Class#forName(java.lang.String) }
- * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()}
- * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() }
- * </ul>
- *
- * @param className The name of the class to load
- * @param callingClass The Class object of the calling object
- * @throws ClassNotFoundException If the class cannot be found anywhere.
- */
- public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException {
- try {
- return Thread.currentThread().getContextClassLoader().loadClass(className);
- } catch (ClassNotFoundException e) {
- try {
- return Class.forName(className);
- } catch (ClassNotFoundException ex) {
- try {
- return ClassLoaderUtil.class.getClassLoader().loadClass(className);
- } catch (ClassNotFoundException exc) {
- return callingClass.getClassLoader().loadClass(className);
- }
- }
- }
- }
-
- /**
- * Prints the current classloader hierarchy - useful for debugging.
- */
- public static void printClassLoader() {
- System.out.println("ClassLoaderUtils.printClassLoader");
- printClassLoader(Thread.currentThread().getContextClassLoader());
- }
-
- /**
- * Prints the classloader hierarchy from a given classloader - useful for debugging.
- */
- public static void printClassLoader(ClassLoader cl) {
- System.out.println("ClassLoaderUtils.printClassLoader(cl = " + cl + ")");
-
- if (cl != null) {
- printClassLoader(cl.getParent());
- }
- }
-
-
-
- /**
- * Aggregates Enumeration instances into one iterator and filters out duplicates. Always keeps one
- * ahead of the enumerator to protect against returning duplicates.
- */
- static class AggregateIterator<E> implements Iterator<E> {
-
- LinkedList<Enumeration<E>> enums = new LinkedList<>();
- Enumeration<E> cur = null;
- E next = null;
- Set<E> loaded = new HashSet<E>();
-
- public AggregateIterator<E> addEnumeration(Enumeration<E> e) {
- if (e.hasMoreElements()) {
- if (cur == null) {
- cur = e;
- next = e.nextElement();
- loaded.add(next);
- } else {
- enums.add(e);
- }
- }
- return this;
- }
-
- public boolean hasNext() {
- return (next != null);
- }
-
- public E next() {
- if (next != null) {
- E prev = next;
- next = loadNext();
- return prev;
- } else {
- throw new NoSuchElementException();
- }
- }
-
- private Enumeration<E> determineCurrentEnumeration() {
- if (cur != null && !cur.hasMoreElements()) {
- if (enums.size() > 0) {
- cur = enums.removeLast();
- } else {
- cur = null;
- }
- }
- return cur;
- }
-
- private E loadNext() {
- if (determineCurrentEnumeration() != null) {
- E tmp = cur.nextElement();
- int loadedSize = loaded.size();
- while (loaded.contains(tmp)) {
- tmp = loadNext();
- if (tmp == null || loaded.size() > loadedSize) {
- break;
- }
- }
- if (tmp != null) {
- loaded.add(tmp);
- }
- return tmp;
- }
- return null;
-
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java
deleted file mode 100644
index 5743885..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * $Id$
- *
- * Copyright 2003-2004 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;
-
-import com.opensymphony.xwork2.XWorkException;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.HashMap;
-import java.util.Vector;
-
-/**
- * This class is an utility class that will search through the classpath
- * for files whose names match the given pattern. The filename is tested
- * using the given implementation of {@link com.opensymphony.xwork2.util.PatternMatcher} by default it
- * uses {@link com.opensymphony.xwork2.util.WildcardHelper}
- *
- * @version $Rev$ $Date$
- */
-public class ClassPathFinder {
-
- /**
- * The String pattern to test against.
- */
- private String pattern ;
-
- private int[] compiledPattern ;
-
- /**
- * The PatternMatcher implementation to use
- */
- private PatternMatcher<int[]> patternMatcher = new WildcardHelper();
-
- private Vector<String> compared = new Vector<>();
-
- /**
- * retrieves the pattern in use
- */
- public String getPattern() {
- return pattern;
- }
-
- /**
- * sets the String pattern for comparing filenames
- * @param pattern
- */
- public void setPattern(String pattern) {
- this.pattern = pattern;
- }
-
- /**
- * Builds a {@link java.util.Vector} containing Strings which each name a file
- * who's name matches the pattern set by setPattern(String). The classpath is
- * searched recursively, so use with caution.
- *
- * @return Vector<String> containing matching filenames
- */
- public Vector<String> findMatches() {
- Vector<String> matches = new Vector<>();
- URLClassLoader cl = getURLClassLoader();
- if (cl == null ) {
- throw new XWorkException("unable to attain an URLClassLoader") ;
- }
- URL[] parentUrls = cl.getURLs();
- compiledPattern = patternMatcher.compilePattern(pattern);
- for (URL url : parentUrls) {
- if (!"file".equals(url.getProtocol())) {
- continue ;
- }
- URI entryURI ;
- try {
- entryURI = url.toURI();
- } catch (URISyntaxException e) {
- continue;
- }
- File entry = new File(entryURI) ;
- Vector<String> results = checkEntries(entry.list(), entry, "");
- if (results != null ) {
- matches.addAll(results);
- }
- }
- return matches;
- }
-
- private Vector<String> checkEntries(String[] entries, File parent, String prefix) {
-
- if (entries == null ) {
- return null;
- }
-
- Vector<String> matches = new Vector<>();
- for (String listEntry : entries) {
- File tempFile ;
- if (!"".equals(prefix) ) {
- tempFile = new File(parent, prefix + "/" + listEntry);
- }
- else {
- tempFile = new File(parent, listEntry);
- }
- if (tempFile.isDirectory() &&
- !(".".equals(listEntry) || "..".equals(listEntry)) ) {
- if (!"".equals(prefix) ) {
- matches.addAll(checkEntries(tempFile.list(), parent, prefix + "/" + listEntry));
- }
- else {
- matches.addAll(checkEntries(tempFile.list(), parent, listEntry));
- }
- }
- else {
-
- String entryToCheck ;
- if ("".equals(prefix)) {
- entryToCheck = listEntry ;
- }
- else {
- entryToCheck = prefix + "/" + listEntry ;
- }
-
- if (compared.contains(entryToCheck) ) {
- continue;
- }
- else {
- compared.add(entryToCheck) ;
- }
-
- boolean doesMatch = patternMatcher.match(new HashMap<String,String>(), entryToCheck, compiledPattern);
- if (doesMatch) {
- matches.add(entryToCheck);
- }
- }
- }
- return matches ;
- }
-
- /**
- * sets the PatternMatcher implementation to use when comparing filenames
- * @param patternMatcher
- */
- public void setPatternMatcher(PatternMatcher<int[]> patternMatcher) {
- this.patternMatcher = patternMatcher;
- }
-
- private URLClassLoader getURLClassLoader() {
- URLClassLoader ucl = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- if(! (loader instanceof URLClassLoader)) {
- loader = ClassPathFinder.class.getClassLoader();
- if (loader instanceof URLClassLoader) {
- ucl = (URLClassLoader) loader ;
- }
- }
- else {
- ucl = (URLClassLoader) loader;
- }
-
- return ucl ;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClearableValueStack.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClearableValueStack.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClearableValueStack.java
deleted file mode 100644
index e4d129e..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/ClearableValueStack.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * $Id$
- *
- * Copyright 2003-2004 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;
-
-/**
- * ValueStacks implementing this interface provide a way to remove values from
- * their contexts.
- */
-public interface ClearableValueStack {
- /**
- * Remove all values from the context
- */
- void clearContextValues();
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/CompoundRoot.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/CompoundRoot.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/CompoundRoot.java
deleted file mode 100644
index 9abade0..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/CompoundRoot.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * A Stack that is implemented using a List.
- *
- * @author plightbo
- * @version $Revision$
- */
-public class CompoundRoot extends ArrayList {
-
- public CompoundRoot() {
- }
-
- public CompoundRoot(List list) {
- super(list);
- }
-
-
- public CompoundRoot cutStack(int index) {
- return new CompoundRoot(subList(index, size()));
- }
-
- public Object peek() {
- return get(0);
- }
-
- public Object pop() {
- return remove(0);
- }
-
- public void push(Object o) {
- add(0, o);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/CreateIfNull.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/CreateIfNull.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/CreateIfNull.java
deleted file mode 100644
index 050ec2a..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/CreateIfNull.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <!-- START SNIPPET: description -->
- * <p/>Sets the CreateIfNull for type conversion.
- * <!-- END SNIPPET: description -->
- *
- * <p/> <u>Annotation usage:</u>
- *
- * <!-- START SNIPPET: usage -->
- * <p/>The CreateIfNull annotation must be applied at field or method level.
- * <!-- END SNIPPET: usage -->
- * <p/> <u>Annotation parameters:</u>
- *
- * <!-- START SNIPPET: parameters -->
- * <table>
- * <thead>
- * <tr>
- * <th>Parameter</th>
- * <th>Required</th>
- * <th>Default</th>
- * <th>Description</th>
- * </tr>
- * </thead>
- * <tbody>
- * <tr>
- * <td>value</td>
- * <td>no</td>
- * <td>false</td>
- * <td>The CreateIfNull property value.</td>
- * </tr>
- * </tbody>
- * </table>
- * <!-- END SNIPPET: parameters -->
- *
- * <p/> <u>Example code:</u>
- * <pre>
- * <!-- START SNIPPET: example -->
- * @CreateIfNull( value = true )
- * private List<User> users;
- * <!-- END SNIPPET: example -->
- * </pre>
- *
- * @author Rainer Hermanns
- * @version $Id$
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.METHOD})
-public @interface CreateIfNull {
-
- /**
- * The CreateIfNull value.
- * Defaults to <tt>true</tt>.
- */
- boolean value() default true;
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/DomHelper.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/DomHelper.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/DomHelper.java
deleted file mode 100644
index 47d86e1..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/DomHelper.java
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * Copyright 1999-2005 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;
-
-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.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.xml.sax.*;
-import org.xml.sax.helpers.DefaultHandler;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import java.util.Map;
-
-/**
- * Helper class to create and retrieve information from location-enabled
- * DOM-trees.
- *
- * @since 1.2
- */
-public class DomHelper {
-
- private static final Logger LOG = LogManager.getLogger(DomHelper.class);
-
- public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
-
- public static Location getLocationObject(Element element) {
- return LocationAttributes.getLocation(element);
- }
-
-
- /**
- * Creates a W3C Document that remembers the location of each element in
- * the source file. The location of element nodes can then be retrieved
- * using the {@link #getLocationObject(Element)} method.
- *
- * @param inputSource the inputSource to read the document from
- */
- public static Document parse(InputSource inputSource) {
- return parse(inputSource, null);
- }
-
-
- /**
- * Creates a W3C Document that remembers the location of each element in
- * the source file. The location of element nodes can then be retrieved
- * using the {@link #getLocationObject(Element)} method.
- *
- * @param inputSource the inputSource to read the document from
- * @param dtdMappings a map of DTD names and public ids
- */
- public static Document parse(InputSource inputSource, Map<String, String> dtdMappings) {
-
- SAXParserFactory factory = null;
- String parserProp = System.getProperty("xwork.saxParserFactory");
- if (parserProp != null) {
- try {
- Class clazz = ObjectFactory.getObjectFactory().getClassInstance(parserProp);
- factory = (SAXParserFactory) clazz.newInstance();
- } catch (Exception e) {
- LOG.error("Unable to load saxParserFactory set by system property 'xwork.saxParserFactory': {}", parserProp, e);
- }
- }
-
- if (factory == null) {
- factory = SAXParserFactory.newInstance();
- }
-
- factory.setValidating((dtdMappings != null));
- factory.setNamespaceAware(true);
-
- SAXParser parser;
- try {
- parser = factory.newSAXParser();
- } catch (Exception ex) {
- throw new XWorkException("Unable to create SAX parser", ex);
- }
-
-
- DOMBuilder builder = new DOMBuilder();
-
- // Enhance the sax stream with location information
- ContentHandler locationHandler = new LocationAttributes.Pipe(builder);
-
- try {
- parser.parse(inputSource, new StartHandler(locationHandler, dtdMappings));
- } catch (Exception ex) {
- throw new XWorkException(ex);
- }
-
- return builder.getDocument();
- }
-
- /**
- * The <code>DOMBuilder</code> is a utility class that will generate a W3C
- * DOM Document from SAX events.
- *
- * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- */
- static public class DOMBuilder implements ContentHandler {
-
- /** The default transformer factory shared by all instances */
- protected static SAXTransformerFactory FACTORY;
-
- /** The transformer factory */
- protected SAXTransformerFactory factory;
-
- /** The result */
- protected DOMResult result;
-
- /** The parentNode */
- protected Node parentNode;
-
- protected ContentHandler nextHandler;
-
- static {
- String parserProp = System.getProperty("xwork.saxTransformerFactory");
- if (parserProp != null) {
- try {
- Class clazz = ObjectFactory.getObjectFactory().getClassInstance(parserProp);
- FACTORY = (SAXTransformerFactory) clazz.newInstance();
- } catch (Exception e) {
- LOG.error("Unable to load SAXTransformerFactory set by system property 'xwork.saxTransformerFactory': {}", parserProp, e);
- }
- }
-
- if (FACTORY == null) {
- FACTORY = (SAXTransformerFactory) TransformerFactory.newInstance();
- }
- }
-
- /**
- * Construct a new instance of this DOMBuilder.
- */
- public DOMBuilder() {
- this((Node) null);
- }
-
- /**
- * Construct a new instance of this DOMBuilder.
- */
- public DOMBuilder(SAXTransformerFactory factory) {
- this(factory, null);
- }
-
- /**
- * Constructs a new instance that appends nodes to the given parent node.
- */
- public DOMBuilder(Node parentNode) {
- this(null, parentNode);
- }
-
- /**
- * Construct a new instance of this DOMBuilder.
- */
- public DOMBuilder(SAXTransformerFactory factory, Node parentNode) {
- this.factory = factory == null? FACTORY: factory;
- this.parentNode = parentNode;
- setup();
- }
-
- /**
- * Setup this instance transformer and result objects.
- */
- private void setup() {
- try {
- TransformerHandler handler = this.factory.newTransformerHandler();
- nextHandler = handler;
- if (this.parentNode != null) {
- this.result = new DOMResult(this.parentNode);
- } else {
- this.result = new DOMResult();
- }
- handler.setResult(this.result);
- } catch (javax.xml.transform.TransformerException local) {
- throw new XWorkException("Fatal-Error: Unable to get transformer handler", local);
- }
- }
-
- /**
- * Return the newly built Document.
- */
- public Document getDocument() {
- if (this.result == null || this.result.getNode() == null) {
- return null;
- } else if (this.result.getNode().getNodeType() == Node.DOCUMENT_NODE) {
- return (Document) this.result.getNode();
- } else {
- return this.result.getNode().getOwnerDocument();
- }
- }
-
- public void setDocumentLocator(Locator locator) {
- nextHandler.setDocumentLocator(locator);
- }
-
- public void startDocument() throws SAXException {
- nextHandler.startDocument();
- }
-
- public void endDocument() throws SAXException {
- nextHandler.endDocument();
- }
-
- public void startElement(String uri, String loc, String raw, Attributes attrs) throws SAXException {
- nextHandler.startElement(uri, loc, raw, attrs);
- }
-
- public void endElement(String arg0, String arg1, String arg2) throws SAXException {
- nextHandler.endElement(arg0, arg1, arg2);
- }
-
- public void startPrefixMapping(String arg0, String arg1) throws SAXException {
- nextHandler.startPrefixMapping(arg0, arg1);
- }
-
- public void endPrefixMapping(String arg0) throws SAXException {
- nextHandler.endPrefixMapping(arg0);
- }
-
- public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
- nextHandler.characters(arg0, arg1, arg2);
- }
-
- public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
- nextHandler.ignorableWhitespace(arg0, arg1, arg2);
- }
-
- public void processingInstruction(String arg0, String arg1) throws SAXException {
- nextHandler.processingInstruction(arg0, arg1);
- }
-
- public void skippedEntity(String arg0) throws SAXException {
- nextHandler.skippedEntity(arg0);
- }
- }
-
- public static class StartHandler extends DefaultHandler {
-
- private ContentHandler nextHandler;
- private Map<String, String> dtdMappings;
-
- /**
- * Create a filter that is chained to another handler.
- * @param next the next handler in the chain.
- */
- public StartHandler(ContentHandler next, Map<String, String> dtdMappings) {
- nextHandler = next;
- this.dtdMappings = dtdMappings;
- }
-
- @Override
- public void setDocumentLocator(Locator locator) {
- nextHandler.setDocumentLocator(locator);
- }
-
- @Override
- public void startDocument() throws SAXException {
- nextHandler.startDocument();
- }
-
- @Override
- public void endDocument() throws SAXException {
- nextHandler.endDocument();
- }
-
- @Override
- public void startElement(String uri, String loc, String raw, Attributes attrs) throws SAXException {
- nextHandler.startElement(uri, loc, raw, attrs);
- }
-
- @Override
- public void endElement(String arg0, String arg1, String arg2) throws SAXException {
- nextHandler.endElement(arg0, arg1, arg2);
- }
-
- @Override
- public void startPrefixMapping(String arg0, String arg1) throws SAXException {
- nextHandler.startPrefixMapping(arg0, arg1);
- }
-
- @Override
- public void endPrefixMapping(String arg0) throws SAXException {
- nextHandler.endPrefixMapping(arg0);
- }
-
- @Override
- public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
- nextHandler.characters(arg0, arg1, arg2);
- }
-
- @Override
- public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
- nextHandler.ignorableWhitespace(arg0, arg1, arg2);
- }
-
- @Override
- public void processingInstruction(String arg0, String arg1) throws SAXException {
- nextHandler.processingInstruction(arg0, arg1);
- }
-
- @Override
- public void skippedEntity(String arg0) throws SAXException {
- nextHandler.skippedEntity(arg0);
- }
-
- @Override
- public InputSource resolveEntity(String publicId, String systemId) {
- if (dtdMappings != null && dtdMappings.containsKey(publicId)) {
- String dtdFile = dtdMappings.get(publicId);
- return new InputSource(ClassLoaderUtil.getResourceAsStream(dtdFile, DomHelper.class));
- } else {
- LOG.warn("Local DTD is missing for publicID: {} - defined mappings: {}", publicId, dtdMappings);
- }
- return null;
- }
-
- @Override
- public void warning(SAXParseException exception) {
- }
-
- @Override
- public void error(SAXParseException exception) throws SAXException {
- LOG.error("{} at ({}:{}:{})", exception.getMessage(), exception.getPublicId(), exception.getLineNumber(), exception.getColumnNumber(), exception);
- throw exception;
- }
-
- @Override
- public void fatalError(SAXParseException exception) throws SAXException {
- LOG.fatal("{} at ({}:{}:{})", exception.getMessage(), exception.getPublicId(), exception.getLineNumber(), exception.getColumnNumber(), exception);
- throw exception;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/Element.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/Element.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/Element.java
deleted file mode 100644
index 30903d2..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/Element.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <!-- START SNIPPET: description -->
- * <p/>Sets the Element for type conversion.
- * <!-- END SNIPPET: description -->
- *
- * <p/> <u>Annotation usage:</u>
- *
- * <!-- START SNIPPET: usage -->
- * <p/>The Element annotation must be applied at field or method level.
- * <!-- END SNIPPET: usage -->
- * <p/> <u>Annotation parameters:</u>
- *
- * <!-- START SNIPPET: parameters -->
- * <table>
- * <thead>
- * <tr>
- * <th>Parameter</th>
- * <th>Required</th>
- * <th>Default</th>
- * <th>Description</th>
- * </tr>
- * </thead>
- * <tbody>
- * <tr>
- * <td>value</td>
- * <td>no</td>
- * <td>java.lang.Object.class</td>
- * <td>The element property value.</td>
- * </tr>
- * </tbody>
- * </table>
- * <!-- END SNIPPET: parameters -->
- *
- * <p/> <u>Example code:</u>
- * <pre>
- * <!-- START SNIPPET: example -->
- * // The key property for User objects within the users collection is the <code>userName</code> attribute.
- * @Element( value = com.acme.User )
- * private Map<Long, User> userMap;
- *
- * @Element( value = com.acme.User )
- * public List<User> userList;
- * <!-- END SNIPPET: example -->
- * </pre>
- *
- * @author Rainer Hermanns
- * @version $Id$
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.METHOD})
-public @interface Element {
-
- /**
- * The Element value.
- * Defaults to <tt>java.lang.Object.class</tt>.
- */
- Class value() default java.lang.Object.class;
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/Key.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/Key.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/Key.java
deleted file mode 100644
index c1b0fc8..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/Key.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <!-- START SNIPPET: description -->
- * <p/>Sets the Key for type conversion.
- * <!-- END SNIPPET: description -->
- *
- * <p/> <u>Annotation usage:</u>
- *
- * <!-- START SNIPPET: usage -->
- * <p/>The Key annotation must be applied at field or method level.
- * <!-- END SNIPPET: usage -->
- * <p/> <u>Annotation parameters:</u>
- *
- * <!-- START SNIPPET: parameters -->
- * <table>
- * <thead>
- * <tr>
- * <th>Parameter</th>
- * <th>Required</th>
- * <th>Default</th>
- * <th>Description</th>
- * </tr>
- * </thead>
- * <tbody>
- * <tr>
- * <td>value</td>
- * <td>no</td>
- * <td>java.lang.Object.class</td>
- * <td>The key property value.</td>
- * </tr>
- * </tbody>
- * </table>
- * <!-- END SNIPPET: parameters -->
- *
- * <p/> <u>Example code:</u>
- * <pre>
- * <!-- START SNIPPET: example -->
- * // The key property for User objects within the users collection is the <code>userName</code> attribute.
- * @Key( value = java.lang.Long.class )
- * private Map<Long, User> userMap;
- * <!-- END SNIPPET: example -->
- * </pre>
- *
- * @author Rainer Hermanns
- * @version $Id$
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.METHOD})
-public @interface Key {
-
- /**
- * The Key value.
- * Defaults to <tt>java.lang.Object.class</tt>.
- */
- Class value() default java.lang.Object.class;
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/util/KeyProperty.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/KeyProperty.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/KeyProperty.java
deleted file mode 100644
index 8832bee..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/KeyProperty.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <!-- START SNIPPET: description -->
- * <p/>Sets the KeyProperty for type conversion.
- * <!-- END SNIPPET: description -->
- *
- * <p/> <u>Annotation usage:</u>
- *
- * <!-- START SNIPPET: usage -->
- * <p/>The KeyProperty annotation must be applied at field or method level.
- * <p/>This annotation should be used with Generic types, if the key property of the key element needs to be specified.
- * <!-- END SNIPPET: usage -->
- * <p/> <u>Annotation parameters:</u>
- *
- * <!-- START SNIPPET: parameters -->
- * <table>
- * <thead>
- * <tr>
- * <th>Parameter</th>
- * <th>Required</th>
- * <th>Default</th>
- * <th>Description</th>
- * </tr>
- * </thead>
- * <tbody>
- * <tr>
- * <td>value</td>
- * <td>no</td>
- * <td>id</td>
- * <td>The key property value.</td>
- * </tr>
- * </tbody>
- * </table>
- * <!-- END SNIPPET: parameters -->
- *
- * <p/> <u>Example code:</u>
- * <pre>
- * <!-- START SNIPPET: example -->
- * // The key property for User objects within the users collection is the <code>userName</code> attribute.
- * @KeyProperty( value = "userName" )
- * protected List<User> users = null;
- * <!-- END SNIPPET: example -->
- * </pre>
- *
- * @author Patrick Lightbody
- * @author Rainer Hermanns
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.METHOD})
-public @interface KeyProperty {
-
- /**
- * The KeyProperty value.
- * Defaults to the <tt>id</tt> attribute.
- */
- String value() default "id";
-}