1 8 9 package org.uddi4j.datatype.business; 10 11 import java.util.Vector ; 12 13 import org.uddi4j.UDDIElement; 14 import org.uddi4j.UDDIException; 15 import org.uddi4j.datatype.Description; 16 import org.w3c.dom.Element ; 17 import org.w3c.dom.NodeList ; 18 19 41 public class Contact extends UDDIElement { 42 public static final String UDDI_TAG = "contact"; 43 44 protected Element base = null; 45 46 String useType = null; 47 PersonName personName = null; 48 Vector description = new Vector (); 50 Vector phone = new Vector (); 52 Vector email = new Vector (); 54 Vector address = new Vector (); 56 57 63 public Contact() { 64 } 65 66 71 public Contact(String personName) { 72 this.personName = new PersonName( personName ); 73 } 74 75 85 public Contact(Element base) throws UDDIException { 86 super(base); 88 useType = getAttr(base,"useType"); 89 NodeList nl = null; 90 nl = getChildElementsByTagName(base, PersonName.UDDI_TAG); 91 if (nl.getLength() > 0) { 92 personName = new PersonName((Element)nl.item(0)); 93 } 94 nl = getChildElementsByTagName(base, Description.UDDI_TAG); 95 for (int i=0; i < nl.getLength(); i++) { 96 description.addElement(new Description((Element)nl.item(i))); 97 } 98 nl = getChildElementsByTagName(base, Phone.UDDI_TAG); 99 for (int i=0; i < nl.getLength(); i++) { 100 phone.addElement(new Phone((Element)nl.item(i))); 101 } 102 nl = getChildElementsByTagName(base, Email.UDDI_TAG); 103 for (int i=0; i < nl.getLength(); i++) { 104 email.addElement(new Email((Element)nl.item(i))); 105 } 106 nl = getChildElementsByTagName(base, Address.UDDI_TAG); 107 for (int i=0; i < nl.getLength(); i++) { 108 address.addElement(new Address((Element)nl.item(i))); 109 } 110 } 111 112 private String getAttr(Element base, String attrname) 113 { 114 if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() ) 115 { 116 return base.getAttribute(attrname); 117 } 118 return null; 119 } 120 121 public void setUseType(String s) { 122 useType = s; 123 } 124 125 public void setPersonName(PersonName s) { 126 personName = s; 127 } 128 public void setPersonName(String s) { 129 personName = new PersonName(); 130 personName.setText(s); 131 } 132 133 138 public void setDescriptionVector(Vector s) { 139 description = s; 140 } 141 142 147 public void setDefaultDescriptionString(String s) { 148 if (description.size() > 0) { 149 description.setElementAt(new Description(s), 0); 150 } else { 151 description.addElement(new Description(s)); 152 } 153 } 154 155 160 public void setPhoneVector(Vector s) { 161 phone = s; 162 } 163 164 169 public void setEmailVector(Vector s) { 170 email = s; 171 } 172 173 178 public void setAddressVector(Vector s) { 179 address = s; 180 } 181 182 public String getUseType() { 183 return useType; 184 } 185 186 187 public PersonName getPersonName() { 188 return personName; 189 } 190 191 public String getPersonNameString() { 192 return personName.getText(); 193 } 194 195 200 public Vector getDescriptionVector() { 201 return description; 202 } 203 204 209 public String getDefaultDescriptionString() { 210 if ((description).size() > 0) { 211 Description t = (Description)description.elementAt(0); 212 return t.getText(); 213 } else { 214 return null; 215 } 216 } 217 218 223 public Vector getPhoneVector() { 224 return phone; 225 } 226 227 232 public Vector getEmailVector() { 233 return email; 234 } 235 236 241 public Vector getAddressVector() { 242 return address; 243 } 244 245 254 public void saveToXML(Element parent) { 255 base = parent.getOwnerDocument().createElement(UDDI_TAG); 256 if (useType!=null) { 258 base.setAttribute("useType", useType); 259 } 260 if (description!=null) { 261 for (int i=0; i < description.size(); i++) { 262 ((Description)(description.elementAt(i))).saveToXML(base); 263 } 264 } 265 if (personName!=null) { 266 personName.saveToXML(base); 267 } 268 if (phone!=null) { 269 for (int i=0; i < phone.size(); i++) { 270 ((Phone)(phone.elementAt(i))).saveToXML(base); 271 } 272 } 273 if (email!=null) { 274 for (int i=0; i < email.size(); i++) { 275 ((Email)(email.elementAt(i))).saveToXML(base); 276 } 277 } 278 if (address!=null) { 279 for (int i=0; i < address.size(); i++) { 280 ((Address)(address.elementAt(i))).saveToXML(base); 281 } 282 } 283 parent.appendChild(base); 284 } 285 } 286
| Popular Tags
|