使用 Quick 在 Java 对象和 XML 之间进行转换
2010-03-25 00:00:00 来源:WEB开发网Java 类
在许多数据绑定实现中,您现在需要生成 Java 源文件来表示这种类型的 XML 文档。那种类型的实现假设(通常都不是真的)您缺少要使用的 Java 业务对象。更常见的是,您有一组要开始持久存储 XML 的 Java 类。这个用例正是 Quick 所能帮助解决的问题。根据这个用例,清单 4、 5和 6 是三个代表某人的 Java 源文件。
清单 4. Person 类
import java.util.LinkedList;
import java.util.List;
public class Person {
/** The first name of the person */
private String firstName;
/** The last name of the person */
private String lastName;
/** The addresses of the person */
private List addressList;
/** The phone numbers of the person */
private List phoneNumberList;
public Person() {
addressList = new LinkedList();
phoneNumberList = new LinkedList();
}
public Person(String firstName, String lastName,
List addressList, List phoneNumberList) {
this.firstName = firstName;
this.lastName = lastName;
this.addressList = addressList;
this.phoneNumberList = phoneNumberList;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public List getAddressList() {
return addressList;
}
public void setAddressList(List addressList) {
this.addressList = addressList;
}
public void addAddress(Address address) {
addressList.add(address);
}
public List getPhoneNumberList() {
return phoneNumberList;
}
public void setPhoneNumberList(List phoneNumberList) {
this.phoneNumberList = phoneNumberList;
}
public void addPhoneNumber(PhoneNumber phoneNumber) {
phoneNumberList.add(phoneNumber);
}
}
更多精彩
赞助商链接