Customer.java

/* 
 *  Copyright 2007-2008 Yoav Abrahami 
 * 
 *  Licensed 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.abra.j2xb.exampleBeans.choice; 
 
import com.abra.j2xb.exampleBeans.enumsAndValidations.Employee; 
import com.abra.j2xb.exampleBeans.dependentObjectProperty.Person; 
import com.abra.j2xb.exampleBeans.dependentObjectProperty.Address; 
import com.abra.j2xb.annotations.*; 
import com.abra.j2xb.annotations.xmlAnnotations.MOXmlNamespace; 
 
/** 
 * @author Yoav Abrahami 
 * @version 1.0, May 1, 2008 
 * @since   JDK1.5 
 */ 
@MOPersistentBean(xmlName = "Customer") 
@MOXmlNamespace(value = "http://example.abra.com/enumsAndValidations/customer", preferedPrefix = "ex7") 
@MOConstructionDescriptor(constructorArgs = 
        { 
        @MOConstructorArg(sourceProperty = "name", sourcePropertyOf = SourcePropertyOf.constructedInstance) 
                }) 
 
public class Customer { 
  private String name; 
  private Employee employee; 
  private Person person; 
  private CustomerType customerType; 
  private Address address; 
 
  public Customer(String name) { 
    this.name = name; 
  } 
 
  @MOProperty(xmlOrder = 1, xmlName = "name", xmlOptional = false) 
  public String getName() { 
    return name; 
  } 
 
  @MOProperty(xmlOrder = 2, xmlName = "employee", xmlOptional = false) 
  @MOPropertyChoice(discriminator = "customerType", choiceOptions = {"employeeCustomer"}) 
  public Employee getEmployee() { 
    return employee; 
  } 
 
  public void setEmployee(Employee employee) { 
    this.employee = employee; 
  } 
 
  @MOProperty(xmlOrder = 4, xmlName = "address", xmlOptional = false) 
  @MOPropertyChoice(discriminator = "customerType", choiceOptions = {"employeeCustomer","personCustomer"}) 
  public Address getEmployeeAddress() { 
    return address; 
  } 
 
  public void setEmployeeAddress(Address address) { 
    this.address = address; 
  } 
 
 
  @MOProperty(xmlOrder = 3, xmlName = "person") 
  @MOPropertyChoice(discriminator = "customerType", choiceOptions = {"personCustomer"}) 
  public Person getPerson() { 
    return person; 
  } 
 
  public void setPerson(Person person) { 
    this.person = person; 
  } 
 
  @MOChoiceDiscriminator(xmlOrder = 2) 
  public CustomerType getCustomerType() { 
    return customerType; 
  } 
 
  public void setCustomerType(CustomerType customerType) { 
    this.customerType = customerType; 
  } 
 
 
  public enum CustomerType {employeeCustomer, personCustomer} 
 
}