*
* @param args the Java object arguments to the WS operation
* @return the response from the WS as a Java object
*/
public Object invokeTarget(final Object args) throws InvocationTargetException {
WSDLOperationInfo opInfo = wsdlCache.getOperationInfo(operationName);
if (opInfo == null) {
// REVISIT - really map the operation name to a WSDL operation
for (String opName : wsdlCache.getAllOperationInfo().keySet()) {
if (operationName.equalsIgnoreCase(opName)) {
opInfo = wsdlCache.getOperationInfo(opName);
break;
}
}
}
ObjectMessageContext objMsgContext = clientBinding.createObjectContext();
boolean hasInOut = false;
int inOutCount = 0;
Object realArgs[];
Object argsArray[];
if (args.getClass().isArray()) {
argsArray = (Object[]) args;
realArgs = new Object[Array.getLength(args)];
} else {
argsArray = new Object[0];
realArgs = new Object[0];
}
if (opInfo.getParamsLength() == 0) {
// REVISIT - opInfo doesn't return the needed info for the wrapped doc/lit case.
// Bug in Celtix
realArgs = argsArray;
} else {
for (int x = 0; x < argsArray.length; x++) {
if (opInfo.getWebParam(x).mode() == WebParam.Mode.IN) {
realArgs[x] = argsArray[x];
} else {
realArgs[x] = new Holder<Object>(argsArray[x]);
inOutCount++;
hasInOut = true;
}
}
}
objMsgContext.setMessageObjects(realArgs);
boolean isOneway = opInfo.isOneWay();
DataBindingCallback callback = new SCADataBindingCallback(opInfo, hasInOut, typeHelper);
try {
if (isOneway) {
clientBinding.invokeOneWay(objMsgContext, callback);
} else {
objMsgContext = clientBinding.invoke(objMsgContext, callback);
}
} catch (IOException e) {
throw new InvocationTargetException(e);
}
if (objMsgContext.getException() != null) {
// REVISIT - Exceptions
/*
* if (isValidException(objMsgContext)) { throw
* (Exception)objMsgContext.getException(); } else { throw new
* ProtocolException(objMsgContext.getException()); }
*/
throw new InvocationTargetException(objMsgContext.getException());
}
if (hasInOut) {
Object ret[] = new Object[inOutCount + 1];
ret[0] = objMsgContext.getReturn();
inOutCount = 1;
for (int x = 0; x < argsArray.length; x++) {
if (opInfo.getWebParam(x).mode() != WebParam.Mode.IN) {
Holder<?> holder = (Holder<?>) realArgs[x];
ret[inOutCount] = holder.value;
inOutCount++;
}
}