KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > axis > builder > LightweightOperationDescBuilder


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.axis.builder;
18
19 import java.lang.reflect.Method JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.xml.namespace.QName JavaDoc;
24 import javax.wsdl.Part;
25 import javax.wsdl.BindingOperation;
26
27 import org.apache.geronimo.axis.client.OperationInfo;
28 import org.apache.geronimo.common.DeploymentException;
29 import org.apache.axis.soap.SOAPConstants;
30 import org.apache.axis.description.OperationDesc;
31 import org.apache.axis.description.ParameterDesc;
32 import org.apache.axis.constants.Style;
33 import org.apache.axis.constants.Use;
34 import org.objectweb.asm.Type;
35
36 /**
37  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
38  */

39 public class LightweightOperationDescBuilder extends OperationDescBuilder {
40
41     private final Method JavaDoc method;
42
43     public LightweightOperationDescBuilder(BindingOperation bindingOperation, Method JavaDoc method) throws DeploymentException{
44         super(bindingOperation);
45         if (bindingOperation == null) {
46             throw new DeploymentException("No BindingOperation supplied for method " + method.getName());
47         }
48
49         this.method = method;
50
51         operationDesc.setName(operationName);
52         operationDesc.setStyle(Style.RPC);
53         operationDesc.setUse(Use.ENCODED);
54     }
55
56     public OperationInfo buildOperationInfo(SOAPConstants soapVersion) throws DeploymentException {
57         buildOperationDesc();
58         String JavaDoc soapActionURI = soapOperation.getSoapActionURI();
59         boolean usesSOAPAction = (soapActionURI != null);
60         QName JavaDoc operationQName = getOperationNameFromSOAPBody();
61
62         String JavaDoc methodName = method.getName();
63         String JavaDoc methodDesc = Type.getMethodDescriptor(method);
64
65
66         OperationInfo operationInfo = new OperationInfo(operationDesc, usesSOAPAction, soapActionURI, soapVersion, operationQName, methodName, methodDesc);
67         return operationInfo;
68     }
69
70     public OperationDesc buildOperationDesc() throws DeploymentException {
71         if (built) {
72             return operationDesc;
73         }
74
75         built = true;
76
77         operationDesc.setMethod(method);
78
79         //section 7.3.2, we don't have to look at parameter ordering.
80
//unless it turns out we have to validate it.
81
// List order = operation.getParameterOrdering();
82

83         // Verify we have the right number of args for this method
84
Class JavaDoc[] methodParamTypes = method.getParameterTypes();
85         List JavaDoc inputParts = input.getOrderedParts(null);
86         if (methodParamTypes.length != inputParts.size()) {
87             throw new DeploymentException("mismatch in parameter counts: method has " + methodParamTypes.length + " whereas the input message has " + inputParts.size());
88         }
89
90         // Map the input parts to method args
91
int i = 0;
92         for (Iterator JavaDoc parts = inputParts.iterator(); parts.hasNext();) {
93             Part part = (Part) parts.next();
94             String JavaDoc partName = part.getName();
95             QName JavaDoc name = new QName JavaDoc("", partName);
96             byte mode = ParameterDesc.IN;
97             QName JavaDoc typeQName = part.getTypeName() == null ? part.getElementName() : part.getTypeName();
98             Class JavaDoc javaClass = methodParamTypes[i++];
99             //lightweight mapping has no parts in headers, so inHeader and outHeader are false
100
ParameterDesc parameter = new ParameterDesc(name, mode, typeQName, javaClass, false, false);
101             operationDesc.addParameter(parameter);
102         }
103
104         // Can't have multiple return values
105
if (output != null && output.getParts().size() > 1) {
106             throw new DeploymentException("Lightweight mapping has at most one part in the (optional) output message, not: " + output.getParts().size());
107         }
108
109         // Map the return message, if there is one
110
if (output != null && output.getParts().size() == 1) {
111             Part part = (Part) output.getParts().values().iterator().next();
112
113             // Set the element name
114
QName JavaDoc returnName = part.getElementName() == null ? new QName JavaDoc(part.getName()) : part.getElementName();
115             operationDesc.setReturnQName(returnName);
116
117             // Set the element type
118
QName JavaDoc returnType = part.getTypeName() == null ? part.getElementName() : part.getTypeName();
119             operationDesc.setReturnType(returnType);
120
121             operationDesc.setReturnClass(method.getReturnType());
122         }
123
124         //TODO add faults
125
// TFault[] faults = tOperation.getFaultArray();
126
// for (int i = 0; i < faults.length; i++) {
127
// TFault fault = faults[i];
128
// QName faultQName = new QName("", fault.getName());
129
// String className = ;
130
// QName faultTypeQName = ;
131
// boolean isComplex = ;
132
// FaultDesc faultDesc = new FaultDesc(faultQName, className, faultTypeQName, isComplex)
133
// }
134
return operationDesc;
135     }
136 }
137
Popular Tags