KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > util > KeyedReference


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.util;
10
11 import org.uddi4j.UDDIElement;
12 import org.uddi4j.UDDIException;
13 import org.w3c.dom.Element JavaDoc;
14
15 /**
16  * Represents the keyedReference element within the UDDI version 2.0 schema.
17  * This class contains the following types of methods:
18  *
19  * <ul>
20  * <li>A constructor that passes the required fields.
21  * <li>A 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>A SaveToXML method that serializes this class within a passed in
26  * 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  * <p><b>Element description:</b>
33  * <p>Service element. Represents a namespace qualified name-value
34  * pair. Depending upon the context in which it is used, this structure can be
35  * utilized within different convention frameworks.
36  *
37  * @author David Melgar (dmelgar@us.ibm.com)
38  */

39 public class KeyedReference extends UDDIElement
40 {
41     public static final String JavaDoc UDDI_TAG = "keyedReference";
42
43     protected Element base = null;
44
45     String JavaDoc tModelKey = null;
46     String JavaDoc keyName = null;
47     String JavaDoc keyValue = 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     public KeyedReference() {
56     }
57
58     /**
59      * Construct the object with required fields.
60      *
61      * @param keyName String
62      * @param keyValue String
63      */

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

85     public KeyedReference(Element base) throws UDDIException {
86         // Check if it is a fault. Throws an exception if it is.
87
super(base);
88         tModelKey = base.getAttribute("tModelKey");
89       keyName = getAttr(base,"keyName");
90       keyValue = getAttr(base,"keyValue");
91     }
92
93    private String JavaDoc getAttr(Element base, String JavaDoc attrname)
94    {
95      if(base.getAttributeNode(attrname)!=null && base.getAttributeNode(attrname).getSpecified() )
96      {
97        return base.getAttribute(attrname);
98      }
99      return null;
100    }
101
102     public void setTModelKey(String JavaDoc s) {
103         tModelKey = s;
104     }
105
106     public void setKeyName(String JavaDoc s) {
107         keyName = s;
108     }
109
110     public void setKeyValue(String JavaDoc s) {
111         keyValue = s;
112     }
113
114     public String JavaDoc getTModelKey() {
115         return tModelKey;
116     }
117
118
119     public String JavaDoc getKeyName() {
120         return keyName;
121     }
122
123
124     public String JavaDoc getKeyValue() {
125         return keyValue;
126     }
127
128
129     /**
130      * Save an object to the DOM tree. Used to serialize an object
131      * to a DOM tree, usually to send a UDDI message.
132      *
133      * <BR>Used by UDDIProxy.
134      *
135      * @param parent Object will serialize as a child element under the
136      * passed in parent element.
137      */

138     public void saveToXML(Element parent) {
139         base = parent.getOwnerDocument().createElement(UDDI_TAG);
140         // Save attributes.
141
if (tModelKey!=null)
142         {
143             base.setAttribute("tModelKey", tModelKey);
144         }
145         if (keyName!=null)
146         {
147             base.setAttribute("keyName", keyName);
148         }
149         if (keyValue!=null)
150         {
151             base.setAttribute("keyValue", keyValue);
152         }
153         parent.appendChild(base);
154     }
155
156     //KJ ADDED FOR JAXR
157
public boolean equals(Object JavaDoc obj)
158     {
159         boolean result = false;
160         if (obj != null && obj instanceof KeyedReference)
161         {
162             KeyedReference otherKeyedReference = (KeyedReference)obj;
163             if ((tModelKey == null && otherKeyedReference.tModelKey == null) ||
164                 (tModelKey != null && tModelKey.equalsIgnoreCase(otherKeyedReference.tModelKey)))
165             {
166                 if ((keyName == null && otherKeyedReference.keyName == null) ||
167                     (keyName != null && keyName.equals(otherKeyedReference.keyName)))
168                 {
169                     if ((keyValue == null && otherKeyedReference.keyValue == null) ||
170                         (keyValue != null && keyValue.equals(otherKeyedReference.keyValue)))
171                     {
172                         result = true;
173                     }
174                 }
175             }
176         }
177         return result;
178     }
179
180 }
181
Popular Tags