KickJava   Java API By Example, From Geeks To Geeks.

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


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

43 public class ServiceInfo extends UDDIElement {
44    public static final String JavaDoc UDDI_TAG = "serviceInfo";
45
46    protected Element base = null;
47
48    String JavaDoc serviceKey = null;
49    String JavaDoc businessKey = null;
50    // Vector of name
51
Vector JavaDoc nameVector = new Vector JavaDoc();
52
53    /**
54     * Default constructor.
55     * Avoid using the default constructor for validation. It does not validate
56     * required fields. Instead, use the required fields constructor to perform
57     * validation.
58     */

59
60    public ServiceInfo() {
61    }
62
63    /**
64     * Construct the object with required fields.
65     *
66     * @param serviceKey String
67     * @param name String
68     */

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

85
86    public ServiceInfo(Element base) throws UDDIException {
87       // Check if it is a fault. Throws an exception if it is.
88
super(base);
89       serviceKey = base.getAttribute("serviceKey");
90       businessKey = base.getAttribute("businessKey");
91       NodeList JavaDoc nl = null;
92       nl = getChildElementsByTagName(base, Name.UDDI_TAG);
93       for (int i=0; i<nl.getLength(); i++) {
94          nameVector.addElement(new Name((Element)nl.item(0)));
95       }
96    }
97
98    public void setServiceKey(String JavaDoc s) {
99       serviceKey = s;
100    }
101
102    public void setBusinessKey(String JavaDoc s) {
103       businessKey = s;
104    }
105
106    /**
107     * @deprecated This method has been deprecated. Use
108     * {@link #setNameVector (Vector)} or
109     * {@link #setDefaultName (Name)} instead
110     */

111     public void setName(Name s) {
112       setDefaultName(s);
113     }
114
115    /**
116     * @deprecated This method has been deprecated. Use
117     * {@link #setNameVector (Vector)} or
118     * {@link #setDefaultNameString (String, String)} instead
119     */

120     public void setName(String JavaDoc s) {
121        setDefaultNameString(s, null);
122     }
123
124   /**
125    * This method stores this name as the Default Name (i.e., places it in the first
126    * location in the Vector).
127    */

128    public void setDefaultName(Name name) {
129      if (nameVector.size() > 0) {
130       nameVector.setElementAt(name,0);
131      } else {
132       nameVector.addElement(name);
133      }
134    }
135
136   /**
137    * This method stores this String, in the given language as the Default Name
138    * (i.e., places it in the first location in the Vector).
139    */

140    public void setDefaultNameString(String JavaDoc value, String JavaDoc lang) {
141       Name name = new Name(value, lang);
142        if (nameVector.size() > 0) {
143          nameVector.setElementAt(name,0);
144        } else {
145          nameVector.addElement(name);
146        }
147    }
148
149   /**
150    * @param s Vector of <I> Name </I> objects
151    */

152    public void setNameVector(Vector JavaDoc s) {
153       nameVector = s;
154    }
155
156    public String JavaDoc getServiceKey() {
157       return serviceKey;
158    }
159
160
161    public String JavaDoc getBusinessKey() {
162       return businessKey;
163    }
164
165   /**
166    * @deprecated This method has been deprecated. Use
167    * {@link #getNameVector ()} or
168    * {@link #getDefaultName ()} instead
169    */

170    public Name getName() {
171       return getDefaultName();
172    }
173
174   /**
175    * @deprecated This method has been deprecated. Use
176    * {@link #getNameVector ()} or
177    * {@link #getDefaultNameString ()} instead
178    */

179    public String JavaDoc getNameString() {
180       return getDefaultNameString();
181    }
182
183
184    public Name getDefaultName() {
185       return (Name) nameVector.elementAt(0);
186    }
187
188   /**
189     * Get default name string.
190     *
191     * @return String
192     */

193    public String JavaDoc getDefaultNameString() {
194        if ((nameVector).size() > 0) {
195         return ((Name)nameVector.elementAt(0)).getText();
196        } else {
197            return null;
198        }
199    }
200
201    /**
202     * Get all names.
203     *
204     * @return Vector of <I>Name</I> objects.
205     */

206    public Vector JavaDoc getNameVector() {
207       return nameVector ;
208    }
209
210    /**
211     * Save an object to the DOM tree. Used to serialize an object
212     * to a DOM tree, usually to send a UDDI message.
213     *
214     * <BR>Used by UDDIProxy.
215     *
216     * @param parent Object will serialize as a child element under the
217     * passed in parent element.
218     */

219
220    public void saveToXML(Element parent) {
221       base = parent.getOwnerDocument().createElement(UDDI_TAG);
222       // Save attributes
223
if (serviceKey!=null) {
224          base.setAttribute("serviceKey", serviceKey);
225       }
226       if (businessKey!=null) {
227          base.setAttribute("businessKey", businessKey);
228       }
229       if (nameVector!=null && nameVector.size()>0) {
230          for(int i=0;i<nameVector.size();i++) {
231            ((Name)nameVector.elementAt(i)).saveToXML(base);
232          }
233       }
234       parent.appendChild(base);
235    }
236 }
237
Popular Tags