http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionFileProcessor.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionFileProcessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionFileProcessor.java deleted file mode 100644 index 8d2803f..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionFileProcessor.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.opensymphony.xwork2.conversion; - -import java.util.Map; - -/** - * Used to process <clazz>-conversion.properties file to read defined Converters - */ -public interface ConversionFileProcessor { - - /** - * Process conversion file to create mapping for key (property, type) and corresponding converter - * - * @param mapping keeps converters per given key - * @param clazz class which should be converted by the converter - * @param converterFilename to read converters from - */ - void process(Map<String, Object> mapping, Class clazz, String converterFilename); - -}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionPropertiesProcessor.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionPropertiesProcessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionPropertiesProcessor.java deleted file mode 100644 index 8d0bab8..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ConversionPropertiesProcessor.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.opensymphony.xwork2.conversion; - -/** - * Used to read converters from Properties file - */ -public interface ConversionPropertiesProcessor { - - /** - * Process given property to load converters as not required (Properties file doesn't have to exist) - * - * @param propsName Properties file name - */ - void process(String propsName); - - /** - * Process given property to load converters as required (Properties file must exist) - * - * @param propsName Properties file name - */ - void processRequired(String propsName); - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/NullHandler.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/NullHandler.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/NullHandler.java deleted file mode 100644 index 86d71f0..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/NullHandler.java +++ /dev/null @@ -1,54 +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; - -import java.util.Map; - -/** -* Interface for handling null results from Chains. -* Object has the opportunity to substitute an object for the -* null and continue. -* @author Luke Blanshard ([email protected]) -* @author Drew Davidson ([email protected]) -*/ -public interface NullHandler -{ - /** - Method called on target returned null. - */ - public Object nullMethodResult(Map<String, Object> context, Object target, String methodName, Object[] args); - - /** - Property in target evaluated to null. Property can be a constant - String property name or a DynamicSubscript. - */ - public Object nullPropertyValue(Map<String, Object> context, Object target, Object property); -} \ 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/ObjectTypeDeterminer.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ObjectTypeDeterminer.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ObjectTypeDeterminer.java deleted file mode 100644 index fe2b748..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/ObjectTypeDeterminer.java +++ /dev/null @@ -1,36 +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; - -/** - * Determines what the key and and element class of a Map or Collection should be. For Maps, the elements are the - * values. For Collections, the elements are the elements of the collection. - * <p/> - * See the implementations for javadoc description for the methods as they are dependent on the concrete implementation. - * - * @author Gabriel Zimmerman - */ -public interface ObjectTypeDeterminer { - - public Class getKeyClass(Class parentClass, String property); - - public Class getElementClass(Class parentClass, String property, Object key); - - public String getKeyProperty(Class parentClass, String property); - - public boolean shouldCreateIfNew(Class parentClass, String property, Object target, String keyProperty, boolean isIndexAccessed); - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConversionException.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConversionException.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConversionException.java deleted file mode 100644 index 033ee73..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConversionException.java +++ /dev/null @@ -1,61 +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; - -import com.opensymphony.xwork2.XWorkException; - - -/** - * TypeConversionException should be thrown by any TypeConverters which fail to convert values - * - * @author Jason Carreira - * Created Oct 3, 2003 12:18:33 AM - */ -public class TypeConversionException extends XWorkException { - - /** - * Constructs a <code>XWorkException</code> with no detail message. - */ - public TypeConversionException() { - } - - /** - * Constructs a <code>XWorkException</code> with the specified - * detail message. - * - * @param s the detail message. - */ - public TypeConversionException(String s) { - super(s); - } - - /** - * Constructs a <code>XWorkException</code> with no detail message. - */ - public TypeConversionException(Throwable cause) { - super(cause); - } - - /** - * Constructs a <code>XWorkException</code> with the specified - * detail message. - * - * @param s the detail message. - */ - public TypeConversionException(String s, Throwable cause) { - super(s, cause); - } -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java deleted file mode 100644 index 0fb67d7..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverter.java +++ /dev/null @@ -1,64 +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; - -import java.lang.reflect.Member; -import java.util.Map; - -/** - * Interface for accessing the type conversion facilities within a context. - * - * This interface was copied from OGNL's TypeConverter - * - * @author Luke Blanshard ([email protected]) - * @author Drew Davidson ([email protected]) - */ -public interface TypeConverter -{ - /** - * Converts the given value to a given type. The OGNL context, target, member and - * name of property being set are given. This method should be able to handle - * conversion in general without any context, target, member or property name specified. - * @param context context under which the conversion is being done - * @param target target object in which the property is being set - * @param member member (Constructor, Method or Field) being set - * @param propertyName property name being set - * @param value value to be converted - * @param toType type to which value is converted - * @return Converted value of type toType or TypeConverter.NoConversionPossible to indicate that the - conversion was not possible. - */ - public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType); - - public static final Object NO_CONVERSION_POSSIBLE = "ognl.NoConversionPossible"; - - public static final String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter"; -} \ 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/TypeConverterCreator.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverterCreator.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverterCreator.java deleted file mode 100644 index 738bbe8..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverterCreator.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.opensymphony.xwork2.conversion; - -/** - * Instantiate converter classes, if cannot create TypeConverter throws exception - */ -public interface TypeConverterCreator { - - /** - * Creates {@link TypeConverter} from given class - * - * @param className convert class - * @return instance of {@link TypeConverter} - * @throws Exception when cannot create/cast to {@link TypeConverter} - */ - TypeConverter createTypeConverter(String className) throws Exception; - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverterHolder.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverterHolder.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverterHolder.java deleted file mode 100644 index 6a67b8b..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/TypeConverterHolder.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.opensymphony.xwork2.conversion; - -import java.util.Map; - -/** - * Holds all mappings related to {@link TypeConverter}s - */ -public interface TypeConverterHolder { - - /** - * Adds mapping for default type converters - application scoped - * - * @param className name of the class with associated converter - * @param typeConverter {@link TypeConverter} instance for associated class - */ - void addDefaultMapping(String className, TypeConverter typeConverter); - - /** - * Checks if converter was already defined for given class - * - * @param className name of the class to check for - * @return true if default mapping was already specified - */ - boolean containsDefaultMapping(String className); - - /** - * Returns instance of {@link TypeConverter} associated with given class - * - * @param className name of the class to return converter for - * @return instance of {@link TypeConverter} to be used to convert class - */ - TypeConverter getDefaultMapping(String className); - - /** - * Target class conversion Mappings. - * - * @param clazz class to convert to/from - * @return {@link TypeConverter} for given class - */ - Map<String, Object> getMapping(Class clazz); - - /** - * Assign mapping of converters for given class - * - * @param clazz class to convert to/from - * @param mapping property converters - */ - void addMapping(Class clazz, Map<String, Object> mapping); - - /** - * Check if there is no mapping for given class to convert - * - * @param clazz class to convert to/from - * @return true if mapping couldn't be found - */ - boolean containsNoMapping(Class clazz); - - /** - * Adds no mapping flag for give class - * - * @param clazz class to register missing converter - */ - void addNoMapping(Class clazz); - - /** - * Checks if no mapping was defined for given class name - * FIXME lukaszlenart: maybe it should be merged with NoMapping - * - * @param className name of the class to check for - * @return true if converter was defined for given class name - */ - boolean containsUnknownMapping(String className); - - /** - * Adds no converter flag for given class name - * FIXME lukaszlenart: maybe it should be merged with NoMapping - * - * @param className name of the class to mark there is no converter for it - */ - void addUnknownMapping(String className); - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/Conversion.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/Conversion.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/Conversion.java deleted file mode 100644 index 07a50d1..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/Conversion.java +++ /dev/null @@ -1,95 +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.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * <!-- START SNIPPET: description --> - * A marker annotation for type conversions at Type level. - * <!-- END SNIPPET: description --> - * - * <p/> <u>Annotation usage:</u> - * - * <!-- START SNIPPET: usage --> - * The Conversion annotation must be applied at Type 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>conversion</td> - * <td>no</td> - * <td> </td> - * <td>used for Type Conversions applied at Type level.</td> - * </tr> - * </tbody> - * </table> - * <!-- END SNIPPET: parameters --> - * - * <p/> <u>Example code:</u> - * - * <pre> - * <!-- START SNIPPET: example --> - * @Conversion( - * conversions = { - * // key must be the name of a property for which converter should be used - * @TypeConversion(key = "date", converter = "org.demo.converter.DateConverter") - * } - * ) - * public class ConversionAction implements Action { - * - * private Date date; - * - * public setDate(Date date) { - * this.date = date; - * } - * - * public Date getDate() { - * return date; - * } - * - * } - * - * <!-- END SNIPPET: example --> - * </pre> - * - * @author Rainer Hermanns - * @version $Id$ - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -public @interface Conversion { - - /** - * Allow Type Conversions being applied at Type level. - */ - TypeConversion[] conversions() default {}; -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionRule.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionRule.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionRule.java deleted file mode 100644 index e30bea4..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionRule.java +++ /dev/null @@ -1,33 +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.annotations; - -/** - * <code>ConversionRule</code> - * - * @author Rainer Hermanns - * @version $Id$ - */ -public enum ConversionRule { - - PROPERTY, COLLECTION, MAP, KEY, KEY_PROPERTY, ELEMENT, CREATE_IF_NULL; - - @Override - public String toString() { - return super.toString().toUpperCase(); - } -} - http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionType.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionType.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionType.java deleted file mode 100644 index d80a926..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/ConversionType.java +++ /dev/null @@ -1,34 +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.annotations; - -/** - * <code>ConversionType</code> - * - * @author <a href="mailto:[email protected]">Rainer Hermanns</a> - * @version $Id$ - */ -public enum ConversionType { - - - APPLICATION, CLASS; - - @Override - public String toString() { - return super.toString().toUpperCase(); - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/TypeConversion.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/TypeConversion.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/TypeConversion.java deleted file mode 100644 index d54bd2f..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/TypeConversion.java +++ /dev/null @@ -1,178 +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.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * <!-- START SNIPPET: description --> - * <p/>This annotation is used for class and application wide conversion rules. - * <p> - * Class wide conversion:<br/> - * The conversion rules will be assembled in a file called <code>XXXAction-conversion.properties</code> - * within the same package as the related action class. - * Set type to: <code>type = ConversionType.CLASS</code> - * </p> - * <p> - * Allication wide conversion:<br/> - * The conversion rules will be assembled within the <code>xwork-conversion.properties</code> file within the classpath root. - * Set type to: <code>type = ConversionType.APPLICATION</code> - * <p/> - * <!-- END SNIPPET: description --> - * - * <p/> <u>Annotation usage:</u> - * - * <!-- START SNIPPET: usage --> - * The TypeConversion annotation can be applied at property and 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>key</td> - * <td>no</td> - * <td>The annotated property/key name</td> - * <td>The optional property name mostly used within TYPE level annotations.</td> - * </tr> - * <tr> - * <td>type</td> - * <td>no</td> - * <td>ConversionType.CLASS</td> - * <td>Enum value of ConversionType. Determines whether the conversion should be applied at application or class level.</td> - * </tr> - * <tr> - * <td>rule</td> - * <td>no</td> - * <td>ConversionRule.PROPERTY</td> - * <td>Enum value of ConversionRule. The ConversionRule can be a property, a Collection or a Map.</td> - * </tr> - * <tr> - * <td>converter</td> - * <td>either this or value</td> - * <td> </td> - * <td>The class name of the TypeConverter to be used as converter.</td> - * </tr> - * <tr> - * <td>value</td> - * <td>either converter or this</td> - * <td> </td> - * <td>The value to set for ConversionRule.KEY_PROPERTY.</td> - * </tr> - * </tbody> - * </table> - * - * <!-- END SNIPPET: parameters --> - * - * <p/> <u>Example code:</u> - * - * <pre> - * <!-- START SNIPPET: example --> - * @Conversion() - * public class ConversionAction implements Action { - * - * private String convertInt; - * - * private String convertDouble; - * private List users = null; - * - * private HashMap keyValues = null; - * - * @TypeConversion(type = ConversionType.APPLICATION, converter = "com.opensymphony.xwork2.util.XWorkBasicConverter") - * public void setConvertInt( String convertInt ) { - * this.convertInt = convertInt; - * } - * - * @TypeConversion(converter = "com.opensymphony.xwork2.util.XWorkBasicConverter") - * public void setConvertDouble( String convertDouble ) { - * this.convertDouble = convertDouble; - * } - * - * @TypeConversion(rule = ConversionRule.COLLECTION, converter = "java.util.String") - * public void setUsers( List users ) { - * this.users = users; - * } - * - * @TypeConversion(rule = ConversionRule.MAP, converter = "java.math.BigInteger") - * public void setKeyValues( HashMap keyValues ) { - * this.keyValues = keyValues; - * } - * - * @TypeConversion(type = ConversionType.APPLICATION, property = "java.util.Date", converter = "com.opensymphony.xwork2.util.XWorkBasicConverter") - * public String execute() throws Exception { - * return SUCCESS; - * } - * } - * <!-- END SNIPPET: example --> - * </pre> - * - * @author Rainer Hermanns - * @version $Id$ - */ -@Target({ ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -public @interface TypeConversion { - - /** - * The optional key name used within TYPE level annotations. - * Defaults to the property name. - */ - String key() default ""; - - /** - * The ConversionType can be either APPLICATION or CLASS. - * Defaults to CLASS. - * - * Note: If you use ConversionType.APPLICATION, you can not set a value! - */ - ConversionType type() default ConversionType.CLASS; - - /** - * The ConversionRule can be a PROPERTY, KEY, KEY_PROPERTY, ELEMENT, COLLECTION (deprecated) or a MAP. - * Note: Collection and Map conversion rules can be determined via com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer. - * - * @see com.opensymphony.xwork2.conversion.impl.DefaultObjectTypeDeterminer - */ - ConversionRule rule() default ConversionRule.PROPERTY; - - /** - * The class of the TypeConverter to be used as converter. - * - * Note: This can not be used with ConversionRule.KEY_PROPERTY! - */ - String converter() default ""; - - /** - * If used with ConversionRule.KEY_PROPERTY specify a value here! - * - * Note: If you use ConversionType.APPLICATION, you can not set a value! - */ - String value() default ""; - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/package.html ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/package.html deleted file mode 100644 index e2a91d0..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/annotations/package.html +++ /dev/null @@ -1 +0,0 @@ -<body>Type conversion annotations.</body> http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverter.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverter.java deleted file mode 100644 index 988e463..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverter.java +++ /dev/null @@ -1,91 +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; - -/** - * <!-- 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), XWork'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 - * XWork 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, XWork 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 <ww:property value="post"/> 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 XWork (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:[email protected]">Pat Lightbody</a> - * @author Rainer Hermanns - * @see com.opensymphony.xwork2.conversion.impl.XWorkConverter - * @deprecated Since XWork 2.0.4, the implementation of XWorkConverter handles the processing of annotations. - */ -@Deprecated public class AnnotationXWorkConverter extends XWorkConverter { -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/ArrayConverter.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/ArrayConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/ArrayConverter.java deleted file mode 100644 index 09addae..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/ArrayConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.opensymphony.xwork2.conversion.impl; - -import com.opensymphony.xwork2.conversion.TypeConverter; - -import java.lang.reflect.Array; -import java.lang.reflect.Member; -import java.util.Map; - -public class ArrayConverter extends DefaultTypeConverter { - - @Override - public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) { - Object result = null; - Class componentType = toType.getComponentType(); - - if (componentType != null) { - TypeConverter converter = getTypeConverter(context); - - if (value.getClass().isArray()) { - int length = Array.getLength(value); - result = Array.newInstance(componentType, length); - - for (int i = 0; i < length; i++) { - Object valueItem = Array.get(value, i); - Array.set(result, i, converter.convertValue(context, target, member, propertyName, valueItem, componentType)); - } - } else { - result = Array.newInstance(componentType, 1); - Array.set(result, 0, converter.convertValue(context, target, member, propertyName, value, componentType)); - } - } - - return result; - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/CollectionConverter.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/CollectionConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/CollectionConverter.java deleted file mode 100644 index dfe4030..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/CollectionConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.opensymphony.xwork2.conversion.impl; - -import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer; -import com.opensymphony.xwork2.conversion.TypeConverter; -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.XWorkList; - -import java.lang.reflect.Member; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -public class CollectionConverter extends DefaultTypeConverter { - - private ObjectTypeDeterminer objectTypeDeterminer; - - @Inject - public void setObjectTypeDeterminer(ObjectTypeDeterminer determiner) { - this.objectTypeDeterminer = determiner; - } - - public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) { - Collection result; - Class memberType = String.class; - - if (target != null) { - memberType = objectTypeDeterminer.getElementClass(target.getClass(), propertyName, null); - - if (memberType == null) { - memberType = String.class; - } - } - - if (toType.isAssignableFrom(value.getClass())) { - // no need to do anything - result = (Collection) value; - } else if (value.getClass().isArray()) { - Object[] objArray = (Object[]) value; - TypeConverter converter = getTypeConverter(context); - result = createCollection(toType, memberType, objArray.length); - - for (Object anObjArray : objArray) { - Object convertedValue = converter.convertValue(context, target, member, propertyName, anObjArray, memberType); - if (!TypeConverter.NO_CONVERSION_POSSIBLE.equals(convertedValue)) { - result.add(convertedValue); - } - } - } else if (Collection.class.isAssignableFrom(value.getClass())) { - Collection col = (Collection) value; - TypeConverter converter = getTypeConverter(context); - result = createCollection(toType, memberType, col.size()); - - for (Object aCol : col) { - Object convertedValue = converter.convertValue(context, target, member, propertyName, aCol, memberType); - if (!TypeConverter.NO_CONVERSION_POSSIBLE.equals(convertedValue)) { - result.add(convertedValue); - } - } - } else { - result = createCollection(toType, memberType, -1); - result.add(value); - } - - return result; - - } - - private Collection createCollection(Class toType, Class memberType, int size) { - Collection result; - - if (toType == Set.class) { - if (size > 0) { - result = new HashSet(size); - } else { - result = new HashSet(); - } - } else if (toType == SortedSet.class) { - result = new TreeSet(); - } else { - if (size > 0) { - result = new XWorkList(memberType, size); - } else { - result = new XWorkList(memberType); - } - } - - return result; - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DateConverter.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DateConverter.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DateConverter.java deleted file mode 100644 index 99b1558..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DateConverter.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.opensymphony.xwork2.conversion.impl; - -import com.opensymphony.xwork2.XWorkException; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Member; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.Map; - -public class DateConverter extends DefaultTypeConverter { - - @Override - public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) { - Date result = null; - - if (value instanceof String && value != null && ((String) value).length() > 0) { - String sa = (String) value; - Locale locale = getLocale(context); - - DateFormat df = null; - if (java.sql.Time.class == toType) { - df = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); - } else if (java.sql.Timestamp.class == toType) { - Date check = null; - SimpleDateFormat dtfmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.MEDIUM, - locale); - SimpleDateFormat fullfmt = new SimpleDateFormat(dtfmt.toPattern() + MILLISECOND_FORMAT, - locale); - - SimpleDateFormat dfmt = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, - locale); - - SimpleDateFormat[] fmts = {fullfmt, dtfmt, dfmt}; - for (SimpleDateFormat fmt : fmts) { - try { - check = fmt.parse(sa); - df = fmt; - if (check != null) { - break; - } - } catch (ParseException ignore) { - } - } - } else if (java.util.Date.class == toType) { - Date check; - DateFormat[] dfs = getDateFormats(locale); - for (DateFormat df1 : dfs) { - try { - check = df1.parse(sa); - df = df1; - if (check != null) { - break; - } - } catch (ParseException ignore) { - } - } - } - //final fallback for dates without time - if (df == null) { - df = DateFormat.getDateInstance(DateFormat.SHORT, locale); - } - try { - df.setLenient(false); // let's use strict parsing (XW-341) - result = df.parse(sa); - if (!(Date.class == toType)) { - try { - Constructor constructor = toType.getConstructor(new Class[]{long.class}); - return constructor.newInstance(new Object[]{Long.valueOf(result.getTime())}); - } catch (Exception e) { - throw new XWorkException("Couldn't create class " + toType + " using default (long) constructor", e); - } - } - } catch (ParseException e) { - throw new XWorkException("Could not parse date", e); - } - } else if (Date.class.isAssignableFrom(value.getClass())) { - result = (Date) value; - } - return result; - } - - private DateFormat[] getDateFormats(Locale locale) { - DateFormat dt1 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale); - DateFormat dt2 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); - DateFormat dt3 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); - - DateFormat d1 = DateFormat.getDateInstance(DateFormat.SHORT, locale); - DateFormat d2 = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); - DateFormat d3 = DateFormat.getDateInstance(DateFormat.LONG, locale); - - DateFormat rfc3399 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - - return new DateFormat[]{dt1, dt2, dt3, rfc3399, d1, d2, d3}; - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionAnnotationProcessor.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionAnnotationProcessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionAnnotationProcessor.java deleted file mode 100644 index c3faae3..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionAnnotationProcessor.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.opensymphony.xwork2.conversion.impl; - -import com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor; -import com.opensymphony.xwork2.conversion.TypeConverter; -import com.opensymphony.xwork2.conversion.TypeConverterCreator; -import com.opensymphony.xwork2.conversion.TypeConverterHolder; -import com.opensymphony.xwork2.conversion.annotations.ConversionRule; -import com.opensymphony.xwork2.conversion.annotations.ConversionType; -import com.opensymphony.xwork2.conversion.annotations.TypeConversion; -import com.opensymphony.xwork2.inject.Inject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.Map; - -/** - * Default implementation of {@link ConversionAnnotationProcessor} - */ -public class DefaultConversionAnnotationProcessor implements ConversionAnnotationProcessor { - - private static final Logger LOG = LogManager.getLogger(DefaultConversionAnnotationProcessor.class); - - private TypeConverterCreator converterCreator; - private TypeConverterHolder converterHolder; - - @Inject - public void setTypeConverterCreator(TypeConverterCreator converterCreator) { - this.converterCreator = converterCreator; - } - - @Inject - public void setTypeConverterHolder(TypeConverterHolder converterHolder) { - this.converterHolder = converterHolder; - } - - public void process(Map<String, Object> mapping, TypeConversion tc, String key) { - LOG.debug("TypeConversion [{}] with key: [{}]", tc.converter(), key); - if (key == null) { - return; - } - try { - if (tc.type() == ConversionType.APPLICATION) { - converterHolder.addDefaultMapping(key, converterCreator.createTypeConverter(tc.converter())); - } else { - if (tc.rule() == ConversionRule.KEY_PROPERTY || tc.rule() == ConversionRule.CREATE_IF_NULL) { - mapping.put(key, tc.value()); - } - //for properties of classes - else if (tc.rule() != ConversionRule.ELEMENT || tc.rule() == ConversionRule.KEY || tc.rule() == ConversionRule.COLLECTION) { - mapping.put(key, converterCreator.createTypeConverter(tc.converter())); - } - //for keys of Maps - else if (tc.rule() == ConversionRule.KEY) { - Class converterClass = Thread.currentThread().getContextClassLoader().loadClass(tc.converter()); - LOG.debug("Converter class: [{}]", converterClass); - //check if the converter is a type converter if it is one - //then just put it in the map as is. Otherwise - //put a value in for the type converter of the class - if (converterClass.isAssignableFrom(TypeConverter.class)) { - mapping.put(key, converterCreator.createTypeConverter(tc.converter())); - } else { - mapping.put(key, converterClass); - LOG.debug("Object placed in mapping for key [{}] is [{}]", key, mapping.get(key)); - } - } - //elements(values) of maps / lists - else { - mapping.put(key, Thread.currentThread().getContextClassLoader().loadClass(tc.converter())); - } - } - } catch (Exception e) { - LOG.debug("Got exception for {}", key, e); - } - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionFileProcessor.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionFileProcessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionFileProcessor.java deleted file mode 100644 index 488d9ce8..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionFileProcessor.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.opensymphony.xwork2.conversion.impl; - -import com.opensymphony.xwork2.FileManager; -import com.opensymphony.xwork2.FileManagerFactory; -import com.opensymphony.xwork2.conversion.ConversionFileProcessor; -import com.opensymphony.xwork2.conversion.TypeConverter; -import com.opensymphony.xwork2.conversion.TypeConverterCreator; -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.ClassLoaderUtil; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; - -/** - * Default implementation of {@link ConversionFileProcessor} - */ -public class DefaultConversionFileProcessor implements ConversionFileProcessor { - - private static final Logger LOG = LogManager.getLogger(DefaultConversionFileProcessor.class); - - private FileManager fileManager; - private TypeConverterCreator converterCreator; - - @Inject - public void setFileManagerFactory(FileManagerFactory factory) { - fileManager = factory.getFileManager(); - } - - @Inject - public void setTypeConverterCreator(TypeConverterCreator converterCreator) { - this.converterCreator = converterCreator; - } - - public void process(Map<String, Object> mapping, Class clazz, String converterFilename) { - try { - InputStream is = fileManager.loadFile(ClassLoaderUtil.getResource(converterFilename, clazz)); - - if (is != null) { - LOG.debug("Processing conversion file [{}] for class [{}]", converterFilename, clazz); - - Properties prop = new Properties(); - prop.load(is); - - for (Map.Entry<Object, Object> entry : prop.entrySet()) { - String key = (String) entry.getKey(); - - if (mapping.containsKey(key)) { - break; - } - // for keyProperty of Set - if (key.startsWith(DefaultObjectTypeDeterminer.KEY_PROPERTY_PREFIX) - || key.startsWith(DefaultObjectTypeDeterminer.CREATE_IF_NULL_PREFIX)) { - LOG.debug("\t{}:{} [treated as String]", key, entry.getValue()); - mapping.put(key, entry.getValue()); - } - //for properties of classes - else if (!(key.startsWith(DefaultObjectTypeDeterminer.ELEMENT_PREFIX) || - key.startsWith(DefaultObjectTypeDeterminer.KEY_PREFIX) || - key.startsWith(DefaultObjectTypeDeterminer.DEPRECATED_ELEMENT_PREFIX)) - ) { - TypeConverter _typeConverter = converterCreator.createTypeConverter((String) entry.getValue()); - LOG.debug("\t{}:{} [treated as TypeConverter {}]", key, entry.getValue(), _typeConverter); - mapping.put(key, _typeConverter); - } - //for keys of Maps - else if (key.startsWith(DefaultObjectTypeDeterminer.KEY_PREFIX)) { - - Class converterClass = Thread.currentThread().getContextClassLoader().loadClass((String) entry.getValue()); - - //check if the converter is a type converter if it is one - //then just put it in the map as is. Otherwise - //put a value in for the type converter of the class - if (converterClass.isAssignableFrom(TypeConverter.class)) { - TypeConverter _typeConverter = converterCreator.createTypeConverter((String) entry.getValue()); - LOG.debug("\t{}:{} [treated as TypeConverter {}]", key, entry.getValue(), _typeConverter); - mapping.put(key, _typeConverter); - } else { - LOG.debug("\t{}:{} [treated as Class {}]", key, entry.getValue(), converterClass); - mapping.put(key, converterClass); - } - } - //elements(values) of maps / lists - else { - Class _c = Thread.currentThread().getContextClassLoader().loadClass((String) entry.getValue()); - LOG.debug("\t{}:{} [treated as Class {}]", key, entry.getValue(), _c); - mapping.put(key, _c); - } - } - } - } catch (Exception ex) { - LOG.error("Problem loading properties for {}", clazz.getName(), ex); - } - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionPropertiesProcessor.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionPropertiesProcessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionPropertiesProcessor.java deleted file mode 100644 index 762496f..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultConversionPropertiesProcessor.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.opensymphony.xwork2.conversion.impl; - -import com.opensymphony.xwork2.XWorkException; -import com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor; -import com.opensymphony.xwork2.conversion.TypeConverter; -import com.opensymphony.xwork2.conversion.TypeConverterCreator; -import com.opensymphony.xwork2.conversion.TypeConverterHolder; -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.ClassLoaderUtil; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - -import java.io.IOException; -import java.net.URL; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; - -/** - * TODO lukaszlenart: add a comment - */ -public class DefaultConversionPropertiesProcessor implements ConversionPropertiesProcessor { - - private static final Logger LOG = LogManager.getLogger(DefaultConversionPropertiesProcessor.class); - - private TypeConverterCreator converterCreator; - private TypeConverterHolder converterHolder; - - @Inject - public void setTypeConverterCreator(TypeConverterCreator converterCreator) { - this.converterCreator = converterCreator; - } - - @Inject - public void setTypeConverterHolder(TypeConverterHolder converterHolder) { - this.converterHolder = converterHolder; - } - - public void process(String propsName) { - loadConversionProperties(propsName, false); - } - - public void processRequired(String propsName) { - loadConversionProperties(propsName, true); - } - - public void loadConversionProperties(String propsName, boolean require) { - try { - Iterator<URL> resources = ClassLoaderUtil.getResources(propsName, getClass(), true); - while (resources.hasNext()) { - URL url = resources.next(); - Properties props = new Properties(); - props.load(url.openStream()); - - LOG.debug("Processing conversion file [{}]", propsName); - - for (Object o : props.entrySet()) { - Map.Entry entry = (Map.Entry) o; - String key = (String) entry.getKey(); - - try { - TypeConverter _typeConverter = converterCreator.createTypeConverter((String) entry.getValue()); - if (LOG.isDebugEnabled()) { - LOG.debug("\t{}:{} [treated as TypeConverter {}]", key, entry.getValue(), _typeConverter); - } - converterHolder.addDefaultMapping(key, _typeConverter); - } catch (Exception e) { - LOG.error("Conversion registration error", e); - } - } - } - } catch (IOException ex) { - if (require) { - throw new XWorkException("Cannot load conversion properties file: "+propsName, ex); - } else { - LOG.debug("Cannot load conversion properties file: {}", propsName, ex); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java deleted file mode 100644 index 3b35102..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java +++ /dev/null @@ -1,294 +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.conversion.ObjectTypeDeterminer; -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.CreateIfNull; -import com.opensymphony.xwork2.util.Element; -import com.opensymphony.xwork2.util.Key; -import com.opensymphony.xwork2.util.KeyProperty; -import com.opensymphony.xwork2.util.reflection.ReflectionException; -import com.opensymphony.xwork2.util.reflection.ReflectionProvider; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.beans.IntrospectionException; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Map; - -/** - * <!-- START SNIPPET: javadoc --> - * - * This {@link ObjectTypeDeterminer} looks at the <b>Class-conversion.properties</b> for entries that indicated what - * objects are contained within Maps and Collections. For Collections, such as Lists, the element is specified using the - * pattern <b>Element_xxx</b>, where xxx is the field name of the collection property in your action or object. For - * Maps, both the key and the value may be specified by using the pattern <b>Key_xxx</b> and <b>Element_xxx</b>, - * respectively. - * - * <p/> From WebWork 2.1.x, the <b>Collection_xxx</b> format is still supported and honored, although it is deprecated - * and will be removed eventually. - * - * <!-- END SNIPPET: javadoc --> - * - * @author Gabriel Zimmerman - */ -public class DefaultObjectTypeDeterminer implements ObjectTypeDeterminer { - - protected static final Logger LOG = LogManager.getLogger(DefaultObjectTypeDeterminer.class); - - 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 CREATE_IF_NULL_PREFIX = "CreateIfNull_"; - public static final String DEPRECATED_ELEMENT_PREFIX = "Collection_"; - - private ReflectionProvider reflectionProvider; - private XWorkConverter xworkConverter; - - @Inject - public DefaultObjectTypeDeterminer(@Inject XWorkConverter converter, @Inject ReflectionProvider provider) { - this.reflectionProvider = provider; - this.xworkConverter = converter; - } - - /** - * Determines the key class by looking for the value of @Key annotation for the given class. - * If no annotation is found, the key class is determined by using the generic parametrics. - * - * As fallback, it determines the key class by looking for the value of Key_${property} in the properties - * file for the given class. - * - * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. - * @param property the property of the Map or Collection for the given parent class - * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getKeyClass(Class, String) - */ - public Class getKeyClass(Class parentClass, String property) { - Key annotation = getAnnotation(parentClass, property, Key.class); - if (annotation != null) { - return annotation.value(); - } - Class clazz = getClass(parentClass, property, false); - if (clazz != null) { - return clazz; - } - return (Class) xworkConverter.getConverter(parentClass, KEY_PREFIX + property); - } - - /** - * Determines the element class by looking for the value of @Element annotation for the given - * class. - * If no annotation is found, the element class is determined by using the generic parametrics. - * - * As fallback, it determines the key class by looking for the value of Element_${property} in the properties - * file for the given class. Also looks for the deprecated Collection_${property} - * - * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. - * @param property the property of the Map or Collection for the given parent class - * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getElementClass(Class, String, Object) - */ - public Class getElementClass(Class parentClass, String property, Object key) { - Element annotation = getAnnotation(parentClass, property, Element.class); - if (annotation != null) { - return annotation.value(); - } - Class clazz = getClass(parentClass, property, true); - if (clazz != null) { - return clazz; - } - clazz = (Class) xworkConverter.getConverter(parentClass, ELEMENT_PREFIX + property); - if (clazz == null) { - clazz = (Class) xworkConverter.getConverter(parentClass, DEPRECATED_ELEMENT_PREFIX + property); - if (clazz != null) { - LOG.info("The Collection_xxx pattern for collection type conversion is deprecated. Please use Element_xxx!"); - } - } - return clazz; - } - - /** - * Determines the key property for a Collection by getting it from the @KeyProperty annotation. - * - * As fallback, it determines the String key property for a Collection by getting it from the conversion properties - * file using the KeyProperty_ prefix. KeyProperty_${property}=somePropertyOfBeansInTheSet - * - * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. - * @param property the property of the Map or Collection for the given parent class - * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getKeyProperty(Class, String) - */ - public String getKeyProperty(Class parentClass, String property) { - KeyProperty annotation = getAnnotation(parentClass, property, KeyProperty.class); - if (annotation != null) { - return annotation.value(); - } - return (String) xworkConverter.getConverter(parentClass, KEY_PROPERTY_PREFIX + property); - } - - /** - * Determines the createIfNull property for a Collection or Map by getting it from the @CreateIfNull annotation. - * - * As fallback, it determines the boolean CreateIfNull property for a Collection or Map by getting it from the - * conversion properties file using the CreateIfNull_ prefix. CreateIfNull_${property}=true|false - * - * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. - * @param property the property of the Map or Collection for the given parent class - * @param target the target object - * @param keyProperty the keyProperty value - * @param isIndexAccessed <tt>true</tt>, if the collection or map is accessed via index, <tt>false</tt> otherwise. - * @return <tt>true</tt>, if the Collection or Map should be created, <tt>false</tt> otherwise. - * @see ObjectTypeDeterminer#getKeyProperty(Class, String) - */ - public boolean shouldCreateIfNew(Class parentClass, String property, Object target, String keyProperty, boolean isIndexAccessed) { - CreateIfNull annotation = getAnnotation(parentClass, property, CreateIfNull.class); - if (annotation != null) { - return annotation.value(); - } - String configValue = (String) xworkConverter.getConverter(parentClass, CREATE_IF_NULL_PREFIX + property); - //check if a value is in the config - if (configValue != null) { - return BooleanUtils.toBoolean(configValue); - } - - //default values depend on target type - //and whether this is accessed by an index - //in the case of List - return (target instanceof Map) || isIndexAccessed; - } - - /** - * Retrieves an annotation for the specified property of field, setter or getter. - * - * @param <T> the annotation type to be retrieved - * @param parentClass the class - * @param property the property - * @param annotationClass the annotation - * @return the field or setter/getter annotation or <code>null</code> if not found - */ - protected <T extends Annotation> T getAnnotation(Class parentClass, String property, Class<T> annotationClass) { - T annotation = null; - Field field = reflectionProvider.getField(parentClass, property); - - if (field != null) { - annotation = field.getAnnotation(annotationClass); - } - if (annotation == null) { // HINT: try with setter - annotation = getAnnotationFromSetter(parentClass, property, annotationClass); - } - if (annotation == null) { // HINT: try with getter - annotation = getAnnotationFromGetter(parentClass, property, annotationClass); - } - - return annotation; - } - - /** - * Retrieves an annotation for the specified field of getter. - * - * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. - * @param property the property of the Map or Collection for the given parent class - * @param annotationClass The annotation - * @return concrete Annotation instance or <tt>null</tt> if none could be retrieved. - */ - private <T extends Annotation> T getAnnotationFromGetter(Class parentClass, String property, Class<T> annotationClass) { - try { - Method getter = reflectionProvider.getGetMethod(parentClass, property); - - if (getter != null) { - return getter.getAnnotation(annotationClass); - } - } catch (ReflectionException | IntrospectionException e) { - // ignore - } - return null; - } - - /** - * Retrieves an annotation for the specified field of setter. - * - * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. - * @param property the property of the Map or Collection for the given parent class - * @param annotationClass The annotation - * @return concrete Annotation instance or <tt>null</tt> if none could be retrieved. - */ - private <T extends Annotation> T getAnnotationFromSetter(Class parentClass, String property, Class<T> annotationClass) { - try { - Method setter = reflectionProvider.getSetMethod(parentClass, property); - - if (setter != null) { - return setter.getAnnotation(annotationClass); - } - } catch (ReflectionException | IntrospectionException e) { - // ignore - } - return null; - } - - /** - * Returns the class for the given field via generic type check. - * - * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. - * @param property the property of the Map or Collection for the given parent class - * @param element <tt>true</tt> for indexed types and Maps. - * @return Class of the specified field. - */ - private Class getClass(Class parentClass, String property, boolean element) { - try { - Field field = reflectionProvider.getField(parentClass, property); - Type genericType = null; - // Check fields first - if (field != null) { - genericType = field.getGenericType(); - } - // Try to get ParameterType from setter method - if (genericType == null || !(genericType instanceof ParameterizedType)) { - try { - Method setter = reflectionProvider.getSetMethod(parentClass, property); - genericType = setter != null ? setter.getGenericParameterTypes()[0] : null; - } catch (ReflectionException | IntrospectionException e) { - // ignore - } - } - - // Try to get ReturnType from getter method - if (genericType == null || !(genericType instanceof ParameterizedType)) { - try { - Method getter = reflectionProvider.getGetMethod(parentClass, property); - genericType = getter.getGenericReturnType(); - } catch (ReflectionException | IntrospectionException e) { - // ignore - } - } - - if (genericType instanceof ParameterizedType) { - ParameterizedType type = (ParameterizedType) genericType; - int index = (element && type.getRawType().toString().contains(Map.class.getName())) ? 1 : 0; - Type resultType = type.getActualTypeArguments()[index]; - if (resultType instanceof ParameterizedType) { - return (Class) ((ParameterizedType) resultType).getRawType(); - } - return (Class) resultType; - } - } catch (Exception e) { - LOG.debug("Error while retrieving generic property class for property: {}", property, e); - } - return null; - } -}
