View Javadoc

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.sandesha.Constants;
22  
23  import javax.xml.soap.SOAPException;
24  import java.util.Iterator;
25  
26  /***
27   * class LastMessage
28   *
29   * @author Amila Navarathna
30   * @author Jaliya Ekanayaka
31   * @author Sudar Nimalan
32   */
33  public class Accept extends MessageElement implements IRmElement {
34  
35      /***
36       * Field lastMsgElement
37       */
38      private MessageElement acceptElement;
39  
40      private AcksTo acksTo;
41  
42      /***
43       * Constructor LastMessage
44       */
45      public Accept() {
46          acceptElement = new MessageElement();
47          acceptElement.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.ACCEPT);
48      }
49  
50      /*
51       * (non-Javadoc)
52       *
53       * @see org.apache.sandesha.ws.rm.IRmElement#getSoapElement()
54       */
55  
56      /***
57       * Method getSoapElement
58       *
59       * @return MessageElement
60       */
61      public MessageElement getSoapElement() throws SOAPException {
62          acceptElement.addChildElement(acksTo.getSoapElement());
63          return acceptElement;
64      }
65  
66      public Accept fromSOAPEnvelope(MessageElement bodyElement) throws SOAPException {
67  
68          Iterator iterator = bodyElement.getChildElements();
69          MessageElement childElement;
70  
71          while (iterator.hasNext()) {
72              childElement = (MessageElement) iterator.next();
73  
74              if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.ACKS_TO)) {
75                  acksTo = new AcksTo();
76                  acksTo.fromSOAPEnvelope(childElement);
77              }
78  
79              if (childElement.getName().equals(Constants.WSRM.ACKS_TO)) {
80                  acksTo = new AcksTo();
81                  acksTo.fromSOAPEnvelope(childElement);
82              }
83  
84          }
85  
86          return this;
87      }
88  
89      /***
90       * Method toSOAPEnvelope
91       *
92       * @param msgElement
93       * @return MessageElement
94       * @throws SOAPException
95       */
96      public MessageElement toSOAPEnvelope(MessageElement msgElement) throws SOAPException {
97          MessageElement messageElement = new MessageElement("", Constants.WSRM.NS_PREFIX_RM, Constants.WSRM.NS_URI_RM);
98          messageElement.setName(Constants.WSRM.ACCEPT);
99          acksTo.toSOAPEnvelope(messageElement);
100         msgElement.addChildElement(messageElement);
101         return msgElement;
102     }
103 
104 
105     public void addChildElement(MessageElement element) {
106 
107     }
108 
109     /***
110      * Method getLastMsgElement
111      *
112      * @return MessageElement
113      */
114     public MessageElement getAcceptElement() {
115         return acceptElement;
116     }
117 
118     /***
119      * Method setLastMsgElement
120      *
121      * @param element
122      */
123     public void setAcceptElement(MessageElement element) {
124         acceptElement = element;
125     }
126 
127     public void setAcksTo(AcksTo acksTo) {
128         this.acksTo = acksTo;
129     }
130 
131     public AcksTo getAcksTo() {
132         return this.acksTo;
133     }
134 
135 
136 }