package com.sun.j2ee.blueprints.contactinfo.ejb;
import java.io.*;
import java.util.*;
import java.net.*;
import javax.xml.transform.*;
import javax.xml.transform.sax.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import com.sun.j2ee.blueprints.xmldocuments.XMLDocumentUtils;
import com.sun.j2ee.blueprints.xmldocuments.XMLDocumentException;
import com.sun.j2ee.blueprints.address.ejb.Address;
public class ContactInfo {
public static final String DTD_PUBLIC_ID = "-//Sun Microsystems, Inc. - J2EE Blueprints Group//DTD ContactInfo 1.1//EN";
public static final String DTD_SYSTEM_ID = "/com/sun/j2ee/blueprints/contactinfo/rsrc/schemas/ContactInfo.dtd";
public static final String XML_CONTACTINFO = "ContactInfo";
public static final String XML_FAMILY_NAME = "FamilyName";
public static final String XML_GIVEN_NAME = "GivenName";
public static final String XML_ADDRESS = "Address";
public static final String XML_EMAIL = "Email";
public static final String XML_PHONE = "Phone";
private String familyName;
private String givenName;
private Address address;
private String email;
private String phone;
public ContactInfo() {}
public ContactInfo(String familyName, String givenName, Address address, String email, String phone) {
this.familyName = familyName;
this.givenName = givenName;
this.address = address;
this.email = email;
this.phone = phone;
return;
}
public String getFamilyName() {
return familyName;
}
public String getGivenName() {
return givenName;
}
public Address getAddress() {
return address;
}
public String getEmail() {
return email;
}
public String getPhone() {
return phone;
}
public void setFamilyName(String familyName) {
this.familyName = familyName;
return;
}
public void setGivenName(String givenName) {
this.givenName = givenName;
return;
}
public void setAddress(Address address) {
this.address = address;
return;
}
public void setEmail(String email) {
this.email = email;
return;
}
public void setPhone(String phone) {
this.phone = phone;
return;
}
public Node toDOM(Document document) {
Element root = document.createElement(XML_CONTACTINFO);
XMLDocumentUtils.appendChild(document, root, XML_FAMILY_NAME, familyName);
XMLDocumentUtils.appendChild(document, root, XML_GIVEN_NAME, givenName);
root.appendChild(address.toDOM(document));
XMLDocumentUtils.appendChild(document, root, XML_EMAIL, email);
XMLDocumentUtils.appendChild(document, root, XML_PHONE, phone);
return root;
}
public static ContactInfo fromDOM(Node node) throws XMLDocumentException {
Element element;
if (node.getNodeType() == Node.ELEMENT_NODE && (element = ((Element) node)).getTagName().equals(XML_CONTACTINFO)) {
Element child;
ContactInfo contactInfo = new ContactInfo();
child = XMLDocumentUtils.getFirstChild(element, XML_FAMILY_NAME, false);
contactInfo.familyName = XMLDocumentUtils.getContentAsString(child, false);
child = child = XMLDocumentUtils.getNextSibling(child, XML_GIVEN_NAME, false);
contactInfo.givenName = XMLDocumentUtils.getContentAsString(child, false);
child = XMLDocumentUtils.getNextSibling(child, Address.XML_ADDRESS, false);
contactInfo.address = Address.fromDOM(child);
child = XMLDocumentUtils.getNextSibling(child, XML_EMAIL, false);
contactInfo.email = XMLDocumentUtils.getContentAsString(child, true );
child = XMLDocumentUtils.getNextSibling(child, XML_PHONE, false);
contactInfo.phone = XMLDocumentUtils.getContentAsString(child, false);
return contactInfo;
}
throw new XMLDocumentException(XML_CONTACTINFO + " element expected.");
}
public String toString() {
return "ContactInfo[familyName=" + familyName + ", "
+ "givenName=" + givenName + ", "
+ "address=" + address.toString() + ", "
+ "email=" + email + ", "
+ "phone=" + phone + "]";
}
}