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: */package org.apache.openejb.server.axis.assembler;
018:
019: import org.apache.openejb.OpenEJBException;
020:
021: import javax.wsdl.BindingOperation;
022: import javax.wsdl.Message;
023: import javax.wsdl.Operation;
024: import javax.wsdl.Part;
025: import javax.xml.namespace.QName;
026: import java.lang.reflect.Method;
027: import java.util.List;
028:
029: public class LightweightOperationInfoBuilder {
030: private final String operationName;
031: private final Message inputMessage;
032: private final Message outputMessage;
033: private final Method method;
034:
035: private JaxRpcOperationInfo operationInfo;
036:
037: public LightweightOperationInfoBuilder(
038: BindingOperation bindingOperation, Method method)
039: throws OpenEJBException {
040: if (bindingOperation == null) {
041: throw new OpenEJBException(
042: "No BindingOperation supplied for method "
043: + method.getName());
044: }
045:
046: Operation operation = bindingOperation.getOperation();
047: this .operationName = operation.getName();
048: this .inputMessage = operation.getInput().getMessage();
049: this .outputMessage = operation.getOutput() == null ? null
050: : operation.getOutput().getMessage();
051: this .method = method;
052: }
053:
054: public JaxRpcOperationInfo buildOperationInfo()
055: throws OpenEJBException {
056: if (operationInfo != null) {
057: return operationInfo;
058: }
059:
060: operationInfo = new JaxRpcOperationInfo();
061: operationInfo.name = operationName;
062: operationInfo.bindingStyle = BindingStyle.RPC_ENCODED;
063: operationInfo.javaMethodName = method.getName();
064:
065: // Verify we have the right number of args for this method
066: Class[] methodParamTypes = method.getParameterTypes();
067: List inputParts = inputMessage.getOrderedParts(null);
068: if (methodParamTypes.length != inputParts.size()) {
069: throw new OpenEJBException(
070: "mismatch in parameter counts: method has "
071: + methodParamTypes.length
072: + " whereas the input message has "
073: + inputParts.size());
074: }
075:
076: // Map parameters
077: int i = 0;
078: for (Object inputPart : inputParts) {
079: Part part = (Part) inputPart;
080:
081: JaxRpcParameterInfo parameter = new JaxRpcParameterInfo();
082: parameter.qname = new QName("", part.getName());
083: parameter.mode = JaxRpcParameterInfo.Mode.IN;
084:
085: if (part.getTypeName() == null) {
086: parameter.xmlType = part.getElementName();
087: } else {
088: parameter.xmlType = part.getTypeName();
089: }
090:
091: parameter.javaType = methodParamTypes[i++].getName();
092: parameter.soapHeader = false;
093:
094: operationInfo.parameters.add(parameter);
095: }
096:
097: // Lightweight can't have multiple return values
098: if (outputMessage != null
099: && outputMessage.getParts().size() > 1) {
100: throw new OpenEJBException(
101: "Lightweight mapping has at most one part in the (optional) output message, not: "
102: + outputMessage.getParts().size());
103: }
104:
105: // Map return type mapping
106: if (outputMessage != null
107: && outputMessage.getParts().size() == 1) {
108: Part part = (Part) outputMessage.getParts().values()
109: .iterator().next();
110:
111: // return qname
112: if (part.getElementName() == null) {
113: operationInfo.returnQName = new QName(part.getName());
114: } else {
115: operationInfo.returnQName = part.getElementName();
116: }
117:
118: // return xml schema type
119: if (part.getTypeName() == null) {
120: operationInfo.returnXmlType = part.getElementName();
121: } else {
122: operationInfo.returnXmlType = part.getTypeName();
123: }
124:
125: // return java type
126: operationInfo.returnJavaType = method.getReturnType()
127: .getName();
128: }
129:
130: //TODO add faults
131: // TFault[] faults = tOperation.getFaultArray();
132: // for (int i = 0; i < faults.length; i++) {
133: // TFault fault = faults[i];
134: // QName faultQName = new QName("", fault.getName());
135: // String className = ;
136: // QName faultTypeQName = ;
137: // boolean isComplex = ;
138: // FaultDesc faultDesc = new FaultDesc(faultQName, className, faultTypeQName, isComplex)
139: // }
140: return operationInfo;
141: }
142: }
|