KickJava   Java API By Example, From Geeks To Geeks.

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


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.w3c.dom.Element JavaDoc;
16 import org.w3c.dom.NodeList JavaDoc;
17
18 /**
19  * Represents the contacts element within the UDDI version 2.0 schema.
20  * This class contains the following types of methods:
21  *
22  * <ul>
23  * <li>Constructor passing required fields.
24  * <li>Constructor that will instantiate the object from an appropriate XML
25  * DOM element.
26  * <li>Get/set methods for each attribute that this element can contain.
27  * <li>A get/setVector method is provided for sets of attributes.
28  * <li>SaveToXML method. Serializes this class within a passed in element.
29  * </ul>
30  *
31  * Typically, this class is used to construct parameters for, or interpret
32  * responses from methods in the UDDIProxy class.
33  *
34  * <p><b>Element description:</b>
35  * <p>Service element: accessor for one or more contacts.
36  *
37  * @author David Melgar (dmelgar@us.ibm.com)
38  */

39 public class Contacts extends UDDIElement {
40    public static final String JavaDoc UDDI_TAG = "contacts";
41
42    protected Element base = null;
43
44    // Vector of Contact objects
45
Vector JavaDoc contact = new Vector JavaDoc();
46
47    /**
48     * Default constructor.
49     * Avoid using the default constructor for validation. It does not validate
50     * required fields. Instead, use the required fields constructor to perform
51     * validation.
52     */

53    public Contacts() {
54    }
55
56    /**
57     * Construct the object from a DOM tree. Used by
58     * UDDIProxy to construct an object from a received UDDI
59     * message.
60     *
61     * @param base Element with the name appropriate for this class.
62     *
63     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
64     * or a disposition report indicating a UDDI error.
65     */

66    public Contacts(Element base) throws UDDIException {
67       // Check if its a fault. Throws an exception if it is.
68
super(base);
69       NodeList JavaDoc nl = null;
70       nl = getChildElementsByTagName(base, Contact.UDDI_TAG);
71       for (int i=0; i < nl.getLength(); i++) {
72          contact.addElement(new Contact((Element)nl.item(i)));
73       }
74    }
75
76    /**
77     * Set contact vector.
78     *
79     * @param s Vector of <I>Contact</I> objects.
80     */

81    public void setContactVector(Vector JavaDoc s) {
82       contact = s;
83    }
84
85    /**
86     * Get contact.
87     *
88     * @return s Vector of <I>Contact</I> objects.
89     */

90    public Vector JavaDoc getContactVector() {
91       return contact;
92    }
93
94    /**
95     * Add a Contact object to the collection
96     * @param c Contact to be added
97     */

98    public void add (Contact c) {
99       contact.add (c);
100    }
101
102    /**
103     * Remove a Contact object from the collection
104     * @param c Contact to be removed
105     * @return True if object was removed, false if it
106     * was not found in the collection.
107     */

108    public boolean remove (Contact c) {
109       return contact.remove (c);
110    }
111
112    /**
113     * Retrieve the Contact at the specified index within the collection.
114     * @param index Index to retrieve from.
115     * @return Contact at that index
116     */

117    public Contact get (int index) {
118       return (Contact) contact.get (index);
119    }
120
121    /**
122     * Return current size of the collection.
123     * @return Number of Contacts in the collection
124     */

125    public int size () {
126       return contact.size ();
127    }
128
129    /**
130     * Save an object to the DOM tree. Used to serialize an object
131     * to a DOM tree, usually to send a UDDI message.
132     *
133     * <BR>Used by UDDIProxy.
134     *
135     * @param parent Object will serialize as a child element under the
136     * passed in parent element.
137     */

138    public void saveToXML(Element parent) {
139       base = parent.getOwnerDocument().createElement(UDDI_TAG);
140       // Save attributes
141
if (contact!=null) {
142         for (int i=0; i < contact.size(); i++) {
143            ((Contact)(contact.elementAt(i))).saveToXML(base);
144         }
145       }
146       parent.appendChild(base);
147    }
148 }
149
Popular Tags