/** * Use reflection to configure Grizzly setter. */ private void configureProperties(){ for (String name : properties.keySet()) { String value = properties.get(name).toString(); IntrospectionUtils.setProperty(this, name, value); } }
/** * Construct a URL classpath from files in a directory, a cpath property, * and tools.jar. */ @SuppressWarnings("unchecked") public static URL[] getClassPath(String dir, String cpath, String cpathProp, boolean addTools) throws IOException, MalformedURLException { Vector<URL> jarsV = new Vector<URL>(); if (dir != null) { // Add dir/classes first, if it exists URL url = getURL(dir, "classes"); if (url != null) jarsV.addElement(url); addToClassPath(jarsV, dir); } if (cpath != null) addJarsFromClassPath(jarsV, cpath); if (cpathProp != null) { String cpath1 = System.getProperty(cpathProp); addJarsFromClassPath(jarsV, cpath1); } if (addTools) addToolsJar(jarsV); return getClassPath(jarsV); }
public static boolean processArgs(Object proxy, String args[]) throws Exception { String args0[] = null; if (null != findMethod(proxy.getClass(), "getOptions1", new Class[] {})) { args0 = (String[]) callMethod0(proxy, "getOptions1"); } if (args0 == null) { //args0=findVoidSetters(proxy.getClass()); args0 = findBooleanSetters(proxy.getClass()); } Hashtable h = null; if (null != findMethod(proxy.getClass(), "getOptionAliases", new Class[] {})) { h = (Hashtable) callMethod0(proxy, "getOptionAliases"); } return processArgs(proxy, args, args0, null, h); }
public static Object callMethod0(Object target, String methodN) throws Exception { if (target == null) { d("Assert: Illegal params " + target); return null; } if (dbg > 0) d("callMethod0 " + target.getClass().getName() + "." + methodN); Class params[] = new Class[0]; Method m = findMethod(target.getClass(), methodN, params); if (m == null) throw new NoSuchMethodException(target.getClass().getName() + " " + methodN); return m.invoke(target, emptyArray); }
d("setProperty(" + o.getClass() + " " + name + "=" + value + ")"); String setter = "set" + capitalize(name); Method methods[] = findMethods(o.getClass()); Method setPropertyMethodVoid = null; Method setPropertyMethodBool = null; params[0] = InetAddress.getByName(value); } catch (UnknownHostException exc) { d("Unable to resolve host name:" + value); ok = false; d("Unknown type " + paramType.getName());
@SuppressWarnings("unchecked") public static String[] findVoidSetters(Class c) { Method m[] = findMethods(c); if (m == null) return null; Vector v = new Vector(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 0) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = (String) v.elementAt(i); } return s; }
/** */ public static void setProperty(Object o, String name) { String setter = "set" + capitalize(name); try { Method methods[] = findMethods(o.getClass()); Method setPropertyMethod = null; // find setFoo() method for (int i = 0; i < methods.length; i++) { Class<?> paramT[] = methods[i].getParameterTypes(); if (setter.equals(methods[i].getName()) && paramT.length == 0) { methods[i].invoke(o, new Object[] {}); return; } } } catch (Exception ex1) { if (dbg > 0) d("Exception for " + o.getClass() + " " + name); if (dbg > 1) ex1.printStackTrace(); } }
/** * Call execute() - any ant-like task should work */ public static void execute(Object proxy, String method) throws Exception { Method executeM = null; Class c = proxy.getClass(); Class params[] = new Class[0]; // params[0]=args.getClass(); executeM = findMethod(c, method, params); if (executeM == null) { throw new RuntimeException("No execute in " + proxy.getClass()); } executeM.invoke(proxy, (Object[]) null);//new Object[] { args }); }
public static Method findMethod(Class<?> c, String name, Class<?> params[]) { Method methods[] = findMethods(c); if (methods == null) return null; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { Class<?> methodParams[] = methods[i].getParameterTypes(); if (methodParams == null) if (params == null || params.length == 0) return methods[i]; if (params == null) if (methodParams == null || methodParams.length == 0) return methods[i]; if (params.length != methodParams.length) continue; boolean found = true; for (int j = 0; j < params.length; j++) { if (params[j] != methodParams[j]) { found = false; break; } } if (found) return methods[i]; } } return null; }
public static Object callMethod0(Object target, String methodN) throws Exception { if (target == null) { d("Assert: Illegal params " + target); return null; } if (dbg > 0) d("callMethod0 " + target.getClass().getName() + "." + methodN); Class params[] = new Class[0]; Method m = findMethod(target.getClass(), methodN, params); if (m == null) throw new NoSuchMethodException(target.getClass().getName() + " " + methodN); return m.invoke(target, emptyArray); }
d("setProperty(" + o.getClass() + " " + name + "=" + value + ")"); String setter = "set" + capitalize(name); Method methods[] = findMethods(o.getClass()); Method setPropertyMethodVoid = null; Method setPropertyMethodBool = null; params[0] = InetAddress.getByName(value); } catch (UnknownHostException exc) { d("Unable to resolve host name:" + value); ok = false; d("Unknown type " + paramType.getName());
@SuppressWarnings("unchecked") public static String[] findVoidSetters(Class c) { Method m[] = findMethods(c); if (m == null) return null; Vector v = new Vector(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 0) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = (String) v.elementAt(i); } return s; }
/** */ public static void setProperty(Object o, String name) { String setter = "set" + capitalize(name); try { Method methods[] = findMethods(o.getClass()); Method setPropertyMethod = null; // find setFoo() method for (int i = 0; i < methods.length; i++) { Class paramT[] = methods[i].getParameterTypes(); if (setter.equals(methods[i].getName()) && paramT.length == 0) { methods[i].invoke(o, new Object[] {}); return; } } } catch (Exception ex1) { if (dbg > 0) d("Exception for " + o.getClass() + " " + name); if (dbg > 1) ex1.printStackTrace(); } }
/** * Call execute() - any ant-like task should work */ public static void execute(Object proxy, String method) throws Exception { Method executeM = null; Class<?> c = proxy.getClass(); Class<?> params[] = new Class[0]; // params[0]=args.getClass(); executeM = findMethod(c, method, params); if (executeM == null) { throw new RuntimeException("No execute in " + proxy.getClass()); } executeM.invoke(proxy, (Object[]) null);//new Object[] { args }); }
public static Method findMethod(Class c, String name, Class params[]) { Method methods[] = findMethods(c); if (methods == null) return null; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { Class methodParams[] = methods[i].getParameterTypes(); if (methodParams == null) if (params == null || params.length == 0) return methods[i]; if (params == null) if (methodParams == null || methodParams.length == 0) return methods[i]; if (params.length != methodParams.length) continue; boolean found = true; for (int j = 0; j < params.length; j++) { if (params[j] != methodParams[j]) { found = false; break; } } if (found) return methods[i]; } } return null; }
/** * Construct a URL classpath from files in a directory, a cpath property, * and tools.jar. */ @SuppressWarnings("unchecked") public static URL[] getClassPath(String dir, String cpath, String cpathProp, boolean addTools) throws IOException, MalformedURLException { Vector jarsV = new Vector(); if (dir != null) { // Add dir/classes first, if it exists URL url = getURL(dir, "classes"); if (url != null) jarsV.addElement(url); addToClassPath(jarsV, dir); } if (cpath != null) addJarsFromClassPath(jarsV, cpath); if (cpathProp != null) { String cpath1 = System.getProperty(cpathProp); addJarsFromClassPath(jarsV, cpath1); } if (addTools) addToolsJar(jarsV); return getClassPath(jarsV); }
public static boolean processArgs(Object proxy, String args[]) throws Exception { String args0[] = null; if (null != findMethod(proxy.getClass(), "getOptions1", new Class[] {})) { args0 = (String[]) callMethod0(proxy, "getOptions1"); } if (args0 == null) { //args0=findVoidSetters(proxy.getClass()); args0 = findBooleanSetters(proxy.getClass()); } Hashtable h = null; if (null != findMethod(proxy.getClass(), "getOptionAliases", new Class[] {})) { h = (Hashtable) callMethod0(proxy, "getOptionAliases"); } return processArgs(proxy, args, args0, null, h); }
/** * Use reflection to configure Object setter. * * @param object Populate this object with available properties. */ private void configureProperties(Object object){ for (String s : properties.keySet()) { String value = properties.get(s).toString(); IntrospectionUtils.setProperty(object, s, value); } }