KickJava   Java API By Example, From Geeks To Geeks.

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


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;
11
12 import org.uddi4j.UDDIElement;
13 import org.uddi4j.UDDIException;
14 import org.w3c.dom.Element JavaDoc;
15
16 /**
17  * Represents the description element within the UDDI version 2.0 schema.
18  * This class contains the following types of methods:
19  *
20  * <ul>
21  * <li>Constructor passing required fields.
22  * <li>Constructor that will instantiate the object from an appropriate XML
23  * DOM element.
24  * <li>Get/set methods for each attribute that this element can contain.
25  * <li>A get/setVector method is provided for sets of attributes.
26  * <li>SaveToXML method. Serializes this class within a passed in element.
27  * </ul>
28  *
29  * Typically, this class is used to construct parameters for, or interpret
30  * responses from methods in the UDDIProxy class.
31  *
32  * @author David Melgar (dmelgar@us.ibm.com)
33  * @author Ravi Trivedi (ravi_trivedi@hp.com)
34  */

35 public class Description extends UDDIElement
36 {
37     public static final String JavaDoc UDDI_TAG = "description";
38
39     protected Element base = null;
40
41     String JavaDoc text = null;
42     String JavaDoc lang = null;
43
44     /**
45      * Default constructor.
46      * Avoid using the default constructor for validation. It does not validate
47      * required fields. Instead, use the required fields constructor to perform
48      * validation.
49      */

50     public Description()
51     {
52     }
53
54     /**
55      * Construct the object with required fields.
56      *
57      * @param value String value
58      */

59     public Description(String JavaDoc value)
60     {
61         setText(value);
62     }
63
64     /**
65       * Construct the object with required fields.
66       *
67       * @param value String value
68       * @param lang String Language used for the name. Possible values defined
69       * in ISO3166.
70       */

71     public Description(String JavaDoc value, String JavaDoc lang)
72     {
73         setText(value);
74         setLang(lang);
75     }
76
77     /**
78      * Construct the object from a DOM tree. Used by
79      * UDDIProxy to construct an object from a received UDDI
80      * message.
81      *
82      * @param base Element with the name appropriate for this class.
83      * @exception UDDIException Thrown if DOM tree contains a SOAP fault or
84      * disposition report indicating a UDDI error.
85      */

86     public Description(Element base) throws UDDIException
87     {
88         // Check if it is a fault. Throws an exception if it is.
89
super(base);
90         text = getText(base);
91         lang = base.getAttribute("xml:lang");
92     }
93
94     public void setText(String JavaDoc s)
95     {
96         text = s;
97     }
98
99     /**
100      * Set the language identifier for this string element.
101      * Possible values are defined in ISO3166.
102      *
103      * @param s Language string.
104      */

105     public void setLang(String JavaDoc s)
106     {
107         lang = s;
108     }
109
110     public String JavaDoc getText()
111     {
112         return text;
113     }
114
115     public String JavaDoc getLang()
116     {
117         return lang;
118     }
119
120     /**
121      * Save an object to the DOM tree. Used to serialize an object
122      * to a DOM tree, usually to send a UDDI message.
123      *
124      * <BR>Used by UDDIProxy.
125      *
126      * @param parent Object will serialize as a child element under the
127      * passed in parent element.
128      */

129     public void saveToXML(Element parent)
130     {
131         base = parent.getOwnerDocument().createElement(UDDI_TAG);
132         // Save attributes
133
if (text != null)
134         {
135             base.appendChild(parent.getOwnerDocument().createTextNode(text));
136         }
137         if ((lang != null) && !(lang.equals("")))
138         {
139             base.setAttribute("xml:lang", lang);
140         }
141         parent.appendChild(base);
142     }
143
144     public boolean equals(Object JavaDoc object)
145     {
146         boolean result = false;
147         if (object != null && object instanceof Description)
148         {
149             Description otherDescription = (Description) object;
150             if ((this.text == null && otherDescription.text == null) || (this.text != null && this.text.equals(otherDescription.text)))
151             {
152                 //text matches
153
if ((this.lang == null && otherDescription.lang == null) || (this.lang != null && this.lang.equals(otherDescription.lang)))
154                 {
155                     //lang matches as well - objects are equal
156
result = true;
157                 }
158                 //else lang does not match - result is false.
159
}
160             //else text does not match - result is false.
161
}
162         return result;
163     }
164 }
165
Popular Tags