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: /**
021: *
022: */package org.apache.axis2.jaxws.description.builder;
023:
024: import java.util.ArrayList;
025: import java.util.Iterator;
026: import java.util.List;
027:
028: public class MethodDescriptionComposite implements
029: TMAnnotationComposite, TMFAnnotationComposite {
030:
031: //Method reflective information
032: private String methodName; //a public method name in this class
033: private String returnType; //Methods return type
034: private String[] exceptions;
035: private String declaringClass; //the class/interface that actually declares this method
036:
037: boolean oneWayAnnotated;
038: // boolean that indicates if an @XmlList annotation was found on the method
039: private boolean isListType = false;
040: private WebMethodAnnot webMethodAnnot;
041: private WebResultAnnot webResultAnnot;
042: private WebServiceContextAnnot webServiceContextAnnot;
043: private HandlerChainAnnot handlerChainAnnot;
044: private SoapBindingAnnot soapBindingAnnot;
045: private WebServiceRefAnnot webServiceRefAnnot;
046: private WebEndpointAnnot webEndpointAnnot;
047: private RequestWrapperAnnot requestWrapperAnnot; //TODO EDIT CHECK: only on methods of SEI
048: private ResponseWrapperAnnot responseWrapperAnnot;//TODO EDIT CHECK: only on methods of SEI
049: private List<ParameterDescriptionComposite> parameterDescriptions;//TODO EDIT CHECK: only on methods of SEI
050:
051: private DescriptionBuilderComposite parentDBC;
052:
053: /*
054: * Default Constructor
055: */
056: public MethodDescriptionComposite() {
057: parameterDescriptions = new ArrayList<ParameterDescriptionComposite>();
058: }
059:
060: public MethodDescriptionComposite(String methodName,
061: String returnType, WebMethodAnnot webMethodAnnot,
062: WebResultAnnot webResultAnnot, boolean oneWayAnnotated,
063: HandlerChainAnnot handlerChainAnnot,
064: SoapBindingAnnot soapBindingAnnot,
065: WebServiceRefAnnot webServiceRefAnnot,
066: WebEndpointAnnot webEndpointAnnot,
067: RequestWrapperAnnot requestWrapperAnnot,
068: ResponseWrapperAnnot responseWrapperAnnot,
069: WebServiceContextAnnot webServiceContextAnnot) {
070:
071: this .methodName = methodName;
072: this .returnType = returnType;
073: this .webMethodAnnot = webMethodAnnot;
074: this .webResultAnnot = webResultAnnot;
075: this .oneWayAnnotated = oneWayAnnotated;
076: this .handlerChainAnnot = handlerChainAnnot;
077: this .soapBindingAnnot = soapBindingAnnot;
078: this .webServiceRefAnnot = webServiceRefAnnot;
079: this .webEndpointAnnot = webEndpointAnnot;
080: this .requestWrapperAnnot = requestWrapperAnnot;
081: this .responseWrapperAnnot = responseWrapperAnnot;
082: this .webServiceContextAnnot = webServiceContextAnnot;
083: }
084:
085: /** @return Returns the methodName */
086: public String getMethodName() {
087: return methodName;
088: }
089:
090: /**
091: * Returns the String descrbing this method result type. Note that this string is unparsed. For
092: * example, if it represents a java.util.List<my.package.Foo>, then that excact string will be
093: * returned, i.e. "java.util.List<my.package.Foo>". You can use other methods on this object to
094: * retrieve parsed values for Generics and Holders.
095: *
096: * @return Returns the returnType
097: */
098: public String getReturnType() {
099: return returnType;
100: }
101:
102: /**
103: * Returns the class associated with the method result type. Note that if the resturn type a
104: * generic (such as java.util.List<my.package.Foo>) then the class associated with the raw type is
105: * returned (i.e. java.util.List).
106: * <p/>
107: * There are other methods that return the class for the actual type for certain JAX-WS specific
108: * generics such as Response<T>
109: *
110: * @return Returns the parameterTypeClass.
111: */
112: public Class getReturnTypeClass() {
113: Class returnTypeClass = null;
114: String fullReturnType = getReturnType();
115: if (fullReturnType != null) {
116: returnTypeClass = DescriptionBuilderUtils
117: .getPrimitiveClass(fullReturnType);
118: if (returnTypeClass == null) {
119: // If this is a Generic, we need to load the class associated with the Raw Type,
120: // i.e. for List<Foo>, we want to load List. Othwerise, load the type directly.
121: String classToLoad = null;
122: if (DescriptionBuilderUtils.getRawType(fullReturnType) != null) {
123: classToLoad = DescriptionBuilderUtils
124: .getRawType(fullReturnType);
125: } else {
126: classToLoad = fullReturnType;
127: }
128: returnTypeClass = loadClassFromMDC(classToLoad);
129: }
130: }
131:
132: return returnTypeClass;
133: }
134:
135: private Class loadClassFromMDC(String classToLoad) {
136: Class returnClass = null;
137: ClassLoader classLoader = null;
138:
139: if (getDescriptionBuilderCompositeRef() != null) {
140: classLoader = getDescriptionBuilderCompositeRef()
141: .getClassLoader();
142: }
143: returnClass = DescriptionBuilderUtils.loadClassFromComposite(
144: classToLoad, classLoader);
145: return returnClass;
146: }
147:
148: /** @return returns whether this is OneWay */
149: public boolean isOneWay() {
150: return oneWayAnnotated;
151: }
152:
153: /** @return Returns the webEndpointAnnot. */
154: public WebEndpointAnnot getWebEndpointAnnot() {
155: return webEndpointAnnot;
156: }
157:
158: /** @return Returns the requestWrapperAnnot. */
159: public RequestWrapperAnnot getRequestWrapperAnnot() {
160: return requestWrapperAnnot;
161: }
162:
163: /** @return Returns the responseWrapperAnnot. */
164: public ResponseWrapperAnnot getResponseWrapperAnnot() {
165: return responseWrapperAnnot;
166: }
167:
168: /** @return Returns the webServiceContextAnnot. */
169: public WebServiceContextAnnot getWebServiceContextAnnot() {
170: return webServiceContextAnnot;
171: }
172:
173: /** @return Returns the handlerChainAnnot. */
174: public HandlerChainAnnot getHandlerChainAnnot() {
175: return handlerChainAnnot;
176: }
177:
178: /** @return Returns the soapBindingAnnot. */
179: public SoapBindingAnnot getSoapBindingAnnot() {
180: return soapBindingAnnot;
181: }
182:
183: /** @return Returns the webMethodAnnot. */
184: public WebMethodAnnot getWebMethodAnnot() {
185: return webMethodAnnot;
186: }
187:
188: /** @return Returns the webResultAnnot. */
189: public WebResultAnnot getWebResultAnnot() {
190: return webResultAnnot;
191: }
192:
193: /** @return Returns the webServiceRefAnnot. */
194: public WebServiceRefAnnot getWebServiceRefAnnot() {
195: return webServiceRefAnnot;
196: }
197:
198: /** @return Returns the exceptions. */
199: public String[] getExceptions() {
200: return exceptions;
201: }
202:
203: /** @return Returns the exceptions. */
204: public Class[] getExceptionTypes() {
205: //TODO: Implement this...
206: //for each exception in the array, convert it to a class, and return that
207: //If a classloader was not set, then just use the default
208: Class[] classes = new Class[0];
209: return classes;
210: }
211:
212: /** @return Returns the fully qualified name of the declaring class. */
213: public String getDeclaringClass() {
214: if (declaringClass == null && parentDBC != null) {
215: return parentDBC.getClassName();
216: }
217: return declaringClass;
218: }
219:
220: /** @return Returns the ModuleClassType. */
221: public DescriptionBuilderComposite getDescriptionBuilderCompositeRef() {
222:
223: return this .parentDBC;
224: }
225:
226: /** @param methodName The methodName to set. */
227: public void setMethodName(String methodName) {
228: this .methodName = methodName;
229: }
230:
231: /** @param returnType The returnType to set. */
232: public void setReturnType(String returnType) {
233: this .returnType = returnType;
234: }
235:
236: /** @param oneWayAnnotated The oneWay boolean to set */
237: public void setOneWayAnnot(boolean oneWayAnnotated) {
238: this .oneWayAnnotated = oneWayAnnotated;
239: }
240:
241: /** @param webEndpointAnnotImpl The webEndpointAnnotImpl to set. */
242: public void setWebEndpointAnnot(WebEndpointAnnot webEndpointAnnot) {
243: this .webEndpointAnnot = webEndpointAnnot;
244: }
245:
246: /** @param requestWrapperAnnot The requestWrapperAnnot to set. */
247: public void setRequestWrapperAnnot(
248: RequestWrapperAnnot requestWrapperAnnot) {
249: this .requestWrapperAnnot = requestWrapperAnnot;
250: }
251:
252: /** @param responseWrapperAnnot The responseWrapperAnnot to set. */
253: public void setResponseWrapperAnnot(
254: ResponseWrapperAnnot responseWrapperAnnot) {
255: this .responseWrapperAnnot = responseWrapperAnnot;
256: }
257:
258: /** @param webServiceContextAnnot The webServiceContextAnnot to set. */
259: public void setWebServiceContextAnnot(
260: WebServiceContextAnnot webServiceContextAnnot) {
261: this .webServiceContextAnnot = webServiceContextAnnot;
262: }
263:
264: /** @param handlerChainAnnot The handlerChainAnnot to set. */
265: public void setHandlerChainAnnot(HandlerChainAnnot handlerChainAnnot) {
266: this .handlerChainAnnot = handlerChainAnnot;
267: }
268:
269: /** @param soapBindingAnnot The soapBindingAnnot to set. */
270: public void setSoapBindingAnnot(SoapBindingAnnot soapBindingAnnot) {
271: this .soapBindingAnnot = soapBindingAnnot;
272: }
273:
274: /** @param webMethodAnnot The webMethodAnnot to set. */
275: public void setWebMethodAnnot(WebMethodAnnot webMethodAnnot) {
276: this .webMethodAnnot = webMethodAnnot;
277: }
278:
279: /** @param webResultAnnot The webResultAnnot to set. */
280: public void setWebResultAnnot(WebResultAnnot webResultAnnot) {
281: this .webResultAnnot = webResultAnnot;
282: }
283:
284: /** @param webServiceRefAnnot The webServiceRefAnnot to set. */
285: public void setWebServiceRefAnnot(
286: WebServiceRefAnnot webServiceRefAnnot) {
287: this .webServiceRefAnnot = webServiceRefAnnot;
288: }
289:
290: /** @param parameterDescription The parameterDescription to add to the set. */
291: public void addParameterDescriptionComposite(
292: ParameterDescriptionComposite parameterDescription) {
293: parameterDescriptions.add(parameterDescription);
294: }
295:
296: /**
297: * @param parameterDescription The parameterDescription to add to the set.
298: * @param index The index at which to place this parameterDescription
299: */
300: public void addParameterDescriptionComposite(
301: ParameterDescriptionComposite parameterDescription,
302: int index) {
303: parameterDescription.setListOrder(index);
304: parameterDescriptions.add(index, parameterDescription);
305: }
306:
307: /** @param parameterDescription The parameterDescription to add to the set. */
308: public void setParameterDescriptionCompositeList(
309: List<ParameterDescriptionComposite> parameterDescriptionList) {
310: this .parameterDescriptions = parameterDescriptionList;
311: }
312:
313: /** @param parameterDescription The parameterDescription to add to the set. */
314: public ParameterDescriptionComposite getParameterDescriptionComposite(
315: int index) {
316: return parameterDescriptions.get(index);
317: }
318:
319: /**
320: */
321: public List<ParameterDescriptionComposite> getParameterDescriptionCompositeList() {
322: return parameterDescriptions;
323: }
324:
325: /** @param exceptions The exceptions to set. */
326: public void setExceptions(String[] exceptions) {
327: this .exceptions = exceptions;
328: }
329:
330: /** @param declaringClass The wrapper class to set. */
331: public void setDeclaringClass(String declaringClass) {
332: this .declaringClass = declaringClass;
333: }
334:
335: /** @return Returns the ModuleClassType. */
336: public void setDescriptionBuilderCompositeRef(
337: DescriptionBuilderComposite dbc) {
338:
339: this .parentDBC = dbc;
340: }
341:
342: public boolean compare(Object obj) {
343: if (obj instanceof MethodDescriptionComposite) {
344: MethodDescriptionComposite mdc = (MethodDescriptionComposite) obj;
345: if (!(this .methodName.equals(mdc.getMethodName()))) {
346: return false;
347: }
348: List<ParameterDescriptionComposite> this ParamList = this .parameterDescriptions;
349: List<ParameterDescriptionComposite> paramList = mdc
350: .getParameterDescriptionCompositeList();
351: if (this ParamList.size() != paramList.size()) {
352: return false;
353: }
354: for (int i = 0; i < this ParamList.size(); i++) {
355: if (!(this ParamList.get(i).compare(paramList.get(i)))) {
356: return false;
357: }
358: }
359: return true;
360: } else {
361: return super .equals(obj);
362: }
363: }
364:
365: public void setIsListType(boolean isListType) {
366: this .isListType = isListType;
367: }
368:
369: public boolean isListType() {
370: return isListType;
371: }
372:
373: /**
374: * Convenience method for unit testing. We will print all of the
375: * data members here.
376: */
377: public String toString() {
378: StringBuffer sb = new StringBuffer();
379: final String newLine = "\n";
380: final String sameLine = "; ";
381: sb.append(super .toString());
382: sb.append(newLine);
383: sb.append("Name: " + methodName);
384: sb.append(sameLine);
385: sb.append("ReturnType: " + returnType);
386:
387: sb.append(newLine);
388: sb.append("Exceptions: ");
389: if (exceptions != null) {
390: for (int i = 0; i < exceptions.length; i++) {
391: sb.append(exceptions[i]);
392: sb.append(sameLine);
393: }
394: }
395:
396: if (oneWayAnnotated) {
397: sb.append(newLine);
398: sb.append("OneWay");
399: }
400:
401: if (webMethodAnnot != null) {
402: sb.append(newLine);
403: sb.append("WebMethod: ");
404: sb.append(webMethodAnnot.toString());
405: }
406:
407: if (requestWrapperAnnot != null) {
408: sb.append(newLine);
409: sb.append("RequestWrapper: ");
410: sb.append(requestWrapperAnnot.toString());
411: }
412:
413: if (responseWrapperAnnot != null) {
414: sb.append(newLine);
415: sb.append("ResponsetWrapper: ");
416: sb.append(responseWrapperAnnot.toString());
417: }
418:
419: if (soapBindingAnnot != null) {
420: sb.append(newLine);
421: sb.append("SOAPBinding: ");
422: sb.append(soapBindingAnnot.toString());
423: }
424:
425: if (webEndpointAnnot != null) {
426: sb.append(newLine);
427: sb.append("WebEndpoint: ");
428: sb.append(webEndpointAnnot.toString());
429: }
430:
431: if (webResultAnnot != null) {
432: sb.append(newLine);
433: sb.append("WebResult: ");
434: sb.append(webResultAnnot.toString());
435: }
436:
437: if (webServiceRefAnnot != null) {
438: sb.append(newLine);
439: sb.append("WebServiceRef: ");
440: sb.append(webServiceRefAnnot.toString());
441: }
442:
443: if (handlerChainAnnot != null) {
444: sb.append(newLine);
445: sb.append("HandlerChain: ");
446: sb.append(handlerChainAnnot.toString());
447: }
448:
449: sb.append(newLine);
450: sb.append("Number of Parameter Descriptions: "
451: + parameterDescriptions.size());
452: Iterator<ParameterDescriptionComposite> pdcIter = parameterDescriptions
453: .iterator();
454: while (pdcIter.hasNext()) {
455: sb.append(newLine);
456: ParameterDescriptionComposite pdc = pdcIter.next();
457: sb.append(pdc.toString());
458: }
459: return sb.toString();
460: }
461: }
|