KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > request > FindService


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  * Copyright (C) 2001, Hewlett-Packard Company
6  * All Rights Reserved.
7  *
8  */

9
10 package org.uddi4j.request;
11
12 import java.util.Vector JavaDoc;
13
14 import org.uddi4j.UDDIElement;
15 import org.uddi4j.UDDIException;
16 import org.uddi4j.datatype.Name;
17 import org.uddi4j.util.CategoryBag;
18 import org.uddi4j.util.FindQualifiers;
19 import org.uddi4j.util.TModelBag;
20 import org.w3c.dom.Element JavaDoc;
21 import org.w3c.dom.NodeList JavaDoc;
22
23 /**
24  * Represents the find_service element within the UDDI version 2.0 schema.
25  * This class contains the following types of methods:
26  *
27  * <ul>
28  * <li>A constructor that passes the required fields.
29  * <li>A Constructor that will instantiate the object from an appropriate XML
30  * DOM element.
31  * <li>Get/set methods for each attribute that this element can contain.
32  * <li>A get/setVector method is provided for sets of attributes.
33  * <li>A SaveToXML method that serializes this class within a passed in
34  * element.
35  * </ul>
36  *
37  * Typically, this class is used to construct parameters for, or interpret
38  * responses from, methods in the UDDIProxy class.
39  *
40  * <p><b>Element description:</b>
41  * <p>This message is used to search for summary results that list registered
42  * businessService data that matches specific criteria.
43  *
44  * @author David Melgar (dmelgar@us.ibm.com)
45  * @author Ravi Trivedi (ravi_trivedi@hp.com)
46  * @author Vivek Chopra (vivek@soaprpc.com)
47  * @author Ozzy (ozzy@hursley.ibm.com)
48  */

49 public class FindService extends UDDIElement {
50    public static final String JavaDoc UDDI_TAG = "find_service";
51
52    protected Element base = null;
53
54    String JavaDoc maxRows = null;
55    String JavaDoc businessKey = null;
56    FindQualifiers findQualifiers = null;
57    CategoryBag categoryBag = null;
58    TModelBag tModelBag = null;
59    Vector JavaDoc nameVector = new Vector JavaDoc();
60
61    /**
62     * Default constructor.
63     * Avoid using the default constructor for validation. It does not validate
64     * required fields. Instead, use the required fields constructor to perform
65     * validation.
66     */

67    public FindService() {
68    }
69
70    /**
71     * Construct the object with required fields.
72     *
73     * @param businessKey String
74     */

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

89    public FindService(Element base) throws UDDIException {
90       // Check if it is a fault. Throws an exception if it is.
91
super(base);
92       maxRows = base.getAttribute("maxRows");
93       businessKey = base.getAttribute("businessKey");
94       NodeList JavaDoc nl = null;
95       nl = getChildElementsByTagName(base, FindQualifiers.UDDI_TAG);
96       if (nl.getLength() > 0) {
97          findQualifiers = new FindQualifiers((Element)nl.item(0));
98       }
99       nl = getChildElementsByTagName(base, Name.UDDI_TAG);
100             for (int i=0; i < nl.getLength(); i++) {
101                 nameVector.addElement(new Name((Element)nl.item(i)));
102       }
103       nl = getChildElementsByTagName(base, CategoryBag.UDDI_TAG);
104       if (nl.getLength() > 0) {
105          categoryBag = new CategoryBag((Element)nl.item(0));
106       }
107       nl = getChildElementsByTagName(base, TModelBag.UDDI_TAG);
108       if (nl.getLength() > 0) {
109          tModelBag = new TModelBag((Element)nl.item(0));
110       }
111    }
112
113    public void setMaxRows(String JavaDoc s) {
114       maxRows = s;
115    }
116    public void setMaxRows(int s) {
117       maxRows = Integer.toString(s);
118    }
119
120    public void setBusinessKey(String JavaDoc s) {
121       businessKey = s;
122    }
123
124    public void setFindQualifiers(FindQualifiers s) {
125       findQualifiers = s;
126    }
127
128    /**
129     * @deprecated This method has been deprecated. Use
130     * {@link #setNameVector(Vector)} or
131     * {@link #setDefaultName(Name)}
132     */

133    public void setName(Name s) {
134      setDefaultName(s);
135    }
136
137    /**
138     * @deprecated This method has been deprecated. Use
139     * {@link #setNameVector(Vector)} or
140     * {@link #setDefaultNameString(String, String)}
141     */

142    public void setName(String JavaDoc s) {
143       setDefaultNameString(s,null);
144    }
145
146    /**
147     * This method stores this name as the Default Name
148     * (i.e., places it in the first location in the Vector)
149     */

150    public void setDefaultName(Name name) {
151      if (nameVector.size() > 0) {
152       nameVector.setElementAt(name,0);
153      } else {
154       nameVector.addElement(name);
155      }
156    }
157
158    /**
159     * This method stores this String, in the given language, as the
160     * Default Name (i.e., places it in the first location in the Vector).
161     */

162    public void setDefaultNameString(String JavaDoc value, String JavaDoc lang) {
163       Name name = new Name(value, lang);
164        if (nameVector.size() > 0) {
165          nameVector.setElementAt(name,0);
166        } else {
167          nameVector.addElement(name);
168        }
169    }
170
171    /**
172     * @param s Vector of <I> Name </I> objects
173     */

174    public void setNameVector(Vector JavaDoc s) {
175       nameVector = s;
176    }
177
178
179    public void setCategoryBag(CategoryBag s) {
180       categoryBag = s;
181    }
182
183    public void setTModelBag(TModelBag s) {
184       tModelBag = s;
185    }
186
187    public String JavaDoc getMaxRows() {
188       return maxRows;
189    }
190
191    public int getMaxRowsInt() {
192       return Integer.parseInt(maxRows);
193    }
194
195    public String JavaDoc getBusinessKey() {
196       return businessKey;
197    }
198
199
200    public FindQualifiers getFindQualifiers() {
201       return findQualifiers;
202    }
203
204    /**
205     * @deprecated This method has been deprecated. Use
206     * {@link #getNameVector()} or
207     * {@link #getDefaultName()}
208     */

209    public Name getName() {
210       return getDefaultName();
211    }
212
213    /**
214     * @deprecated This method has been deprecated. Use
215     * {@link #getNameVector()} or
216     * {@link #getDefaultNameString()}
217     */

218    public String JavaDoc getNameString() {
219       return getDefaultNameString();
220    }
221
222    public Name getDefaultName() {
223       if(nameVector.size() > 0)
224         return (Name) nameVector.elementAt(0);
225       else
226         return null;
227    }
228
229    public String JavaDoc getDefaultNameString() {
230        if ((nameVector).size() > 0) {
231         return ((Name)nameVector.elementAt(0)).getText();
232        } else {
233            return null;
234        }
235    }
236
237    /**
238     * Get all names.
239     *
240     * @return Vector of <I>Name</I> objects.
241     */

242    public Vector JavaDoc getNameVector() {
243          return nameVector ;
244    }
245
246    public CategoryBag getCategoryBag() {
247       return categoryBag;
248    }
249
250    public TModelBag getTModelBag() {
251       return tModelBag;
252    }
253
254    /**
255     * Save an object to the DOM tree. Used to serialize an object
256     * to a DOM tree, usually to send a UDDI message.
257     *
258     * <BR>Used by UDDIProxy.
259     *
260     * @param parent Object will serialize as a child element under the
261     * passed in parent element.
262     */

263    public void saveToXML(Element parent) {
264       base = parent.getOwnerDocument().createElement(UDDI_TAG);
265       // Save attributes.
266
base.setAttribute("generic", UDDIElement.GENERIC);
267       base.setAttribute("xmlns", UDDIElement.XMLNS);
268       if (maxRows!=null) {
269          base.setAttribute("maxRows", maxRows);
270       }
271       if (businessKey!=null) {
272          base.setAttribute("businessKey", businessKey);
273       }
274       if (findQualifiers!=null) {
275          findQualifiers.saveToXML(base);
276       }
277       if (nameVector!=null) {
278         for (int i=0; i < nameVector.size(); i++) {
279            ((Name)(nameVector.elementAt(i))).saveToXML(base);
280         }
281       }
282       if (categoryBag!=null) {
283          categoryBag.saveToXML(base);
284       }
285       if (tModelBag!=null) {
286          tModelBag.saveToXML(base);
287       }
288       parent.appendChild(base);
289    }
290 }
291
Popular Tags