1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.geronimo.axis.builder;
19
20 import java.lang.reflect.Method;
21 import java.util.List;
22 import java.util.Iterator;
23
24 import javax.xml.namespace.QName;
25 import javax.wsdl.Part;
26 import javax.wsdl.BindingOperation;
27
28 import org.apache.geronimo.axis.client.OperationInfo;
29 import org.apache.geronimo.common.DeploymentException;
30 import org.apache.axis.soap.SOAPConstants;
31 import org.apache.axis.description.OperationDesc;
32 import org.apache.axis.description.ParameterDesc;
33 import org.apache.axis.constants.Style;
34 import org.apache.axis.constants.Use;
35 import org.objectweb.asm.Type;
36
37 /**
38 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
39 */
40 public class LightweightOperationDescBuilder extends OperationDescBuilder {
41
42 private final Method method;
43
44 public LightweightOperationDescBuilder(BindingOperation bindingOperation, Method method) throws DeploymentException{
45 super(bindingOperation);
46 if (bindingOperation == null) {
47 throw new DeploymentException("No BindingOperation supplied for method " + method.getName());
48 }
49
50 this.method = method;
51
52 operationDesc.setName(operationName);
53 operationDesc.setStyle(Style.RPC);
54 operationDesc.setUse(Use.ENCODED);
55 }
56
57 public OperationInfo buildOperationInfo(SOAPConstants soapVersion) throws DeploymentException {
58 buildOperationDesc();
59 String soapActionURI = soapOperation.getSoapActionURI();
60 boolean usesSOAPAction = (soapActionURI != null);
61 QName operationQName = getOperationNameFromSOAPBody();
62
63 String methodName = method.getName();
64 String methodDesc = Type.getMethodDescriptor(method);
65
66
67 OperationInfo operationInfo = new OperationInfo(operationDesc, usesSOAPAction, soapActionURI, soapVersion, operationQName, methodName, methodDesc);
68 return operationInfo;
69 }
70
71 public OperationDesc buildOperationDesc() throws DeploymentException {
72 if (built) {
73 return operationDesc;
74 }
75
76 built = true;
77
78 operationDesc.setMethod(method);
79
80
81
82
83
84
85 Class[] methodParamTypes = method.getParameterTypes();
86 List inputParts = input.getOrderedParts(null);
87 if (methodParamTypes.length != inputParts.size()) {
88 throw new DeploymentException("mismatch in parameter counts: method has " + methodParamTypes.length + " whereas the input message has " + inputParts.size());
89 }
90
91
92 int i = 0;
93 for (Iterator parts = inputParts.iterator(); parts.hasNext();) {
94 Part part = (Part) parts.next();
95 String partName = part.getName();
96 QName name = new QName("", partName);
97 byte mode = ParameterDesc.IN;
98 QName typeQName = part.getTypeName() == null ? part.getElementName() : part.getTypeName();
99 Class javaClass = methodParamTypes[i++];
100
101 ParameterDesc parameter = new ParameterDesc(name, mode, typeQName, javaClass, false, false);
102 operationDesc.addParameter(parameter);
103 }
104
105
106 if (output != null && output.getParts().size() > 1) {
107 throw new DeploymentException("Lightweight mapping has at most one part in the (optional) output message, not: " + output.getParts().size());
108 }
109
110
111 if (output != null && output.getParts().size() == 1) {
112 Part part = (Part) output.getParts().values().iterator().next();
113
114
115 QName returnName = part.getElementName() == null ? new QName(part.getName()) : part.getElementName();
116 operationDesc.setReturnQName(returnName);
117
118
119 QName returnType = part.getTypeName() == null ? part.getElementName() : part.getTypeName();
120 operationDesc.setReturnType(returnType);
121
122 operationDesc.setReturnClass(method.getReturnType());
123 }
124
125
126
127
128
129
130
131
132
133
134
135 return operationDesc;
136 }
137 }