KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.w3c.dom.Element JavaDoc;
18 import org.w3c.dom.NodeList JavaDoc;
19
20 /**
21  * Represents the businessInfo element within the UDDI version 2.0 schema.
22  * This class contains the following types of methods:
23  *
24  * <ul>
25  * <li>A constructor that passes the required fields.
26  * <li>A Constructor that will instantiate the object from an appropriate XML
27  * DOM element.
28  * <li>Get/set methods for each attribute that this element can contain.
29  * <li>A get/setVector method is provided for sets of attributes.
30  * <li>A SaveToXML method that serializes this class within a passed in
31  * element.
32  * </ul>
33  *
34  * Typically, this class is used to construct parameters for, or interpret
35  * responses from, methods in the UDDIProxy class.
36  *
37  * <p><b>Element description:</b>
38  * <p>This element is used as a short form of the BusinessEntity
39  * element. It is used as a first pass result set for "find businesses" queries.
40  *
41  * @author David Melgar (dmelgar@us.ibm.com)
42  * @author Ozzy (ozzy@hursley.ibm.com)
43  */

44 public class BusinessInfo extends UDDIElement {
45    public static final String JavaDoc UDDI_TAG = "businessInfo";
46
47    protected Element base = null;
48
49    String JavaDoc businessKey = null;
50    ServiceInfos serviceInfos = null;
51    // Vector of Name objects
52
Vector JavaDoc name = new Vector JavaDoc();
53    // Vector of Description objects
54
Vector JavaDoc description = new Vector JavaDoc();
55
56    /**
57     * Default constructor.
58     * Avoid using the default constructor for validation. It does not validate
59     * required fields. Instead, use the required fields constructor to perform
60     * validation.
61     */

62
63    public BusinessInfo() {
64    }
65
66    /**
67     * Construct the object with required fields.
68     *
69     * @param businessKey String
70     * @param name String
71     * @param serviceInfos ServiceInfos object
72     */

73    public BusinessInfo(String JavaDoc businessKey,
74             String JavaDoc name,
75             ServiceInfos serviceInfos) {
76       this.businessKey = businessKey;
77       this.name.addElement(new Name(name));
78       this.serviceInfos = serviceInfos;
79    }
80
81    /**
82     * Construct the object from a DOM tree. Used by
83     * UDDIProxy to construct an object from a received UDDI
84     * message.
85     *
86     * @param base Element with the name appropriate for this class.
87     *
88     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
89     * or a disposition report indicating a UDDI error.
90     */

91
92    public BusinessInfo(Element base) throws UDDIException {
93       // Check if it is a fault. Throws an exception if it is.
94
super(base);
95       businessKey = base.getAttribute("businessKey");
96       NodeList JavaDoc nl = null;
97       nl = getChildElementsByTagName(base, Name.UDDI_TAG);
98       for(int i=0; i<nl.getLength() ; i++) {
99          name.addElement(new Name((Element)nl.item(i)));
100       }
101       nl = getChildElementsByTagName(base, ServiceInfos.UDDI_TAG);
102       if (nl.getLength() > 0) {
103          serviceInfos = new ServiceInfos((Element)nl.item(0));
104       }
105       nl = getChildElementsByTagName(base, Description.UDDI_TAG);
106       for (int i=0; i < nl.getLength(); i++) {
107          description.addElement(new Description((Element)nl.item(i)));
108       }
109    }
110
111    public void setBusinessKey(String JavaDoc s) {
112       businessKey = s;
113    }
114    /**
115     * @deprecated This method has been deprecated. Use
116     * {@link #setNameVector( Vector )} or
117     * {@link #setDefaultName( Name )} instead
118     */

119    public void setName(Name s) {
120      setDefaultName(s);
121    }
122    /**
123     * @deprecated This method has been deprecated. Use
124     * {@link #setNameVector( Vector )} or
125     * {@link #setDefaultNameString(String, String)} instead.
126     */

127    public void setName(String JavaDoc s) {
128      setDefaultNameString(s,null);
129    }
130    /**
131     * This method stores this name as the Default Name (i.e., places it in the
132     * first location in the Vector).
133     */

134    public void setDefaultName(Name name) {
135       if (this.name.size() > 0) {
136         this.name.setElementAt(name,0);
137       }else{
138         this.name.addElement(name);
139       }
140    }
141    /**
142     * This method stores this String, in the given language as the Default Name
143     * (i.e., places it in the first location in the Vector).
144     */

145    public void setDefaultNameString(String JavaDoc value, String JavaDoc lang) {
146       Name n = new Name(value, lang);
147       if(this.name.size() > 0) {
148         name.setElementAt(n,0);
149       }else{
150         name.addElement(n);
151       }
152    }
153    /**
154     * @param s Vector of <i>Name</i> objects
155     */

156    public void setNameVector(Vector JavaDoc s) {
157      name = s;
158    }
159
160    public void setServiceInfos(ServiceInfos s) {
161       serviceInfos = s;
162    }
163
164    /**
165     * Set description vector
166     *
167     * @param s Vector of <I>Description</I> objects.
168     */

169    public void setDescriptionVector(Vector JavaDoc s) {
170       description = s;
171    }
172
173    /**
174     * Set default (english) description string
175     *
176     * @param s String
177     */

178    public void setDefaultDescriptionString(String JavaDoc s) {
179       if (description.size() > 0) {
180          description.setElementAt(new Description(s), 0);
181       } else {
182          description.addElement(new Description(s));
183       }
184    }
185
186    public String JavaDoc getBusinessKey() {
187       return businessKey;
188    }
189
190    /**
191     * @deprecated This method has been deprecated. Use
192     * {@link #getNameVector ()} or
193     * {@link #getDefaultName ()} instead.
194     */

195    public Name getName() {
196      return getDefaultName();
197    }
198    
199    /**
200     * @deprecated This method has been deprecated. Use
201     * {@link #getNameVector ()} or
202     * {@link #getDefaultNameString ()} instead.
203     */

204    public String JavaDoc getNameString() {
205       return getDefaultNameString();
206    }
207
208    /**
209     * Get default name
210     * @return Name
211     */

212    public Name getDefaultName() {
213      if(name.size() > 0) {
214        return (Name) name.elementAt(0);
215      }else{
216        return null;
217      }
218    }
219
220    /**
221     * Get default name string
222     * @return String
223     */

224    public String JavaDoc getDefaultNameString() {
225      if( name.size() > 0) {
226        return ((Name)name.elementAt(0)).getText();
227      }else{
228        return null;
229      }
230    }
231
232    /**
233     * Get all Names.
234     * @return Vector of <i>Name</i> objects.
235     */

236    public Vector JavaDoc getNameVector() {
237      return name;
238    }
239
240    public ServiceInfos getServiceInfos() {
241       return serviceInfos;
242    }
243
244
245    /**
246     * Get description
247     *
248     * @return s Vector of <I>Description</I> objects.
249     */

250    public Vector JavaDoc getDescriptionVector() {
251       return description;
252    }
253
254    /**
255     * Get default description string
256     *
257     * @return s String
258     */

259    public String JavaDoc getDefaultDescriptionString() {
260       if ((description).size() > 0) {
261          Description t = (Description)description.elementAt(0);
262          return t.getText();
263       } else {
264          return null;
265       }
266    }
267
268    /**
269     * Save an object to the DOM tree. Used to serialize an object
270     * to a DOM tree, usually to send a UDDI message.
271     *
272     * <BR>Used by UDDIProxy.
273     *
274     * @param parent Object will serialize as a child element under the
275     * passed in parent element.
276     */

277
278    public void saveToXML(Element parent) {
279       base = parent.getOwnerDocument().createElement(UDDI_TAG);
280       // Save attributes
281
if (businessKey!=null) {
282          base.setAttribute("businessKey", businessKey);
283       }
284       if (name!=null) {
285          for (int i=0; i < name.size(); i++) {
286            ((Name)(name.elementAt(i))).saveToXML(base);
287          }
288       }
289       if (description!=null) {
290          for (int i=0; i < description.size(); i++) {
291             ((Description)(description.elementAt(i))).saveToXML(base);
292      }
293       }
294       if (serviceInfos!=null) {
295          serviceInfos.saveToXML(base);
296       }
297       parent.appendChild(base);
298    }
299 }
300
Popular Tags