class MethodInvoker {

	public Object invoke(Object obj, Object[] arguments) {
		Object returnObject = null;

		try {
			Object[] newArguments = arguments;

			if (converters != null) {
				int size = arguments.length;
				newArguments = new Object[size];
				for (int i = 0; i < size; i++) {
					newArguments[i] = converters.get(i).convert(arguments[i]);
				}
			}
			if (method != null) {
				AccessController.doPrivileged(new PrivilegedAction<Object>() {
					public Object run() {
						method.setAccessible(true);
						return null;
					}
				});
				returnObject = method.invoke(obj, newArguments);
			} else if (constructor != null) {
				constructor.setAccessible(true);
				returnObject = constructor.newInstance(newArguments);
			}
		} catch (InvocationTargetException ie) {
			logger.log(Level.WARNING, "Exception occurred in client code.", ie);
			throw new Py4JJavaException(ie.getCause());
		} catch (Exception e) {
			logger.log(Level.WARNING, "Could not invoke method or received an exception while invoking.", e);
			throw new Py4JException(e);
		}

		return returnObject;
	}

	public  MethodInvoker(Constructor<?> constructor, TypeConverter[] converters, int cost);
	public  MethodInvoker(Method method, TypeConverter[] converters, int cost);

}