KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > response > AuthToken


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

41 public class AuthToken extends UDDIElement {
42    public static final String JavaDoc UDDI_TAG = "authToken";
43
44    protected Element base = null;
45
46    String JavaDoc operator = null;
47    AuthInfo authInfo = null;
48
49    /**
50     * Default constructor.
51     * Avoid using the default constructor for validation. It does not validate
52     * required fields. Instead, use the required fields constructor to perform
53     * validation.
54     */

55
56    public AuthToken() {
57    }
58
59    /**
60     * Construct the object with required fields.
61     *
62     * @param operator String
63     * @param authInfo String
64     */

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

81
82    public AuthToken(Element base) throws UDDIException {
83       // Check if it is a fault. Throws an exception if it is.
84
super(base);
85       operator = base.getAttribute("operator");
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    }
92
93    public void setOperator(String JavaDoc s) {
94       operator = s;
95    }
96
97    public void setAuthInfo(AuthInfo s) {
98       authInfo = s;
99    }
100    public void setAuthInfo(String JavaDoc s) {
101       authInfo = new AuthInfo();
102       authInfo.setText(s);
103    }
104
105    public String JavaDoc getOperator() {
106       return operator;
107    }
108
109
110    public AuthInfo getAuthInfo() {
111       return authInfo;
112    }
113
114    public String JavaDoc getAuthInfoString() {
115       if(authInfo!=null)
116         return authInfo.getText();
117       else
118         return null;
119    }
120
121    /**
122     * Save an object to the DOM tree. Used to serialize an object
123     * to a DOM tree, usually to send a UDDI message.
124     *
125     * <BR>Used by UDDIProxy.
126     *
127     * @param parent Object will serialize as a child element under the
128     * passed in parent element.
129     */

130
131    public void saveToXML(Element parent) {
132       base = parent.getOwnerDocument().createElement(UDDI_TAG);
133       // Save attributes
134
base.setAttribute("generic", UDDIElement.GENERIC);
135       base.setAttribute("xmlns", UDDIElement.XMLNS);
136       if (operator!=null) {
137          base.setAttribute("operator", operator);
138       }
139       if (authInfo!=null) {
140          authInfo.saveToXML(base);
141       }
142       parent.appendChild(base);
143    }
144 }
145
Popular Tags