KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > datatype > OverviewDoc


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.datatype;
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 overviewDoc element within the UDDI version 2.0 schema.
20  * This class contains the following types of methods:
21  *
22  * <ul>
23  * <li>Constructor passing the required fields.
24  * <li>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>For sets of attributes, a get/setVector method is provided.
28  * <li>SaveToXML method. Serializes this class within a passed in element.
29  * </ul>
30  *
31  * Typically this class is used to construct parameters for, or interpret
32  * responses from methods in the UDDIProxy class.
33  *
34  * <p><b>Element description:</b>
35  * <p>Support element - used to contain an on-line description and a
36  * URL pointer to additional in-depth or external documentation.
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  */

40 public class OverviewDoc extends UDDIElement {
41    public static final String JavaDoc UDDI_TAG = "overviewDoc";
42
43    protected Element base = null;
44
45    OverviewURL overviewURL = null;
46    // Vector of Description objects
47
Vector JavaDoc description = new Vector JavaDoc();
48
49   /**
50     * Default constructor.
51     * Avoid using the default constructor for validation. It does not validate
52     * required fields. Instead, use the required fields constructor to perform
53     * validation.
54     */

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

68    public OverviewDoc(Element base) throws UDDIException {
69       // Check if it is a fault. Throw exception if it is a fault.
70
super(base);
71       NodeList JavaDoc nl = null;
72       nl = getChildElementsByTagName(base, OverviewURL.UDDI_TAG);
73       if (nl.getLength() > 0) {
74          overviewURL = new OverviewURL((Element)nl.item(0));
75       }
76       nl = getChildElementsByTagName(base, Description.UDDI_TAG);
77       for (int i=0; i < nl.getLength(); i++) {
78          description.addElement(new Description((Element)nl.item(i)));
79       }
80    }
81
82    public void setOverviewURL(OverviewURL s) {
83       overviewURL = s;
84    }
85    public void setOverviewURL(String JavaDoc s) {
86       overviewURL = new OverviewURL();
87       overviewURL.setText(s);
88    }
89
90    /**
91     * Set a description vector.
92     *
93     * @param s Vector of <I>Description</I> objects.
94     */

95    public void setDescriptionVector(Vector JavaDoc s) {
96       description = s;
97    }
98
99    /**
100     * Set default (english) description string.
101     *
102     * @param s String
103     */

104    public void setDefaultDescriptionString(String JavaDoc s) {
105       if (description.size() > 0) {
106          description.setElementAt(new Description(s), 0);
107       } else {
108          description.addElement(new Description(s));
109       }
110    }
111
112    public OverviewURL getOverviewURL() {
113       return overviewURL;
114    }
115
116    public String JavaDoc getOverviewURLString() {
117       if (overviewURL != null) {
118          return overviewURL.getText();
119       } else {
120          return null;
121       }
122    }
123
124    /**
125     * Get description.
126     *
127     * @return s Vector of <I>Description</I> objects.
128     */

129    public Vector JavaDoc getDescriptionVector() {
130       return description;
131    }
132
133    /**
134     * Get default description string.
135     *
136     * @return s String
137     */

138    public String JavaDoc getDefaultDescriptionString() {
139       if ((description).size() > 0) {
140          Description t = (Description)description.elementAt(0);
141          return t.getText();
142       } else {
143          return null;
144       }
145    }
146
147    /**
148     * Save the object to a DOM tree. Used to serialize an object
149     * to a DOM tree, usually to send a UDDI message.
150     *
151     * <BR>Used by UDDIProxy.
152     *
153     * @param parent Object will serialize as a child element under the
154     * passed in parent element.
155     */

156    public void saveToXML(Element parent) {
157       base = parent.getOwnerDocument().createElement(UDDI_TAG);
158       // Save attributes
159
if (description!=null) {
160         for (int i=0; i < description.size(); i++) {
161            ((Description)(description.elementAt(i))).saveToXML(base);
162         }
163       }
164       if (overviewURL!=null) {
165          overviewURL.saveToXML(base);
166       }
167       parent.appendChild(base);
168    }
169    
170    
171    public boolean equals(Object JavaDoc object)
172    {
173         boolean result = false;
174         if (object != null && object instanceof OverviewDoc)
175         {
176             OverviewDoc otherOverviewDoc = (OverviewDoc)object;
177             if ((this.description == null && otherOverviewDoc.description == null)
178                 || (this.description != null && this.description.equals(otherOverviewDoc.description)))
179             {
180                 //description matches
181
if ((this.overviewURL == null && otherOverviewDoc.overviewURL == null)
182                     || (this.overviewURL != null && this.overviewURL.equals(otherOverviewDoc.overviewURL)))
183                 {
184                     //overviewURL matches as well.
185
result = true;
186                 }
187                 //else overviewURL does not match - result it false.
188
}
189             //else description does not match - result is false.
190
}
191         return result;
192    }
193 }
194
Popular Tags