KickJava   Java API By Example, From Geeks To Geeks.

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


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, Hewlett-Packard Company
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.uddi4j.datatype.Description;
16 import org.uddi4j.datatype.Name;
17 import org.uddi4j.util.BusinessKey;
18 import org.w3c.dom.Element JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20
21 /**
22  * Represents the relatedBusinessInfo element within the UDDI version 2.0 schema.
23  * This class contains the following types of methods:
24  *
25  * <ul>
26  * <li>A constructor that passes the required fields.
27  * <li>A Constructor that will instantiate the object from an appropriate XML
28  * DOM element.
29  * <li>Get/set methods for each attribute that this element can contain.
30  * <li>A get/setVector method is provided for sets of attributes.
31  * <li>A SaveToXML method that serializes this class within a passed in
32  * element.
33  * </ul>
34  *
35  * Typically, this class is used to construct parameters for, or interpret
36  * responses from, methods in the UDDIProxy class.
37  *
38  * <p><b>Element description:</b>
39  * <p>This structure contains information about one or more relationships between
40  * two businessEntitys. The information can be a businessKey, name and optional
41  * description data, and a collection element named sharedRelationships.
42  * The sharedRelationships element can contain zero or more keyedReference
43  * elements. The information in the keyedReference and businessKey elements,
44  * for a specific businessEntity, represent complete relationships when they
45  * match publisher assertions made by the publisher for each businessEntity.
46  *
47  * @author Ravi Trivedi (ravi_trivedi@hp.com)
48  * @author Ozzy (ozzy@hursley.ibm.com)
49  */

50 public class RelatedBusinessInfo extends UDDIElement {
51
52    public static final String JavaDoc UDDI_TAG = "relatedBusinessInfo";
53    protected Element base = null;
54    BusinessKey businessKey = null;
55    //vector of name/description/sharedRelationships
56
Vector JavaDoc nameVector = new Vector JavaDoc();
57    Vector JavaDoc description = new Vector JavaDoc();
58    Vector JavaDoc sharedRelationships = new Vector JavaDoc();
59
60    /**
61     * Default constructor.
62     * Avoid using the default constructor for validation. It does not validate
63     * required fields. Instead, use the required fields constructor to perform
64     * validation.
65     */

66    public RelatedBusinessInfo() {
67    }
68
69
70    /**
71     * Required fields constructor.
72     * This constructor initialises the object with the fields
73     * required by the uddi specification.
74     * @param businessKey BusinessKey
75     * @param names Vector of Name objects
76     * @param sharedRelationships Vector of SharedRelationship objects
77     */

78    public RelatedBusinessInfo( BusinessKey businessKey, Vector JavaDoc names, Vector JavaDoc sharedRelationships) {
79      this.businessKey=businessKey;
80      this.nameVector=names;
81      this.sharedRelationships=sharedRelationships;
82    }
83
84    /**
85     * Required fields constructor.
86     * This constructor initialises the object with the fields
87     * required by the uddi specification.
88     * @param businessKey String
89     * @param names Vector of Name objects
90     * @param sharedRelationships Vector of SharedRelationship objects
91     */

92    public RelatedBusinessInfo( String JavaDoc businessKey, Vector JavaDoc names, Vector JavaDoc sharedRelationships) {
93      this.businessKey=new BusinessKey(businessKey);
94      this.nameVector=names;
95      this.sharedRelationships=sharedRelationships;
96    }
97
98    /**
99     * Required fields constructor.
100     * This constructor initialises the object with the fields
101     * required by the uddi specification.
102     * @param businessKey String
103     * @param name String The default name for this RelatedBusinessInfo
104     * @param sharedRelationships Vector of SharedRelationship objects
105     */

106    public RelatedBusinessInfo( String JavaDoc businessKey, String JavaDoc name, Vector JavaDoc sharedRelationships) {
107      this.businessKey=new BusinessKey(businessKey);
108      setDefaultNameString(name,null);
109      this.sharedRelationships=sharedRelationships;
110    }
111    
112
113    /**
114     * Construct the object from a DOM tree. Used by
115     * UDDIProxy to construct an object from a received UDDI
116     * message.
117     *
118     * @param base Element with the name appropriate for this class.
119     *
120     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
121     * or a disposition report indicating a UDDI error.
122     */

123    public RelatedBusinessInfo(Element base) throws UDDIException {
124       // Check if it is a fault. Throws an exception if it is.
125
super(base);
126         NodeList JavaDoc nl = null;
127         nl = getChildElementsByTagName(base, BusinessKey.UDDI_TAG);
128         if (nl.getLength() > 0) {
129            businessKey = new BusinessKey((Element)nl.item(0));
130         }
131
132         nl = getChildElementsByTagName(base, Name.UDDI_TAG);
133         for (int i = 0 ; i < nl.getLength(); i++ ) {
134            nameVector.addElement(new Name((Element)nl.item(i)));
135         }
136
137         nl = getChildElementsByTagName(base, Description.UDDI_TAG);
138         for (int i = 0 ; i < nl.getLength(); i++) {
139            description.addElement(new Description((Element)nl.item(i)));
140         }
141
142         nl = getChildElementsByTagName(base, SharedRelationships.UDDI_TAG);
143         for (int i = 0 ; i < nl.getLength(); i++) {
144            sharedRelationships.addElement(new SharedRelationships((Element)nl.item(i)));
145         }
146
147    }
148    /**
149     * @deprecated This method has been deprecated. Use
150     * {@link #setSharedRelationshipsVector(Vector)} or
151     * {@link #setDefaultSharedRelationships(SharedRelationships)} instead
152     */

153    public void setSharedRelationships(SharedRelationships s) {
154      setDefaultSharedRelationships(s);
155    }
156
157    /**
158     * This method stores this name as the Default SharedRelationship
159     * (i.e., places it in the first location in the Vector).
160     */

161    public void setDefaultSharedRelationships(SharedRelationships s) {
162      if (this.sharedRelationships.size() > 0) {
163       this.sharedRelationships.setElementAt(s,0);
164      } else {
165       this.sharedRelationships.addElement(s);
166      }
167    }
168
169    /**
170     * @param s Vector of <I> SharedRelationships </I> objects
171     */

172    public void setSharedRelationshipsVector(Vector JavaDoc s) {
173       sharedRelationships = s;
174    }
175
176    /**
177     * @deprecated This method has been deprecated. Use
178     * {@link #setNameVector(Vector)} or
179     * {@link #setDefaultName(Name)} instead
180     */

181    public void setName(Name s) {
182      setDefaultName(s);
183    }
184
185    /**
186     * @deprecated This method has been deprecated. Use
187     * {@link #setNameVector(Vector)} or
188     * {@link #setDefaultNameString(String, String)} instead
189     */

190    public void setName(String JavaDoc s) {
191       setDefaultNameString(s, null);
192    }
193
194    /**
195     * This method stores this name as the Default Name (i.e., places it in the first
196     * location in the Vector).
197     */

198    public void setDefaultName(Name name) {
199      if (nameVector.size() > 0) {
200       nameVector.setElementAt(name,0);
201      } else {
202       nameVector.addElement(name);
203      }
204    }
205
206    /**
207     * This method stores this String, in the given language as the Default Name
208     * (i.e., places it in the first location in the Vector).
209     */

210    public void setDefaultNameString(String JavaDoc value, String JavaDoc lang) {
211       Name name = new Name(value, lang);
212        if (nameVector.size() > 0) {
213          nameVector.setElementAt(name,0);
214        } else {
215          nameVector.addElement(name);
216        }
217    }
218
219    /**
220     * @param s Vector of <I> Name </I> objects
221     */

222    public void setNameVector(Vector JavaDoc s) {
223       nameVector = s;
224    }
225
226    /**
227     * @deprecated This method has been deprecated. Use
228     * {@link #setDescriptionVector(Vector)} or
229     * {@link #setDefaultDescription(Description)} instead
230     */

231    public void setDescription(Description s) {
232        setDefaultDescription(s);
233    }
234
235    /**
236     * @deprecated This method has been deprecated. Use
237     * {@link #setDescriptionVector(Vector)} or
238     * {@link #setDefaultDescriptionString(String, String)} instead
239     */

240    public void setDescriptionString(String JavaDoc s) {
241        setDefaultDescriptionString(s,null);
242    }
243
244    /**
245     * This method stores this Description as the Default Description
246     * (i.e., places it in the first location in the Vector).
247     *
248     * @param s Description
249     */

250    public void setDefaultDescription(Description s) {
251       if (description.size() > 0) {
252          description.setElementAt(s,0);
253       } else {
254          description.addElement(s);
255       }
256    }
257
258    /**
259     * This method stores this String as the Default Description
260     * (i.e., places it in the first location in the Vector).
261     *
262     * @param s String
263     */

264    public void setDefaultDescriptionString(String JavaDoc s, String JavaDoc lang) {
265       if (description.size() > 0) {
266          description.setElementAt(new Description(s,lang), 0);
267       } else {
268          description.addElement(new Description(s,lang));
269       }
270    }
271
272    /**
273     * Set description vector.
274     *
275     * @param s Vector of <I>Description</I> objects.
276     */

277    public void setDescriptionVector(Vector JavaDoc s) {
278       description = s;
279    }
280
281
282    public void setBusinessKey(String JavaDoc s) {
283        businessKey = new BusinessKey(s);
284    }
285
286
287   /**
288    * @deprecated This method has been deprecated. Use
289    * {@link #getSharedRelationshipsVector()} or
290    * {@link #getDefaultSharedRelationships()} instead
291    */

292    public SharedRelationships getSharedRelationships() {
293       return getDefaultSharedRelationships();
294    }
295
296    /**
297     * Get the default SharedRelationships.
298     * (i.e., the one in the first position in the vector)
299     * @return SharedRelationships
300     */

301    public SharedRelationships getDefaultSharedRelationships() {
302       if(sharedRelationships.size() > 0)
303         return (SharedRelationships) sharedRelationships.elementAt(0);
304       else
305         return null;
306    }
307
308    /**
309     * Get all SharedRelationships.
310     *
311     * @return Vector of <I>SharedRelationships</I> objects.
312     */

313    public Vector JavaDoc getSharedRelationshipsVector() {
314       return sharedRelationships;
315    }
316
317   /**
318    * @deprecated This method has been deprecated. Use
319    * {@link #getNameVector()} or
320    * {@link #getDefaultName()} instead
321    */

322    public Name getName() {
323       return getDefaultName();
324    }
325
326   /**
327    * @deprecated This method has been deprecated. Use
328    * {@link #getNameVector()} or
329    * {@link #getDefaultNameString()} instead
330    */

331    public String JavaDoc getNameString() {
332       return getDefaultNameString();
333    }
334
335    /**
336     * Get the default name.
337     * (i.e., the one in the first position in the vector)
338     * @return Name
339     */

340    public Name getDefaultName() {
341       if(nameVector.size() > 0)
342         return (Name) nameVector.elementAt(0);
343       else
344         return null;
345    }
346
347   /**
348     * Get default name string.
349     * (i.e., the one in the first position in the vector)
350     * @return String
351     */

352    public String JavaDoc getDefaultNameString() {
353        if ((nameVector).size() > 0) {
354         return ((Name)nameVector.elementAt(0)).getText();
355        } else {
356            return null;
357        }
358    }
359
360    /**
361     * Get all names.
362     *
363     * @return Vector of <I>Name</I> objects.
364     */

365    public Vector JavaDoc getNameVector() {
366       return nameVector ;
367    }
368
369   /**
370    * @deprecated This method has been deprecated. Use
371    * {@link #getDescriptionVector()} or
372    * {@link #getDefaultDescription()} instead
373    */

374    public Description getDescription() {
375      return getDefaultDescription();
376    }
377   /**
378    * @deprecated This method has been deprecated. Use
379    * {@link #getDescriptionVector()} or
380    * {@link #getDefaultDescriptionString()} instead
381    */

382    public String JavaDoc getDescriptionString() {
383      return getDefaultDescriptionString();
384    }
385   /**
386    * Get the default Description.
387    * (i.e., the one in the first position in the vector)
388    * @return Description
389    */

390    public Description getDefaultDescription() {
391       if(description.size() > 0)
392         return ((Description) description.elementAt(0));
393       else
394         return null;
395    }
396   /**
397    * Get the default Description as a String.
398    * (i.e., the first string representing the first Description in the vector)
399    * @return String
400    */

401    public String JavaDoc getDefaultDescriptionString() {
402       if(description.size() > 0)
403         return ((Description) description.elementAt(0)).getText();
404       else
405         return null;
406    }
407    
408    /**
409     * Get all deascriptions.
410     *
411     * @return Vector of <I>Description</i> objects.
412     */

413    public Vector JavaDoc getDescriptionVector() {
414      return description;
415    }
416
417    public String JavaDoc getBusinessKey() {
418        return this.businessKey.getText();
419    }
420
421    /**
422     * Save an object to the DOM tree. Used to serialize an object
423     * to a DOM tree, usually to send a UDDI message.
424     *
425     * <BR>Used by UDDIProxy.
426     *
427     * @param parent Object will serialize as a child element under the
428     * passed in parent element.
429     */

430
431    public void saveToXML(Element parent) {
432         base = parent.getOwnerDocument().createElement(UDDI_TAG);
433          // Save attributes
434
if (businessKey!=null) {
435             businessKey.saveToXML(base);
436          }
437
438          if (nameVector!=null && nameVector.size()>0) {
439             for(int i=0; i<nameVector.size(); i++) {
440               ((Name)nameVector.elementAt(i)).saveToXML(base);
441             }
442          }
443
444          if (description!=null && description.size()>0) {
445             for(int i=0; i<description.size(); i++) {
446               ((Description)description.elementAt(i)).saveToXML(base);
447             }
448          }
449
450          if (sharedRelationships!=null && sharedRelationships.size()>0) {
451             for(int i=0; i<sharedRelationships.size(); i++) {
452               ((SharedRelationships)sharedRelationships.elementAt(i)).saveToXML(base);
453             }
454          }
455          parent.appendChild(base);
456    }
457 }
458
Popular Tags