KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > datatype > Name


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  * Copyright (C) 2001, Hewlett-Packard Company
6  * All Rights Reserved.
7  *
8  */

9
10 package org.uddi4j.datatype;
11
12 import org.uddi4j.UDDIElement;
13 import org.uddi4j.UDDIException;
14 import org.w3c.dom.Element JavaDoc;
15
16 /**
17  * Represents the name element within the UDDI version 2.0 schema.
18  * This class contains the following types of methods:
19  *
20  * <ul>
21  * <li>Constructor passing required fields.
22  * <li>Constructor that will instantiate the object from an appropriate
23  * XML DOM element.
24  * <li>Get/set methods for each attribute that this element can contain.
25  * <li>A get/setVector method is provided, for sets of attributes.
26  * <li>SaveToXML method. Serializes this class within a passed in element.
27  * </ul>
28  *
29  * Typically, this class is used to construct parameters for, or interpret
30  * responses from, methods in the UDDIProxy class.
31  *
32  * @author David Melgar (dmelgar@us.ibm.com)
33  * @author Ravi Trivedi (ravi_trivedi@hp.com)
34  */

35 public class Name extends UDDIElement {
36    public static final String JavaDoc UDDI_TAG = "name";
37
38    protected Element base = null;
39
40    String JavaDoc text = null;
41    String JavaDoc lang = null;
42
43    /**
44     * Default constructor.
45     * Avoid using the default constructor for validation. It does not validate
46     * required fields. Instead, use the required fields constructor to perform
47     * validation.
48     */

49    public Name() {
50    }
51
52    /**
53     * Construct the object with required fields.
54     *
55     * @param value String value
56     */

57    public Name(String JavaDoc value) {
58       setText(value);
59    }
60
61    /**
62     * Construct the object with required fields.
63     * @param lang String Language used for the name. Possible values defined
64     * in ISO3166.
65     * @param value String value
66     */

67    public Name(String JavaDoc value, String JavaDoc lang){
68        setText(value);
69        setLang(lang);
70    }
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     * @exception UDDIException Thrown if DOM tree contains a SOAP fault or
80     * disposition report indicating a UDDI error.
81     */

82    public Name(Element base) throws UDDIException {
83       // Checks for a fault. Throws an exception if it is.
84
super(base);
85       text = getText(base);
86       lang = getAttr(base,"xml:lang");
87    }
88
89    private String JavaDoc getAttr(Element base, String JavaDoc attrname)
90    {
91      //XML:LANG is special cased in the serializer of this class
92
// to not write itself if its value is an empty string.
93
//
94
//This allows this function in this class to avoid namespace issues
95
//when checking if the xml:lang attribute is declared.
96

97      //if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() )
98
//{
99
return base.getAttribute(attrname);
100      //}
101
//return null;
102
}
103
104    public void setText(String JavaDoc s) {
105       text = s;
106    }
107
108   /**
109     * Set the language identifier for this string element.
110     * Possible values defined in ISO3166.
111     *
112     * @param s Language string.
113     */

114    public void setLang(String JavaDoc s) {
115       lang = s;
116    }
117
118    public String JavaDoc getText() {
119       return text;
120    }
121
122    public String JavaDoc getLang() {
123          return lang;
124    }
125
126    /**
127     * Save object to DOM tree. Used to serialize object
128     * to a DOM tree, usually to send a UDDI message.
129     *
130     * <BR>Used by UDDIProxy.
131     *
132     * @param parent Object will serialize as a child element under the
133     * passed in parent element.
134     */

135    public void saveToXML(Element parent) {
136       base = parent.getOwnerDocument().createElement(UDDI_TAG);
137       // Save attributes
138
if (text!=null) {
139          base.appendChild(parent.getOwnerDocument().createTextNode(text));
140       }
141       if ((lang !=null) && !(lang.equals("")) ) {
142                base.setAttribute("xml:lang", lang);
143       }
144       parent.appendChild(base);
145    }
146 }
147
Popular Tags