01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.description.builder.converter;
20:
21: import org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite;
22: import org.apache.axis2.jaxws.description.builder.WebParamAnnot;
23:
24: import javax.jws.WebParam;
25: import java.lang.annotation.Annotation;
26: import java.lang.reflect.ParameterizedType;
27: import java.lang.reflect.Type;
28: import java.util.ArrayList;
29: import java.util.List;
30:
31: public class JavaParamToPDCConverter {
32:
33: private Type[] paramTypes;
34:
35: private Annotation[][] paramAnnotations;
36:
37: public JavaParamToPDCConverter(Type[] paramTypes,
38: Annotation[][] paramAnnotations) {
39: this .paramTypes = paramTypes;
40: this .paramAnnotations = paramAnnotations;
41: }
42:
43: public List<ParameterDescriptionComposite> convertParams() {
44: List<ParameterDescriptionComposite> pdcList = new ArrayList<ParameterDescriptionComposite>();
45: for (int i = 0; i < paramTypes.length; i++) {
46: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
47: Type paramType = paramTypes[i];
48: String fullType = ConverterUtils.getType(paramType, "");
49: pdc.setParameterType(fullType);
50: pdc.setListOrder(i);
51: attachWebParamAnnotation(pdc, i);
52: pdcList.add(pdc);
53: }
54: return pdcList;
55: }
56:
57: /**
58: * This method will attach @WebParam annotation data to the <code> ParameterDescriptionComposite</code>
59: * if the annotation was found on the parameter represented by this index in the parameter list.
60: *
61: * @param pdc - <code>ParameterDescriptionComposite</code>
62: * @param order - the current index in the parameter list
63: */
64: private void attachWebParamAnnotation(
65: ParameterDescriptionComposite pdc, int order) {
66: Annotation[] orderAnnots = paramAnnotations[order];
67: for (Annotation annot : orderAnnots) {
68: if (annot instanceof WebParam) {
69: WebParam webParam = (WebParam) annot;
70: WebParamAnnot wpAnnot = WebParamAnnot
71: .createWebParamAnnotImpl();
72: wpAnnot.setHeader(webParam.header());
73: wpAnnot.setMode(webParam.mode());
74: wpAnnot.setName(webParam.name());
75: wpAnnot.setPartName(webParam.partName());
76: wpAnnot.setTargetNamespace(webParam.targetNamespace());
77: pdc.setWebParamAnnot(wpAnnot);
78: }
79: }
80: }
81: }
|