private Class<?> findClassInPaths(List<String> paths, String... classNames) { Class<?> k = null; for (int i = 0; i < classNames.length && k == null; i++) k = findClassInPaths(paths, classNames[i]); return k; }
private Method findMatchingMethod(String[] methodNames, Method[] methods, int nArgs) { Method method = null; for (int i = 0; i < methodNames.length && method == null; i++) method = findMatchingMethod(methodNames[i], methods, nArgs); return method; }
protected Class<?> handleClassCacheMiss(String className) { return super.getClass(className); }
@Override public Object createInstance(List<String> paths, String className, Object[] args) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class<?> k = searchPathsForClass(paths, className); Constructor<?> constructor = getConstructor(k, args); if (constructor == null) { throw new SlimError(String.format("message:<<%s %s>>", SlimServer.NO_CONSTRUCTOR, className)); } return newInstance(args, constructor); }
final Object[] convertedArgs = getConvertedConstructorArgsTypes(constructor, args); final boolean matchedConstructorArgsTypes = hasConstructorArgsTypes(constructorArgs, convertedArgs); if (matchedConstructorArgsTypes) { currentDiffCounter = getConstructorArgsConvertionDiff(args, convertedArgs);
@Override public MethodExecutionResult findAndInvoke(String methodName, Object instance, Object... args) throws Throwable { Method method = findMatchingMethod(methodName, instance, args); if (method != null) { return this.invokeMethod(instance, method, args); } return MethodExecutionResult.noMethod(methodName, instance.getClass(), args.length); }
protected MethodExecutionResult invokeMethod(Object instance, Method method, Object[] args) throws Throwable { Object[] convertedArgs = convertArgs(method, args); Object retval = callMethod(instance, method, convertedArgs); Class<?> retType = method.getReturnType(); return new MethodExecutionResult(retval, retType); }
protected Class<?> searchPathsForClass(List<String> paths, String className) { Class<?> k = getClass(className); if (k == null) k = findClassInPaths(paths, className, swapCaseOfFirstLetter(className)); if (k != null) return k; else throw new SlimError(String.format("message:<<%s %s>>", SlimServer.NO_CLASS, className)); }
protected Constructor<?> handleConstructorCacheMiss(Class<?> clazz, Object[] args) { return super.getConstructor(clazz, args); }
protected Method handleMethodCacheMiss(String methodName, Object instance, Object[] args) { return super.findMatchingMethod(methodName, instance, args); }
private Class<?> findClassInPaths(List<String> paths, String className) { Class<?> k = null; for (int i = 0; i < paths.size() && k == null; i++) k = getClass(paths.get(i) + "." + className); return k; }
protected Method findMatchingMethod(String methodName, Object instance, Object... args) { String[] methodNames = new String[]{methodName, swapCaseOfFirstLetter(methodName)}; return findMatchingMethod(methodNames, instance.getClass().getMethods(), args.length); }