KickJava   Java API By Example, From Geeks To Geeks.

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


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 categoryBag 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 in searching and categorization.
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  * @author Ozzy (ozzy@hursley.ibm.com)
40  */

41 public class CategoryBag extends UDDIElement {
42    public static final String JavaDoc UDDI_TAG = "categoryBag";
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 CategoryBag() {
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 CategoryBag(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     * Save an object to the DOM tree. Used to serialize an object
135     * to a DOM tree, usually to send a UDDI message.
136     *
137     * <BR>Used by UDDIProxy.
138     *
139     * @param parent Object will serialize as a child element under the
140     * passed in parent element.
141     */

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