KickJava   Java API By Example, From Geeks To Geeks.

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


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 tModelBag 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>A support element used in searches by tModel key values.
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  * @author Vivek Chopra (vivek@soaprpc.com)
40  */

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

55    public TModelBag() {
56    }
57
58    /**
59     * Construct the object with required fields.
60     *
61     * @param tModelKeyStrings Vector of TModelKey Strings.
62     */

63    public TModelBag(Vector JavaDoc tModelKeyStrings) {
64       Vector JavaDoc objects;
65       objects = new Vector JavaDoc();
66       for (int i = 0; i < tModelKeyStrings.size(); i++) {
67          objects.addElement( new TModelKey((String JavaDoc)tModelKeyStrings.elementAt(i)) );
68       }
69
70       this.tModelKey = objects;
71    }
72
73    /**
74     * Construct the object from a DOM tree. Used by
75     * UDDIProxy to construct an object from a received UDDI
76     * message.
77     *
78     * @param base Element with the name appropriate for this class.
79     *
80     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
81     * or a disposition report indicating a UDDI error.
82     */

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

98    public void setTModelKeyVector(Vector JavaDoc s) {
99       tModelKey = s;
100    }
101
102    /**
103     * Set tModelKey.
104     *
105     * @param s Vector of <I>String</I> objects.
106     */

107    public void setTModelKeyStrings(Vector JavaDoc s) {
108       tModelKey = new Vector JavaDoc();
109       for (int i = 0; i < s.size(); i++) {
110          tModelKey.addElement( new TModelKey((String JavaDoc)s.elementAt(i)) );
111       }
112    }
113
114    /**
115     * Get tModelKey.
116     *
117     * @return s Vector of <I>TModelKey</I> objects.
118     */

119    public Vector JavaDoc getTModelKeyVector() {
120       return tModelKey;
121    }
122
123    /**
124     * Get tModelKey.
125     *
126     * @return s Vector of <I>String</I> objects.
127     */

128    public Vector JavaDoc getTModelKeyStrings() {
129       Vector JavaDoc strings = new Vector JavaDoc();
130       for (int i = 0; i < tModelKey.size(); i++) {
131          strings.addElement( ((TModelKey)tModelKey.elementAt(i)).getText());
132       }
133       return strings;
134    }
135
136    /**
137     * Add a TModelKey object to the collection
138     * @param t TModelKey to be added
139     */

140    public void add (TModelKey t) {
141       tModelKey.add (t);
142    }
143
144    /**
145     * Remove a TModelKey object from the collection
146     * @param t TModelKey to be removed
147     * @return True if object was removed, false if it
148     * was not found in the collection.
149     */

150    public boolean remove (TModelKey t) {
151       return tModelKey.remove (t);
152    }
153
154    /**
155     * Retrieve the TModelKey at the specified index within the collection.
156     * @param index Index to retrieve from.
157     * @return TModelKey at that index
158     */

159    public TModelKey get (int index) {
160       return (TModelKey) tModelKey.get (index);
161    }
162
163    /**
164     * Return current size of the collection.
165     * @return Number of TModelKeys in the collection
166     */

167    public int size () {
168       return tModelKey.size ();
169    }
170
171
172    /**
173     * Save an object to the DOM tree. Used to serialize an object
174     * to a DOM tree, usually to send a UDDI message.
175     *
176     * <BR>Used by UDDIProxy.
177     *
178     * @param parent Object will serialize as a child element under the
179     * passed in parent element.
180     */

181    public void saveToXML(Element parent) {
182       base = parent.getOwnerDocument().createElement(UDDI_TAG);
183       // Save attributes.
184
if (tModelKey!=null) {
185          for (int i=0; i < tModelKey.size(); i++) {
186             ((TModelKey)(tModelKey.elementAt(i))).saveToXML(base);
187      }
188       }
189       parent.appendChild(base);
190    }
191 }
192
Popular Tags