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:09 UTC
[09/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/conversion/impl/DefaultTypeConverter.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverter.java
deleted file mode 100644
index 47bcd1b..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverter.java
+++ /dev/null
@@ -1,355 +0,0 @@
-//--------------------------------------------------------------------------
-// Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-// Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-// Neither the name of the Drew Davidson nor the names of its contributors
-// may be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-// DAMAGE.
-//--------------------------------------------------------------------------
-package com.opensymphony.xwork2.conversion.impl;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.LocaleProvider;
-import com.opensymphony.xwork2.conversion.TypeConverter;
-import com.opensymphony.xwork2.inject.Container;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.ognl.XWorkTypeConverterWrapper;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Member;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * Default type conversion. Converts among numeric types and also strings. Contains the basic
- * type mapping code from OGNL.
- *
- * @author Luke Blanshard (blanshlu@netscape.net)
- * @author Drew Davidson (drew@ognl.org)
- */
-public abstract class DefaultTypeConverter implements TypeConverter {
-
- protected static String MILLISECOND_FORMAT = ".SSS";
-
- private static final String NULL_STRING = "null";
-
- private static final Map<Class, Object> primitiveDefaults;
-
- private Container container;
-
- static {
- 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));
- map.put(Character.TYPE, new Character((char) 0));
- map.put(Integer.TYPE, Integer.valueOf(0));
- map.put(Long.TYPE, Long.valueOf(0L));
- map.put(Float.TYPE, new Float(0.0f));
- map.put(Double.TYPE, new Double(0.0));
- map.put(BigInteger.class, new BigInteger("0"));
- map.put(BigDecimal.class, new BigDecimal(0.0));
- primitiveDefaults = Collections.unmodifiableMap(map);
- }
-
- @Inject
- public void setContainer(Container container) {
- this.container = container;
- }
-
- public Object convertValue(Map<String, Object> context, Object value, Class toType) {
- return convertValue(value, toType);
- }
-
- public Object convertValue(Map<String, Object> context, Object target, Member member,
- String propertyName, Object value, Class toType) {
- return convertValue(context, value, toType);
- }
-
- public TypeConverter getTypeConverter( Map<String, Object> context )
- {
- Object obj = context.get(TypeConverter.TYPE_CONVERTER_CONTEXT_KEY);
- if (obj instanceof TypeConverter) {
- return (TypeConverter) obj;
-
- // for backwards-compatibility
- } else if (obj instanceof ognl.TypeConverter) {
- return new XWorkTypeConverterWrapper((ognl.TypeConverter) obj);
- }
- return null;
- }
-
- /**
- * Returns the value converted numerically to the given class type
- *
- * This method also detects when arrays are being converted and converts the
- * components of one array to the type of the other.
- *
- * @param value
- * an object to be converted to the given type
- * @param toType
- * class type to be converted to
- * @return converted value of the type given, or value if the value cannot
- * be converted to the given type.
- */
- public Object convertValue(Object value, Class toType) {
- Object result = null;
-
- if (value != null) {
- /* If array -> array then convert components of array individually */
- if (value.getClass().isArray() && toType.isArray()) {
- Class componentType = toType.getComponentType();
-
- result = Array.newInstance(componentType, Array
- .getLength(value));
- for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
- Array.set(result, i, convertValue(Array.get(value, i),
- componentType));
- }
- } else {
- if ((toType == Integer.class) || (toType == Integer.TYPE))
- result = (int) longValue(value);
- if ((toType == Double.class) || (toType == Double.TYPE))
- 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) longValue(value);
- if ((toType == Character.class) || (toType == Character.TYPE))
- result = (char) longValue(value);
- if ((toType == Short.class) || (toType == Short.TYPE))
- result = (short) longValue(value);
- if ((toType == Long.class) || (toType == Long.TYPE))
- result = longValue(value);
- if ((toType == Float.class) || (toType == Float.TYPE))
- result = new Float(doubleValue(value));
- if (toType == BigInteger.class)
- result = bigIntValue(value);
- if (toType == BigDecimal.class)
- result = bigDecValue(value);
- if (toType == String.class)
- result = stringValue(value);
- if (Enum.class.isAssignableFrom(toType))
- result = enumValue(toType, value);
- }
- } else {
- if (toType.isPrimitive()) {
- result = primitiveDefaults.get(toType);
- }
- }
- return result;
- }
-
- /**
- * Evaluates the given object as a boolean: if it is a Boolean object, it's
- * easy; if it's a Number or a Character, returns true for non-zero objects;
- * and otherwise returns true for non-null objects.
- *
- * @param value
- * an object to interpret as a boolean
- * @return the boolean value implied by the given object
- */
- public static boolean booleanValue(Object value) {
- if (value == null)
- return false;
- Class c = value.getClass();
- if (c == Boolean.class)
- return (Boolean) value;
- // if ( c == String.class )
- // return ((String)value).length() > 0;
- if (c == Character.class)
- return (Character) value != 0;
- if (value instanceof Number)
- return ((Number) value).doubleValue() != 0;
- return true; // non-null
- }
-
- public Enum<?> enumValue(Class toClass, Object o) {
- Enum<?> result = null;
- if (o == null) {
- result = null;
- } else if (o instanceof String[]) {
- result = Enum.valueOf(toClass, ((String[]) o)[0]);
- } else if (o instanceof String) {
- result = Enum.valueOf(toClass, (String) o);
- }
- return result;
- }
-
- /**
- * Evaluates the given object as a long integer.
- *
- * @param value
- * an object to interpret as a long integer
- * @return the long integer value implied by the given object
- * @throws NumberFormatException
- * if the given object can't be understood as a long integer
- */
- public static long longValue(Object value) throws NumberFormatException {
- if (value == null)
- return 0L;
- Class c = value.getClass();
- if (c.getSuperclass() == Number.class)
- return ((Number) value).longValue();
- if (c == Boolean.class)
- return (Boolean) value ? 1 : 0;
- if (c == Character.class)
- return (Character) value;
- return Long.parseLong(stringValue(value, true));
- }
-
- /**
- * Evaluates the given object as a double-precision floating-point number.
- *
- * @param value
- * an object to interpret as a double
- * @return the double value implied by the given object
- * @throws NumberFormatException
- * if the given object can't be understood as a double
- */
- public static double doubleValue(Object value) throws NumberFormatException {
- if (value == null)
- return 0.0;
- Class c = value.getClass();
- if (c.getSuperclass() == Number.class)
- return ((Number) value).doubleValue();
- if (c == Boolean.class)
- return (Boolean) value ? 1 : 0;
- if (c == Character.class)
- return (Character) value;
- String s = stringValue(value, true);
-
- return (s.length() == 0) ? 0.0 : Double.parseDouble(s);
- /*
- * For 1.1 parseDouble() is not available
- */
- // return Double.valueOf( value.toString() ).doubleValue();
- }
-
- /**
- * Evaluates the given object as a BigInteger.
- *
- * @param value
- * an object to interpret as a BigInteger
- * @return the BigInteger value implied by the given object
- * @throws NumberFormatException
- * if the given object can't be understood as a BigInteger
- */
- public static BigInteger bigIntValue(Object value)
- throws NumberFormatException {
- if (value == null)
- return BigInteger.valueOf(0L);
- Class c = value.getClass();
- if (c == BigInteger.class)
- return (BigInteger) value;
- if (c == BigDecimal.class)
- return ((BigDecimal) value).toBigInteger();
- if (c.getSuperclass() == Number.class)
- return BigInteger.valueOf(((Number) value).longValue());
- if (c == Boolean.class)
- return BigInteger.valueOf((Boolean) value ? 1 : 0);
- if (c == Character.class)
- return BigInteger.valueOf(((Character) value).charValue());
- return new BigInteger(stringValue(value, true));
- }
-
- /**
- * Evaluates the given object as a BigDecimal.
- *
- * @param value
- * an object to interpret as a BigDecimal
- * @return the BigDecimal value implied by the given object
- * @throws NumberFormatException
- * if the given object can't be understood as a BigDecimal
- */
- public static BigDecimal bigDecValue(Object value)
- throws NumberFormatException {
- if (value == null)
- return BigDecimal.valueOf(0L);
- Class c = value.getClass();
- if (c == BigDecimal.class)
- return (BigDecimal) value;
- if (c == BigInteger.class)
- return new BigDecimal((BigInteger) value);
- if (c.getSuperclass() == Number.class)
- return new BigDecimal(((Number) value).doubleValue());
- if (c == Boolean.class)
- return BigDecimal.valueOf((Boolean) value ? 1 : 0);
- if (c == Character.class)
- return BigDecimal.valueOf(((Character) value).charValue());
- return new BigDecimal(stringValue(value, true));
- }
-
- /**
- * Evaluates the given object as a String and trims it if the trim flag is
- * true.
- *
- * @param value
- * an object to interpret as a String
- * @return the String value implied by the given object as returned by the
- * toString() method, or "null" if the object is null.
- */
- public static String stringValue(Object value, boolean trim) {
- String result;
-
- if (value == null) {
- result = NULL_STRING;
- } else {
- result = value.toString();
- if (trim) {
- result = result.trim();
- }
- }
- return result;
- }
-
- /**
- * Evaluates the given object as a String.
- *
- * @param value
- * an object to interpret as a String
- * @return the String value implied by the given object as returned by the
- * toString() method, or "null" if the object is null.
- */
- public static String stringValue(Object value) {
- return stringValue(value, false);
- }
-
- protected Locale getLocale(Map<String, Object> context) {
- Locale locale = null;
- if (context != null) {
- locale = (Locale) context.get(ActionContext.LOCALE);
- }
- if (locale == null) {
- locale = container.getInstance(LocaleProvider.class).getLocale();
- }
- return locale;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterCreator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterCreator.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterCreator.java
deleted file mode 100644
index ed6ac22..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterCreator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.opensymphony.xwork2.conversion.impl;
-
-import com.opensymphony.xwork2.ObjectFactory;
-import com.opensymphony.xwork2.conversion.TypeConverter;
-import com.opensymphony.xwork2.conversion.TypeConverterCreator;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.ognl.XWorkTypeConverterWrapper;
-
-/**
- * Default implementation of {@link TypeConverterCreator}
- */
-public class DefaultTypeConverterCreator implements TypeConverterCreator {
-
- private ObjectFactory objectFactory;
-
- @Inject
- public void setObjectFactory(ObjectFactory objectFactory) {
- this.objectFactory = objectFactory;
- }
-
- public TypeConverter createTypeConverter(String className) throws Exception {
- // type converters are used across users
- Object obj = objectFactory.buildBean(className, null);
- if (obj instanceof TypeConverter) {
- return (TypeConverter) obj;
-
- // For backwards compatibility
- } else if (obj instanceof ognl.TypeConverter) {
- return new XWorkTypeConverterWrapper((ognl.TypeConverter) obj);
- } else {
- throw new IllegalArgumentException("Type converter class " + obj.getClass() + " doesn't implement com.opensymphony.xwork2.conversion.TypeConverter");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterHolder.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterHolder.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterHolder.java
deleted file mode 100644
index 2acaf96..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultTypeConverterHolder.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package com.opensymphony.xwork2.conversion.impl;
-
-import com.opensymphony.xwork2.conversion.TypeConverter;
-import com.opensymphony.xwork2.conversion.TypeConverterHolder;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-/**
- * Default implementation of {@link TypeConverterHolder}
- */
-public class DefaultTypeConverterHolder implements TypeConverterHolder {
-
- /**
- * Record class and its type converter mapping.
- * <pre>
- * - String - classname as String
- * - TypeConverter - instance of TypeConverter
- * </pre>
- */
- private HashMap<String, TypeConverter> defaultMappings = new HashMap<>(); // non-action (eg. returned value)
-
- /**
- * Target class conversion Mappings.
- * <pre>
- * Map<Class, Map<String, Object>>
- * - Class -> convert to class
- * - Map<String, Object>
- * - String -> property name
- * eg. Element_property, property etc.
- * - Object -> String to represent properties
- * eg. value part of
- * KeyProperty_property=id
- * -> TypeConverter to represent an Ognl TypeConverter
- * eg. value part of
- * property=foo.bar.MyConverter
- * -> Class to represent a class
- * eg. value part of
- * Element_property=foo.bar.MyObject
- * </pre>
- */
- 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<>(); // action
-
- /**
- * Record classes that doesn't have conversion mapping defined.
- * <pre>
- * - String -> classname as String
- * </pre>
- */
- protected HashSet<String> unknownMappings = new HashSet<>(); // non-action (eg. returned value)
-
- public void addDefaultMapping(String className, TypeConverter typeConverter) {
- defaultMappings.put(className, typeConverter);
- if (unknownMappings.contains(className)) {
- unknownMappings.remove(className);
- }
- }
-
- public boolean containsDefaultMapping(String className) {
- return defaultMappings.containsKey(className);
- }
-
- public TypeConverter getDefaultMapping(String className) {
- return defaultMappings.get(className);
- }
-
- public Map<String, Object> getMapping(Class clazz) {
- return mappings.get(clazz);
- }
-
- public void addMapping(Class clazz, Map<String, Object> mapping) {
- mappings.put(clazz, mapping);
- }
-
- public boolean containsNoMapping(Class clazz) {
- return noMapping.contains(clazz);
- }
-
- public void addNoMapping(Class clazz) {
- noMapping.add(clazz);
- }
-
- public boolean containsUnknownMapping(String className) {
- return unknownMappings.contains(className);
- }
-
- public void addUnknownMapping(String className) {
- unknownMappings.add(className);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/EnumTypeConverter.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/EnumTypeConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/EnumTypeConverter.java
deleted file mode 100644
index 949eede..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/EnumTypeConverter.java
+++ /dev/null
@@ -1,124 +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.conversion.impl;
-
-import java.util.Map;
-
-
-/**
- * <code>EnumTypeConverter</code>
- *
- * <!-- START SNIPPET: description -->
- * This class converts java 5 enums to String and from String[] to enum.
- * <p/>
- * One of Java 5's improvements is providing enumeration facility.
- * Up to now, there existed no enumerations. The only way to simulate was the so-called int Enum pattern:
- * {code}
- * public static final int SEASON_WINTER = 0;
- * public static final int SEASON_SPRING = 1;
- * public static final int SEASON_SUMMER = 2;
- * public static final int SEASON_FALL = 3;
- * {code}
- * <p/>
- * Java 5.0 now provides the following construct:
- * {code}
- * public static enum Season { WINTER, SPRING, SUMMER, FALL };
- * {code}
- * <!-- END SNIPPET: description -->
- *
- * <!-- START SNIPPET: example -->
- * h3. Implementing Java 5 Enumeration Type Conversion
- * <p/>
- * 1. myAction-conversion.properties*
- * <p/>
- * Place a myAction-conversion.properties-file in the path of your Action.
- * Add the following entry to the properties-file:
- * {code}
- * nameOfYourField=fullyClassifiedNameOfYourConverter
- * {code}
- *
- * <p/>
- * 2. myAction.java*
- * Your action contains the _enumeration_:
- * {code}
- * public enum Criticality {DEBUG, INFO, WARNING, ERROR, FATAL}
- * {code}
- *
- * * Your action contains the _private field_:
- * {code}
- * private myEnum myFieldForEnum;
- * {code}
- *
- * Your action contains _getters and setters_ for your field:
- * {code}
- * public myEnum getCriticality() {
- * return myFieldForEnum;
- * }
- *
- * public void setCriticality(myEnum myFieldForEnum) {
- * this.myFieldForEnum= myFieldForEnum;
- * }
- * {code}
- * <p/>
- * 3. JSP*
- * <p/>
- * In your jsp you can access an enumeration value just normal by using the known <ww:property>-Tag:
- * {code}
- * <ww:property value="myField"/>
- * {code}
- * <!-- END SNIPPET: example -->
- *
- * @author Tamara Cattivelli
- * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
- * @version $Id$
- * @deprecated Since Struts 2.1.0 as enum support is now built into XWork
- */
-@Deprecated public class EnumTypeConverter extends DefaultTypeConverter {
-
- /**
- * Converts the given object to a given type. How this is to be done is implemented in toClass. The OGNL context, o
- * and toClass are given. This method should be able to handle conversion in general without any context or object
- * specified.
- *
- * @param context - OGNL context under which the conversion is being done
- * @param o - the object to be converted
- * @param toClass - the class that contains the code to convert to enumeration
- * @return Converted value of type declared in toClass or TypeConverter.NoConversionPossible to indicate that the
- * conversion was not possible.
- */
- @Override
- public Object convertValue(Map<String, Object> context, Object o, Class toClass) {
- if (o instanceof String[]) {
- return convertFromString(((String[]) o)[0], toClass);
- } else if (o instanceof String) {
- return convertFromString((String) o, toClass);
- }
-
- return super.convertValue(context, o, toClass);
- }
-
- /**
- * Converts one or more String values to the specified class.
- * @param value - the String values to be converted, such as those submitted from an HTML form
- * @param toClass - the class to convert to
- * @return the converted object
- */
- public java.lang.Enum convertFromString(String value, Class toClass) {
- return Enum.valueOf(toClass, value);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/GenericsObjectTypeDeterminer.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/GenericsObjectTypeDeterminer.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/GenericsObjectTypeDeterminer.java
deleted file mode 100644
index 69f1ced..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/GenericsObjectTypeDeterminer.java
+++ /dev/null
@@ -1,38 +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.conversion.impl;
-
-import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
-
-
-/**
- * GenericsObjectTypeDeterminer
- *
- * @author Patrick Lightbody
- * @author Rainer Hermanns
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- *
- * @deprecated Use DefaultObjectTypeDeterminer instead. Since XWork 2.0.4 the DefaultObjectTypeDeterminer handles the
- * annotation processing.
- */
-@Deprecated public class GenericsObjectTypeDeterminer extends DefaultObjectTypeDeterminer {
-
- public GenericsObjectTypeDeterminer(XWorkConverter conv,
- XWorkBasicConverter basicConv, ReflectionProvider prov) {
- super(conv, prov);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java
deleted file mode 100644
index 386d070..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandler.java
+++ /dev/null
@@ -1,157 +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.conversion.impl;
-
-import com.opensymphony.xwork2.ObjectFactory;
-import com.opensymphony.xwork2.conversion.NullHandler;
-import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
-import com.opensymphony.xwork2.inject.Inject;
-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.*;
-
-
-/**
- * <!-- START SNIPPET: javadoc -->
- *
- * Provided that the key {@link ReflectionContextState#CREATE_NULL_OBJECTS} is in the action context with a value of true (this key is set
- * only during the execution of the {@link com.opensymphony.xwork2.interceptor.ParametersInterceptor}), OGNL expressions
- * that have caused a NullPointerException will be temporarily stopped for evaluation while the system automatically
- * tries to solve the null references by automatically creating the object.
- *
- * <p/> The following rules are used when handling null references:
- *
- * <ul>
- *
- * <li>If the property is declared <i>exactly</i> as a {@link Collection} or {@link List}, then an ArrayList shall be
- * returned and assigned to the null references.</li>
- *
- * <li>If the property is declared as a {@link Map}, then a HashMap will be returned and assigned to the null
- * references.</li>
- *
- * <li>If the null property is a simple bean with a no-arg constructor, it will simply be created using the {@link
- * ObjectFactory#buildBean(java.lang.Class, java.util.Map)} method.</li>
- *
- * </ul>
- *
- * <!-- END SNIPPET: javadoc -->
- *
- * <!-- START SNIPPET: example -->
- *
- * For example, if a form element has a text field named <b>person.name</b> and the expression <i>person</i> evaluates
- * to null, then this class will be invoked. Because the <i>person</i> expression evaluates to a <i>Person</i> class, a
- * new Person is created and assigned to the null reference. Finally, the name is set on that object and the overall
- * effect is that the system automatically created a Person object for you, set it by calling setUsers() and then
- * finally called getUsers().setName() as you would typically expect.
- *
- * <!-- END SNIPPET: example>
- *
- * @author Matt Ho
- * @author Patrick Lightbody
- */
-public class InstantiatingNullHandler implements NullHandler {
-
- /**
- * @deprecated Use {@link ReflectionContextState#CREATE_NULL_OBJECTS} instead
- */
- @Deprecated public static final String CREATE_NULL_OBJECTS = ReflectionContextState.CREATE_NULL_OBJECTS;
- private static final Logger LOG = LogManager.getLogger(InstantiatingNullHandler.class);
- private ReflectionProvider reflectionProvider;
- private ObjectFactory objectFactory;
- private ObjectTypeDeterminer objectTypeDeterminer;
-
- @Inject
- public void setObjectTypeDeterminer(ObjectTypeDeterminer det) {
- this.objectTypeDeterminer = det;
- }
-
- @Inject
- public void setReflectionProvider(ReflectionProvider prov) {
- this.reflectionProvider = prov;
- }
-
- @Inject
- public void setObjectFactory(ObjectFactory fac) {
- this.objectFactory = fac;
- }
-
- public Object nullMethodResult(Map<String, Object> context, Object target, String methodName, Object[] args) {
- LOG.debug("Entering nullMethodResult");
- return null;
- }
-
- public Object nullPropertyValue(Map<String, Object> context, Object target, Object property) {
- LOG.debug("Entering nullPropertyValue [target={}, property={}]", target, property);
- boolean c = ReflectionContextState.isCreatingNullObjects(context);
-
- if (!c) {
- return null;
- }
-
- if ((target == null) || (property == null)) {
- return null;
- }
-
- try {
- String propName = property.toString();
- Object realTarget = reflectionProvider.getRealTarget(propName, context, target);
- Class clazz = null;
-
- if (realTarget != null) {
- PropertyDescriptor pd = reflectionProvider.getPropertyDescriptor(realTarget.getClass(), propName);
- if (pd == null) {
- return null;
- }
-
- clazz = pd.getPropertyType();
- }
-
- if (clazz == null) {
- // can't do much here!
- return null;
- }
-
- Object param = createObject(clazz, realTarget, propName, context);
-
- reflectionProvider.setValue(propName, context, realTarget, param);
-
- return param;
- } catch (Exception e) {
- LOG.error("Could not create and/or set value back on to object", e);
- }
-
- return null;
- }
-
- private Object createObject(Class clazz, Object target, String property, Map<String, Object> context) throws Exception {
- if (Set.class.isAssignableFrom(clazz)) {
- return new HashSet();
- } else if (Collection.class.isAssignableFrom(clazz)) {
- return new ArrayList();
- } else if (clazz == Map.class) {
- return new HashMap();
- } else if (clazz == EnumMap.class) {
- Class keyClass = objectTypeDeterminer.getKeyClass(target.getClass(), property);
- return new EnumMap(keyClass);
- }
-
- return objectFactory.buildBean(clazz, context);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/NumberConverter.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/NumberConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/NumberConverter.java
deleted file mode 100644
index ab6efc0..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/NumberConverter.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package com.opensymphony.xwork2.conversion.impl;
-
-import com.opensymphony.xwork2.XWorkException;
-
-import java.lang.reflect.Member;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Map;
-
-public class NumberConverter extends DefaultTypeConverter {
-
- public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) {
- if (value instanceof String) {
- if (toType == BigDecimal.class) {
- return new BigDecimal((String) value);
- } else if (toType == BigInteger.class) {
- return new BigInteger((String) value);
- } else if (toType.isPrimitive()) {
- Object convertedValue = super.convertValue(context, value, toType);
- String stringValue = (String) value;
- if (!isInRange((Number) convertedValue, stringValue, toType))
- throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + convertedValue.getClass().getName());
-
- return convertedValue;
- } else {
- String stringValue = (String) value;
- if (!toType.isPrimitive() && (stringValue == null || stringValue.length() == 0)) {
- return null;
- }
- NumberFormat numFormat = NumberFormat.getInstance(getLocale(context));
- ParsePosition parsePos = new ParsePosition(0);
- if (isIntegerType(toType)) {
- numFormat.setParseIntegerOnly(true);
- }
- numFormat.setGroupingUsed(true);
- Number number = numFormat.parse(stringValue, parsePos);
-
- if (parsePos.getIndex() != stringValue.length()) {
- throw new XWorkException("Unparseable number: \"" + stringValue + "\" at position "
- + parsePos.getIndex());
- } else {
- if (!isInRange(number, stringValue, toType))
- throw new XWorkException("Overflow or underflow casting: \"" + stringValue + "\" into class " + number.getClass().getName());
-
- value = super.convertValue(context, number, toType);
- }
- }
- } else if (value instanceof Object[]) {
- Object[] objArray = (Object[]) value;
-
- if (objArray.length == 1) {
- return convertValue(context, null, null, null, objArray[0], toType);
- }
- }
-
- // pass it through DefaultTypeConverter
- return super.convertValue(context, value, toType);
- }
-
- protected boolean isInRange(Number value, String stringValue, Class toType) {
- Number bigValue = null;
- Number lowerBound = null;
- Number upperBound = null;
-
- try {
- if (double.class == toType || Double.class == toType) {
- bigValue = new BigDecimal(stringValue);
- // Double.MIN_VALUE is the smallest positive non-zero number
- lowerBound = BigDecimal.valueOf(Double.MAX_VALUE).negate();
- upperBound = BigDecimal.valueOf(Double.MAX_VALUE);
- } else if (float.class == toType || Float.class == toType) {
- bigValue = new BigDecimal(stringValue);
- // Float.MIN_VALUE is the smallest positive non-zero number
- lowerBound = BigDecimal.valueOf(Float.MAX_VALUE).negate();
- upperBound = BigDecimal.valueOf(Float.MAX_VALUE);
- } else if (byte.class == toType || Byte.class == toType) {
- bigValue = new BigInteger(stringValue);
- lowerBound = BigInteger.valueOf(Byte.MIN_VALUE);
- upperBound = BigInteger.valueOf(Byte.MAX_VALUE);
- } else if (char.class == toType || Character.class == toType) {
- bigValue = new BigInteger(stringValue);
- lowerBound = BigInteger.valueOf(Character.MIN_VALUE);
- upperBound = BigInteger.valueOf(Character.MAX_VALUE);
- } else if (short.class == toType || Short.class == toType) {
- bigValue = new BigInteger(stringValue);
- lowerBound = BigInteger.valueOf(Short.MIN_VALUE);
- upperBound = BigInteger.valueOf(Short.MAX_VALUE);
- } else if (int.class == toType || Integer.class == toType) {
- bigValue = new BigInteger(stringValue);
- lowerBound = BigInteger.valueOf(Integer.MIN_VALUE);
- upperBound = BigInteger.valueOf(Integer.MAX_VALUE);
- } else if (long.class == toType || Long.class == toType) {
- bigValue = new BigInteger(stringValue);
- lowerBound = BigInteger.valueOf(Long.MIN_VALUE);
- upperBound = BigInteger.valueOf(Long.MAX_VALUE);
- } else {
- throw new IllegalArgumentException("Unexpected numeric type: " + toType.getName());
- }
- } catch (NumberFormatException e) {
- //shoult it fail here? BigInteger doesnt seem to be so nice parsing numbers as NumberFormat
- return true;
- }
-
- return ((Comparable)bigValue).compareTo(lowerBound) >= 0 && ((Comparable)bigValue).compareTo(upperBound) <= 0;
- }
-
- private boolean isIntegerType(Class type) {
- if (double.class == type || float.class == type || Double.class == type || Float.class == type
- || char.class == type || Character.class == type) {
- return false;
- }
-
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/StringConverter.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/StringConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/StringConverter.java
deleted file mode 100644
index 9c6cc8f..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/StringConverter.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.opensymphony.xwork2.conversion.impl;
-
-import org.apache.commons.lang3.StringUtils;
-
-import java.lang.reflect.Member;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-public class StringConverter extends DefaultTypeConverter {
-
- @Override
- public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) {
- String result = null;
-
- if (value instanceof int[]) {
- int[] x = (int[]) value;
- List<Integer> intArray = new ArrayList<>(x.length);
-
- for (int aX : x) {
- intArray.add(Integer.valueOf(aX));
- }
-
- result = StringUtils.join(intArray, ", ");
- } else if (value instanceof long[]) {
- long[] x = (long[]) value;
- List<Long> longArray = new ArrayList<>(x.length);
-
- for (long aX : x) {
- longArray.add(Long.valueOf(aX));
- }
-
- result = StringUtils.join(longArray, ", ");
- } else if (value instanceof double[]) {
- double[] x = (double[]) value;
- List<Double> doubleArray = new ArrayList<>(x.length);
-
- for (double aX : x) {
- doubleArray.add(new Double(aX));
- }
-
- result = StringUtils.join(doubleArray, ", ");
- } else if (value instanceof boolean[]) {
- boolean[] x = (boolean[]) value;
- List<Boolean> booleanArray = new ArrayList<>(x.length);
-
- for (boolean aX : x) {
- booleanArray.add(new Boolean(aX));
- }
-
- result = StringUtils.join(booleanArray, ", ");
- } else if (value instanceof Date) {
- DateFormat df = null;
- if (value instanceof java.sql.Time) {
- df = DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale(context));
- } else if (value instanceof java.sql.Timestamp) {
- SimpleDateFormat dfmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT,
- DateFormat.MEDIUM,
- getLocale(context));
- df = new SimpleDateFormat(dfmt.toPattern() + MILLISECOND_FORMAT);
- } else {
- df = DateFormat.getDateInstance(DateFormat.SHORT, getLocale(context));
- }
- result = df.format(value);
- } else if (value instanceof String[]) {
- result = StringUtils.join((String[]) value, ", ");
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java
deleted file mode 100644
index 69e78b7..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright 2002-2007,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.conversion.impl;
-
-import com.opensymphony.xwork2.XWorkConstants;
-import com.opensymphony.xwork2.XWorkException;
-import com.opensymphony.xwork2.conversion.TypeConverter;
-import com.opensymphony.xwork2.inject.Container;
-import com.opensymphony.xwork2.inject.Inject;
-
-import java.lang.reflect.Member;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-
-
-/**
- * <!-- START SNIPPET: javadoc -->
- * <p/>
- * XWork will automatically handle the most common type conversion for you. This includes support for converting to
- * and from Strings for each of the following:
- * <p/>
- * <ul>
- * <li>String</li>
- * <li>boolean / Boolean</li>
- * <li>char / Character</li>
- * <li>int / Integer, float / Float, long / Long, double / Double</li>
- * <li>dates - uses the SHORT format for the Locale associated with the current request</li>
- * <li>arrays - assuming the individual strings can be coverted to the individual items</li>
- * <li>collections - if not object type can be determined, it is assumed to be a String and a new ArrayList is
- * created</li>
- * </ul>
- * <p/> Note that with arrays the type conversion will defer to the type of the array elements and try to convert each
- * item individually. As with any other type conversion, if the conversion can't be performed the standard type
- * conversion error reporting is used to indicate a problem occurred while processing the type conversion.
- * <!-- END SNIPPET: javadoc -->
- *
- * @author <a href="mailto:plightbo@gmail.com">Pat Lightbody</a>
- * @author Mike Mosiewicz
- * @author Rainer Hermanns
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- */
-public class XWorkBasicConverter extends DefaultTypeConverter {
-
- private Container container;
-
- @Inject
- public void setContainer(Container container) {
- this.container = container;
- }
-
- @Override
- public Object convertValue(Map<String, Object> context, Object o, Member member, String propertyName, Object value, Class toType) {
- Object result = null;
-
- if (value == null || toType.isAssignableFrom(value.getClass())) {
- // no need to convert at all, right?
- return value;
- }
-
- if (toType == String.class) {
- /* the code below has been disabled as it causes sideffects in Struts2 (XW-512)
- // if input (value) is a number then use special conversion method (XW-490)
- Class inputType = value.getClass();
- if (Number.class.isAssignableFrom(inputType)) {
- result = doConvertFromNumberToString(context, value, inputType);
- if (result != null) {
- return result;
- }
- }*/
- // okay use default string conversion
- result = doConvertToString(context, value);
- } else if (toType == boolean.class) {
- result = doConvertToBoolean(value);
- } else if (toType == Boolean.class) {
- result = doConvertToBoolean(value);
- } else if (toType.isArray()) {
- result = doConvertToArray(context, o, member, propertyName, value, toType);
- } else if (Date.class.isAssignableFrom(toType)) {
- result = doConvertToDate(context, value, toType);
- } else if (Calendar.class.isAssignableFrom(toType)) {
- result = doConvertToCalendar(context, value);
- } else if (Collection.class.isAssignableFrom(toType)) {
- result = doConvertToCollection(context, o, member, propertyName, value, toType);
- } else if (toType == Character.class) {
- result = doConvertToCharacter(value);
- } else if (toType == char.class) {
- result = doConvertToCharacter(value);
- } else if (Number.class.isAssignableFrom(toType) || toType.isPrimitive()) {
- result = doConvertToNumber(context, value, toType);
- } else if (toType == Class.class) {
- result = doConvertToClass(value);
- }
-
- if (result == null) {
- if (value instanceof Object[]) {
- Object[] array = (Object[]) value;
-
- if (array.length >= 1) {
- value = array[0];
- } else {
- value = null;
- }
-
- // let's try to convert the first element only
- result = convertValue(context, o, member, propertyName, value, toType);
- } else if (!"".equals(value)) { // we've already tried the types we know
- result = super.convertValue(context, value, toType);
- }
-
- if (result == null && value != null && !"".equals(value)) {
- throw new XWorkException("Cannot create type " + toType + " from value " + value);
- }
- }
-
- return result;
- }
-
- private Object doConvertToCalendar(Map<String, Object> context, Object value) {
- Object result = null;
- Date dateResult = (Date) doConvertToDate(context, value, Date.class);
- if (dateResult != null) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(dateResult);
- result = calendar;
- }
- return result;
- }
-
- private Object doConvertToCharacter(Object value) {
- if (value instanceof String) {
- String cStr = (String) value;
- return (cStr.length() > 0) ? cStr.charAt(0) : null;
- }
- return null;
- }
-
- private Object doConvertToBoolean(Object value) {
- if (value instanceof String) {
- String bStr = (String) value;
- return Boolean.valueOf(bStr);
- }
- return null;
- }
-
- private Class doConvertToClass(Object value) {
- Class clazz = null;
- if (value != null && value instanceof String && ((String) value).length() > 0) {
- try {
- clazz = Class.forName((String) value);
- } catch (ClassNotFoundException e) {
- throw new XWorkException(e.getLocalizedMessage(), e);
- }
- }
- return clazz;
- }
-
- private Object doConvertToCollection(Map<String, Object> context, Object o, Member member, String prop, Object value, Class toType) {
- TypeConverter converter = container.getInstance(CollectionConverter.class);
- if (converter == null) {
- throw new XWorkException("TypeConverter with name [#0] must be registered first!", XWorkConstants.COLLECTION_CONVERTER);
- }
- return converter.convertValue(context, o, member, prop, value, toType);
- }
-
- private Object doConvertToArray(Map<String, Object> context, Object o, Member member, String prop, Object value, Class toType) {
- TypeConverter converter = container.getInstance(ArrayConverter.class);
- if (converter == null) {
- throw new XWorkException("TypeConverter with name [#0] must be registered first!", XWorkConstants.ARRAY_CONVERTER);
- }
- return converter.convertValue(context, o, member, prop, value, toType);
- }
-
- private Object doConvertToDate(Map<String, Object> context, Object value, Class toType) {
- TypeConverter converter = container.getInstance(DateConverter.class);
- if (converter == null) {
- throw new XWorkException("TypeConverter with name [#0] must be registered first!", XWorkConstants.DATE_CONVERTER);
- }
- return converter.convertValue(context, null, null, null, value, toType);
- }
-
- private Object doConvertToNumber(Map<String, Object> context, Object value, Class toType) {
- TypeConverter converter = container.getInstance(NumberConverter.class);
- if (converter == null) {
- throw new XWorkException("TypeConverter with name [#0] must be registered first!", XWorkConstants.NUMBER_CONVERTER);
- }
- return converter.convertValue(context, null, null, null, value, toType);
- }
-
- private Object doConvertToString(Map<String, Object> context, Object value) {
- TypeConverter converter = container.getInstance(StringConverter.class);
- if (converter == null) {
- throw new XWorkException("TypeConverter with name [#0] must be registered first!", XWorkConstants.STRING_CONVERTER);
- }
- return converter.convertValue(context, null, null, null, value, null);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java
deleted file mode 100644
index c0086ee..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java
+++ /dev/null
@@ -1,595 +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.conversion.impl;
-
-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.*;
-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;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
-/**
- * XWorkConverter is a singleton used by many of the Struts 2's Ognl extention points,
- * such as InstantiatingNullHandler, XWorkListPropertyAccessor etc to do object
- * conversion.
- * <p/>
- * <!-- START SNIPPET: javadoc -->
- * <p/>
- * Type conversion is great for situations where you need to turn a String in to a more complex object. Because the web
- * is type-agnostic (everything is a string in HTTP), Struts 2's type conversion features are very useful. For instance,
- * if you were prompting a user to enter in coordinates in the form of a string (such as "3, 22"), you could have
- * Struts 2 do the conversion both from String to Point and from Point to String.
- * <p/>
- * <p/> Using this "point" example, if your action (or another compound object in which you are setting properties on)
- * has a corresponding ClassName-conversion.properties file, Struts 2 will use the configured type converters for
- * conversion to and from strings. So turning "3, 22" in to new Point(3, 22) is done by merely adding the following
- * entry to <b>ClassName-conversion.properties</b> (Note that the PointConverter should impl the TypeConverter
- * interface):
- * <p/>
- * <p/><b>point = com.acme.PointConverter</b>
- * <p/>
- * <p/> Your type converter should be sure to check what class type it is being requested to convert. Because it is used
- * for both to and from strings, you will need to split the conversion method in to two parts: one that turns Strings in
- * to Points, and one that turns Points in to Strings.
- * <p/>
- * <p/> After this is done, you can now reference your point (using <s:property value="point"/> in JSP or ${point}
- * in FreeMarker) and it will be printed as "3, 22" again. As such, if you submit this back to an action, it will be
- * converted back to a Point once again.
- * <p/>
- * <p/> In some situations you may wish to apply a type converter globally. This can be done by editing the file
- * <b>xwork-conversion.properties</b> in the root of your class path (typically WEB-INF/classes) and providing a
- * property in the form of the class name of the object you wish to convert on the left hand side and the class name of
- * the type converter on the right hand side. For example, providing a type converter for all Point objects would mean
- * adding the following entry:
- * <p/>
- * <p/><b>com.acme.Point = com.acme.PointConverter</b>
- * <p/>
- * <!-- END SNIPPET: javadoc -->
- * <p/>
- * <p/>
- * <p/>
- * <!-- START SNIPPET: i18n-note -->
- * <p/>
- * Type conversion should not be used as a substitute for i18n. It is not recommended to use this feature to print out
- * properly formatted dates. Rather, you should use the i18n features of Struts 2 (and consult the JavaDocs for JDK's
- * MessageFormat object) to see how a properly formatted date should be displayed.
- * <p/>
- * <!-- END SNIPPET: i18n-note -->
- * <p/>
- * <p/>
- * <p/>
- * <!-- START SNIPPET: error-reporting -->
- * <p/>
- * Any error that occurs during type conversion may or may not wish to be reported. For example, reporting that the
- * input "abc" could not be converted to a number might be important. On the other hand, reporting that an empty string,
- * "", cannot be converted to a number might not be important - especially in a web environment where it is hard to
- * distinguish between a user not entering a value vs. entering a blank value.
- * <p/>
- * <p/> By default, all conversion errors are reported using the generic i18n key <b>xwork.default.invalid.fieldvalue</b>,
- * which you can override (the default text is <i>Invalid field value for field "xxx"</i>, where xxx is the field name)
- * in your global i18n resource bundle.
- * <p/>
- * <p/>However, sometimes you may wish to override this message on a per-field basis. You can do this by adding an i18n
- * key associated with just your action (Action.properties) using the pattern <b>invalid.fieldvalue.xxx</b>, where xxx
- * is the field name.
- * <p/>
- * <p/>It is important to know that none of these errors are actually reported directly. Rather, they are added to a map
- * called <i>conversionErrors</i> in the ActionContext. There are several ways this map can then be accessed and the
- * errors can be reported accordingly.
- * <p/>
- * <!-- END SNIPPET: error-reporting -->
- *
- * @author <a href="mailto:plightbo@gmail.com">Pat Lightbody</a>
- * @author Rainer Hermanns
- * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
- * @author tm_jee
- * @version $Date$ $Id$
- * @see XWorkBasicConverter
- */
-public class XWorkConverter extends DefaultTypeConverter {
-
- private static final Logger LOG = LogManager.getLogger(XWorkConverter.class);
-
- public static final String REPORT_CONVERSION_ERRORS = "report.conversion.errors";
- public static final String CONVERSION_PROPERTY_FULLNAME = "conversion.property.fullName";
- public static final String CONVERSION_ERROR_PROPERTY_PREFIX = "invalid.fieldvalue.";
- public static final String CONVERSION_COLLECTION_PREFIX = "Collection_";
-
- public static final String LAST_BEAN_CLASS_ACCESSED = "last.bean.accessed";
- public static final String LAST_BEAN_PROPERTY_ACCESSED = "last.property.accessed";
- public static final String MESSAGE_INDEX_PATTERN = "\\[\\d+\\]\\.";
- public static final String MESSAGE_INDEX_BRACKET_PATTERN = "[\\[\\]\\.]";
- public static final String PERIOD = ".";
- public static final Pattern messageIndexPattern = Pattern.compile(MESSAGE_INDEX_PATTERN);
-
- private TypeConverter defaultTypeConverter;
- private FileManager fileManager;
- private boolean reloadingConfigs;
-
- private ConversionFileProcessor fileProcessor;
- private ConversionAnnotationProcessor annotationProcessor;
-
- private TypeConverterHolder converterHolder;
-
- protected XWorkConverter() {
- }
-
- @Inject
- public void setDefaultTypeConverter(XWorkBasicConverter converter) {
- this.defaultTypeConverter = converter;
- }
-
- @Inject
- public void setFileManagerFactory(FileManagerFactory fileManagerFactory) {
- this.fileManager = fileManagerFactory.getFileManager();
- }
-
- @Inject(value = XWorkConstants.RELOAD_XML_CONFIGURATION, required = false)
- public void setReloadingConfigs(String reloadingConfigs) {
- this.reloadingConfigs = Boolean.parseBoolean(reloadingConfigs);
- }
-
- @Inject
- public void setConversionPropertiesProcessor(ConversionPropertiesProcessor propertiesProcessor) {
- // note: this file is deprecated
- propertiesProcessor.process("xwork-default-conversion.properties");
- propertiesProcessor.process("xwork-conversion.properties");
- }
-
- @Inject
- public void setConversionFileProcessor(ConversionFileProcessor fileProcessor) {
- this.fileProcessor = fileProcessor;
- }
-
- @Inject
- public void setConversionAnnotationProcessor(ConversionAnnotationProcessor annotationProcessor) {
- this.annotationProcessor = annotationProcessor;
- }
-
- @Inject
- public void setTypeConverterHolder(TypeConverterHolder converterHolder) {
- this.converterHolder = converterHolder;
- }
-
- public static String getConversionErrorMessage(String propertyName, ValueStack stack) {
- String defaultMessage = LocalizedTextUtil.findDefaultText(XWorkMessages.DEFAULT_INVALID_FIELDVALUE,
- ActionContext.getContext().getLocale(),
- new Object[]{
- propertyName
- });
-
- List<String> indexValues = getIndexValues(propertyName);
-
- propertyName = removeAllIndexesInPropertyName(propertyName);
-
- String getTextExpression = "getText('" + CONVERSION_ERROR_PROPERTY_PREFIX + propertyName + "','" + defaultMessage + "')";
- String message = (String) stack.findValue(getTextExpression);
-
- if (message == null) {
- message = defaultMessage;
- } else {
- message = MessageFormat.format(message, indexValues.toArray());
- }
-
- return message;
- }
-
- 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<>();
- while (matcher.find()) {
- Integer index = new Integer(matcher.group().replaceAll(MESSAGE_INDEX_BRACKET_PATTERN, "")) + 1;
- indexes.add(Integer.toString(index));
- }
- return indexes;
- }
-
- public String buildConverterFilename(Class clazz) {
- String className = clazz.getName();
- return className.replace('.', '/') + "-conversion.properties";
- }
-
- @Override
- public Object convertValue(Map<String, Object> map, Object o, Class aClass) {
- return convertValue(map, null, null, null, o, aClass);
- }
-
- /**
- * Convert value from one form to another.
- * Minimum requirement of arguments:
- * <ul>
- * <li>supplying context, toClass and value</li>
- * <li>supplying context, target and value.</li>
- * </ul>
- *
- * @see TypeConverter#convertValue(java.util.Map, java.lang.Object, java.lang.reflect.Member, java.lang.String, java.lang.Object, java.lang.Class)
- */
- @Override
- public Object convertValue(Map<String, Object> context, Object target, Member member, String property, Object value, Class toClass) {
- //
- // Process the conversion using the default mappings, if one exists
- //
- TypeConverter tc = null;
-
- if ((value != null) && (toClass == value.getClass())) {
- return value;
- }
-
- // allow this method to be called without any context
- // i.e. it can be called with as little as "Object value" and "Class toClass"
- if (target != null) {
- Class clazz = target.getClass();
-
- Object[] classProp = null;
-
- // this is to handle weird issues with setValue with a different type
- if ((target instanceof CompoundRoot) && (context != null)) {
- classProp = getClassProperty(context);
- }
-
- if (classProp != null) {
- clazz = (Class) classProp[0];
- property = (String) classProp[1];
- }
-
- tc = (TypeConverter) getConverter(clazz, property);
- LOG.debug("field-level type converter for property [{}] = {}", property, (tc == null ? "none found" : tc));
- }
-
- if (tc == null && context != null) {
- // ok, let's see if we can look it up by path as requested in XW-297
- Object lastPropertyPath = context.get(ReflectionContextState.CURRENT_PROPERTY_PATH);
- Class clazz = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
- if (lastPropertyPath != null && clazz != null) {
- String path = lastPropertyPath + "." + property;
- tc = (TypeConverter) getConverter(clazz, path);
- }
- }
-
- if (tc == null) {
- if (toClass.equals(String.class) && (value != null) && !(value.getClass().equals(String.class) || value.getClass().equals(String[].class))) {
- // when converting to a string, use the source target's class's converter
- tc = lookup(value.getClass());
- } else {
- // when converting from a string, use the toClass's converter
- tc = lookup(toClass);
- }
-
- if (LOG.isDebugEnabled())
- LOG.debug("global-level type converter for property [{}] = {} ", property, (tc == null ? "none found" : tc));
- }
-
-
- if (tc != null) {
- try {
- return tc.convertValue(context, target, member, property, value, toClass);
- } catch (Exception e) {
- LOG.debug("Unable to convert value using type converter [{}]", tc.getClass().getName(), e);
- handleConversionException(context, property, value, target);
-
- return TypeConverter.NO_CONVERSION_POSSIBLE;
- }
- }
-
- if (defaultTypeConverter != null) {
- try {
- LOG.debug("Falling back to default type converter [{}]", defaultTypeConverter);
- return defaultTypeConverter.convertValue(context, target, member, property, value, toClass);
- } catch (Exception e) {
- LOG.debug("Unable to convert value using type converter [{}]", defaultTypeConverter.getClass().getName(), e);
- handleConversionException(context, property, value, target);
-
- return TypeConverter.NO_CONVERSION_POSSIBLE;
- }
- } else {
- try {
- LOG.debug("Falling back to Ognl's default type conversion");
- return super.convertValue(value, toClass);
- } catch (Exception e) {
- LOG.debug("Unable to convert value using type converter [{}]", super.getClass().getName(), e);
- handleConversionException(context, property, value, target);
-
- return TypeConverter.NO_CONVERSION_POSSIBLE;
- }
- }
- }
-
- /**
- * Looks for a TypeConverter in the default mappings.
- *
- * @param className name of the class the TypeConverter must handle
- * @return a TypeConverter to handle the specified class or null if none can be found
- */
- public TypeConverter lookup(String className, boolean isPrimitive) {
- if (converterHolder.containsUnknownMapping(className) && !converterHolder.containsDefaultMapping(className)) {
- return null;
- }
-
- TypeConverter result = converterHolder.getDefaultMapping(className);
-
- //Looks for super classes
- if (result == null && !isPrimitive) {
- Class clazz = null;
-
- try {
- clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
- } catch (ClassNotFoundException cnfe) {
- LOG.debug("Cannot load class {}", className, cnfe);
- }
-
- result = lookupSuper(clazz);
-
- if (result != null) {
- //Register now, the next lookup will be faster
- registerConverter(className, result);
- } else {
- // if it isn't found, never look again (also faster)
- registerConverterNotFound(className);
- }
- }
-
- return result;
- }
-
- /**
- * Looks for a TypeConverter in the default mappings.
- *
- * @param clazz the class the TypeConverter must handle
- * @return a TypeConverter to handle the specified class or null if none can be found
- */
- public TypeConverter lookup(Class clazz) {
- TypeConverter result = lookup(clazz.getName(), clazz.isPrimitive());
-
- if (result == null && clazz.isPrimitive()) {
- /**
- * if it is primitive use default converter which allows to define different converters per type
- * @see XWorkBasicConverter
- */
- return defaultTypeConverter;
- }
-
- return result;
- }
-
- protected Object getConverter(Class clazz, String property) {
- LOG.debug("Retrieving convert for class [{}] and property [{}]", clazz, property);
-
- synchronized (clazz) {
- if ((property != null) && !converterHolder.containsNoMapping(clazz)) {
- try {
- Map<String, Object> mapping = converterHolder.getMapping(clazz);
-
- if (mapping == null) {
- mapping = buildConverterMapping(clazz);
- } else {
- mapping = conditionalReload(clazz, mapping);
- }
-
- Object converter = mapping.get(property);
- if (converter == null && LOG.isDebugEnabled()) {
- LOG.debug("Converter is null for property [{}]. Mapping size [{}]:", property, mapping.size());
- for (String next : mapping.keySet()) {
- LOG.debug("{}:{}", next, mapping.get(next));
- }
- }
- return converter;
- } catch (Throwable t) {
- LOG.debug("Got exception trying to resolve convert for class [{}] and property [{}]", clazz, property, t);
- converterHolder.addNoMapping(clazz);
- }
- }
- }
- return null;
- }
-
- protected void handleConversionException(Map<String, Object> context, String property, Object value, Object object) {
- if (context != null && (Boolean.TRUE.equals(context.get(REPORT_CONVERSION_ERRORS)))) {
- String realProperty = property;
- String fullName = (String) context.get(CONVERSION_PROPERTY_FULLNAME);
-
- if (fullName != null) {
- realProperty = fullName;
- }
-
- Map<String, Object> conversionErrors = (Map<String, Object>) context.get(ActionContext.CONVERSION_ERRORS);
-
- if (conversionErrors == null) {
- conversionErrors = new HashMap<>();
- context.put(ActionContext.CONVERSION_ERRORS, conversionErrors);
- }
-
- conversionErrors.put(realProperty, value);
- }
- }
-
- public synchronized void registerConverter(String className, TypeConverter converter) {
- converterHolder.addDefaultMapping(className, converter);
- }
-
- public synchronized void registerConverterNotFound(String className) {
- converterHolder.addUnknownMapping(className);
- }
-
- private Object[] getClassProperty(Map<String, Object> context) {
- Object lastClass = context.get(LAST_BEAN_CLASS_ACCESSED);
- Object lastProperty = context.get(LAST_BEAN_PROPERTY_ACCESSED);
- return (lastClass != null && lastProperty != null) ? new Object[] {lastClass, lastProperty} : null;
- }
-
- /**
- * Looks for converter mappings for the specified class and adds it to an existing map. Only new converters are
- * added. If a converter is defined on a key that already exists, the converter is ignored.
- *
- * @param mapping an existing map to add new converter mappings to
- * @param clazz class to look for converter mappings for
- */
- protected void addConverterMapping(Map<String, Object> mapping, Class clazz) {
- // Process <clazz>-conversion.properties file
- String converterFilename = buildConverterFilename(clazz);
- fileProcessor.process(mapping, clazz, converterFilename);
-
- // Process annotations
- Annotation[] annotations = clazz.getAnnotations();
-
- for (Annotation annotation : annotations) {
- if (annotation instanceof Conversion) {
- Conversion conversion = (Conversion) annotation;
- for (TypeConversion tc : conversion.conversions()) {
- if (mapping.containsKey(tc.key())) {
- break;
- }
- if (LOG.isDebugEnabled()) {
- if (StringUtils.isEmpty(tc.key())) {
- LOG.debug("WARNING! key of @TypeConversion [{}] applied to [{}] is empty!", tc.converter(), clazz.getName());
- } else {
- LOG.debug("TypeConversion [{}] with key: [{}]", tc.converter(), tc.key());
- }
- }
- annotationProcessor.process(mapping, tc, tc.key());
- }
- }
- }
-
- // Process annotated methods
- for (Method method : clazz.getMethods()) {
- annotations = method.getAnnotations();
- for (Annotation annotation : annotations) {
- if (annotation instanceof TypeConversion) {
- TypeConversion tc = (TypeConversion) annotation;
- if (mapping.containsKey(tc.key())) {
- break;
- }
- String key = tc.key();
- // Default to the property name
- if (StringUtils.isEmpty(key)) {
- key = AnnotationUtils.resolvePropertyName(method);
- LOG.debug("Retrieved key [{}] from method name [{}]", key, method.getName());
- }
- annotationProcessor.process(mapping, tc, key);
- }
- }
- }
- }
-
-
- /**
- * Looks for converter mappings for the specified class, traversing up its class hierarchy and interfaces and adding
- * any additional mappings it may find. Mappings lower in the hierarchy have priority over those higher in the
- * hierarcy.
- *
- * @param clazz the class to look for converter mappings for
- * @return the converter mappings
- */
- protected Map<String, Object> buildConverterMapping(Class clazz) throws Exception {
- Map<String, Object> mapping = new HashMap<>();
-
- // check for conversion mapping associated with super classes and any implemented interfaces
- Class curClazz = clazz;
-
- while (!curClazz.equals(Object.class)) {
- // add current class' mappings
- addConverterMapping(mapping, curClazz);
-
- // check interfaces' mappings
- Class[] interfaces = curClazz.getInterfaces();
-
- for (Class anInterface : interfaces) {
- addConverterMapping(mapping, anInterface);
- }
-
- curClazz = curClazz.getSuperclass();
- }
-
- if (mapping.size() > 0) {
- converterHolder.addMapping(clazz, mapping);
- } else {
- converterHolder.addNoMapping(clazz);
- }
-
- return mapping;
- }
-
- private Map<String, Object> conditionalReload(Class clazz, Map<String, Object> oldValues) throws Exception {
- Map<String, Object> mapping = oldValues;
-
- if (reloadingConfigs) {
- URL fileUrl = ClassLoaderUtil.getResource(buildConverterFilename(clazz), clazz);
- if (fileManager.fileNeedsReloading(fileUrl)) {
- mapping = buildConverterMapping(clazz);
- }
- }
-
- return mapping;
- }
-
- /**
- * Recurses through a class' interfaces and class hierarchy looking for a TypeConverter in the default mapping that
- * can handle the specified class.
- *
- * @param clazz the class the TypeConverter must handle
- * @return a TypeConverter to handle the specified class or null if none can be found
- */
- TypeConverter lookupSuper(Class clazz) {
- TypeConverter result = null;
-
- if (clazz != null) {
- result = converterHolder.getDefaultMapping(clazz.getName());
-
- if (result == null) {
- // Looks for direct interfaces (depth = 1 )
- Class[] interfaces = clazz.getInterfaces();
-
- for (Class anInterface : interfaces) {
- if (converterHolder.containsDefaultMapping(anInterface.getName())) {
- result = converterHolder.getDefaultMapping(anInterface.getName());
- break;
- }
- }
-
- if (result == null) {
- // Looks for the superclass
- // If 'clazz' is the Object class, an interface, a primitive type or void then clazz.getSuperClass() returns null
- result = lookupSuper(clazz.getSuperclass());
- }
- }
- }
-
- return result;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/ConversionDescription.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/ConversionDescription.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/ConversionDescription.java
deleted file mode 100644
index 340dc84..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/ConversionDescription.java
+++ /dev/null
@@ -1,184 +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.conversion.metadata;
-
-import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
-import com.opensymphony.xwork2.conversion.impl.DefaultObjectTypeDeterminer;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-/**
- * <code>ConversionDescription</code>
- *
- * @author Rainer Hermanns
- * @version $Id$
- */
-public class ConversionDescription {
-
- /**
- * Jakarta commons-logging reference.
- */
- protected static Logger log = null;
-
-
- public static final String KEY_PREFIX = "Key_";
- public static final String ELEMENT_PREFIX = "Element_";
- public static final String KEY_PROPERTY_PREFIX = "KeyProperty_";
- public static final String DEPRECATED_ELEMENT_PREFIX = "Collection_";
-
- /**
- * Key used for type conversion of maps.
- */
- String MAP_PREFIX = "Map_";
-
- public String property;
- public String typeConverter = "";
- public String rule = "";
- public String value = "";
- public String fullQualifiedClassName;
- public String type = null;
-
- public ConversionDescription() {
- log = LogManager.getLogger(this.getClass());
- }
-
- /**
- * Creates an ConversionDescription with the specified property name.
- *
- * @param property
- */
- public ConversionDescription(String property) {
- this.property = property;
- log = LogManager.getLogger(this.getClass());
- }
-
- /**
- * <p>
- * Sets the property name to be inserted into the related conversion.properties file.<br/>
- * Note: Do not add COLLECTION_PREFIX or MAP_PREFIX keys to property names.
- * </p>
- *
- * @param property The property to be converted.
- */
- public void setProperty(String property) {
- this.property = property;
- }
-
- /**
- * Sets the class name of the type converter to be used.
- *
- * @param typeConverter The class name of the type converter.
- */
- public void setTypeConverter(String typeConverter) {
- this.typeConverter = typeConverter;
- }
-
- /**
- * Sets the rule prefix for COLLECTION_PREFIX or MAP_PREFIX key.
- * Defaults to en emtpy String.
- *
- * @param rule
- */
- public void setRule(String rule) {
- if (rule != null && rule.length() > 0) {
- if (rule.equals(ConversionRule.COLLECTION.toString())) {
- this.rule = DefaultObjectTypeDeterminer.DEPRECATED_ELEMENT_PREFIX;
- } else if (rule.equals(ConversionRule.ELEMENT.toString())) {
- this.rule = DefaultObjectTypeDeterminer.ELEMENT_PREFIX;
- } else if (rule.equals(ConversionRule.KEY.toString())) {
- this.rule = DefaultObjectTypeDeterminer.KEY_PREFIX;
- } else if (rule.equals(ConversionRule.KEY_PROPERTY.toString())) {
- this.rule = DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX;
- } else if (rule.equals(ConversionRule.MAP.toString())) {
- this.rule = MAP_PREFIX;
- }
- }
- }
-
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getType() {
- return type;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- /**
- * Returns the conversion description as property entry.
- * <p>
- * Example:<br/>
- * property.name = converter.className<br/>
- * Collection_property.name = converter.className<br/>
- * Map_property.name = converter.className
- * KeyProperty_name = id
- * </p>
- *
- * @return the conversion description as property entry.
- */
- public String asProperty() {
- StringWriter sw = new StringWriter();
- PrintWriter writer = null;
- try {
- writer = new PrintWriter(sw);
- writer.print(rule);
- writer.print(property);
- writer.print("=");
- if ( rule.startsWith(DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX) && value != null && value.length() > 0 ) {
- writer.print(value);
- } else {
- writer.print(typeConverter);
- }
- } finally {
- if (writer != null) {
- writer.flush();
- writer.close();
- }
- }
-
- return sw.toString();
-
- }
-
- /**
- * Returns the fullQualifiedClassName attribute is used to create the special <code>conversion.properties</code> file name.
- *
- * @return fullQualifiedClassName
- */
- public String getFullQualifiedClassName() {
- return fullQualifiedClassName;
- }
-
- /**
- * The fullQualifiedClassName attribute is used to create the special <code>conversion.properties</code> file name.
- *
- * @param fullQualifiedClassName
- */
- public void setFullQualifiedClassName(String fullQualifiedClassName) {
- this.fullQualifiedClassName = fullQualifiedClassName;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/package.html
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/package.html
deleted file mode 100644
index c50a611..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/metadata/package.html
+++ /dev/null
@@ -1 +0,0 @@
-<body>Type conversion meta data classes.</body>
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java
deleted file mode 100644
index d33cb1d..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.opensymphony.xwork2.factory;
-
-import com.opensymphony.xwork2.config.entities.ActionConfig;
-
-import java.util.Map;
-
-/**
- * Used by {@link com.opensymphony.xwork2.ObjectFactory} to build actions
- */
-public interface ActionFactory {
-
- /**
- * Builds action instance
- */
- Object buildAction(String actionName, String namespace, ActionConfig config, Map<String, Object> extraContext) throws Exception;
-
-}
-
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ConverterFactory.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ConverterFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ConverterFactory.java
deleted file mode 100644
index 289eefe..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/factory/ConverterFactory.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.opensymphony.xwork2.factory;
-
-import com.opensymphony.xwork2.conversion.TypeConverter;
-
-import java.util.Map;
-
-/**
- * Dedicated interface used by {@link com.opensymphony.xwork2.ObjectFactory} to build {@link TypeConverter}
- */
-public interface ConverterFactory {
-
- /**
- * Build converter of given type
- *
- * @param converterClass to instantiate
- * @param extraContext a Map of extra context which uses the same keys as the {@link com.opensymphony.xwork2.ActionContext}
- * @return instance of converterClass with inject dependencies
- */
- TypeConverter buildConverter(Class<? extends TypeConverter> converterClass, Map<String, Object> extraContext) throws Exception;
-
-}