KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > request > SaveBusiness


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.request;
10
11 import java.util.Vector JavaDoc;
12
13 import org.uddi4j.UDDIElement;
14 import org.uddi4j.UDDIException;
15 import org.uddi4j.datatype.business.BusinessEntity;
16 import org.uddi4j.util.AuthInfo;
17 import org.uddi4j.util.UploadRegister;
18 import org.w3c.dom.Element JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20
21 /**
22  * Represents the save_business element within the UDDI version 2.0 schema.
23  * This class contains the following types of methods:
24  *
25  * <ul>
26  * <li>A constructor that passes the required fields.
27  * <li>A Constructor that will instantiate the object from an appropriate XML
28  * DOM element.
29  * <li>Get/set methods for each attribute that this element can contain.
30  * <li>A get/setVector method is provided for sets of attributes.
31  * <li>A SaveToXML method that serializes this class within a passed in
32  * element.
33  * </ul>
34  *
35  * Typically, this class is used to construct parameters for, or interpret
36  * responses from, methods in the UDDIProxy class.
37  *
38  * <p><b>Element description:</b>
39  * <p>This message is used to save added/updated information describing
40  * one or more businessEntity structures. Either a businessEntity or an
41  * uploadRegister object is required. A message is invalid if contains both
42  * types or neither type.
43  *
44  * @author David Melgar (dmelgar@us.ibm.com)
45  * @author Ozzy (ozzy@hursley.ibm.com)
46  */

47 public class SaveBusiness extends UDDIElement {
48    public static final String JavaDoc UDDI_TAG = "save_business";
49
50    protected Element base = null;
51
52    AuthInfo authInfo = null;
53    // Vector of BusinessEntity objects
54
Vector JavaDoc businessEntity = new Vector JavaDoc();
55    // Vector of UploadRegister objects
56
Vector JavaDoc uploadRegister = new Vector JavaDoc();
57
58    /**
59     * Default constructor.
60     * Avoid using the default constructor for validation. It does not validate
61     * required fields. Instead, use the required fields constructor to perform
62     * validation.
63     */

64    public SaveBusiness() {
65    }
66
67    /**
68     * Construct the object with required fields.
69     *
70     * @param authInfo String
71     */

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

86    public SaveBusiness(Element base) throws UDDIException {
87       // Check if it is a fault. Throws an exception if it is.
88
super(base);
89       NodeList JavaDoc nl = null;
90       nl = getChildElementsByTagName(base, AuthInfo.UDDI_TAG);
91       if (nl.getLength() > 0) {
92          authInfo = new AuthInfo((Element)nl.item(0));
93       }
94       nl = getChildElementsByTagName(base, BusinessEntity.UDDI_TAG);
95       for (int i=0; i < nl.getLength(); i++) {
96          businessEntity.addElement(new BusinessEntity((Element)nl.item(i)));
97       }
98       nl = getChildElementsByTagName(base, UploadRegister.UDDI_TAG);
99       for (int i=0; i < nl.getLength(); i++) {
100          uploadRegister.addElement(new UploadRegister((Element)nl.item(i)));
101       }
102    }
103
104    public void setAuthInfo(AuthInfo s) {
105       authInfo = s;
106    }
107    public void setAuthInfo(String JavaDoc s) {
108       authInfo = new AuthInfo();
109       authInfo.setText(s);
110    }
111
112    /**
113     * Set businessEntity vector.
114     *
115     * @param s Vector of <I>BusinessEntity</I> objects.
116     */

117    public void setBusinessEntityVector(Vector JavaDoc s) {
118       businessEntity = s;
119    }
120
121    /**
122     * Set uploadRegister vector.
123     *
124     * @param s Vector of <I>UploadRegister</I> objects.
125     * @deprecated
126     */

127    public void setUploadRegisterVector(Vector JavaDoc s) {
128       uploadRegister = s;
129    }
130
131    /**
132     * Set uploadRegister.
133     *
134     * @param s Vector of <I>String</I> objects.
135     * @deprecated
136     */

137    public void setUploadRegisterStrings(Vector JavaDoc s) {
138       uploadRegister = new Vector JavaDoc();
139       for (int i = 0; i < s.size(); i++) {
140          uploadRegister.addElement( new UploadRegister((String JavaDoc)s.elementAt(i)) );
141       }
142    }
143
144    public AuthInfo getAuthInfo() {
145       return authInfo;
146    }
147
148    public String JavaDoc getAuthInfoString() {
149       if(authInfo!=null)
150         return authInfo.getText();
151       else
152         return null;
153    }
154
155    /**
156     * Get businessEntity vector.
157     *
158     * @return s Vector of <I>BusinessEntity</I> objects.
159     */

160    public Vector JavaDoc getBusinessEntityVector() {
161       return businessEntity;
162    }
163
164    /**
165     * Get uploadRegister vector.
166     *
167     * @return s Vector of <I>UploadRegister</I> objects.
168     * @deprecated
169     */

170    public Vector JavaDoc getUploadRegisterVector() {
171       return uploadRegister;
172    }
173
174    /**
175     * Get uploadRegister.
176     *
177     * @return s Vector of <I>String</I> objects.
178     * @deprecated
179     */

180    public Vector JavaDoc getUploadRegisterStrings() {
181       Vector JavaDoc strings = new Vector JavaDoc();
182       for (int i = 0; i < uploadRegister.size(); i++) {
183          strings.addElement( ((UploadRegister)uploadRegister.elementAt(i)).getText());
184       }
185       return strings;
186    }
187
188    /**
189     * Save an object to the DOM tree. Used to serialize an object
190     * to a DOM tree, usually to send a UDDI message.
191     *
192     * <BR>Used by UDDIProxy.
193     *
194     * @param parent Object will serialize as a child element under the
195     * passed in parent element.
196     */

197    public void saveToXML(Element parent) {
198       base = parent.getOwnerDocument().createElement(UDDI_TAG);
199       // Save attributes.
200
base.setAttribute("generic", UDDIElement.GENERIC);
201       base.setAttribute("xmlns", UDDIElement.XMLNS);
202       if (authInfo!=null) {
203          authInfo.saveToXML(base);
204       }
205       if (businessEntity!=null) {
206         for (int i=0; i < businessEntity.size(); i++) {
207            ((BusinessEntity)(businessEntity.elementAt(i))).saveToXML(base);
208         }
209       }
210       if (uploadRegister!=null) {
211         for (int i=0; i < uploadRegister.size(); i++) {
212            ((UploadRegister)(uploadRegister.elementAt(i))).saveToXML(base);
213         }
214       }
215       parent.appendChild(base);
216    }
217 }
218
Popular Tags