KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

60     public SaveBinding()
61     {
62     }
63
64     /**
65      * Construct the object with required fields.
66      *
67      * @param authInfo String
68      * @param bindingTemplate Vector of BindingTemplate objects.
69      */

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

118     public void setBindingTemplateVector(Vector JavaDoc s)
119     {
120         bindingTemplate = s;
121     }
122
123     public AuthInfo getAuthInfo()
124     {
125         return authInfo;
126     }
127
128     public String JavaDoc getAuthInfoString()
129     {
130         if (authInfo != null)
131             return authInfo.getText();
132         else
133             return null;
134     }
135
136     /**
137      * Get bindingTemplate vector.
138      *
139      * @return s Vector of <I>BindingTemplate</I> objects.
140      */

141     public Vector JavaDoc getBindingTemplateVector()
142     {
143         return bindingTemplate;
144     }
145
146     /**
147      * Save an object to the DOM tree. Used to serialize an object
148      * to a DOM tree, usually to send a UDDI message.
149      *
150      * <BR>Used by UDDIProxy.
151      *
152      * @param parent Object will serialize as a child element under the
153      * passed in parent element.
154      */

155     public void saveToXML(Element parent)
156     {
157         base = parent.getOwnerDocument().createElement(UDDI_TAG);
158         // Save attributes.
159
base.setAttribute("generic", UDDIElement.GENERIC);
160         base.setAttribute("xmlns", UDDIElement.XMLNS);
161         if (authInfo != null)
162         {
163             authInfo.saveToXML(base);
164         }
165         if (bindingTemplate != null)
166         {
167             for (int i = 0; i < bindingTemplate.size(); i++)
168             {
169                 ((BindingTemplate) (bindingTemplate.elementAt(i))).saveToXML(base);
170             }
171         }
172         parent.appendChild(base);
173     }
174 }
175
Popular Tags