|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@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.
customerType == employeeCustomer
, the properties employee
and
employeeAddress
are mapped.
customerType == personCustomer
, the properties person
and
employeeAddress
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>
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). |
public abstract int xmlOrder
public abstract boolean xmlOptional
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |