KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > response > ServiceInfos


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.response;
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 serviceInfos 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>An accessor container for one or more serviceInfo structures.
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  */

40 public class ServiceInfos extends UDDIElement {
41    public static final String JavaDoc UDDI_TAG = "serviceInfos";
42
43    protected Element base = null;
44
45    // Vector of ServiceInfo objects
46
Vector JavaDoc serviceInfo = new Vector JavaDoc();
47
48    /**
49     * Default constructor.
50     *
51     */

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

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

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

90    public Vector JavaDoc getServiceInfoVector() {
91       return serviceInfo;
92    }
93
94    /**
95     * Add a ServiceInfo object to the collection
96     * @param s ServiceInfo to be added
97     */

98    public void add (ServiceInfo s) {
99       serviceInfo.add (s);
100    }
101
102    /**
103     * Remove a ServiceInfo object from the collection
104     * @param s ServiceInfo 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 (ServiceInfo s) {
109       return serviceInfo.remove (s);
110    }
111
112    /**
113     * Retrieve the ServiceInfo at the specified index within the collection.
114     * @param index Index to retrieve from.
115     * @return ServiceInfo at that index
116     */

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

125    public int size () {
126       return serviceInfo.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
139    public void saveToXML(Element parent) {
140       base = parent.getOwnerDocument().createElement(UDDI_TAG);
141       // Save attributes
142
if (serviceInfo!=null) {
143          for (int i=0; i < serviceInfo.size(); i++) {
144             ((ServiceInfo)(serviceInfo.elementAt(i))).saveToXML(base);
145          }
146       }
147       parent.appendChild(base);
148    }
149 }
150
Popular Tags