KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > datatype > service > BusinessService


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.datatype.service;
11
12 import java.util.Vector JavaDoc;
13
14 import org.uddi4j.UDDIElement;
15 import org.uddi4j.UDDIException;
16 import org.uddi4j.datatype.Description;
17 import org.uddi4j.datatype.Name;
18 import org.uddi4j.datatype.binding.BindingTemplates;
19 import org.uddi4j.util.CategoryBag;
20 import org.w3c.dom.Element JavaDoc;
21 import org.w3c.dom.NodeList JavaDoc;
22
23 /**
24  * Represents the businessService element within the UDDI version 2.0 schema.
25  * This class contains the following types of methods:
26  *
27  * <ul>
28  * <li>Constructor passing required fields.
29  * <li>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>SaveToXML method. Serializes this class within a passed in element.
34  * </ul>
35  *
36  * Typically, this class is used to construct parameters for, or interpret
37  * responses from methods in the UDDIProxy class.
38  *
39  * <p><b>Element description:</b>
40  * <p>Primary Data type: Describes a logical service type in business terms.
41  *
42  * @author David Melgar (dmelgar@us.ibm.com)
43  * @author Ravi Trivedi (ravi_trivedi@hp.com)
44  * @author Vivek Chopra (vivek@soaprpc.com)
45  */

46 public class BusinessService extends UDDIElement {
47    public static final String JavaDoc UDDI_TAG = "businessService";
48
49    protected Element base = null;
50
51    String JavaDoc serviceKey = null;
52    String JavaDoc businessKey = null;
53    BindingTemplates bindingTemplates = null;
54    CategoryBag categoryBag = null;
55    // Vector of Description objects
56
Vector JavaDoc description = new Vector JavaDoc();
57    Vector JavaDoc nameVector = new Vector JavaDoc();
58
59    /**
60     * Default constructor.
61     * Avoid using the default constructor for validation. It does not validate
62     * required fields. Instead, use the required fields constructor to perform
63     * validation.
64     */

65    public BusinessService() {
66    }
67
68    /**
69     * Construct the object with required fields.
70     *
71     * @param serviceKey String
72     * @param name String
73     * @param bindingTemplates
74     * @deprecated Name, and bindingTemplates are no longer required in UDDI
75     * version 2 errata 3.
76     * For the required fields constructor, use
77     * {@link #BusinessService(String)} instead.
78     */

79    public BusinessService(String JavaDoc serviceKey,
80             String JavaDoc name,
81             BindingTemplates bindingTemplates) {
82       this.serviceKey = serviceKey;
83       nameVector.addElement(new Name(name));
84       this.bindingTemplates = bindingTemplates;
85    }
86
87    /**
88     * Construct the object with required fields.
89     *
90     * @param serviceKey String
91     */

92    public BusinessService(String JavaDoc serviceKey) {
93       this.serviceKey = serviceKey;
94    }
95
96    /**
97     * Construct the object from a DOM tree. Used by
98     * UDDIProxy to construct an object from a received UDDI
99     * message.
100     *
101     * @param base Element with the name appropriate for this class.
102     *
103     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
104     * or a disposition report indicating a UDDI error.
105     */

106    public BusinessService(Element base) throws UDDIException {
107       // Check if its a fault. Throws an exception if it is.
108
super(base);
109       serviceKey = base.getAttribute("serviceKey");
110       businessKey = getAttr(base,"businessKey");
111       NodeList JavaDoc nl = null;
112       nl = getChildElementsByTagName(base, Name.UDDI_TAG);
113       for (int i=0; i < nl.getLength(); i++) {
114           nameVector.addElement(new Name((Element)nl.item(i)));
115       }
116       nl = getChildElementsByTagName(base, BindingTemplates.UDDI_TAG);
117       if (nl.getLength() > 0) {
118          bindingTemplates = new BindingTemplates((Element)nl.item(0));
119       }
120       nl = getChildElementsByTagName(base, CategoryBag.UDDI_TAG);
121       if (nl.getLength() > 0) {
122          categoryBag = new CategoryBag((Element)nl.item(0));
123       }
124       nl = getChildElementsByTagName(base, Description.UDDI_TAG);
125       for (int i=0; i < nl.getLength(); i++) {
126          description.addElement(new Description((Element)nl.item(i)));
127       }
128    }
129
130    private String JavaDoc getAttr(Element base, String JavaDoc attrname)
131    {
132      if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() )
133      {
134        return base.getAttribute(attrname);
135      }
136      return null;
137    }
138
139    public void setServiceKey(String JavaDoc s) {
140       serviceKey = s;
141    }
142
143    public void setBusinessKey(String JavaDoc s) {
144       businessKey = s;
145    }
146
147    /**
148     * @deprecated This method has been deprecated. Use
149     * {@link #setNameVector (Vector)} or
150     * {@link #setDefaultName (Name)} instead
151     */

152     public void setName(Name s) {
153       setDefaultName(s);
154     }
155
156    /**
157     * @deprecated This method has been deprecated. Use
158     * {@link #setNameVector (Vector)} or
159     * {@link #setDefaultNameString (String, String)} instead
160     */

161     public void setName(String JavaDoc s) {
162        setDefaultNameString(s, null);
163    }
164
165   /**
166    * This method stores this name as the Default Name (i.e., places it in the first
167    * location in the Vector)
168    */

169    public void setDefaultName(Name name) {
170      if (nameVector.size() > 0) {
171       nameVector.setElementAt(name,0);
172      } else {
173       nameVector.addElement(name);
174      }
175    }
176
177   /**
178    * This method stores this String , in the given language, as the Default Name
179    * (i.e., places it in the first location in the Vector.)
180    */

181    public void setDefaultNameString(String JavaDoc value, String JavaDoc lang) {
182       Name name = new Name(value, lang);
183        if (nameVector.size() > 0) {
184          nameVector.setElementAt(name,0);
185        } else {
186          nameVector.addElement(name);
187        }
188    }
189
190   /**
191    * @param s Vector of <I> Name </I> objects
192    */

193    public void setNameVector(Vector JavaDoc s) {
194       nameVector = s;
195    }
196
197    public void setBindingTemplates(BindingTemplates s) {
198       bindingTemplates = s;
199    }
200
201    public void setCategoryBag(CategoryBag s) {
202       categoryBag = s;
203    }
204
205    /**
206     * Set description vector.
207     *
208     * @param s Vector of <I>Description</I> objects.
209     */

210    public void setDescriptionVector(Vector JavaDoc s) {
211       description = s;
212    }
213
214    /**
215     * Set default description string.
216     *
217     * @param s String
218     */

219    public void setDefaultDescriptionString(String JavaDoc s) {
220       if (description.size() > 0) {
221          description.setElementAt(new Description(s), 0);
222       } else {
223          description.addElement(new Description(s));
224       }
225    }
226
227    public String JavaDoc getServiceKey() {
228       return serviceKey;
229    }
230
231
232    public String JavaDoc getBusinessKey() {
233       return businessKey;
234    }
235
236   /**
237    * @deprecated This method has been deprecated. Use
238    * {@link #getNameVector ()} or
239    * {@link #getDefaultName ()} instead
240    */

241    public Name getName() {
242       return getDefaultName();
243    }
244
245   /**
246    * @deprecated This method has been deprecated. Use
247    * {@link #getNameVector ()} or
248    * {@link #getDefaultNameString ()} instead
249    */

250    public String JavaDoc getNameString() {
251       return getDefaultNameString();
252    }
253
254    public Name getDefaultName() {
255       if (nameVector.size() > 0) {
256       return (Name) nameVector.elementAt(0);
257       } else {
258          return null;
259       }
260    }
261
262    public String JavaDoc getDefaultNameString() {
263        if ((nameVector).size() > 0) {
264         return ((Name)nameVector.elementAt(0)).getText();
265        } else {
266            return null;
267        }
268    }
269
270    /**
271     * Get all names.
272     *
273     * @return Vector of <I>Name</I> objects.
274     */

275    public Vector JavaDoc getNameVector() {
276          return nameVector ;
277       }
278
279
280    public BindingTemplates getBindingTemplates() {
281       return bindingTemplates;
282    }
283
284
285    public CategoryBag getCategoryBag() {
286       return categoryBag;
287    }
288
289
290    /**
291     * Get description.
292     *
293     * @return s Vector of <I>Description</I> objects.
294     */

295    public Vector JavaDoc getDescriptionVector() {
296       return description;
297    }
298
299    /**
300     * Get default description string.
301     *
302     * @return s String
303     */

304    public String JavaDoc getDefaultDescriptionString() {
305       if ((description).size() > 0) {
306          Description t = (Description)description.elementAt(0);
307          return t.getText();
308       } else {
309          return null;
310       }
311    }
312
313    /**
314     * Save an object to the DOM tree. Used to serialize an object
315     * to a DOM tree, usually to send a UDDI message.
316     *
317     * <BR>Used by UDDIProxy.
318     *
319     * @param parent Object will serialize as a child element under the
320     * passed in parent element.
321     */

322    public void saveToXML(Element parent) {
323       base = parent.getOwnerDocument().createElement(UDDI_TAG);
324       // Save attributes
325
if (serviceKey!=null) {
326          base.setAttribute("serviceKey", serviceKey);
327       }
328       if (businessKey!=null) {
329          base.setAttribute("businessKey", businessKey);
330       }
331       if (nameVector!=null) {
332         for (int i=0; i < nameVector.size(); i++) {
333            ((Name)(nameVector.elementAt(i))).saveToXML(base);
334         }
335       }
336       if (description!=null) {
337         for (int i=0; i < description.size(); i++) {
338            ((Description)(description.elementAt(i))).saveToXML(base);
339         }
340       }
341       if (bindingTemplates!=null) {
342          bindingTemplates.saveToXML(base);
343       }
344       if (categoryBag!=null) {
345          categoryBag.saveToXML(base);
346       }
347       parent.appendChild(base);
348    }
349 }
350
Popular Tags