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 javax.wsdl.Definition;
025: import java.net.URL;
026: import java.util.ArrayList;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: public class DescriptionBuilderComposite implements
031: TMAnnotationComposite, TMFAnnotationComposite {
032: /*
033: * This structure contains the full reflected class, as well as, the
034: * possible annotations found for this class...the class description
035: * must be complete enough for full validation between class info and annotations
036: * The annotations will be added to the corresponding class members.
037: */
038:
039: public DescriptionBuilderComposite() {
040:
041: methodDescriptions = new ArrayList<MethodDescriptionComposite>();
042: fieldDescriptions = new ArrayList<FieldDescriptionComposite>();
043: webServiceRefAnnotList = new ArrayList<WebServiceRefAnnot>();
044: interfacesList = new ArrayList<String>();
045: }
046:
047: //Class type within the module
048: public static enum ModuleClassType {
049: SERVICEIMPL, SEI, SERVICE, SUPER, PROVIDER, FAULT
050: }
051:
052: private ModuleClassType moduleClassType = null;
053:
054: //Note: a WSDL is not necessary
055: private Definition wsdlDefinition = null;
056: private URL wsdlURL = null;
057:
058: // Class-level annotations
059: private WebServiceAnnot webServiceAnnot;
060: private WebServiceProviderAnnot webServiceProviderAnnot;
061: private ServiceModeAnnot serviceModeAnnot;
062: private WebServiceClientAnnot webServiceClientAnnot;
063: private WebFaultAnnot webFaultAnnot;
064: private HandlerChainAnnot handlerChainAnnot;
065: private SoapBindingAnnot soapBindingAnnot;
066: private List<WebServiceRefAnnot> webServiceRefAnnotList;
067: private BindingTypeAnnot bindingTypeAnnot;
068: private WebServiceContextAnnot webServiceContextAnnot;
069:
070: // Class information
071: private String className;
072: private String[] classModifiers; //public, abstract, final, strictfp...
073: private String extendsClass; //Set to the name of the super class
074: private List<String> interfacesList; //Set this for all implemented interfaces
075: private boolean isInterface = false;
076:
077: private List<MethodDescriptionComposite> methodDescriptions;
078: private List<FieldDescriptionComposite> fieldDescriptions;
079:
080: private WsdlGenerator wsdlGenerator;
081: private ClassLoader classLoader;
082:
083: // Methods
084: public WebServiceAnnot getWebServiceAnnot() {
085: return this .webServiceAnnot;
086: }
087:
088: /** @return Returns the classModifiers. */
089: public String[] getClassModifiers() {
090: return classModifiers;
091: }
092:
093: /** @return Returns the className. */
094: public String getClassName() {
095: return className;
096: }
097:
098: /** @return Returns the super class name. */
099: public String getSuperClassName() {
100: return extendsClass;
101: }
102:
103: /** @return Returns the list of implemented interfaces. */
104: public List<String> getInterfacesList() {
105: return interfacesList;
106: }
107:
108: /** @return Returns the handlerChainAnnotImpl. */
109: public HandlerChainAnnot getHandlerChainAnnot() {
110: return handlerChainAnnot;
111: }
112:
113: /** @return Returns the serviceModeAnnot. */
114: public ServiceModeAnnot getServiceModeAnnot() {
115: return serviceModeAnnot;
116: }
117:
118: /** @return Returns the soapBindingAnnot. */
119: public SoapBindingAnnot getSoapBindingAnnot() {
120: return soapBindingAnnot;
121: }
122:
123: /** @return Returns the webFaultAnnot. */
124: public WebFaultAnnot getWebFaultAnnot() {
125: return webFaultAnnot;
126: }
127:
128: /** @return Returns the webServiceClientAnnot. */
129: public WebServiceClientAnnot getWebServiceClientAnnot() {
130: return webServiceClientAnnot;
131: }
132:
133: /** @return Returns the webServiceProviderAnnot. */
134: public WebServiceProviderAnnot getWebServiceProviderAnnot() {
135: return webServiceProviderAnnot;
136: }
137:
138: /** @return Returns the webServiceRefAnnot list. */
139: public List<WebServiceRefAnnot> getAllWebServiceRefAnnots() {
140: return webServiceRefAnnotList;
141: }
142:
143: /** @return Returns the webServiceRefAnnot. */
144: public WebServiceRefAnnot getWebServiceRefAnnot(String name) {
145:
146: WebServiceRefAnnot wsra = null;
147: Iterator<WebServiceRefAnnot> iter = webServiceRefAnnotList
148: .iterator();
149:
150: while (iter.hasNext()) {
151: wsra = iter.next();
152: if (wsra.name().equals(name))
153: return wsra;
154: }
155: return wsra;
156: }
157:
158: /** @return Returns the webServiceRefAnnot. */
159: public BindingTypeAnnot getBindingTypeAnnot() {
160: return bindingTypeAnnot;
161: }
162:
163: /** @return Returns the webServiceContextAnnot. */
164: public WebServiceContextAnnot getWebServiceContextAnnot() {
165: return webServiceContextAnnot;
166: }
167:
168: /** @return Returns the wsdlDefinition */
169: public Definition getWsdlDefinition() {
170: return wsdlDefinition;
171: }
172:
173: /** @return Returns the wsdlURL */
174: public URL getWsdlURL() {
175: return this .wsdlURL;
176: }
177:
178: /** Returns a collection of all MethodDescriptionComposites that match the specified name */
179: public List<MethodDescriptionComposite> getMethodDescriptionComposite(
180: String methodName) {
181: ArrayList<MethodDescriptionComposite> matchingMethods = new ArrayList<MethodDescriptionComposite>();
182: Iterator<MethodDescriptionComposite> iter = methodDescriptions
183: .iterator();
184: while (iter.hasNext()) {
185: MethodDescriptionComposite composite = iter.next();
186:
187: if (composite.getMethodName() != null) {
188: if (composite.getMethodName().equals(methodName)) {
189: matchingMethods.add(composite);
190: }
191: }
192: }
193:
194: return matchingMethods;
195: }
196:
197: /**
198: * Returns the nth occurence of this MethodComposite. Since method names are not unique, we have
199: * to account for multiple occurrences
200: *
201: * @param methodName
202: * @param occurence The nth occurance to return; not this is NOT 0 based
203: * @return Returns the methodDescriptionComposite
204: */
205: public MethodDescriptionComposite getMethodDescriptionComposite(
206: String methodName, int occurence) {
207: MethodDescriptionComposite returnMDC = null;
208: List<MethodDescriptionComposite> matchingMethods = getMethodDescriptionComposite(methodName);
209: if (matchingMethods != null && !matchingMethods.isEmpty()
210: && occurence > 0 && occurence <= matchingMethods.size()) {
211: returnMDC = matchingMethods.get(--occurence);
212: }
213: return returnMDC;
214: }
215:
216: public List<MethodDescriptionComposite> getMethodDescriptionsList() {
217: return methodDescriptions;
218: }
219:
220: /** @return Returns the methodDescriptionComposite..null if not found */
221: public FieldDescriptionComposite getFieldDescriptionComposite(
222: String fieldName) {
223:
224: FieldDescriptionComposite composite = null;
225: Iterator<FieldDescriptionComposite> iter = fieldDescriptions
226: .iterator();
227:
228: while (iter.hasNext()) {
229: composite = iter.next();
230: if (composite.getFieldName().equals(fieldName))
231: return composite;
232: }
233: return composite;
234: }
235:
236: /** @return Returns the ModuleClassType. */
237: public WsdlGenerator getCustomWsdlGenerator() {
238:
239: return this .wsdlGenerator;
240: }
241:
242: /** @return Returns the ClassLoader. */
243: public ClassLoader getClassLoader() {
244:
245: return this .classLoader;
246: }
247:
248: /** @return Returns true if this is an interface */
249: public boolean isInterface() {
250:
251: return isInterface;
252: }
253:
254: //++++++++
255: //Setters
256: //++++++++
257: public void setWebServiceAnnot(WebServiceAnnot webServiceAnnot) {
258: this .webServiceAnnot = webServiceAnnot;
259: }
260:
261: /** @param classModifiers The classModifiers to set. */
262: public void setClassModifiers(String[] classModifiers) {
263: this .classModifiers = classModifiers;
264: }
265:
266: /** @param className The className to set. */
267: public void setClassName(String className) {
268: this .className = className;
269: }
270:
271: /** @param extendsClass The name of the super class to set. */
272: public void setSuperClassName(String extendsClass) {
273: this .extendsClass = extendsClass;
274: }
275:
276: /** @param interfacesList The interfacesList to set. */
277: public void setInterfacesList(List<String> interfacesList) {
278: this .interfacesList = interfacesList;
279: }
280:
281: /** @param handlerChainAnnot The handlerChainAnnot to set. */
282: public void setHandlerChainAnnot(HandlerChainAnnot handlerChainAnnot) {
283: this .handlerChainAnnot = handlerChainAnnot;
284: }
285:
286: /** @param serviceModeAnnot The serviceModeAnnot to set. */
287: public void setServiceModeAnnot(ServiceModeAnnot serviceModeAnnot) {
288: this .serviceModeAnnot = serviceModeAnnot;
289: }
290:
291: /** @param soapBindingAnnot The soapBindingAnnot to set. */
292: public void setSoapBindingAnnot(SoapBindingAnnot soapBindingAnnot) {
293: this .soapBindingAnnot = soapBindingAnnot;
294: }
295:
296: /** @param webFaultAnnot The webFaultAnnot to set. */
297: public void setWebFaultAnnot(WebFaultAnnot webFaultAnnot) {
298: this .webFaultAnnot = webFaultAnnot;
299: }
300:
301: /** @param webServiceClientAnnot The webServiceClientAnnot to set. */
302: public void setWebServiceClientAnnot(
303: WebServiceClientAnnot webServiceClientAnnot) {
304: this .webServiceClientAnnot = webServiceClientAnnot;
305: }
306:
307: /** @param webServiceProviderAnnot The webServiceProviderAnnot to set. */
308: public void setWebServiceProviderAnnot(
309: WebServiceProviderAnnot webServiceProviderAnnot) {
310: this .webServiceProviderAnnot = webServiceProviderAnnot;
311: }
312:
313: /** @param webServiceRefAnnot The webServiceRefAnnot to add to the list. */
314: public void addWebServiceRefAnnot(
315: WebServiceRefAnnot webServiceRefAnnot) {
316: webServiceRefAnnotList.add(webServiceRefAnnot);
317: }
318:
319: public void setWebServiceRefAnnot(
320: WebServiceRefAnnot webServiceRefAnnot) {
321: addWebServiceRefAnnot(webServiceRefAnnot);
322: }
323:
324: /** @param wsdlDefinition The wsdlDefinition to set. */
325: public void setWsdlDefinition(Definition wsdlDefinition) {
326: this .wsdlDefinition = wsdlDefinition;
327: }
328:
329: /** @param wsdlURL The wsdlURL to set. */
330: public void setwsdlURL(URL wsdlURL) {
331: this .wsdlURL = wsdlURL;
332: }
333:
334: /** @param BindingTypeAnnot The BindingTypeAnnot to set. */
335: public void setBindingTypeAnnot(BindingTypeAnnot bindingTypeAnnot) {
336: this .bindingTypeAnnot = bindingTypeAnnot;
337: }
338:
339: /** @param webServiceContextAnnot The webServiceContextAnnot to set. */
340: public void setWebServiceContextAnnot(
341: WebServiceContextAnnot webServiceContextAnnot) {
342: this .webServiceContextAnnot = webServiceContextAnnot;
343: }
344:
345: /** @param isInterface Sets whether this composite represents a class or interface */
346: public void setIsInterface(boolean isInterface) {
347: this .isInterface = isInterface;
348: }
349:
350: /** @param methodDescription The methodDescription to add to the set. */
351: public void addMethodDescriptionComposite(
352: MethodDescriptionComposite methodDescription) {
353: methodDescriptions.add(methodDescription);
354: }
355:
356: /** @param methodDescription The methodDescription to add to the set. */
357: public void addFieldDescriptionComposite(
358: FieldDescriptionComposite fieldDescription) {
359: fieldDescriptions.add(fieldDescription);
360: }
361:
362: /** @return Returns the ModuleClassType. */
363: public ModuleClassType getClassType() {
364:
365: if (moduleClassType == null) {
366: //TODO: Determine the class type
367: }
368: return moduleClassType;
369: }
370:
371: /** @return Returns the ModuleClassType. */
372: public void setCustomWsdlGenerator(WsdlGenerator wsdlGenerator) {
373:
374: this .wsdlGenerator = wsdlGenerator;
375: }
376:
377: /** @return Returns the ModuleClassType. */
378: public void setClassLoader(ClassLoader classLoader) {
379:
380: this .classLoader = classLoader;
381: }
382:
383: /**
384: * Convenience method for unit testing. We will print all of the
385: * data members here.
386: */
387:
388: public String toString() {
389: StringBuffer sb = new StringBuffer();
390: final String newLine = "\n";
391: final String sameLine = "; ";
392: sb.append(super .toString());
393: sb.append(newLine);
394: sb.append("ClassName: " + className);
395: sb.append(sameLine);
396: sb.append("SuperClass:" + extendsClass);
397:
398: sb.append(newLine);
399: sb.append("Class modifiers: ");
400: if (classModifiers != null) {
401: for (int i = 0; i < classModifiers.length; i++) {
402: sb.append(classModifiers[i]);
403: sb.append(sameLine);
404: }
405: }
406:
407: sb.append(newLine);
408: sb.append("Interfaces: ");
409: Iterator<String> intIter = interfacesList.iterator();
410: while (intIter.hasNext()) {
411: String inter = intIter.next();
412: sb.append(inter);
413: sb.append(sameLine);
414: }
415:
416: if (webServiceAnnot != null) {
417: sb.append(newLine);
418: sb.append("WebService: ");
419: sb.append(webServiceAnnot.toString());
420: }
421:
422: if (webServiceProviderAnnot != null) {
423: sb.append(newLine);
424: sb.append("WebServiceProvider: ");
425: sb.append(webServiceProviderAnnot.toString());
426: }
427:
428: if (bindingTypeAnnot != null) {
429: sb.append(newLine);
430: sb.append("BindingType: ");
431: sb.append(bindingTypeAnnot.toString());
432: }
433:
434: if (webServiceClientAnnot != null) {
435: sb.append(newLine);
436: sb.append("WebServiceClient: ");
437: sb.append(webServiceClientAnnot.toString());
438: }
439:
440: if (webFaultAnnot != null) {
441: sb.append(newLine);
442: sb.append("WebFault: ");
443: sb.append(webFaultAnnot.toString());
444: }
445:
446: if (serviceModeAnnot != null) {
447: sb.append(newLine);
448: sb.append("ServiceMode: ");
449: sb.append(serviceModeAnnot.toString());
450: }
451:
452: if (soapBindingAnnot != null) {
453: sb.append(newLine);
454: sb.append("SOAPBinding: ");
455: sb.append(soapBindingAnnot.toString());
456: }
457:
458: if (handlerChainAnnot != null) {
459: sb.append(newLine);
460: sb.append("HandlerChain: ");
461: sb.append(handlerChainAnnot.toString());
462: }
463:
464: if (webServiceRefAnnotList.size() > 0) {
465: sb.append(newLine);
466: sb.append("Number of WebServiceRef: "
467: + webServiceRefAnnotList.size());
468: Iterator<WebServiceRefAnnot> wsrIter = webServiceRefAnnotList
469: .iterator();
470: while (wsrIter.hasNext()) {
471: WebServiceRefAnnot wsr = wsrIter.next();
472: sb.append(wsr.toString());
473: sb.append(sameLine);
474: }
475: }
476:
477: sb.append(newLine);
478: sb.append("Number of Method Descriptions: "
479: + methodDescriptions.size());
480: Iterator<MethodDescriptionComposite> mdcIter = methodDescriptions
481: .iterator();
482: while (mdcIter.hasNext()) {
483: sb.append(newLine);
484: MethodDescriptionComposite mdc = mdcIter.next();
485: sb.append(mdc.toString());
486: }
487:
488: sb.append(newLine);
489: sb.append("Number of Field Descriptions: "
490: + fieldDescriptions.size());
491: Iterator<FieldDescriptionComposite> fdcIter = fieldDescriptions
492: .iterator();
493: while (fdcIter.hasNext()) {
494: sb.append(newLine);
495: FieldDescriptionComposite fdc = fdcIter.next();
496: sb.append(fdc.toString());
497: }
498: return sb.toString();
499: }
500:
501: }
|