KickJava   Java API By Example, From Geeks To Geeks.

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


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.business;
11
12 import java.util.Vector JavaDoc;
13
14 import org.uddi4j.UDDIElement;
15 import org.uddi4j.UDDIException;
16 import org.w3c.dom.Element JavaDoc;
17 import org.w3c.dom.NodeList JavaDoc;
18
19 /**
20  * Represents the address element within the UDDI version 2.0 schema.
21  * This class contains the following types of methods:
22  *
23  * <ul>
24  * <li>Constructor passing required fields.
25  * <li>Constructor that will instantiate the object from an appropriate XML
26  * DOM element.
27  * <li>Get/set methods for each attribute that this element can contain.
28  * <li>A get/setVector method is provided for sets of attributes.
29  * <li>SaveToXML method. Serializes 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>Data: a printable, free form address. Typed by convention. Sort not used.
37  *
38  * @author David Melgar (dmelgar@us.ibm.com)
39  * @author Ravi Trivedi (ravi_trivedi@hp.com)
40  */

41
42 public class Address extends UDDIElement
43 {
44     public static final String JavaDoc UDDI_TAG = "address";
45
46     protected Element base = null;
47
48     String JavaDoc useType = null;
49     String JavaDoc sortCode = null;
50     String JavaDoc tModelKey = null;
51     // Vector of AddressLine objects
52
Vector JavaDoc addressLine = 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 Address()
61     {
62     }
63
64     /**
65      * Construct the object from a DOM tree. Used by
66      * UDDIProxy to construct an object from a received UDDI
67      * message.
68      *
69      * @param base Element with the name appropriate for this class.
70      *
71      * @exception UDDIException Thrown if DOM tree contains a SOAP fault
72      * or a disposition report indicating a UDDI error.
73      */

74
75     public Address(Element base) throws UDDIException
76     {
77         // Check if its a fault. Throw exception if it is
78
super(base);
79       useType = getAttr(base,"useType");
80       sortCode = getAttr(base,"sortCode");
81       tModelKey = getAttr(base,"tModelKey");
82         NodeList JavaDoc nl = null;
83         nl = getChildElementsByTagName(base, AddressLine.UDDI_TAG);
84         for (int i = 0; i < nl.getLength(); i++)
85         {
86             addressLine.addElement(new AddressLine((Element) nl.item(i)));
87         }
88     }
89
90    private String JavaDoc getAttr(Element base, String JavaDoc attrname)
91    {
92      if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() )
93      {
94        return base.getAttribute(attrname);
95      }
96      return null;
97    }
98
99     public void setUseType(String JavaDoc s)
100     {
101         useType = s;
102     }
103
104     public void setSortCode(String JavaDoc s)
105     {
106         sortCode = s;
107     }
108
109     /**
110      * Set addressLine vector
111      *
112      * @param s Vector of <I>AddressLine</I> objects.
113      */

114     public void setAddressLineVector(Vector JavaDoc s)
115     {
116         addressLine = s;
117     }
118
119     /**
120      * Set addressLine
121      *
122      * @param s Vector of <I>String</I> objects.
123      */

124     public void setAddressLineStrings(Vector JavaDoc s)
125     {
126         addressLine = new Vector JavaDoc();
127         for (int i = 0; i < s.size(); i++)
128         {
129             addressLine.addElement(new AddressLine((String JavaDoc) s.elementAt(i)));
130         }
131     }
132
133     public void setTModelKey(String JavaDoc key)
134     {
135         tModelKey = key;
136     }
137
138     public String JavaDoc getUseType()
139     {
140         return useType;
141     }
142
143     public String JavaDoc getSortCode()
144     {
145         return sortCode;
146     }
147
148     /**
149      * Get addressLine
150      *
151      * @return s Vector of <I>AddressLine</I> objects.
152      */

153     public Vector JavaDoc getAddressLineVector()
154     {
155         return addressLine;
156     }
157
158     /**
159      * Get addressLine
160      *
161      * @return s Vector of <I>String</I> objects.
162      */

163     public Vector JavaDoc getAddressLineStrings()
164     {
165         Vector JavaDoc strings = new Vector JavaDoc();
166         for (int i = 0; i < addressLine.size(); i++)
167         {
168             strings.addElement(((AddressLine) addressLine.elementAt(i)).getText());
169         }
170         return strings;
171     }
172
173     public String JavaDoc getTModelKey()
174     {
175         return tModelKey;
176     }
177
178     /**
179      * Save an object to the DOM tree. Used to serialize an object
180      * to a DOM tree, usually to send a UDDI message.
181      *
182      * <BR>Used by UDDIProxy.
183      *
184      * @param parent Object will serialize as a child element under the
185      * passed in parent element.
186      */

187     public void saveToXML(Element parent)
188     {
189         base = parent.getOwnerDocument().createElement(UDDI_TAG);
190         // Save attributes
191
if (useType != null)
192         {
193             base.setAttribute("useType", useType);
194         }
195         if (sortCode != null)
196         {
197             base.setAttribute("sortCode", sortCode);
198         }
199         if (tModelKey != null)
200         {
201             base.setAttribute("tModelKey", tModelKey);
202         }
203         if (addressLine != null)
204         {
205             for (int i = 0; i < addressLine.size(); i++)
206             {
207                 ((AddressLine) (addressLine.elementAt(i))).saveToXML(base);
208             }
209         }
210         parent.appendChild(base);
211     }
212 }
213
Popular Tags