KickJava   Java API By Example, From Geeks To Geeks.

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


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 identifierBag 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>Service element. Used when searching and categorizing.
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  * @author Ozzy (ozzy@hursley.ibm.com)
40  */

41 public class IdentifierBag extends UDDIElement {
42    public static final String JavaDoc UDDI_TAG = "identifierBag";
43
44    protected Element base = null;
45
46    // Vector of KeyedReference objects
47
Vector JavaDoc keyedReference = new Vector JavaDoc();
48
49    /**
50     * Default constructor.
51     *
52     */

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

66    public IdentifierBag(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, KeyedReference.UDDI_TAG);
71       for (int i=0; i < nl.getLength(); i++) {
72          keyedReference.addElement(new KeyedReference((Element)nl.item(i)));
73       }
74    }
75
76    /**
77     * Set keyedReference vector
78     *
79     * @param s Vector of <I>KeyedReference</I> objects.
80     */

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

90    public Vector JavaDoc getKeyedReferenceVector() {
91       return keyedReference;
92    }
93
94    /**
95     * Add a keyed reference to this collection
96     *
97     * @param kr KeyedReference
98     */

99    public void add(KeyedReference kr) {
100       keyedReference.add(kr);
101    }
102
103    /**
104     * Remove the specified object from the collection.
105     *
106     * @param kr Keyed reference to remove
107     * @return True if object was removed, false if it
108     * was not found in the collection.
109     */

110    public boolean remove(KeyedReference kr) {
111       return keyedReference.remove(kr);
112    }
113
114    /**
115     * Retrieve the object at the specified index within the collection.
116     *
117     * @param index
118     * @return KeyedReference
119     */

120    public KeyedReference get(int index) {
121       return (KeyedReference)keyedReference.get(index);
122    }
123
124    /**
125     * Return current size of the collection.
126     *
127     * @return int
128     */

129    public int size() {
130       return keyedReference.size();
131    }
132
133
134    /**
135     * Save an object to the DOM tree. Used to serialize an object
136     * to a DOM tree, usually to send a UDDI message.
137     *
138     * <BR>Used by UDDIProxy.
139     *
140     * @param parent Object will serialize as a child element under the
141     * passed in parent element.
142     */

143    public void saveToXML(Element parent) {
144       base = parent.getOwnerDocument().createElement(UDDI_TAG);
145       // Save attributes
146
if (keyedReference!=null) {
147          for (int i=0; i < keyedReference.size(); i++) {
148             ((KeyedReference)(keyedReference.elementAt(i))).saveToXML(base);
149      }
150       }
151       parent.appendChild(base);
152    }
153 }
154
Popular Tags