KickJava   Java API By Example, From Geeks To Geeks.

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


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 bindingTemplate element within the UDDI version 2.0 schema.
21  * This class contains the following types of methods:
22  *
23  * <ul>
24  * <li>Constructors for passing required fields.
25  * <li>Constructor that will instantiate the object from an XML DOM element
26  * that is the appropriate element for this object.
27  * <li>Get/set methods for each attribute that this element can contain.
28  * <li>For sets of attributes, a get/setVector method is provided.
29  * <li>SaveToXML method. Serialized 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>Primary Data type: Describes an instance of a web service in technical terms.
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  * @author Ozzy (ozzy@hursley.ibm.com)
40  */

41 public class BindingTemplate extends UDDIElement {
42    public static final String JavaDoc UDDI_TAG = "bindingTemplate";
43
44    protected Element base = null;
45
46    String JavaDoc bindingKey = null;
47    String JavaDoc serviceKey = null;
48    AccessPoint accessPoint = null;
49    HostingRedirector hostingRedirector = null;
50    TModelInstanceDetails tModelInstanceDetails = null;
51    // Vector of Description objects
52
Vector JavaDoc description = new Vector JavaDoc();
53
54    /**
55     * Default constructor.
56     * Use of this constructor should be avoided. Use the required fields
57     * constructor to provide validation. No validation of required
58     * fields is performed when using the default constructor.
59     *
60     */

61    public BindingTemplate() {
62    }
63
64    /**
65     * Construct the object with required fields.
66     *
67     * @param bindingKey String
68     * @param tModelInstanceDetails TModelInstanceDetails object
69     * @deprecated This method has been deprecated. Use
70     * {@link #BindingTemplate(String, TModelInstanceDetails, AccessPoint)} or
71     * {@link #BindingTemplate(String, TModelInstanceDetails, HostingRedirector)} instead.
72     */

73    public BindingTemplate(String JavaDoc bindingKey,
74       TModelInstanceDetails tModelInstanceDetails) {
75       this.bindingKey = bindingKey;
76       this.tModelInstanceDetails = tModelInstanceDetails;
77    }
78
79    /**
80     * Construct the object with required fields.
81     *
82     * @param bindingKey String
83     * @param tModelInstanceDetails TModelInstanceDetails object
84     * @param accessPoint AccessPoint object
85     */

86    public BindingTemplate(String JavaDoc bindingKey,
87       TModelInstanceDetails tModelInstanceDetails,
88       AccessPoint accessPoint) {
89       this.bindingKey = bindingKey;
90       this.tModelInstanceDetails = tModelInstanceDetails;
91       this.accessPoint = accessPoint;
92    }
93
94    /**
95     * Construct the object with required fields.
96     *
97     * @param bindingKey String
98     * @param tModelInstanceDetails TModelInstanceDetails object
99     * @param hostingRedirector Hosting Redirector object
100     */

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

119    public BindingTemplate(Element base) throws UDDIException {
120       // Checks if it is a fault. Throw exception if it is a fault.
121
super(base);
122       bindingKey = base.getAttribute("bindingKey");
123       serviceKey = getAttr(base,"serviceKey");
124       NodeList JavaDoc nl = null;
125       nl = getChildElementsByTagName(base, AccessPoint.UDDI_TAG);
126       if (nl.getLength() > 0) {
127          accessPoint = new AccessPoint((Element)nl.item(0));
128       }
129       nl = getChildElementsByTagName(base, HostingRedirector.UDDI_TAG);
130       if (nl.getLength() > 0) {
131          hostingRedirector = new HostingRedirector((Element)nl.item(0));
132       }
133       nl = getChildElementsByTagName(base, TModelInstanceDetails.UDDI_TAG);
134       if (nl.getLength() > 0) {
135          tModelInstanceDetails = new TModelInstanceDetails((Element)nl.item(0));
136       }
137       nl = getChildElementsByTagName(base, Description.UDDI_TAG);
138       for (int i=0; i < nl.getLength(); i++) {
139          description.addElement(new Description((Element)nl.item(i)));
140       }
141    }
142
143    private String JavaDoc getAttr(Element base, String JavaDoc attrname)
144    {
145      if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() )
146      {
147        return base.getAttribute(attrname);
148      }
149      return null;
150    }
151
152    public void setBindingKey(String JavaDoc s) {
153       bindingKey = s;
154    }
155
156    public void setServiceKey(String JavaDoc s) {
157       serviceKey = s;
158    }
159
160    public void setAccessPoint(AccessPoint s) {
161       accessPoint = s;
162       // if user has just set a real access point, then wipe the hostingRedirector
163
if( accessPoint != null && hostingRedirector != null )
164         hostingRedirector = null;
165    }
166
167    public void setHostingRedirector(HostingRedirector s) {
168       hostingRedirector = s;
169       // if user has just set a real hostingRedirector, then wipe the accessPoint
170
if( hostingRedirector != null && accessPoint != null )
171         accessPoint = null;
172    }
173
174    public void setTModelInstanceDetails(TModelInstanceDetails s) {
175       tModelInstanceDetails = s;
176    }
177
178    /**
179     * Set description vector.
180     *
181     * @param s Vector of <I>Description</I> objects.
182     */

183    public void setDescriptionVector(Vector JavaDoc s) {
184       description = s;
185    }
186
187    /**
188     * Set default (english) description string.
189     *
190     * @param s String
191     */

192    public void setDefaultDescriptionString(String JavaDoc s) {
193       if (description.size() > 0) {
194          description.setElementAt(new Description(s), 0);
195       } else {
196          description.addElement(new Description(s));
197       }
198    }
199
200    public String JavaDoc getBindingKey() {
201       return bindingKey;
202    }
203
204
205    public String JavaDoc getServiceKey() {
206       return serviceKey;
207    }
208
209
210    public AccessPoint getAccessPoint() {
211       return accessPoint;
212    }
213
214
215    public HostingRedirector getHostingRedirector() {
216       return hostingRedirector;
217    }
218
219
220    public TModelInstanceDetails getTModelInstanceDetails() {
221       return tModelInstanceDetails;
222    }
223
224
225    /**
226     * Get description.
227     *
228     * @return s Vector of <I>Description</I> objects.
229     */

230    public Vector JavaDoc getDescriptionVector() {
231       return description;
232    }
233
234    /**
235     * Get default description string.
236     *
237     * @return s String
238     */

239    public String JavaDoc getDefaultDescriptionString() {
240       if ((description).size() > 0) {
241          Description t = (Description)description.elementAt(0);
242          return t.getText();
243       } else {
244          return null;
245       }
246    }
247
248    /**
249     * Save object to DOM tree. Used to serialize object
250     * to a DOM tree, usually to send a UDDI message.
251     *
252     * <BR>Used by UDDIProxy.
253     *
254     * @param parent Object will serialize as a child element under the
255     * passed in parent element.
256     */

257    public void saveToXML(Element parent) {
258       base = parent.getOwnerDocument().createElement(UDDI_TAG);
259       // Save attributes
260
if (bindingKey!=null) {
261          base.setAttribute("bindingKey", bindingKey);
262       }
263       if (serviceKey!=null) {
264          base.setAttribute("serviceKey", serviceKey);
265       }
266       if (description!=null) {
267         for (int i=0; i < description.size(); i++) {
268            ((Description)(description.elementAt(i))).saveToXML(base);
269         }
270       }
271       if (accessPoint!=null) {
272          accessPoint.saveToXML(base);
273       }
274       if (hostingRedirector!=null) {
275          hostingRedirector.saveToXML(base);
276       }
277       if (tModelInstanceDetails!=null) {
278          tModelInstanceDetails.saveToXML(base);
279       }
280       parent.appendChild(base);
281    }
282 }
283
Popular Tags