KickJava   Java API By Example, From Geeks To Geeks.

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


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.SOAPEnvelope;
22 import org.apache.axis.message.SOAPHeaderElement;
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  * This is the SequenceFault element.
31  *
32  * @author Jaliya Ekanayake
33  */

34 public class SequenceFault extends MessageElement implements IRmElement {
35
36
37     private MessageElement sequenceFault;
38
39     private FaultCode faultCode;
40
41     public SequenceFault() {
42         sequenceFault = new MessageElement();
43         sequenceFault.setName(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.SEQUENCE_FAULT);
44     }
45
46
47     public MessageElement getSoapElement() throws SOAPException JavaDoc {
48
49
50         sequenceFault.addChildElement(faultCode.getSoapElement());
51
52         return sequenceFault;
53     }
54
55
56     public SOAPEnvelope toSoapEnvelop(SOAPEnvelope envelope) throws Exception JavaDoc {
57
58         SOAPEnvelope env = envelope;
59
60         if (env.getHeader() == null) {
61             env.addHeader();
62         }
63
64         Name JavaDoc name = env.createName("", Constants.WSRM.NS_PREFIX_RM,
65                 Constants.WSRM.NS_URI_RM);
66         SOAPHeaderElement headerElement = (SOAPHeaderElement) env.getHeader()
67                 .addHeaderElement(name);
68
69         headerElement.setActor(null);
70         headerElement.setName(Constants.WSRM.SEQUENCE_FAULT);
71         headerElement.setMustUnderstand(true);
72
73         if (faultCode != null) {
74             faultCode.toSOAPEnvelope(headerElement);
75         }
76
77         return env;
78     }
79
80
81     public SequenceFault fromSOAPEnveploe(SOAPHeaderElement headerElement) {
82         Iterator JavaDoc iterator = headerElement.getChildElements();
83         MessageElement childElement;
84
85         while (iterator.hasNext()) {
86             childElement = (MessageElement) iterator.next();
87
88             if (childElement.getName().equals(Constants.WSRM.NS_PREFIX_RM + Constants.COLON + Constants.WSRM.FAULT_CODE)) {
89                 faultCode = new FaultCode();
90                 faultCode.fromSOAPEnvelope(childElement);
91             }
92
93
94         }
95
96         return this;
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see org.apache.sandesha.ws.rm.IRmElement#addChildElement(org.apache.axis.message.MessageElement)
103      */

104
105     /**
106      * Method addChildElement
107      *
108      * @param element
109      * @throws SOAPException
110      */

111     public void addChildElement(MessageElement element) throws SOAPException JavaDoc {
112         sequenceFault.addChildElement(element);
113     }
114
115     public MessageElement getSequenceFault() {
116         return sequenceFault;
117     }
118
119     public void setSequenceFault(MessageElement sequenceFault) {
120         this.sequenceFault = sequenceFault;
121     }
122 }
123
Popular Tags