KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > datatype > binding > TModelInstanceInfo


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.datatype.binding;
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.w3c.dom.Element JavaDoc;
17 import org.w3c.dom.NodeList JavaDoc;
18
19 /**
20  * Represents the tModelInstanceInfo element within the UDDI version 2.0 schema.
21  * This class contains the following types of methods:
22  *
23  * <ul>
24  * <li>Constructor passing required fields.
25  * <li>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>SaveToXML method. Serializes this class within a passed in element.
30  * </ul>
31  *
32  * Typically, this class is used to construct parameters for, or interpret
33  * responses from methods in the UDDIProxy class.
34  *
35  * <p><b>Element description:</b>
36  * <p>Support element used to contain implementation instance specific information
37  * about compatible specifications (via tModel reference) and optional setting's
38  * details.
39  *
40  * @author David Melgar (dmelgar@us.ibm.com)
41  */

42 public class TModelInstanceInfo extends UDDIElement {
43    public static final String JavaDoc UDDI_TAG = "tModelInstanceInfo";
44
45    protected Element base = null;
46
47    String JavaDoc tModelKey = null;
48    InstanceDetails instanceDetails = null;
49    // Vector of Description objects
50
Vector JavaDoc description = new Vector JavaDoc();
51
52    /**
53     * Default constructor.
54     * Avoid using the default constructor for validation. It does not validate
55     * required fields. Instead, use the required fields constructor to perform
56     * validation.
57     */

58    public TModelInstanceInfo() {
59    }
60
61    /**
62     * Construct the object with required fields.
63     *
64     * @param tModelKey String
65     */

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

80    public TModelInstanceInfo(Element base) throws UDDIException {
81       // Check if it is a fault. Throw exception if it is.
82
super(base);
83       tModelKey = base.getAttribute("tModelKey");
84       NodeList JavaDoc nl = null;
85       nl = getChildElementsByTagName(base, InstanceDetails.UDDI_TAG);
86       if (nl.getLength() > 0) {
87          instanceDetails = new InstanceDetails((Element)nl.item(0));
88       }
89       nl = getChildElementsByTagName(base, Description.UDDI_TAG);
90       for (int i=0; i < nl.getLength(); i++) {
91          description.addElement(new Description((Element)nl.item(i)));
92       }
93    }
94
95    public void setTModelKey(String JavaDoc s) {
96       tModelKey = s;
97    }
98
99    public void setInstanceDetails(InstanceDetails s) {
100       instanceDetails = s;
101    }
102
103    /**
104     * Set description vector.
105     *
106     * @param s Vector of <I>Description</I> objects.
107     */

108    public void setDescriptionVector(Vector JavaDoc s) {
109       description = s;
110    }
111
112    /**
113     * Set default (english) description string.
114     *
115     * @param s String
116     */

117    public void setDefaultDescriptionString(String JavaDoc s) {
118       if (description.size() > 0) {
119          description.setElementAt(new Description(s), 0);
120       } else {
121          description.addElement(new Description(s));
122       }
123    }
124
125    public String JavaDoc getTModelKey() {
126       return tModelKey;
127    }
128
129
130    public InstanceDetails getInstanceDetails() {
131       return instanceDetails;
132    }
133
134
135    /**
136     * Get description.
137     *
138     * @return s Vector of <I>Description</I> objects.
139     */

140    public Vector JavaDoc getDescriptionVector() {
141       return description;
142    }
143
144    /**
145     * Get default description string.
146     *
147     * @return s String
148     */

149    public String JavaDoc getDefaultDescriptionString() {
150       if ((description).size() > 0) {
151          Description t = (Description)description.elementAt(0);
152          return t.getText();
153       } else {
154          return null;
155       }
156    }
157
158    /**
159     * Save an object to the DOM tree. Used to serialize an object
160     * to a DOM tree, usually to send a UDDI message.
161     *
162     * <BR>Used by UDDIProxy.
163     *
164     * @param parent Object will serialize as a child element under the
165     * passed in parent element.
166     */

167    public void saveToXML(Element parent) {
168       base = parent.getOwnerDocument().createElement(UDDI_TAG);
169       // Save attributes
170
if (tModelKey!=null) {
171          base.setAttribute("tModelKey", tModelKey);
172       }
173       if (description!=null) {
174         for (int i=0; i < description.size(); i++) {
175            ((Description)(description.elementAt(i))).saveToXML(base);
176         }
177       }
178       if (instanceDetails!=null) {
179          instanceDetails.saveToXML(base);
180       }
181       parent.appendChild(base);
182    }
183 }
184
Popular Tags