001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.jaxws.description.impl;
021:
022: import org.apache.axis2.jaxws.description.FaultDescription;
023: import org.apache.axis2.jaxws.description.FaultDescriptionJava;
024: import org.apache.axis2.jaxws.description.FaultDescriptionWSDL;
025: import org.apache.axis2.jaxws.description.OperationDescription;
026: import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
027: import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
028:
029: import javax.xml.ws.WebFault;
030: import java.lang.reflect.Method;
031: import java.util.StringTokenizer;
032:
033: /** @see ../FaultDescription */
034:
035: class FaultDescriptionImpl implements FaultDescription,
036: FaultDescriptionJava, FaultDescriptionWSDL {
037:
038: private Class exceptionClass;
039: private DescriptionBuilderComposite composite;
040: private WebFault annotation;
041: private OperationDescription parent;
042:
043: private String name = ""; // WebFault.name
044: private String faultBean = ""; // WebFault.faultBean
045: private String targetNamespace = ""; // WebFault.targetNamespace
046: private String faultInfo = null;
047:
048: private static final String FAULT = "Fault";
049:
050: /**
051: * The FaultDescriptionImpl class will only be used to describe exceptions declared to be thrown
052: * by a service that has a WebFault annotation. No generic exception should ever have a
053: * FaultDescription associated with it. It is the responsibility of the user of the
054: * FaultDescriptionImpl class to avoid instantiating this object for non-annotated generic
055: * exceptions.
056: *
057: * @param exceptionClass an exception declared to be thrown by the service on which this
058: * FaultDescription may apply.
059: * @param beanName fully qualified package+classname of the bean associated with this
060: * exception
061: * @param annotation the WebFault annotation object on this exception class
062: * @param parent the OperationDescription that is the parent of this FaultDescription
063: */
064: FaultDescriptionImpl(Class exceptionClass, WebFault annotation,
065: OperationDescription parent) {
066: this .exceptionClass = exceptionClass;
067: this .annotation = annotation;
068: this .parent = parent;
069: }
070:
071: FaultDescriptionImpl(DescriptionBuilderComposite faultDBC,
072: OperationDescription parent) {
073: this .composite = faultDBC;
074: this .parent = parent;
075: }
076:
077: public WebFault getAnnoWebFault() {
078:
079: if (annotation == null) {
080: if (isDBC()) {
081: annotation = this .composite.getWebFaultAnnot();
082: }
083: }
084:
085: return annotation;
086: }
087:
088: public String getExceptionClassName() {
089: if (!isDBC()) {
090: // no need for defaults here. The exceptionClass stored in this
091: // FaultDescription object is one that has been declared to be
092: // thrown from the service method
093: return exceptionClass.getCanonicalName();
094: } else {
095: return composite.getClassName();
096: }
097: }
098:
099: public String getFaultInfo() {
100: if (faultInfo != null) {
101: return faultInfo;
102: }
103: if (!isDBC()) {
104: try {
105: Method method = exceptionClass.getMethod(
106: "getFaultInfo", null);
107: faultInfo = method.getReturnType().getCanonicalName();
108: } catch (Exception e) {
109: // This must be a legacy exception
110: faultInfo = "";
111: }
112: } else {
113: MethodDescriptionComposite mdc = composite
114: .getMethodDescriptionComposite("getFaultInfo", 1);
115: if (mdc != null) {
116: faultInfo = mdc.getReturnType();
117: } else {
118: faultInfo = "";
119: }
120: }
121: return faultInfo;
122: }
123:
124: public String getFaultBean() {
125: if (faultBean != null && faultBean.length() > 0) {
126: // Return the faultBean if it was already calculated
127: return faultBean;
128: } else {
129: // Load up the WebFault annotation and get the faultBean.
130: // @WebFault may not be present
131: WebFault annotation = getAnnoWebFault();
132:
133: if (annotation != null && annotation.faultBean() != null
134: && annotation.faultBean().length() > 0) {
135: faultBean = annotation.faultBean();
136: } else {
137: // There is no default. But it seems reasonable to return
138: // the fault info type.
139: faultBean = getFaultInfo();
140:
141: // The faultBean still may be "" at this point. The JAXWS runtime
142: // is responsible for finding/buildin a representative fault bean.
143: }
144: }
145: return faultBean;
146: }
147:
148: public String getName() {
149: if (name.length() > 0) {
150: return name;
151: } else {
152: // Load the annotation. The annotation may not be present in WSGen cases
153: WebFault annotation = this .getAnnoWebFault();
154: if (annotation != null && annotation.name().length() > 0) {
155: name = annotation.name();
156: } else {
157: // The default is undefined.
158: // The JAX-WS layer may use the fault bean information to determine the name
159: }
160: }
161: return name;
162: }
163:
164: public String getTargetNamespace() {
165: if (targetNamespace.length() > 0) {
166: return targetNamespace;
167: } else {
168: // Load the annotation. The annotation may not be present in WSGen cases
169: WebFault annotation = this .getAnnoWebFault();
170: if (annotation != null
171: && annotation.targetNamespace().length() > 0) {
172: targetNamespace = annotation.targetNamespace();
173: } else {
174: // The default is undefined
175: // The JAX-WS layer may use the fault bean information to determine the name
176: }
177: }
178: return targetNamespace;
179: }
180:
181: public OperationDescription getOperationDescription() {
182: return parent;
183: }
184:
185: /**
186: * utility method to get the last token in a "."-delimited package+classname string
187: *
188: * @return
189: */
190: private static String getSimpleName(String in) {
191: if (in == null || in.length() == 0) {
192: return in;
193: }
194: String out = null;
195: StringTokenizer tokenizer = new StringTokenizer(in, ".");
196: if (tokenizer.countTokens() == 0)
197: out = in;
198: else {
199: while (tokenizer.hasMoreTokens()) {
200: out = tokenizer.nextToken();
201: }
202: }
203: return out;
204: }
205:
206: private boolean isDBC() {
207: if (this .composite != null)
208: return true;
209: else
210: return false;
211: }
212:
213: public String toString() {
214: final String newline = "\n";
215: final String sameline = "; ";
216: StringBuffer string = new StringBuffer();
217: try {
218: string.append(super .toString());
219: string.append(newline);
220: string
221: .append("Exception class: "
222: + getExceptionClassName());
223: string.append(newline);
224: string.append("Name: " + getName());
225: string.append(newline);
226: string.append("Namespace: " + getName());
227: string.append(newline);
228: string.append("FaultBean: " + getFaultBean());
229: string.append(newline);
230: string.append("FaultInfo Type Name : " + getFaultInfo());
231:
232: } catch (Throwable t) {
233: string.append(newline);
234: string
235: .append("Complete debug information not currently available for "
236: + "FaultDescription");
237: return string.toString();
238: }
239: return string.toString();
240: }
241: }
|