Commits

Anonymous committed 3295eec

o added annotations for type conversion

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@615e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (4)

tiger/src/java/com/opensymphony/xwork/conversion/annotations/Conversion.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.conversion.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * <code>Conversion</code>
+ *
+ * A marker annotations for conversions at type level.
+ *
+ * @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 {};
+}

tiger/src/java/com/opensymphony/xwork/conversion/annotations/ConversionRule.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.conversion.annotations;
+
+/**
+ * <code>ConversionRule</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public enum ConversionRule {
+
+    PROPERTY, COLLECTION, MAP;
+
+    @Override
+    public String toString() {
+        return super.toString().toUpperCase();
+    }
+}
+

tiger/src/java/com/opensymphony/xwork/conversion/annotations/ConversionType.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.conversion.annotations;
+
+/**
+ * <code>ConversionType</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id$
+ */
+public enum ConversionType {
+
+
+    APPLICATION, CLASS;
+
+    @Override
+    public String toString() {
+        return super.toString().toUpperCase();
+    }
+
+}

tiger/src/java/com/opensymphony/xwork/conversion/annotations/TypeConversion.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.conversion.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * <code>TypeConversion</code>
+ *
+ * This annotations 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/>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+@Target({ ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TypeConversion {
+
+    /**
+     * The optional property name used within TYPE or PACKAGE level annotations.
+     */
+    String property() default "";
+
+    /**
+     * The ConversionType can be either APPLICATION or CLASS.
+     * Defaults to APPLICATION.
+     */
+    ConversionType type() default ConversionType.CLASS;
+
+    /**
+     * The ConversionRule can be a property, a Collection or a Map.
+     * Note: Collection and Map vonversion rules can be determined via com.opensymphony.xwork.util.GenericsObjectTypeDeterminer.
+     *
+     * @see com.opensymphony.xwork.util.GenericsObjectTypeDeterminer
+     */
+    ConversionRule rule() default ConversionRule.PROPERTY;
+
+    /**
+     * The class of the TypeConverter to be used as converter.
+     */
+    Class converter();
+
+}