com.abra.j2xb.annotations
Annotation Type MOPolymorphicAtomProperty


@Target(value={METHOD,PARAMETER})
@Retention(value=RUNTIME)
public @interface MOPolymorphicAtomProperty

Defines an atomic property that is polimorphic - it can take more then one Java type. The XML representation of polimorphic atomic properties is using the XML Union construct.

When reading the XML representation, the order of defining the MOPolymorphicAtomType annotations becomes important - the matching is done by order. In the following example, if we replace the order of the MOPolymorphicAtomType annotations, numbers will never be read as numbers, because all number values are also valid string values.

For instance, the simplest of example is a Java property that can take a value of a String or an integer (int). Normally, such a property is created with the Object class in Java. Such a property is mapped as follows:

 @MOProperty()
 @MOPolymorphicAtomProperty({
         @MOPolymorphicAtomType(Integer.class),
         @MOPolymorphicAtomType(String.class)})
 public Object getStringOrInt1() {
         return stringOrInt1;
 }
 

The corresponding XML schema is then

 <xs:element name="stringOrInt1">
         <xs:simpleType>
                 <xs:union>
                         <xs:simpleType>
                                 <xs:restriction base="xs:int">
                                 </xs:restriction>
                         </xs:simpleType>
                         <xs:simpleType>
                                 <xs:restriction base="xs:string">
                                 </xs:restriction>
                         </xs:simpleType>
                 </xs:union>
         </xs:simpleType>
 </xs:element>
 

Polymorphic atomic properties can be used anywhere other atomic properties can be used. In addition, for each polymorphic type, we can define additional constraints (see MOPolymorphicAtomType).

A more complex example - usage of polymorphic atomic property as a collection item, with additional constraints

 @MOProperty()
 @MOXmlListStyle()
 @MOPolymorphicAtomProperty({
         @MOPolymorphicAtomType(value = Integer.class, xmlDerivedType = @MOXmlDerivedType(MoXmlBaseSimpleType.xmlUnsignedShort)),
         @MOPolymorphicAtomType(value = String.class, validationString = @MOValidationString(minLength = 3))})
 public List<Object> getPolymorphicListAsListStyle() {
         return polymorphicListAsListStyle;
 }
 

will be mapped using the following XML schema

 <xs:element name="polymorphicListAsListStyle">
         <xs:simpleType>
                 <xs:list>
                         <xs:simpleType>
                                 <xs:union>
                                         <xs:simpleType>
                                                 <xs:restriction base="xs:unsignedShort">
                                                 </xs:restriction>
                                         </xs:simpleType>
                                         <xs:simpleType>
                                                 <xs:restriction base="xs:string">
                                                         <xs:minLength value="3"/>
                                                 </xs:restriction>
                                         </xs:simpleType>
                                 </xs:union>
                         </xs:simpleType>
                 </xs:list>
         </xs:simpleType>
 </xs:element>
 

Since:
JDK1.5
Version:
1.0, May 1, 2008
Author:
Yoav Abrahami
See Also:
MOProperty, MOPolymorphicAtomType

Required Element Summary
 MOPolymorphicAtomType[] value
          the list of possible values this property can take.
 

Element Detail

value

public abstract MOPolymorphicAtomType[] value
the list of possible values this property can take. Should be at least two options.



Copyright © 2008. All Rights Reserved.