int i;
for (i = 0; i < allMethods.length; i++)
if (allMethods[i].equals(method))
break;
if (i >= allMethods.length || !method.equals(allMethods[i]))
throw new WSIFException(
"Method "
+ method.getName()
+ " is not in interface "
+ iface.getName());
String methodName = method.getName();
Class[] types = method.getParameterTypes();
List opList = portType.getOperations();
Iterator opIt = opList.iterator();
Operation matchingOperation = null;
// First try to find this method in the portType's list of operations.
// Be careful of overloaded operations.
while (opIt.hasNext()) {
Operation operation = (Operation) opIt.next();
// If the method name doesn't match the operation name this isn't the operation
if (!methodName.equalsIgnoreCase(operation.getName()))
continue;
Input input = operation.getInput();
Message inputMessage = (input == null) ? null : input.getMessage();
List inputParts = (inputMessage == null)
? new ArrayList()
: inputMessage.getOrderedParts(null);
int numInputParts = inputParts.size();
// Check for a match if neither args nor the operation has any parameters
if (numInputParts == 0 && types.length == 0) {
wsdlOperationTable.put(key, operation);
return operation;
}
// No match if there are different numbers of parameters
if (types != null && (numInputParts != types.length)) {
unWrapIfWrappedDocLit(inputParts, operation.getName());
numInputParts = inputParts.size();
if (numInputParts != types.length) {
continue;
}
}
// Go through all the parameters making sure all their datatypes match
Iterator partIt = inputParts.iterator();
boolean foundAllArgs = true;
boolean exactMatchAllArgs = true;
for (int argIndex = 0;
partIt.hasNext() && foundAllArgs;
argIndex++) {
Part part = (Part) partIt.next();
QName partTypeName = part.getTypeName();
if (partTypeName==null) {
partTypeName = part.getElementName();
}
/* for wrapped document literal operations AXIS uses a wrapper
* element class with ">" prefixed to the namespace local part
*/
QName partTypeNameWrapped =
new QName(partTypeName.getNamespaceURI(), ">" + partTypeName.getLocalPart());
boolean foundThisArg = false;
boolean exactMatchThisArg = false;
// Look this parameter up in the typeMap.
for (Iterator mapIt = typeMap.iterator();
mapIt.hasNext() && !foundThisArg;
) {
WSIFDynamicTypeMapping mapping =
(WSIFDynamicTypeMapping) mapIt.next();
if (mapping.getXmlType().equals(partTypeName)
|| (mapping.getXmlType().equals(partTypeNameWrapped))) {
if (mapping
.getJavaType()
.isAssignableFrom(types[argIndex])
|| (args[argIndex] != null
&& mapping.getJavaType().isAssignableFrom(
args[argIndex].getClass()))) {
foundThisArg = true;
if (mapping.getJavaType().equals(types[argIndex])
|| (args[argIndex] != null
&& mapping.getJavaType().equals(
args[argIndex].getClass())))
exactMatchThisArg = true;
} else
break;
}
}
// Look for a simple type that matches
TypeMapping tm =
(TypeMapping) (simpleTypeReg.get(partTypeName));
if (!foundThisArg) {
if (tm != null) {
String simpleType = tm.javaType;
if (types[argIndex].toString().equals(simpleType)) {
// this works for simple types (float, int)
foundThisArg = true;
exactMatchThisArg = true;
} else
try // this works for String, Date
{
Class simpleClass =
Class.forName(
simpleType,
true,
Thread
.currentThread()
.getContextClassLoader());
if (simpleClass
.isAssignableFrom(types[argIndex])) {
foundThisArg = true;
if (simpleClass.equals(types[argIndex]))
exactMatchThisArg = true;
}
} catch (ClassNotFoundException ignored) {
Trc.ignoredException(ignored);
}
} else if (types[argIndex].equals(DataHandler.class))
// There is no (simple or complex) type mapping for
// this argument. If it's a DataHandler, then assume
// it's a mime type, since we do automatic registering
// of DataHandlers for Mime types. We should really look
// in the WSDL binding to make sure it is a mime part.
foundThisArg = true;
}
if (!foundThisArg)
foundAllArgs = false;
if (!exactMatchThisArg)
exactMatchAllArgs = false;
}
if (foundAllArgs) {
if (exactMatchAllArgs) {
wsdlOperationTable.put(key, operation);
return operation;
}
// if matchingOperation!=null then write trace statement.
matchingOperation = operation;
}
} // end while
if (matchingOperation != null) {
wsdlOperationTable.put(key, matchingOperation);
return matchingOperation;
}
// if we get here then we haven't found a matching operation
String argString = new String();
if (types != null)
for (i = 0; i < types.length; i++) {
if (i != 0)
argString += ", ";
argString += types[i];
}
throw new WSIFException(
"Method "
+ methodName
+ "("
+ argString
+ ") was not found in portType "