KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > datatype > business > Contact


1 /*
2  * The source code contained herein is licensed under the IBM Public License
3  * Version 1.0, which has been approved by the Open Source Initiative.
4  * Copyright (C) 2001, International Business Machines Corporation
5  * All Rights Reserved.
6  *
7  */

8
9 package org.uddi4j.datatype.business;
10
11 import java.util.Vector JavaDoc;
12
13 import org.uddi4j.UDDIElement;
14 import org.uddi4j.UDDIException;
15 import org.uddi4j.datatype.Description;
16 import org.w3c.dom.Element JavaDoc;
17 import org.w3c.dom.NodeList JavaDoc;
18
19 /**
20  * Represents the contact element within the UDDI version 2.0 schema.
21  * This class contains the following types of methods:
22  *
23  * <ul>
24  * <li>Constructor passing required fields.
25  * <li>Constructor that will instantiate the object from an appropriate XML
26  * DOM element.
27  * <li>Get/set methods for each attribute that this element can contain.
28  * <li>A get/setVector method is provided for sets of attributes.
29  * <li>SaveToXML method. Serializes this class within a passed in element.
30  * </ul>
31  *
32  * Typically, this class is used to construct parameters for, or interpret
33  * responses from methods in the UDDIProxy class.
34  *
35  * <p><b>Element description:</b>
36  * <p>Data: Can contain a contact’s name, address, phone, e-mail, and a description
37  * of the contact.
38  *
39  * @author David Melgar (dmelgar@us.ibm.com)
40  */

41 public class Contact extends UDDIElement {
42    public static final String JavaDoc UDDI_TAG = "contact";
43
44    protected Element base = null;
45
46    String JavaDoc useType = null;
47    PersonName personName = null;
48    // Vector of Description objects
49
Vector JavaDoc description = new Vector JavaDoc();
50    // Vector of Phone objects
51
Vector JavaDoc phone = new Vector JavaDoc();
52    // Vector of Email objects
53
Vector JavaDoc email = new Vector JavaDoc();
54    // Vector of Address objects
55
Vector JavaDoc address = new Vector JavaDoc();
56
57    /**
58     * Default constructor.
59     * Avoid using the default constructor for validation. It does not validate
60     * required fields. Instead, use the required fields constructor to perform
61     * validation.
62     */

63    public Contact() {
64    }
65
66    /**
67     * Construct the object with required fields.
68     *
69     * @param personName String
70     */

71    public Contact(String JavaDoc personName) {
72       this.personName = new PersonName( personName );
73    }
74
75    /**
76     * Construct the object from a DOM tree. Used by
77     * UDDIProxy to construct an object from a received UDDI
78     * message.
79     *
80     * @param base Element with the name appropriate for this class.
81     *
82     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
83     * or a disposition report indicating a UDDI error.
84     */

85    public Contact(Element base) throws UDDIException {
86       // Check if its a fault. Throws an exception if it is.
87
super(base);
88       useType = getAttr(base,"useType");
89       NodeList JavaDoc 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 JavaDoc getAttr(Element base, String JavaDoc 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 JavaDoc s) {
122       useType = s;
123    }
124
125    public void setPersonName(PersonName s) {
126       personName = s;
127    }
128    public void setPersonName(String JavaDoc s) {
129       personName = new PersonName();
130       personName.setText(s);
131    }
132
133    /**
134     * Set description vector.
135     *
136     * @param s Vector of <I>Description</I> objects.
137     */

138    public void setDescriptionVector(Vector JavaDoc s) {
139       description = s;
140    }
141
142    /**
143     * Set default (english) description string.
144     *
145     * @param s String
146     */

147    public void setDefaultDescriptionString(String JavaDoc 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    /**
156     * Set phone vector.
157     *
158     * @param s Vector of <I>Phone</I> objects.
159     */

160    public void setPhoneVector(Vector JavaDoc s) {
161       phone = s;
162    }
163
164    /**
165     * Set email vector.
166     *
167     * @param s Vector of <I>Email</I> objects.
168     */

169    public void setEmailVector(Vector JavaDoc s) {
170       email = s;
171    }
172
173    /**
174     * Set address vector.
175     *
176     * @param s Vector of <I>Address</I> objects.
177     */

178    public void setAddressVector(Vector JavaDoc s) {
179       address = s;
180    }
181
182    public String JavaDoc getUseType() {
183       return useType;
184    }
185
186
187    public PersonName getPersonName() {
188       return personName;
189    }
190
191    public String JavaDoc getPersonNameString() {
192       return personName.getText();
193    }
194
195    /**
196     * Get description.
197     *
198     * @return s Vector of <I>Description</I> objects.
199     */

200    public Vector JavaDoc getDescriptionVector() {
201       return description;
202    }
203
204    /**
205     * Get default description string.
206     *
207     * @return s String
208     */

209    public String JavaDoc 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    /**
219     * Get phone.
220     *
221     * @return s Vector of <I>Phone</I> objects.
222     */

223    public Vector JavaDoc getPhoneVector() {
224       return phone;
225    }
226
227    /**
228     * Get email.
229     *
230     * @return s Vector of <I>Email</I> objects.
231     */

232    public Vector JavaDoc getEmailVector() {
233       return email;
234    }
235
236    /**
237     * Get address.
238     *
239     * @return s Vector of <I>Address</I> objects.
240     */

241    public Vector JavaDoc getAddressVector() {
242       return address;
243    }
244
245    /**
246     * Save an object to the DOM tree. Used to serialize an object
247     * to a DOM tree, usually to send a UDDI message.
248     *
249     * <BR>Used by UDDIProxy.
250     *
251     * @param parent Object will serialize as a child element under the
252     * passed in parent element.
253     */

254    public void saveToXML(Element parent) {
255       base = parent.getOwnerDocument().createElement(UDDI_TAG);
256       // Save attributes
257
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