KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > symbolTable > FaultInfo


1 /*
2  * Copyright 2001-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 package org.apache.axis.wsdl.symbolTable;
17
18 import org.apache.axis.constants.Use;
19 import org.apache.axis.utils.Messages;
20
21 import javax.wsdl.Fault;
22 import javax.wsdl.Message;
23 import javax.wsdl.Part;
24 import javax.wsdl.extensions.soap.SOAPHeaderFault;
25 import javax.xml.namespace.QName JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * Fault information object. This should probably really be FaultEntry and
31  * it should be a subclass of SymTabEntry, but faults aren't first-class
32  * objects in WSDL, so I'm not sure what the FaultEntry should contain and
33  * how it should be constructed, so for now leave it as a simple object.
34  */

35 public class FaultInfo {
36
37     /** Field message */
38     private Message message;
39
40     /** Field xmlType */
41     private QName JavaDoc xmlType;
42
43     /** Field use */
44     private Use use;
45
46     /** Field qName */
47     private QName JavaDoc qName;
48
49     /** Field name */
50     private String JavaDoc name;
51
52     /**
53      * This constructor creates FaultInfo for a binding fault.
54      * <p/>
55      * If the part of the fault is a type, then the QName is
56      * derived from the element name and the provided namespace
57      * (this namespace SHOULD come from the binding).
58      * <p/>
59      * If the part of the fault is an element, then the QName is
60      * the QName of the element, and the given namespace is ignored.
61      *
62      * @param fault
63      * @param use
64      * @param namespace
65      * @param symbolTable
66      */

67     public FaultInfo(Fault fault, Use use, String JavaDoc namespace,
68                      SymbolTable symbolTable) {
69
70         this.message = fault.getMessage();
71         this.xmlType = getFaultType(symbolTable, getFaultPart());
72         this.use = (use != null) ? use : Use.LITERAL;
73         this.name = fault.getName();
74
75         Part part = getFaultPart();
76
77         if (part == null) {
78             this.qName = null;
79         } else if (part.getTypeName() != null) {
80             this.qName = new QName JavaDoc(namespace, part.getName());
81         } else {
82             this.qName = part.getElementName();
83         }
84     } // ctor
85

86     /**
87      * This constructor creates FaultInfo for a soap:headerFault.
88      *
89      * @param fault
90      * @param symbolTable
91      * @throws IOException
92      */

93     public FaultInfo(SOAPHeaderFault fault, SymbolTable symbolTable)
94             throws IOException JavaDoc {
95
96         MessageEntry mEntry = symbolTable.getMessageEntry(fault.getMessage());
97
98         if (mEntry == null) {
99             throw new IOException JavaDoc(
100                     Messages.getMessage("noMsg", fault.getMessage().toString()));
101         }
102
103         this.message = mEntry.getMessage();
104
105         Part part = message.getPart(fault.getPart());
106
107         this.xmlType = getFaultType(symbolTable, part);
108         this.use = Use.getUse(fault.getUse());
109
110         if (part == null) {
111             this.qName = null;
112         } else if (part.getTypeName() != null) {
113             this.qName = new QName JavaDoc(fault.getNamespaceURI(), part.getName());
114         } else {
115             this.qName = part.getElementName();
116         }
117
118         this.name = qName.getLocalPart();
119     } // ctor
120

121     /**
122      * Constructor FaultInfo
123      *
124      * @param faultMessage
125      * @param faultPart
126      * @param faultUse
127      * @param faultNamespaceURI
128      * @param symbolTable
129      * @throws IOException
130      */

131     public FaultInfo(
132             QName JavaDoc faultMessage, String JavaDoc faultPart, String JavaDoc faultUse, String JavaDoc faultNamespaceURI, SymbolTable symbolTable)
133             throws IOException JavaDoc {
134
135         MessageEntry mEntry = symbolTable.getMessageEntry(faultMessage);
136
137         if (mEntry == null) {
138             throw new IOException JavaDoc(Messages.getMessage("noMsg",
139                     faultMessage.toString()));
140         }
141
142         this.message = mEntry.getMessage();
143
144         Part part = message.getPart(faultPart);
145
146         this.xmlType = getFaultType(symbolTable, part);
147         this.use = Use.getUse(faultUse);
148
149         if (part == null) {
150             this.qName = null;
151         } else if (part.getTypeName() != null) {
152             this.qName = new QName JavaDoc(faultNamespaceURI, part.getName());
153         } else {
154             this.qName = part.getElementName();
155         }
156
157         this.name = qName.getLocalPart();
158     } // ctor
159

160     /**
161      * Method getMessage
162      *
163      * @return
164      */

165     public Message getMessage() {
166         return message;
167     } // getMessage
168

169     /**
170      * Method getXMLType
171      *
172      * @return
173      */

174     public QName JavaDoc getXMLType() {
175         return xmlType;
176     } // getXMLType
177

178     /**
179      * Method getUse
180      *
181      * @return
182      */

183     public Use getUse() {
184         return use;
185     } // getUse
186

187     /**
188      * Return the QName of a fault. This method may return null if no parts
189      * are in the fault message.
190      * <p/>
191      * If the part of the fault is a type, then the QName is
192      * derived from the element name and the provided namespace
193      * (this namespace SHOULD come from the binding).
194      * <p/>
195      * If the part of the fault is an element, then the QName is
196      * the QName of the element, and the given namespace is ignored.
197      *
198      * @return
199      */

200     public QName JavaDoc getQName() {
201         return qName;
202     } // getQName
203

204     /**
205      * Return the name of the fault.
206      * This is the name= attribute from a portType fault
207      * or the localname of a header fault.
208      *
209      * @return
210      */

211     public String JavaDoc getName() {
212         return name;
213     } // getName
214

215     /**
216      * It is assumed at this point that the fault message has only
217      * 0 or 1 parts. If 0, return null. If 1, return it.
218      *
219      * @return
220      */

221     private Part getFaultPart() {
222
223         // get the name of the part
224
Map JavaDoc parts = message.getParts();
225
226         // If no parts, skip it
227
if (parts.size() == 0) {
228             return null;
229         } else {
230             return (Part) parts.values().iterator().next();
231         }
232     }
233
234     /**
235      * Get the XML type (QName) for a Fault - look in the (single) fault
236      * part for type="" or element="" - if type, return the QName. If
237      * element, return the reference type for the element.
238      *
239      * @param part the Fault to dig into
240      * @param st the SymbolTable we're using
241      * @return the XML type of the Fault's part, or null
242      */

243     private QName JavaDoc getFaultType(SymbolTable st, Part part) {
244
245         if (part != null) {
246             if (part.getTypeName() != null) {
247                 return part.getTypeName();
248             }
249
250             // Literal, so get the element's type
251
TypeEntry entry = st.getElement(part.getElementName());
252
253             if ((entry != null) && (entry.getRefType() != null)) {
254                 return entry.getRefType().getQName();
255             }
256         }
257
258         return null;
259     }
260 }
261
Popular Tags