public RemoteReturn delegateCall(RemoteCall remoteCall) throws LipeRMIException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException {
Object implementator = exportedObjects.get(remoteCall.getRemoteInstance());
if (implementator == null)
throw new LipeRMIException(String.format("Class %s doesn't have implementation", remoteCall.getRemoteInstance().getClassName())); //$NON-NLS-1$
RemoteReturn remoteReturn;
Method implementationMethod = null;
for (Method method : implementator.getClass().getMethods()) {
String implementationMethodId = method.toString();
implementationMethodId = implementationMethodId.replace(implementator.getClass().getName(), remoteCall.getRemoteInstance().getClassName());
if (implementationMethodId.endsWith(remoteCall.getMethodId())) {
implementationMethod = method;
break;
}
}
if (implementationMethod == null)
throw new NoSuchMethodException(remoteCall.getMethodId());
try {
Object methodReturn = null;
implementationMethod.setAccessible(true);
methodReturn = implementationMethod.invoke(implementator, remoteCall.getArgs());
if (exportedObjects.containsValue(methodReturn))
methodReturn = getRemoteReference(methodReturn);
remoteReturn = new RemoteReturn(false, methodReturn, remoteCall.getCallId());
} catch (InvocationTargetException e) {
remoteReturn = new RemoteReturn(true, e, remoteCall.getCallId());
}
return remoteReturn;
}