KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.sandesha.ws.rm;
19
20 import org.apache.axis.message.MessageElement;
21 import org.apache.axis.message.SOAPBodyElement;
22 import org.apache.axis.message.SOAPEnvelope;
23 import org.apache.sandesha.Constants;
24
25 import javax.xml.soap.Name JavaDoc;
26 import javax.xml.soap.SOAPException JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 /**
30  * class TerminateSequence
31  *
32  * @author Amila Navarathna
33  * @author Jaliya Ekanayaka
34  * @author Sudar Nimalan
35  */

36 public class TerminateSequence implements IRmElement {
37
38     /**
39      * Field terminateSequence
40      */

41     private MessageElement terminateSequence;
42
43     /**
44      * Field identifier
45      */

46     private Identifier identifier;
47
48     /**
49      * Constructor TerminateSequence
50      */

51     public TerminateSequence() {
52         terminateSequence = new MessageElement();
53         terminateSequence.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.TERMINATE_DEQUENCE);
54     }
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.apache.sandesha.ws.rm.IRmElement#getSoapElement()
60      */

61
62     /**
63      * Method getSoapElement
64      *
65      * @return MessageElement
66      * @throws SOAPException
67      */

68     public MessageElement getSoapElement() throws SOAPException JavaDoc {
69
70         terminateSequence.addChildElement(identifier.getSoapElement());
71
72         return terminateSequence;
73     }
74
75     /**
76      * Method toSoapEnvelop
77      *
78      * @param envelope
79      * @return SOAPEnvelope
80      * @throws SOAPException
81      */

82     public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws SOAPException JavaDoc {
83
84         SOAPEnvelope env = envelope;
85
86         if (env.getBody() == null) {
87             env.addBody();
88         }
89
90         Name JavaDoc name = env.createName("", Constants.WSRM.NS_PREFIX_RM, Constants.WSRM.NS_URI_RM);
91         SOAPBodyElement bodyElement = (SOAPBodyElement) env.getBody().addBodyElement(name);
92
93         bodyElement.setName(Constants.WSRM.TERMINATE_DEQUENCE);
94
95         if (identifier != null) {
96             identifier.toSOAPEnvelope(bodyElement);
97         }
98
99         return env;
100     }
101
102     /**
103      * Method fromSOAPEnveploe
104      *
105      * @param bodyElement
106      * @return TerminateSequence
107      */

108     public TerminateSequence fromSOAPEnveploe(SOAPBodyElement bodyElement) {
109
110         Iterator JavaDoc iterator = bodyElement.getChildElements();
111         MessageElement childElement;
112
113         while (iterator.hasNext()) {
114
115             childElement = (MessageElement) iterator.next();
116
117             if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.IDENTIFIER)) {
118                 identifier = new Identifier();
119
120                 identifier.fromSOAPEnvelope(childElement);
121             }
122
123             if (childElement.getName().equals(Constants.WSRM.IDENTIFIER)) {
124                 identifier = new Identifier();
125
126                 identifier.fromSOAPEnvelope(childElement);
127             }
128         }
129
130         return this;
131     }
132
133     /**
134      * Method addChildElement
135      *
136      * @param element
137      * @throws SOAPException
138      */

139     public void addChildElement(MessageElement element) throws SOAPException JavaDoc {
140
141         terminateSequence.addChildElement(element);
142
143     }
144
145     /**
146      * Method getIdentifier
147      *
148      * @return Identifier
149      */

150     public Identifier getIdentifier() {
151         return identifier;
152     }
153
154     /**
155      * Method setIdentifier
156      *
157      * @param identifier
158      */

159     public void setIdentifier(Identifier identifier) {
160         this.identifier = identifier;
161     }
162 }
Popular Tags