KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > ws > rm > Identifier


1 package org.apache.sandesha.ws.rm;
2
3
4 import org.apache.axis.message.MessageElement;
5 import org.apache.axis.types.URI;
6 import org.apache.sandesha.Constants;
7
8 import javax.xml.soap.SOAPException JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 /**
12  * class Identifier
13  *
14  * @author Amila Navarathna
15  * @author Jaliya Ekanayaka
16  * @author Sudar Nimalan
17  */

18 public class Identifier extends URI {
19
20     /**
21      * Field identifierElement
22      */

23     private MessageElement identifierElement;
24
25     /**
26      * Field identifier
27      */

28     private String JavaDoc identifier = null;
29
30     /**
31      * Constructor Identifier
32      */

33     public Identifier() {
34         identifierElement = new MessageElement();
35         identifierElement.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.IDENTIFIER);
36     }
37
38     /**
39      * Method setUri
40      *
41      * @param uri
42      * @throws SOAPException
43      */

44     public void setUri(String JavaDoc uri) throws SOAPException JavaDoc {
45         identifierElement.addTextNode(uri);
46     }
47
48     /**
49      * Method fromSOAPEnvelope
50      *
51      * @param element
52      * @return
53      */

54     public Identifier fromSOAPEnvelope(MessageElement element) {
55
56         identifier = element.getValue();
57         return this;
58     }
59
60     /**
61      * Method toSOAPEnvelope
62      *
63      * @param msgElement
64      * @return @throws
65      * SOAPException
66      */

67     public MessageElement toSOAPEnvelope(MessageElement msgElement) throws SOAPException JavaDoc {
68         removeIdentifierElementIfAny(msgElement);
69         msgElement.addChildElement(Constants.WSRM.IDENTIFIER, Constants.WSRM.NS_PREFIX_RM)
70                 .addTextNode(identifier);
71         return msgElement;
72     }
73
74     /**
75      * Method getSoapElement
76      *
77      * @return @throws
78      * SOAPException
79      */

80     public MessageElement getSoapElement() throws SOAPException JavaDoc {
81
82         // create the soap element for the message no
83
identifierElement.addTextNode(identifier);
84
85         return identifierElement;
86     }
87
88     /**
89      * Method getIdentifier
90      *
91      * @return String
92      */

93     public String JavaDoc getIdentifier() {
94         return identifier;
95     }
96
97     /**
98      * Method setIdentifier
99      */

100     public void setIdentifier(String JavaDoc string) {
101         identifier = string;
102     }
103
104     /**
105      * Method equals
106      *
107      * @param obj
108      * @return boolean
109      */

110     public boolean equals(Object JavaDoc obj) {
111
112         if (obj instanceof org.apache.sandesha.ws.rm.Identifier) {
113             if (this.identifier ==
114                     ((String JavaDoc) (((org.apache.sandesha.ws.rm.Identifier) obj).getIdentifier()))) {
115                 return true;
116             } else {
117                 return false;
118             }
119         } else {
120             return false;
121         }
122     }
123
124     /**
125      * Method hashCode
126      *
127      * @return int
128      */

129     public int hashCode() {
130         return identifier.hashCode();
131     }
132
133     /**
134      * Method toString
135      *
136      * @return String
137      */

138     public String JavaDoc toString() {
139         return identifier;
140     }
141
142     private void removeIdentifierElementIfAny(MessageElement msgElement) {
143
144         Iterator JavaDoc ite = msgElement.getChildElements();
145         while (ite.hasNext()) {
146             MessageElement childElement = (MessageElement) ite.next();
147             if (Constants.WSRM.IDENTIFIER.equals(childElement.getName()) &&
148                     (Constants.WSRM.NS_URI_RM.equals(childElement.getNamespaceURI()))) {
149                 childElement.detachNode();
150             }
151         }
152     }
153 }
Popular Tags