KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > datatype > business > Email


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

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

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

58    public Email(String JavaDoc value) {
59       setText(value);
60    }
61
62    /**
63     * Construct the object from a DOM tree. Used by
64     * UDDIProxy to construct an object from a received UDDI
65     * message.
66     *
67     * @param base Element with the name appropriate for this class.
68     *
69     * @exception UDDIException Thrown if DOM tree contains a SOAP fault
70     * or a disposition report indicating a UDDI error.
71     */

72    public Email(Element base) throws UDDIException {
73       // Check if its a fault. Throw exception if it is
74
super(base);
75       text = getText(base);
76       useType = getAttr(base,"useType");
77    }
78
79    private String JavaDoc getAttr(Element base, String JavaDoc attrname)
80    {
81      if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() )
82      {
83        return base.getAttribute(attrname);
84      }
85      return null;
86    }
87
88    public void setText(String JavaDoc s) {
89       text = s;
90    }
91
92    public void setUseType(String JavaDoc s) {
93       useType = s;
94    }
95
96    public String JavaDoc getText() {
97       return text;
98    }
99
100    public String JavaDoc getUseType() {
101       return useType;
102    }
103
104    /**
105     * Save an object to the DOM tree. Used to serialize an object
106     * to a DOM tree, usually to send a UDDI message.
107     *
108     * <BR>Used by UDDIProxy.
109     *
110     * @param parent Object will serialize as a child element under the
111     * passed in parent element.
112     */

113    public void saveToXML(Element parent) {
114       base = parent.getOwnerDocument().createElement(UDDI_TAG);
115       // Save attributes
116
if (text!=null) {
117          base.appendChild(parent.getOwnerDocument().createTextNode(text));
118       }
119       if (useType!=null) {
120          base.setAttribute("useType", useType);
121       }
122       parent.appendChild(base);
123    }
124 }
125
Popular Tags