KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.wsdl.symbolTable;
56
57 import org.jboss.axis.enums.Use;
58 import org.jboss.axis.utils.Messages;
59
60 import javax.wsdl.Fault;
61 import javax.wsdl.Message;
62 import javax.wsdl.Part;
63 import javax.wsdl.extensions.soap.SOAPHeaderFault;
64 import javax.xml.namespace.QName JavaDoc;
65 import java.io.IOException JavaDoc;
66 import java.util.Map JavaDoc;
67
68 /**
69  * Fault information object. This should probably really be FaultEntry and
70  * it should be a subclass of SymTabEntry, but faults aren't first-class
71  * objects in WSDL, so I'm not sure what the FaultEntry should contain and
72  * how it should be constructed, so for now leave it as a simple object.
73  */

74
75 public class FaultInfo
76 {
77    private Message message;
78    private QName JavaDoc xmlType;
79    private Use use;
80    private QName JavaDoc qName;
81    private String JavaDoc name;
82
83    /**
84     * This constructor creates FaultInfo for a binding fault.
85     * <p/>
86     * If the part of the fault is a type, then the QName is
87     * derived from the element name and the provided namespace
88     * (this namespace SHOULD come from the binding).
89     * <p/>
90     * If the part of the fault is an element, then the QName is
91     * the QName of the element, and the given namespace is ignored.
92     */

93    public FaultInfo(Fault fault, Use use, String JavaDoc namespace,
94                     SymbolTable symbolTable)
95    {
96       this.message = fault.getMessage();
97       this.xmlType = getFaultType(symbolTable, getFaultPart());
98       this.use = use;
99       this.name = fault.getName();
100
101       Part part = getFaultPart();
102       if (part == null)
103       {
104          this.qName = null;
105       }
106       else if (part.getTypeName() != null)
107       {
108          this.qName = new QName JavaDoc(namespace, part.getName());
109       }
110       else
111       {
112          this.qName = part.getElementName();
113       }
114    } // ctor
115

116    /**
117     * This constructor creates FaultInfo for a soap:headerFault.
118     */

119    public FaultInfo(SOAPHeaderFault fault, SymbolTable symbolTable)
120            throws IOException JavaDoc
121    {
122       MessageEntry mEntry = symbolTable.getMessageEntry(fault.getMessage());
123       if (mEntry == null)
124       {
125          throw new IOException JavaDoc(Messages.getMessage("noMsg",
126                  fault.getMessage().toString()));
127       }
128       this.message = mEntry.getMessage();
129       Part part = message.getPart(fault.getPart());
130       this.xmlType = getFaultType(symbolTable, part);
131       this.use = Use.getUse(fault.getUse());
132
133       if (part == null)
134       {
135          this.qName = null;
136       }
137       else if (part.getTypeName() != null)
138       {
139          this.qName = new QName JavaDoc(fault.getNamespaceURI(), part.getName());
140       }
141       else
142       {
143          this.qName = part.getElementName();
144       }
145       this.name = qName.getLocalPart();
146
147    } // ctor
148

149    public FaultInfo(QName JavaDoc faultMessage, String JavaDoc faultPart, String JavaDoc faultUse, String JavaDoc faultNamespaceURI, SymbolTable symbolTable)
150            throws IOException JavaDoc
151    {
152       MessageEntry mEntry = symbolTable.getMessageEntry(faultMessage);
153       if (mEntry == null)
154       {
155          throw new IOException JavaDoc(Messages.getMessage("noMsg",
156                  faultMessage.toString()));
157       }
158       this.message = mEntry.getMessage();
159       Part part = message.getPart(faultPart);
160       this.xmlType = getFaultType(symbolTable, part);
161       this.use = Use.getUse(faultUse);
162
163       if (part == null)
164       {
165          this.qName = null;
166       }
167       else if (part.getTypeName() != null)
168       {
169          this.qName = new QName JavaDoc(faultNamespaceURI, part.getName());
170       }
171       else
172       {
173          this.qName = part.getElementName();
174       }
175       this.name = qName.getLocalPart();
176
177    } // ctor
178

179    public Message getMessage()
180    {
181       return message;
182    } // getMessage
183

184    public QName JavaDoc getXMLType()
185    {
186       return xmlType;
187    } // getXMLType
188

189    public Use getUse()
190    {
191       return use;
192    } // getUse
193

194    /**
195     * Return the QName of a fault. This method may return null if no parts
196     * are in the fault message.
197     * <p/>
198     * If the part of the fault is a type, then the QName is
199     * derived from the element name and the provided namespace
200     * (this namespace SHOULD come from the binding).
201     * <p/>
202     * If the part of the fault is an element, then the QName is
203     * the QName of the element, and the given namespace is ignored.
204     */

205    public QName JavaDoc getQName()
206    {
207       return qName;
208    } // getQName
209

210    /**
211     * Return the name of the fault.
212     * This is the name= attribute from a portType fault
213     * or the localname of a header fault.
214     */

215    public String JavaDoc getName()
216    {
217       return name;
218    } // getName
219

220    /**
221     * It is assumed at this point that the fault message has only
222     * 0 or 1 parts. If 0, return null. If 1, return it.
223     */

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

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