KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > util > DiscoveryURLs


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.util;
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 discoveryURLs element within the UDDI version 2.0 schema.
20  * This class contains the following types of methods:
21  *
22  * <ul>
23  * <li>A constructor that passes the required fields.
24  * <li>A 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>A SaveToXML method that serializes this class within a passed in
29  * 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>Service Element: accessor for one or more discoveryURL elements
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  * @author Vivek Chopra (vivek@soaprpc.com)
40  */

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

56     public DiscoveryURLs()
57     {
58     }
59
60     /**
61      * Construct the object with required fields.
62      *
63      * @param discoveryURL Vector of DiscoveryURL objects.
64      */

65     public DiscoveryURLs(Vector JavaDoc discoveryURL)
66     {
67         this.discoveryURL = discoveryURL;
68     }
69
70     /**
71      * Construct the object from a DOM tree. Used by
72      * UDDIProxy to construct an object from a received UDDI
73      * message.
74      *
75      * @param base Element with the name appropriate for this class.
76      *
77      * @exception UDDIException Thrown if DOM tree contains a SOAP fault
78      * or a disposition report indicating a UDDI error.
79      */

80     public DiscoveryURLs(Element base) throws UDDIException
81     {
82         // Check if it is a fault. Throws an exception if it is.
83
super(base);
84         NodeList JavaDoc nl = null;
85         nl = getChildElementsByTagName(base, DiscoveryURL.UDDI_TAG);
86         for (int i = 0; i < nl.getLength(); i++)
87         {
88             discoveryURL.addElement(new DiscoveryURL((Element)nl.item(i)));
89         }
90     }
91
92     /**
93      * Set discoveryURL vector.
94      *
95      * @param s Vector of <I>DiscoveryURL</I> objects.
96      */

97     public void setDiscoveryURLVector(Vector JavaDoc s)
98     {
99         discoveryURL = s;
100     }
101
102     /**
103      * Get discoveryURL.
104      *
105      * @return s Vector of <I>DiscoveryURL</I> objects.
106      */

107     public Vector JavaDoc getDiscoveryURLVector()
108     {
109         return discoveryURL;
110     }
111
112     /**
113       * Add a DiscoveryURL object to the collection
114       * @param d Discovery URL to be added
115       */

116     public void add(DiscoveryURL d)
117     {
118         discoveryURL.add(d);
119     }
120
121     /**
122      * Remove a DiscoveryURL object from the collection
123      * @param d Discovery URL to be removed
124      * @return True if object was removed, false if it
125      * was not found in the collection.
126      */

127     public boolean remove(DiscoveryURL d)
128     {
129         return discoveryURL.remove(d);
130     }
131
132     /**
133      * Retrieve the DiscoveryURL at the specified index within the collection.
134      * @param index Index to retrieve from.
135      * @return DiscoveryURL at that index
136      */

137     public DiscoveryURL get(int index)
138     {
139         return (DiscoveryURL)discoveryURL.get(index);
140     }
141
142     /**
143      * Return current size of the collection.
144      * @return Number of Discovery URLs in the collection
145      */

146     public int size()
147     {
148         return discoveryURL.size();
149     }
150
151     /**
152      * Save an object to the DOM tree. Used to serialize an object
153      * to a DOM tree, usually to send a UDDI message.
154      *
155      * <BR>Used by UDDIProxy.
156      *
157      * @param parent Object will serialize as a child element under the
158      * passed in parent element.
159      */

160     public void saveToXML(Element parent)
161     {
162         base = parent.getOwnerDocument().createElement(UDDI_TAG);
163         // Save attributes
164
if (discoveryURL != null)
165         {
166             for (int i = 0; i < discoveryURL.size(); i++)
167             {
168                 ((DiscoveryURL) (discoveryURL.elementAt(i))).saveToXML(base);
169             }
170         }
171         parent.appendChild(base);
172     }
173 }
174
Popular Tags