All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opensymphony.xwork2.conversion.annotations.TypeConversion Maven / Gradle / Ivy

There is a newer version: 6.4.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 
 * 

This annotation is used for class and application wide conversion rules.

* *

* Class wide conversion:
* The conversion rules will be assembled in a file called XXXAction-conversion.properties * within the same package as the related action class. * Set type to: type = ConversionType.CLASS *

* *

* Application wide conversion:
* The conversion rules will be assembled within the xwork-conversion.properties file within the classpath root. * Set type to: type = ConversionType.APPLICATION *

* * *

Annotation usage:

* * *

The TypeConversion annotation can be applied at property and method level.

* * *

Annotation parameters:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ParameterRequiredDefaultDescription
keynoThe annotated property/key nameThe optional property name mostly used within TYPE level annotations.
typenoConversionType.CLASSEnum value of ConversionType. Determines whether the conversion should be applied at application or class level.
rulenoConversionRule.PROPERTYEnum value of ConversionRule. The ConversionRule can be a property, a Collection or a Map.
convertereither this or value The class or bean name of the TypeConverter to be used as converter.
converterClasseither this or valueXWorkBasicConverterThe class of the TypeConverter to be used as converter.
valueeither converter or this The value to set for ConversionRule.KEY_PROPERTY.
* * * *

Example code:

* *
 * 
 * @Conversion()
 * public class ConversionAction implements Action {
 *
 *   private String convertInt;
 *
 *   private String convertDouble;
 *   private List users = null;
 *
 *   private HashMap keyValues = null;
 *
 *   @TypeConversion(type = ConversionType.APPLICATION)
 *   public void setConvertInt( String convertInt ) {
 *       this.convertInt = convertInt;
 *   }
 *
 *   @TypeConversion(converterClass = XWorkBasicConverter.class)
 *   public void setConvertDouble( String convertDouble ) {
 *       this.convertDouble = convertDouble;
 *   }
 *
 *   @TypeConversion(rule = ConversionRule.COLLECTION, converterClass = String.class)
 *   public void setUsers( List users ) {
 *       this.users = users;
 *   }
 *
 *   @TypeConversion(rule = ConversionRule.MAP, converterClass = BigInteger.class)
 *   public void setKeyValues( HashMap keyValues ) {
 *       this.keyValues = keyValues;
 *   }
 *
 *   @TypeConversion(type = ConversionType.APPLICATION, property = "java.util.Date", converterClass = XWorkBasicConverter.class)
 *   public String execute() throws Exception {
 *       return SUCCESS;
 *   }
 * }
 * 
 * 
* * @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. * * @return key */ 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! * * @return the conversion type */ 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 * * @return the conversion rule */ ConversionRule rule() default ConversionRule.PROPERTY; /** * The class or bean name of the TypeConverter to be used as converter. * * Note: This can not be used with ConversionRule.KEY_PROPERTY! * * @return class or bean name of the TypeConverter to be used as converter * @see {@link #converterClass()} */ String converter() default ""; /** * The class of the TypeConverter to be used as converter. * * Note: This can not be used with ConversionRule.KEY_PROPERTY! * * @return class of the TypeConverter to be used as converter */ Class converterClass() default XWorkBasicConverter.class; /** * If used with ConversionRule.KEY_PROPERTY specify a value here! * * Note: If you use ConversionType.APPLICATION, you can not set a value! * * @return value */ String value() default ""; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy