try {
Object result = null;
// Need to get the stuff here because this also initializes fieldInParameterNames
if (fieldIsConstructor) {
if (fieldConstructors.length <= 0)
throw new WSIFException("No constructors found that match the parts specified");
} else {
if (fieldMethods.length <= 0)
throw new WSIFException("No methods named '"
+ fieldJavaOperationModel.getMethodName()
+ "' found that match the parts specified");
}
Object[] arguments = null;
Object part = null;
if ((fieldInParameterNames != null) && (fieldInParameterNames.length > 0)) {
arguments = new Object[fieldInParameterNames.length];
for (int i = 0; i < fieldInParameterNames.length; i++) {
try {
part = input.getObjectPart(fieldInParameterNames[i]);
arguments[i] = part;
} catch (WSIFException e) {
Trc.exception(e);
arguments[i] = null;
}
}
}
boolean invokedOK = false;
if (fieldIsConstructor) {
for (int a = 0; a < fieldConstructors.length; a++) {
try {
// Get a set of arguments which are compatible with the ctor
Object[] compatibleArguments =
getCompatibleArguments(fieldConstructors[a].getParameterTypes(), arguments);
// If we didn't get any arguments then the parts aren't compatible with the ctor
if (compatibleArguments == null)
break;
// Parts are compatible so invoke the ctor with the compatible set
Trc.event(
this,
"Invoking constructor ",
fieldConstructors[a],
" with arguments ",
compatibleArguments);
result =
fieldConstructors[a].newInstance(
compatibleArguments);
Trc.event(
this,
"Returned from constructor, result is ",
result);
fieldPort.setObjectReference(result);
invokedOK = true;
break;
} catch (IllegalArgumentException ia) {
Trc.ignoredException(ia);
// Ignore and try next constructor
}
}
if (!invokedOK)
throw new WSIFException("Failed to call constructor for object in Java operation");
} else {
if (fieldIsStatic) {
for (int a = 0; a < fieldMethods.length; a++) {
try {
// Get a set of arguments which are compatible with the method
Object[] compatibleArguments =
getCompatibleArguments(fieldMethods[a].getParameterTypes(), arguments);
// If we didn't get any arguments then the parts aren't compatible with the method
if (compatibleArguments == null)
break;
// Parts are compatible so invoke the method with the compatible set
Trc.event(
this,
"Invoking method ",
fieldMethods[a],
" with arguments ",
compatibleArguments);
result =
fieldMethods[a].invoke(
null,
compatibleArguments);
Trc.event(
this,
"Returned from method, result is ",
result);
invokedOK = true;
break;
} catch (IllegalArgumentException ia) {
Trc.ignoredException(ia);
// Ignore and try next method
}
}
if (!invokedOK)
throw new WSIFException(
"Failed to invoke method '" + fieldJavaOperationModel.getMethodName() + "'");
} else {
for (int a = 0; a < fieldMethods.length; a++) {
try {
// Get a set of arguments which are compatible with the method
Object[] compatibleArguments =
getCompatibleArguments(fieldMethods[a].getParameterTypes(), arguments);
// If we didn't get any arguments then the parts aren't compatible with the method
if (compatibleArguments == null)
break;
// Parts are compatible so invoke the method with the compatible set
Object objRef = fieldPort.getObjectReference();
Trc.event(
this,
"Invoking object ",
objRef,
" method ",
fieldMethods[a],
" with arguments ",
compatibleArguments);
result =
fieldMethods[a].invoke(
objRef,
compatibleArguments);
Trc.event(
this,
"Returned from method, result is ",
result);
invokedOK = true;
break;
} catch (IllegalArgumentException ia) {
Trc.ignoredException(ia);
// Ignore and try next method
}
}
if (!invokedOK)
throw new WSIFException(
"Failed to invoke method '" + fieldJavaOperationModel.getMethodName() + "'");
}
}
} catch (InvocationTargetException ex) {
Trc.exception(ex);
// Log message
MessageLogger.log(
"WSIF.0005E",
"Java",
fieldJavaOperationModel.getMethodName());
throw new WSIFException(
this
+ " : Invocation of '"
+ fieldJavaOperationModel.getMethodName()
+ "' failed.",
ex);
} catch (Exception ex) {
Trc.exception(ex);
// Log message
MessageLogger.log(
"WSIF.0005E",
"Java",
fieldJavaOperationModel.getMethodName());
throw new WSIFException(
this
+ " : Could not invoke '"
+ fieldJavaOperationModel.getMethodName()
+ "'",
ex);