KickJava   Java API By Example, From Geeks To Geeks.

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


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.tmodel.TModel;
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_tModel 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 register or update a tModel. Either a tModel or
40  * uploadRegister object is required. Invalid if contains both types or neither type.
41  *
42  * @author David Melgar (dmelgar@us.ibm.com)
43  */

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

61    public SaveTModel() {
62    }
63
64    /**
65     * Construct the object with required fields.
66     *
67     * @param authInfo String
68     */

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

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

114    public void setTModelVector(Vector JavaDoc s) {
115       tModel = s;
116    }
117
118    /**
119     * Set uploadRegister vector.
120     *
121     * @param s Vector of <I>UploadRegister</I> objects.
122     */

123    public void setUploadRegisterVector(Vector JavaDoc s) {
124       uploadRegister = s;
125    }
126
127    /**
128     * Set uploadRegister.
129     *
130     * @param s Vector of <I>String</I> objects.
131     */

132    public void setUploadRegisterStrings(Vector JavaDoc s) {
133       uploadRegister = new Vector JavaDoc();
134       for (int i = 0; i < s.size(); i++) {
135          uploadRegister.addElement( new UploadRegister((String JavaDoc)s.elementAt(i)) );
136       }
137    }
138
139    public AuthInfo getAuthInfo() {
140       return authInfo;
141    }
142
143    public String JavaDoc getAuthInfoString() {
144       return authInfo.getText();
145    }
146
147    /**
148     * Get tModel vector.
149     *
150     * @return s Vector of <I>TModel</I> objects.
151     */

152    public Vector JavaDoc getTModelVector() {
153       return tModel;
154    }
155
156    /**
157     * Get uploadRegister vector.
158     *
159     * @return s Vector of <I>UploadRegister</I> objects.
160     */

161    public Vector JavaDoc getUploadRegisterVector() {
162       return uploadRegister;
163    }
164
165    /**
166     * Get uploadRegister.
167     *
168     * @return s Vector of <I>String</I> objects.
169     */

170    public Vector JavaDoc getUploadRegisterStrings() {
171       Vector JavaDoc strings = new Vector JavaDoc();
172       for (int i = 0; i < uploadRegister.size(); i++) {
173          strings.addElement( ((UploadRegister)uploadRegister.elementAt(i)).getText());
174       }
175       return strings;
176    }
177
178    /**
179     * Save an object to the DOM tree. Used to serialize an object
180     * to a DOM tree, usually to send a UDDI message.
181     *
182     * <BR>Used by UDDIProxy.
183     *
184     * @param parent Object will serialize as a child element under the
185     * passed in parent element.
186     */

187    public void saveToXML(Element parent) {
188       base = parent.getOwnerDocument().createElement(UDDI_TAG);
189       // Save attributes
190
base.setAttribute("generic", UDDIElement.GENERIC);
191       base.setAttribute("xmlns", UDDIElement.XMLNS);
192       if (authInfo!=null) {
193          authInfo.saveToXML(base);
194       }
195       if (tModel!=null) {
196         for (int i=0; i < tModel.size(); i++) {
197            ((TModel)(tModel.elementAt(i))).saveToXML(base);
198         }
199       }
200       if (uploadRegister!=null) {
201         for (int i=0; i < uploadRegister.size(); i++) {
202            ((UploadRegister)(uploadRegister.elementAt(i))).saveToXML(base);
203         }
204       }
205       parent.appendChild(base);
206    }
207 }
208
Popular Tags