KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > datatype > business > BusinessEntity


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.business;
11
12 import java.util.Vector JavaDoc;
13
14 import org.uddi4j.UDDIElement;
15 import org.uddi4j.UDDIException;
16 import org.uddi4j.datatype.Description;
17 import org.uddi4j.datatype.Name;
18 import org.uddi4j.datatype.service.BusinessServices;
19 import org.uddi4j.util.CategoryBag;
20 import org.uddi4j.util.DiscoveryURLs;
21 import org.uddi4j.util.IdentifierBag;
22 import org.w3c.dom.Element JavaDoc;
23 import org.w3c.dom.NodeList JavaDoc;
24
25 /**
26  * Represents the businessEntity element within the UDDI version 2.0 schema.
27  * This class contains the following types of methods:
28  *
29  * <ul>
30  * <li>Constructor passing required fields.
31  * <li>Constructor that will instantiate the object from an appropriate XML
32  * DOM element.
33  * <li>Get/set methods for each attribute that this element can contain.
34  * <li>A get/setVector method is provided for sets of attributes.
35  * <li>SaveToXML method. Serializes this class within a passed in element.
36  * </ul>
37  *
38  * Typically, this class is used to construct parameters for, or interpret
39  * responses from methods in the UDDIProxy class.
40  *
41  * <p><b>Element description:</b>
42  * <p>Primary Data type: Describes an instance of a business or business unit.
43  *
44  * @author David Melgar (dmelgar@us.ibm.com)
45  * @author Ravi Trivedi (ravi_trivedi@hp.com)
46  * @author Vivek Chopra (vivek@soaprpc.com)
47  */

48 public class BusinessEntity extends UDDIElement {
49    public static final String JavaDoc UDDI_TAG = "businessEntity";
50
51    protected Element base = null;
52
53    String JavaDoc businessKey = null;
54    String JavaDoc operator = null;
55    String JavaDoc authorizedName = null;
56    DiscoveryURLs discoveryURLs = null;
57    Contacts contacts = null;
58    BusinessServices businessServices = null;
59    IdentifierBag identifierBag = null;
60    CategoryBag categoryBag = null;
61    // Vector of Description objects
62
Vector JavaDoc description = new Vector JavaDoc();
63    Vector JavaDoc nameVector = new Vector JavaDoc();
64
65    /**
66     * Default constructor.
67     * Avoid using the default constructor for validation. It does not validate
68     * required fields. Instead, use the required fields constructor to perform
69     * validation.
70     */

71    public BusinessEntity() {
72    }
73
74    /**
75     * Construct the object with required fields.
76     * Publishing several names (e.g., for romanization purposes) is supported.
77     * To indicate the language that the names are expressed in, a unique
78     * xml:lang value is associated with each name.
79     * <b>Only one name (default language) can omit its unique language
80     * identifier.</b> Other names passed without an xml:lang value associated,
81     * are assigned the default language code of the registering party.
82     * The default language code is established at the time the publishing
83     * credentials are established with an individual Operator Site.
84     * If no default language is provisioned at the time a publisher signs up,
85     * the operator can adopt an appropriate default language code.
86     *
87     * @param businessKey String
88     * @param name String
89     */

90    public BusinessEntity(String JavaDoc businessKey,
91             String JavaDoc name) {
92       this.businessKey = businessKey;
93       nameVector.addElement(new Name(name));
94    }
95
96     /**
97     * Construct the object with required fields.
98     *
99     * @param businessKey String
100     * @param name String
101     * @param lang String
102     */

103    public BusinessEntity(String JavaDoc businessKey,
104             String JavaDoc name, String JavaDoc lang) {
105       this.businessKey = businessKey;
106       nameVector.addElement(new Name(name,lang));
107    }
108
109    /**
110     * Construct the object from a DOM tree. Used by
111     * UDDIProxy to construct an object from a received UDDI
112     * message.
113     *
114     * @param base Element with the name appropriate for this class.
115     *
116     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
117     * or a disposition report indicating a UDDI error.
118     */

119    public BusinessEntity(Element base) throws UDDIException {
120       // Check if its a fault. Throws an exception if it is.
121
super(base);
122       businessKey = base.getAttribute("businessKey");
123       operator = getAttr(base,"operator");
124       authorizedName = getAttr(base,"authorizedName");
125       NodeList JavaDoc nl = null;
126       nl = getChildElementsByTagName(base, DiscoveryURLs.UDDI_TAG);
127       if (nl.getLength() > 0) {
128          discoveryURLs = new DiscoveryURLs((Element)nl.item(0));
129       }
130       nl = getChildElementsByTagName(base, Name.UDDI_TAG);
131       for (int i=0; i < nl.getLength(); i++) {
132           nameVector.addElement(new Name((Element)nl.item(i)));
133       }
134       nl = getChildElementsByTagName(base, Contacts.UDDI_TAG);
135       if (nl.getLength() > 0) {
136          contacts = new Contacts((Element)nl.item(0));
137       }
138       nl = getChildElementsByTagName(base, BusinessServices.UDDI_TAG);
139       if (nl.getLength() > 0) {
140          businessServices = new BusinessServices((Element)nl.item(0));
141       }
142       nl = getChildElementsByTagName(base, IdentifierBag.UDDI_TAG);
143       if (nl.getLength() > 0) {
144          identifierBag = new IdentifierBag((Element)nl.item(0));
145       }
146       nl = getChildElementsByTagName(base, CategoryBag.UDDI_TAG);
147       if (nl.getLength() > 0) {
148          categoryBag = new CategoryBag((Element)nl.item(0));
149       }
150       nl = getChildElementsByTagName(base, Description.UDDI_TAG);
151       for (int i=0; i < nl.getLength(); i++) {
152          description.addElement(new Description((Element)nl.item(i)));
153       }
154    }
155
156    private String JavaDoc getAttr(Element base, String JavaDoc attrname)
157    {
158      if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() )
159      {
160        return base.getAttribute(attrname);
161      }
162      return null;
163    }
164
165    public void setBusinessKey(String JavaDoc s) {
166       businessKey = s;
167    }
168
169    public void setOperator(String JavaDoc s) {
170       operator = s;
171    }
172
173    public void setAuthorizedName(String JavaDoc s) {
174       authorizedName = s;
175    }
176
177    public void setDiscoveryURLs(DiscoveryURLs s) {
178       discoveryURLs = s;
179    }
180
181    /**
182     * @deprecated This method has been deprecated. Use
183     * {@link #setNameVector (Vector)} or
184     * {@link #setDefaultName (Name)} instead
185     */

186     public void setName(Name s) {
187       setDefaultName(s);
188     }
189
190    /**
191     * @deprecated This method has been deprecated. Use
192     * {@link #setNameVector (Vector)} or
193     * {@link #setDefaultNameString (String, String)} instead
194     */

195     public void setName(String JavaDoc s) {
196        setDefaultNameString(s, null);
197     }
198
199   /**
200    * This method stores this name as the Default Name (i.e., places it in the first
201    * location in the Vector).
202    */

203    public void setDefaultName(Name name) {
204      if (nameVector.size() > 0) {
205       nameVector.setElementAt(name,0);
206      } else {
207       nameVector.addElement(name);
208      }
209    }
210
211   /**
212    * This method stores this String, in the given language as the Default Name
213    * (i.e., places it in the first location in the Vector).
214    */

215    public void setDefaultNameString(String JavaDoc value, String JavaDoc lang) {
216       Name name = new Name(value, lang);
217        if (nameVector.size() > 0) {
218          nameVector.setElementAt(name,0);
219        } else {
220          nameVector.addElement(name);
221        }
222    }
223
224   /**
225    * @param s Vector of <I> Name </I> objects
226    */

227    public void setNameVector(Vector JavaDoc s) {
228       nameVector = s;
229    }
230
231    public void setContacts(Contacts s) {
232       contacts = s;
233    }
234
235    public void setBusinessServices(BusinessServices s) {
236       businessServices = s;
237    }
238
239    public void setIdentifierBag(IdentifierBag s) {
240       identifierBag = s;
241    }
242
243    public void setCategoryBag(CategoryBag s) {
244       categoryBag = s;
245    }
246
247    /**
248     * Set description vector.
249     *
250     * @param s Vector of <I>Description</I> objects.
251     */

252    public void setDescriptionVector(Vector JavaDoc s) {
253       description = s;
254    }
255
256    /**
257     * Set default description string.
258     *
259     * @param s String
260     */

261    public void setDefaultDescriptionString(String JavaDoc s) {
262       if (description.size() > 0) {
263          description.setElementAt(new Description(s), 0);
264       } else {
265          description.addElement(new Description(s));
266       }
267    }
268
269
270    public String JavaDoc getBusinessKey() {
271       return businessKey;
272    }
273
274
275    public String JavaDoc getOperator() {
276       return operator;
277    }
278
279
280    public String JavaDoc getAuthorizedName() {
281       return authorizedName;
282    }
283
284
285    public DiscoveryURLs getDiscoveryURLs() {
286       return discoveryURLs;
287    }
288
289   /**
290    * @deprecated This method has been deprecated. Use
291    * {@link #getNameVector ()} or
292    * {@link #getDefaultName ()} instead
293    */

294    public Name getName() {
295       return getDefaultName();
296    }
297
298   /**
299    * @deprecated This method has been deprecated. Use
300    * {@link #getNameVector ()} or
301    * {@link #getDefaultNameString ()} instead
302    */

303    public String JavaDoc getNameString() {
304       return getDefaultNameString();
305    }
306
307
308    public Name getDefaultName() {
309       return (Name) nameVector.elementAt(0);
310    }
311
312   /**
313     * Get default name string.
314     *
315     * @return String
316     */

317    public String JavaDoc getDefaultNameString() {
318        if ((nameVector).size() > 0) {
319         return ((Name)nameVector.elementAt(0)).getText();
320        } else {
321            return null;
322        }
323    }
324
325    /**
326     * Get all names.
327     *
328     * @return Vector of <I>Name</I> objects.
329     */

330    public Vector JavaDoc getNameVector() {
331       return nameVector ;
332    }
333
334    public Contacts getContacts() {
335       return contacts;
336    }
337
338
339    public BusinessServices getBusinessServices() {
340       return businessServices;
341    }
342
343
344    public IdentifierBag getIdentifierBag() {
345       return identifierBag;
346    }
347
348
349    public CategoryBag getCategoryBag() {
350       return categoryBag;
351    }
352
353
354    /**
355     * Get description
356     *
357     * @return s Vector of <I>Description</I> objects.
358     */

359    public Vector JavaDoc getDescriptionVector() {
360       return description;
361    }
362
363
364    /**
365     * Get default description string
366     *
367     * @return s String
368     */

369    public String JavaDoc getDefaultDescriptionString() {
370       if ((description).size() > 0) {
371          Description t = (Description)description.elementAt(0);
372          return t.getText();
373       } else {
374          return null;
375       }
376    }
377
378    /**
379     * Save an object to the DOM tree. Used to serialize an object
380     * to a DOM tree, usually to send a UDDI message.
381     *
382     * <BR>Used by UDDIProxy.
383     *
384     * @param parent Object will serialize as a child element under the
385     * passed in parent element.
386     */

387    public void saveToXML(Element parent) {
388       base = parent.getOwnerDocument().createElement(UDDI_TAG);
389       // Save attributes
390
if (businessKey!=null) {
391          base.setAttribute("businessKey", businessKey);
392       }
393       if (operator!=null) {
394          base.setAttribute("operator", operator);
395       }
396       if (authorizedName!=null) {
397          base.setAttribute("authorizedName", authorizedName);
398       }
399       if (discoveryURLs!=null) {
400          discoveryURLs.saveToXML(base);
401       }
402       if (nameVector!=null) {
403         for (int i=0; i < nameVector.size(); i++) {
404            ((Name)(nameVector.elementAt(i))).saveToXML(base);
405         }
406       }
407       if (description!=null) {
408         for (int i=0; i < description.size(); i++) {
409            ((Description)(description.elementAt(i))).saveToXML(base);
410         }
411       }
412       if (contacts!=null) {
413          contacts.saveToXML(base);
414       }
415       if (businessServices!=null) {
416          businessServices.saveToXML(base);
417       }
418       if (identifierBag!=null) {
419          identifierBag.saveToXML(base);
420       }
421       if (categoryBag!=null) {
422          categoryBag.saveToXML(base);
423       }
424       parent.appendChild(base);
425    }
426 }
427
428
Popular Tags