protected InputStream getMyBatisXmlConfigurationSteam() { return ReflectUtil.getResourceAsStream(DEFAULT_MYBATIS_MAPPING_FILE); }
public static void applyProperty(Object configuration, String key, String stringValue) { Class<?> configurationClass = configuration.getClass(); Method setter = ReflectUtil.getSingleSetter(key, configurationClass); if(setter != null) { try { Class<?> parameterClass = setter.getParameterTypes()[0]; Object value = PropertyHelper.convertToClass(stringValue, parameterClass); setter.invoke(configuration, value); } catch (Exception e) { throw LOG.cannotSetValueForProperty(key, configurationClass.getCanonicalName(), e); } } else { throw LOG.cannotFindSetterForProperty(key, configurationClass.getCanonicalName()); } }
protected <T> T createInstance(Class<? extends T> clazz) { return ReflectUtil.instantiate(clazz); }
private static Method findMethod(Class< ? extends Object> clazz, String methodName, Object[] args) { for (Method method : clazz.getDeclaredMethods()) { // TODO add parameter matching if ( method.getName().equals(methodName) && matches(method.getParameterTypes(), args) ) { return method; } } Class< ? > superClass = clazz.getSuperclass(); if (superClass!=null) { return findMethod(superClass, methodName, args); } return null; }
public static Object instantiate(String className, Object[] args) { Class<?> clazz = loadClass(className); Constructor<?> constructor = findMatchingConstructor(clazz, args); ensureNotNull("couldn't find constructor for " + className + " with args " + Arrays.asList(args), "constructor", constructor); try { return constructor.newInstance(args); } catch (Exception e) { throw LOG.exceptionWhileInstantiatingClass(className, e); } }
ClassLoader classLoader = ReflectUtil.getClassLoader(); Enumeration<URL> resources = null; try {
@SuppressWarnings("unchecked") public GenericManagerFactory(String classname) { managerImplementation = (Class<? extends Session>) ReflectUtil.loadClass(classname); }
protected void createMethodBindings() { Class<?> spinClass = Spin.class; SPIN_FUNCTION_MAP.put("S", ReflectUtil.getMethod(spinClass, "S", Object.class)); SPIN_FUNCTION_MAP.put("XML", ReflectUtil.getMethod(spinClass, "XML", Object.class)); SPIN_FUNCTION_MAP.put("JSON", ReflectUtil.getMethod(spinClass, "JSON", Object.class)); }
public static ClassLoader getClassLoader() { ClassLoader loader = getCustomClassLoader(); if(loader == null) { loader = Thread.currentThread().getContextClassLoader(); } return loader; }
/** * Finds a method by name and parameter types. * * @param declaringType the name of the class * @param methodName the name of the method to look for * @param parameterTypes the types of the parameters */ public static Method getMethod(Class<?> declaringType, String methodName, Class<?>... parameterTypes) { return findMethod(declaringType, methodName, parameterTypes); } }
/** * Returns the setter-method for the given field name or null if no setter exists. */ public static Method getSetter(String fieldName, Class<?> clazz, Class<?> fieldType) { String setterName = buildSetterName(fieldName); try { // Using getMathods(), getMathod(...) expects exact parameter type // matching and ignores inheritance-tree. Method[] methods = clazz.getMethods(); for(Method method : methods) { if(method.getName().equals(setterName)) { Class<?>[] paramTypes = method.getParameterTypes(); if(paramTypes != null && paramTypes.length == 1 && paramTypes[0].isAssignableFrom(fieldType)) { return method; } } } return null; } catch (SecurityException e) { throw LOG.unableToAccessMethod(setterName, clazz.getName()); } }
ClassLoader classLoader = ReflectUtil.getClassLoader(); Enumeration<URL> resources = null; try {
@SuppressWarnings("unchecked") public GenericManagerFactory(String classname) { managerImplementation = (Class<? extends Session>) ReflectUtil.loadClass(classname); }
public static Object instantiate(String className, Object[] args) { Class<?> clazz = loadClass(className); Constructor<?> constructor = findMatchingConstructor(clazz, args); ensureNotNull("couldn't find constructor for " + className + " with args " + Arrays.asList(args), "constructor", constructor); try { return constructor.newInstance(args); } catch (Exception e) { throw LOG.exceptionWhileInstantiatingClass(className, e); } }
public static ClassLoader getClassLoader() { ClassLoader loader = getCustomClassLoader(); if(loader == null) { loader = Thread.currentThread().getContextClassLoader(); } return loader; }
private static Method findMethod(Class< ? extends Object> clazz, String methodName, Object[] args) { for (Method method : clazz.getDeclaredMethods()) { // TODO add parameter matching if ( method.getName().equals(methodName) && matches(method.getParameterTypes(), args) ) { return method; } } Class< ? > superClass = clazz.getSuperclass(); if (superClass!=null) { return findMethod(superClass, methodName, args); } return null; }
/** * Finds a method by name and parameter types. * * @param declaringType the name of the class * @param methodName the name of the method to look for * @param parameterTypes the types of the parameters */ public static Method getMethod(Class<?> declaringType, String methodName, Class<?>... parameterTypes) { return findMethod(declaringType, methodName, parameterTypes); } }
/** * Returns the setter-method for the given field name or null if no setter exists. */ public static Method getSetter(String fieldName, Class<?> clazz, Class<?> fieldType) { String setterName = buildSetterName(fieldName); try { // Using getMathods(), getMathod(...) expects exact parameter type // matching and ignores inheritance-tree. Method[] methods = clazz.getMethods(); for(Method method : methods) { if(method.getName().equals(setterName)) { Class<?>[] paramTypes = method.getParameterTypes(); if(paramTypes != null && paramTypes.length == 1 && paramTypes[0].isAssignableFrom(fieldType)) { return method; } } } return null; } catch (SecurityException e) { throw LOG.unableToAccessMethod(setterName, clazz.getName()); } }
protected InputStream getMyBatisXmlConfigurationSteam() { return ReflectUtil.getResourceAsStream(DEFAULT_MYBATIS_MAPPING_FILE); }