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