List of usage examples for java.lang.reflect Method getName
@Override
public String getName()
From source file:com.tealeaf.plugin.PluginEvent.java
private static String invokeMethod(Object targetObject, Object[] parameters, String methodName, String className) {/*from www . j ava 2 s .co m*/ String retStr = "{}"; if (targetObject == null) { logger.log("{plugins} WARNING: Event could not be delivered for missing plugin:", className); return retStr; } boolean found = false; for (Method method : targetObject.getClass().getMethods()) { if (!method.getName().equals(methodName)) { continue; } Class<?>[] parameterTypes = method.getParameterTypes(); boolean match = true; for (int i = 0; i < parameterTypes.length; i++) { if (parameters[i] == null) { continue; } if (!parameterTypes[i].isAssignableFrom(parameters[i].getClass())) { match = false; break; } } if (!match && parameters.length != 0) { try { // try and coerce string argument in the first place to a JSONObject if (parameters[0] instanceof String) { JSONObject arg = new JSONObject((String) parameters[0]); parameters[0] = arg; if (parameterTypes[0].isAssignableFrom(parameters[0].getClass())) { match = true; } } } catch (JSONException e) { // first param is not valid JSON. Pass. } } if (match) { try { if (method.getReturnType().equals(Void.TYPE)) { method.invoke(targetObject, parameters); } else if (method.getReturnType().equals(String.class)) { retStr = (String) method.invoke(targetObject, parameters); } else { retStr = "" + method.invoke(targetObject, parameters); } found = true; } catch (IllegalArgumentException e) { logger.log(e); } catch (IllegalAccessException e) { logger.log(e); } catch (InvocationTargetException e) { logger.log(e); } } } if (!found) { logger.log("{plugins} WARNING: Unknown event could not be delivered for plugin:", className, ", method:", methodName); } if (retStr == null) { retStr = "{}"; } return retStr; }
From source file:com.p5solutions.trackstate.utils.TrackStateUtility.java
/** * Expose real method./*from w w w. j av a 2 s . c o m*/ * * @param method * the method * @param target * the target * @return the method */ public static Method exposeRealMethod(Method method, Object target) { if (method == null) { return null; } String name = method.getName(); if (hasTrackStateProxy(target)) { TrackStateProxy proxy = (TrackStateProxy) target; Class<?> clazz = proxy.getTarget().getClass(); return ReflectionUtility.findMethod(clazz, name); } return method; }
From source file:com.jerrellmardis.amphitheatre.util.Utils.java
public static int getPaletteColor(Palette palette, String colorType, int defaultColor) { if (colorType.equals("")) { return defaultColor; }//from ww w . j a v a 2 s . c o m Method[] paletteMethods = palette.getClass().getDeclaredMethods(); for (Method method : paletteMethods) { if (StringUtils.containsIgnoreCase(method.getName(), colorType)) { try { Palette.Swatch item = (Palette.Swatch) method.invoke(palette); if (item != null) { return item.getRgb(); } else { return defaultColor; } } catch (Exception ex) { Log.d("getPaletteColor", ex.getMessage()); return defaultColor; } } } return defaultColor; }
From source file:com.sun.socialsite.util.DebugBeanJsonConverter.java
private static String getPropertyName(Method method) { JsonProperty property = method.getAnnotation(JsonProperty.class); if (property == null) { String name = method.getName(); if (name.startsWith("set")) { return name.substring(3, 4).toLowerCase() + name.substring(4); }/* ww w . ja v a 2 s .c o m*/ return null; } else { return property.value(); } }
From source file:edu.washington.cs.mystatus.odk.database.ODKSQLiteOpenHelper.java
private static boolean check_sqlcipher_uses_native_key() { for (Method method : SQLiteDatabase.class.getDeclaredMethods()) { if (method.getName().equals("native_key")) return true; }/* ww w. j a v a 2s . c om*/ return false; }
From source file:fi.foyt.foursquare.api.JSONFieldParser.java
/** * Returns setter method for a field// w ww .j a v a 2 s.c om * * @param entityClass class * @param fieldName field * @return setter method for a field */ private static Method getSetterMethod(Class<?> entityClass, String fieldName) { StringBuilder methodNameBuilder = new StringBuilder(); methodNameBuilder.append("set"); methodNameBuilder.append(Character.toUpperCase(fieldName.charAt(0))); methodNameBuilder.append(fieldName.substring(1)); String methodName = methodNameBuilder.toString(); List<Method> methods = getMethods(entityClass); for (Method method : methods) { if (method.getName().equals(methodName)) { return method; } } return null; }
From source file:info.donsun.core.utils.Reflections.java
/** * ?, ?DeclaredMethod,?. ?Object?, null. ???? * //from ww w . ja v a 2 s.co m * ?. ?Method,?Method.invoke(Object obj, Object... * args) */ public static Method getAccessibleMethodByName(final Class<?> clazz, final String methodName) { Validate.notNull(clazz, "clazz can't be null"); Validate.notBlank(methodName, "methodName can't be blank"); for (Class<?> searchType = clazz; searchType != Object.class; searchType = searchType.getSuperclass()) { Method[] methods = searchType.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(methodName)) { makeAccessible(method); return method; } } } return null; }
From source file:org.fusesource.meshkeeper.util.internal.IntrospectionSupport.java
private static Method findSetterMethod(Class<?> clazz, String name) { // Build the method name. name = "set" + name.substring(0, 1).toUpperCase() + name.substring(1); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; Class<?> params[] = method.getParameterTypes(); if (method.getName().equals(name) && params.length == 1) { return method; }//from w w w . ja va 2 s . com } return null; }
From source file:com.google.gdt.eclipse.designer.ie.util.ReflectionUtils.java
/** * Returns the {@link Method} defined in {@link Class} (exactly). * //from w w w. j a v a 2 s . c o m * @see #getMethodBySignature(Class, String). */ private static Method getMethodBySignature0(Class<?> clazz, String signatureName, String signature) { for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals(signatureName) && getMethodSignature(method).equals(signature)) { method.setAccessible(true); return method; } } // not found return null; }
From source file:nz.co.senanque.validationengine.ValidationUtils.java
public static Map<String, Property> getProperties(Class<? extends ValidationObject> class1) { Map<String, Property> ret = new HashMap<>(class1.getMethods().length); for (Method method : class1.getMethods()) { final String fieldName = ValidationUtils.getFieldNameFromGetterMethodName(method.getName()); if (!ValidationUtils.isUsefulField(fieldName, null)) { continue; }// w w w. ja va2 s. c o m Method getter = ValidationUtils.figureGetter(fieldName, class1); if (getter.isAnnotationPresent(Ignore.class)) { continue; } Method setter = ValidationUtils.figureSetter(fieldName, class1); ret.put(fieldName, new Property(fieldName, getter, setter, class1)); } return ret; }