com.abra.j2xb.annotations
Annotation Type MOChoiceDiscriminator


@Target(value=METHOD)
@Retention(value=RUNTIME)
public @interface MOChoiceDiscriminator

Defines a specific mapping where different combinations of the bean properties are mapped based on a different property value. One Enum property denoted the choice discriminator is mapped using this annotation. For each enum constant, a different set of properties is included (from the properties annotated with MOPropertyChoice).

The XML representation of this mapping is an XML choice construct with the appropriate set of attirbutes.

For example, consider the following class mapping where we have one choice discriminator property and three properties annotated by MOPropertyChoice. The customerType property can take two values - employeeCustomer and personCustomer. For each of those values, different properties are mapped.


 @MOPersistentBean(xmlName = "Customer")
 @MOXmlNamespace(value = "http://example.abra.com/enumsAndValidations/customer", preferedPrefix = "ex7")
 public class Customer {

   // other class members and methods

         @MOProperty(xmlOrder = 2, xmlName = "employee", xmlOptional = false)
         @MOPropertyChoice(discriminator = "customerType", choiceOptions = {"employeeCustomer"})
         public Employee getEmployee() {
                 return employee;
         }

         @MOProperty(xmlOrder = 4, xmlName = "address", xmlOptional = false)
         @MOPropertyChoice(discriminator = "customerType", choiceOptions = {"employeeCustomer","personCustomer"})
         public Address getEmployeeAddress() {
                 return address;
         }

         @MOProperty(xmlOrder = 3, xmlName = "person")
         @MOPropertyChoice(discriminator = "customerType", choiceOptions = {"personCustomer"})
         public Person getPerson() {
                 return person;
         }

         @MOChoiceDiscriminator(xmlOrder = 2)
         public CustomerType getCustomerType() {
                 return customerType;
         }

         public enum CustomerType {employeeCustomer, personCustomer}
}

 

The mapping above will result in the following XML schema:

 <xs:choice>
         <xs:element name="employeeCustomer">
                 <xs:complexType>
                         <xs:sequence>
                                 <xs:element name="employee" type="ex3:EmployeeType"/>
                                 <xs:element name="address" type="ex7:AddressType"/>
                         </xs:sequence>
                 </xs:complexType>
         </xs:element>
         <xs:element name="personCustomer">
                 <xs:complexType>
                         <xs:sequence>
                                 <xs:element name="person" type="ex7:PersonType"/>
                                 <xs:element name="address" type="ex7:AddressType"/>
                         </xs:sequence>
                 </xs:complexType>
         </xs:element>
 </xs:choice>
 

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

Optional Element Summary
 boolean xmlOptional
          difines if the choice element is optional.
 int xmlOrder
          defines the XML ordering of the choice element in the parent XML element (same as MOXmlProperty.xmlOrder).
 

xmlOrder

public abstract int xmlOrder
defines the XML ordering of the choice element in the parent XML element (same as MOXmlProperty.xmlOrder).

Default:
-1

xmlOptional

public abstract boolean xmlOptional
difines if the choice element is optional.

Default:
false


Copyright © 2008. All Rights Reserved.