001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.axis.builder;
017:
018: import java.lang.reflect.Method;
019: import java.util.List;
020: import java.util.Iterator;
021:
022: import javax.xml.namespace.QName;
023: import javax.wsdl.Part;
024: import javax.wsdl.BindingOperation;
025:
026: import org.apache.geronimo.axis.client.OperationInfo;
027: import org.apache.geronimo.common.DeploymentException;
028: import org.apache.axis.soap.SOAPConstants;
029: import org.apache.axis.description.OperationDesc;
030: import org.apache.axis.description.ParameterDesc;
031: import org.apache.axis.constants.Style;
032: import org.apache.axis.constants.Use;
033: import org.objectweb.asm.Type;
034:
035: /**
036: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
037: */
038: public class LightweightOperationDescBuilder extends
039: OperationDescBuilder {
040:
041: private final Method method;
042:
043: public LightweightOperationDescBuilder(
044: BindingOperation bindingOperation, Method method)
045: throws DeploymentException {
046: super (bindingOperation);
047: if (bindingOperation == null) {
048: throw new DeploymentException(
049: "No BindingOperation supplied for method "
050: + method.getName());
051: }
052:
053: this .method = method;
054:
055: operationDesc.setName(operationName);
056: operationDesc.setStyle(Style.RPC);
057: operationDesc.setUse(Use.ENCODED);
058: }
059:
060: public OperationInfo buildOperationInfo(SOAPConstants soapVersion)
061: throws DeploymentException {
062: buildOperationDesc();
063: String soapActionURI = soapOperation.getSoapActionURI();
064: boolean usesSOAPAction = (soapActionURI != null);
065: QName operationQName = getOperationNameFromSOAPBody();
066:
067: String methodName = method.getName();
068: String methodDesc = Type.getMethodDescriptor(method);
069:
070: OperationInfo operationInfo = new OperationInfo(operationDesc,
071: usesSOAPAction, soapActionURI, soapVersion,
072: operationQName, methodName, methodDesc);
073: return operationInfo;
074: }
075:
076: public OperationDesc buildOperationDesc()
077: throws DeploymentException {
078: if (built) {
079: return operationDesc;
080: }
081:
082: built = true;
083:
084: operationDesc.setMethod(method);
085:
086: //section 7.3.2, we don't have to look at parameter ordering.
087: //unless it turns out we have to validate it.
088: // List order = operation.getParameterOrdering();
089:
090: // Verify we have the right number of args for this method
091: Class[] methodParamTypes = method.getParameterTypes();
092: List inputParts = input.getOrderedParts(null);
093: if (methodParamTypes.length != inputParts.size()) {
094: throw new DeploymentException(
095: "mismatch in parameter counts: method has "
096: + methodParamTypes.length
097: + " whereas the input message has "
098: + inputParts.size());
099: }
100:
101: // Map the input parts to method args
102: int i = 0;
103: for (Iterator parts = inputParts.iterator(); parts.hasNext();) {
104: Part part = (Part) parts.next();
105: String partName = part.getName();
106: QName name = new QName("", partName);
107: byte mode = ParameterDesc.IN;
108: QName typeQName = part.getTypeName() == null ? part
109: .getElementName() : part.getTypeName();
110: Class javaClass = methodParamTypes[i++];
111: //lightweight mapping has no parts in headers, so inHeader and outHeader are false
112: ParameterDesc parameter = new ParameterDesc(name, mode,
113: typeQName, javaClass, false, false);
114: operationDesc.addParameter(parameter);
115: }
116:
117: // Can't have multiple return values
118: if (output != null && output.getParts().size() > 1) {
119: throw new DeploymentException(
120: "Lightweight mapping has at most one part in the (optional) output message, not: "
121: + output.getParts().size());
122: }
123:
124: // Map the return message, if there is one
125: if (output != null && output.getParts().size() == 1) {
126: Part part = (Part) output.getParts().values().iterator()
127: .next();
128:
129: // Set the element name
130: QName returnName = part.getElementName() == null ? new QName(
131: part.getName())
132: : part.getElementName();
133: operationDesc.setReturnQName(returnName);
134:
135: // Set the element type
136: QName returnType = part.getTypeName() == null ? part
137: .getElementName() : part.getTypeName();
138: operationDesc.setReturnType(returnType);
139:
140: operationDesc.setReturnClass(method.getReturnType());
141: }
142:
143: //TODO add faults
144: // TFault[] faults = tOperation.getFaultArray();
145: // for (int i = 0; i < faults.length; i++) {
146: // TFault fault = faults[i];
147: // QName faultQName = new QName("", fault.getName());
148: // String className = ;
149: // QName faultTypeQName = ;
150: // boolean isComplex = ;
151: // FaultDesc faultDesc = new FaultDesc(faultQName, className, faultTypeQName, isComplex)
152: // }
153: return operationDesc;
154: }
155: }
|