Location.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.xmlTransformation;
import com.abra.j2xb.annotations.*;
import com.abra.j2xb.annotations.xmlAnnotations.MOXmlNamespace;
/**
* this class demostrates mapping of object to XML including two transformation features
* 1. grouping of properties by parent XML elements
* 2. flattening of a delegate object properties and merge those into the parent object properties
* @author Yoav Abrahami
* @version 1.0, May 1, 2008
* @since JDK1.5
*/
@MOPersistentBean(xmlName = "location")
@MOXmlNamespace(value = "http://example.abra.com/nonTrivialTransformation", preferedPrefix = "ex2")
public class Location {
private String name;
private String type;
private int someProperty;
private Address address = new Address();
private Address address2 = new Address();
@MOProperty(xmlOrder = 1, xmlName = "name", xmlOptional = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@MOPropertyGroup("properties")
@MOProperty(xmlOrder = 2, xmlName = "type", xmlOptional = false)
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@MOPropertyGroup("properties/subgroup")
@MOProperty(xmlOrder = 3, xmlName = "someProperty", xmlOptional = false)
public int getSomeProperty() {
return someProperty;
}
public void setSomeProperty(int someProperty) {
this.someProperty = someProperty;
}
@MODelegateProperty(xmlOrder = 4)
public Address getAddress() {
return address;
}
@MOPropertyGroup("address2")
@MODelegateProperty(xmlOrder = 5)
public Address getAddress2() {
return address2;
}
public void setAddress2(Address address2) {
this.address2 = address2;
}
@MOPersistentDependentBean
public class Address {
private String description;
private String city;
private String state;
private String street;
@MOProperty(xmlOrder = 4, xmlName = "description", xmlOptional = false)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@MOPropertyGroup("properties")
@MOProperty(xmlOrder = 5, xmlName = "city", xmlOptional = false)
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@MOPropertyGroup("properties/subgroup")
@MOProperty(xmlOrder = 6, xmlName = "state", xmlOptional = false)
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
@MOPropertyGroup("properties/subgroup")
@MOProperty(xmlOrder = 7, xmlName = "street", xmlOptional = false)
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
}
}