Java Code Examples for java.beans.MethodDescriptor#getMethod()

The following examples show how to use java.beans.MethodDescriptor#getMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrPluginUtils.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static Method findSetter(Class<?> clazz, String setterName, String key, Class<?> paramClazz, boolean lenient) {
  BeanInfo beanInfo;
  try {
    beanInfo = Introspector.getBeanInfo(clazz);
  } catch (IntrospectionException ie) {
    if (lenient) {
      return null;
    }
    throw new RuntimeException("Error getting bean info for class : " + clazz.getName(), ie);
  }
  for (final boolean matchParamClazz: new boolean[]{true, false}) {
    for (final MethodDescriptor desc : beanInfo.getMethodDescriptors()) {
      final Method m = desc.getMethod();
      final Class<?> p[] = m.getParameterTypes();
      if (m.getName().equals(setterName) && p.length == 1 &&
          (!matchParamClazz || paramClazz.equals(p[0]))) {
        return m;
      }
    }
  }
  if (lenient) {
    return null;
  }
  throw new RuntimeException("No setter corrresponding to '" + key + "' in " + clazz.getName());
}
 
Example 2
Source File: ExtendedBeanInfo.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
	List<Method> matches = new ArrayList<Method>();
	for (MethodDescriptor methodDescriptor : methodDescriptors) {
		Method method = methodDescriptor.getMethod();
		if (isCandidateWriteMethod(method)) {
			matches.add(method);
		}
	}
	// Sort non-void returning write methods to guard against the ill effects of
	// non-deterministic sorting of methods returned from Class#getDeclaredMethods
	// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
	Collections.sort(matches, new Comparator<Method>() {
		@Override
		public int compare(Method m1, Method m2) {
			return m2.toString().compareTo(m1.toString());
		}
	});
	return matches;
}
 
Example 3
Source File: ExtendedBeanInfo.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
	List<Method> matches = new ArrayList<Method>();
	for (MethodDescriptor methodDescriptor : methodDescriptors) {
		Method method = methodDescriptor.getMethod();
		if (isCandidateWriteMethod(method)) {
			matches.add(method);
		}
	}
	// Sort non-void returning write methods to guard against the ill effects of
	// non-deterministic sorting of methods returned from Class#getDeclaredMethods
	// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
	Collections.sort(matches, new Comparator<Method>() {
		@Override
		public int compare(Method m1, Method m2) {
			return m2.toString().compareTo(m1.toString());
		}
	});
	return matches;
}
 
Example 4
Source File: ExtendedBeanInfo.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
	List<Method> matches = new ArrayList<Method>();
	for (MethodDescriptor methodDescriptor : methodDescriptors) {
		Method method = methodDescriptor.getMethod();
		if (isCandidateWriteMethod(method)) {
			matches.add(method);
		}
	}
	// sort non-void returning write methods to guard against the ill effects of
	// non-deterministic sorting of methods returned from Class#getDeclaredMethods
	// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
	Collections.sort(matches, new Comparator<Method>() {
		@Override
		public int compare(Method m1, Method m2) {
			return m2.toString().compareTo(m1.toString());
		}
	});
	return matches;
}
 
Example 5
Source File: Test6277246.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 6
Source File: TaskNotifier.java    From mdw with Apache License 2.0 5 votes vote down vote up
private Method getIncidentSetter(String name) throws IntrospectionException {
    if (incidentBeanInfo == null) {
        incidentBeanInfo = Introspector.getBeanInfo(Incident.class);
    }
    for (MethodDescriptor md : incidentBeanInfo.getMethodDescriptors()) {
        if (name.equals(md.getName()))
            return md.getMethod();
    }
    return null;
}
 
Example 7
Source File: Test6277246.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 8
Source File: Test6277246.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 9
Source File: Test6277246.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 10
Source File: Test6277246.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 11
Source File: Test6277246.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 12
Source File: ExtendedBeanInfo.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
	List<Method> matches = new ArrayList<>();
	for (MethodDescriptor methodDescriptor : methodDescriptors) {
		Method method = methodDescriptor.getMethod();
		if (isCandidateWriteMethod(method)) {
			matches.add(method);
		}
	}
	// Sort non-void returning write methods to guard against the ill effects of
	// non-deterministic sorting of methods returned from Class#getDeclaredMethods
	// under JDK 7. See https://bugs.java.com/view_bug.do?bug_id=7023180
	matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
	return matches;
}
 
Example 13
Source File: Test6277246.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 14
Source File: Test6277246.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 15
Source File: Test6277246.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 16
Source File: Test6277246.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 17
Source File: Test6277246.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 18
Source File: Test6277246.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class type = BASE64Encoder.class;
    System.setSecurityManager(new SecurityManager());
    BeanInfo info = Introspector.getBeanInfo(type);
    for (MethodDescriptor md : info.getMethodDescriptors()) {
        Method method = md.getMethod();
        System.out.println(method);

        String name = method.getDeclaringClass().getName();
        if (name.startsWith("sun.misc.")) {
            throw new Error("found inaccessible method");
        }
    }
}
 
Example 19
Source File: Acl.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
/** Register an AclHandler.
 * All methods with the valid signature will be registered.
 * <pre>
 *     public boolean aclXXX(Object, String[])
 * </pre>
 * or
 * <pre>
 *     public static boolean aclXXX(Object, String[])
 * </pre>
 * Methods without the "acl" prefix are ignored. If a method begins
 * with the "acl" prefix but the method signature is invalid, a
 * warning is logged and the method is ignored.
 *
 * @param aclHandler AclHandler
 */
public void registerHandler(AclHandler aclHandler) {

    try {
        Class clazz = aclHandler.getClass();
        // find all the acl* methods. and store them
        BeanInfo info = Introspector.getBeanInfo(clazz);
        MethodDescriptor[] methodDescriptors = info.getMethodDescriptors();

        for (int i = 0; i < methodDescriptors.length; ++i) {

            MethodDescriptor methodDescriptor = methodDescriptors[i];
            String methodName = methodDescriptor.getName();

            // we only care about methods with signatures:
            // public boolean aclXXX(Object obj, String[] params);
            if (!methodName.startsWith(ACL_PREFIX)) {
                continue;
            }
            Method method = methodDescriptor.getMethod();
            Class[] params = method.getParameterTypes();
            if (!method.getReturnType().equals(Boolean.TYPE) ||
               method.getExceptionTypes().length > 0 ||
               params.length != 2 ||
               !params[0].equals(Object.class) ||
               !params[1].equals(String[].class)) {
               log.warn(LocalizationService.getInstance().getMessage(
                            "bad-signature", method.toString()));

               continue;

            }

            String aclName = methodNameToAclName(methodName);
            handlers.put(aclName,
                    new InstanceMethodPair(aclHandler, method));
        }
    }
    // from reading the javadocs for IntrospectionException,
    // dont' really expect to get this one
    catch (IntrospectionException e) {
        IllegalArgumentException exc = new IllegalArgumentException();
        exc.initCause(e);
        throw exc;
    }

}
 
Example 20
Source File: Acl.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
/** Register an AclHandler.
 * All methods with the valid signature will be registered.
 * <pre>
 *     public boolean aclXXX(Object, String[])
 * </pre>
 * or
 * <pre>
 *     public static boolean aclXXX(Object, String[])
 * </pre>
 * Methods without the "acl" prefix are ignored. If a method begins
 * with the "acl" prefix but the method signature is invalid, a
 * warning is logged and the method is ignored.
 *
 * @param aclHandler AclHandler
 */
public void registerHandler(AclHandler aclHandler) {

    try {
        Class clazz = aclHandler.getClass();
        // find all the acl* methods. and store them
        BeanInfo info = Introspector.getBeanInfo(clazz);
        MethodDescriptor[] methodDescriptors = info.getMethodDescriptors();

        for (int i = 0; i < methodDescriptors.length; ++i) {

            MethodDescriptor methodDescriptor = methodDescriptors[i];
            String methodName = methodDescriptor.getName();

            // we only care about methods with signatures:
            // public boolean aclXXX(Object obj, String[] params);
            if (!methodName.startsWith(ACL_PREFIX)) {
                continue;
            }
            Method method = methodDescriptor.getMethod();
            Class[] params = method.getParameterTypes();
            if (!method.getReturnType().equals(Boolean.TYPE) ||
               method.getExceptionTypes().length > 0 ||
               params.length != 2 ||
               !params[0].equals(Object.class) ||
               !params[1].equals(String[].class)) {
               log.warn(LocalizationService.getInstance().getMessage(
                            "bad-signature", method.toString()));

               continue;

            }

            String aclName = methodNameToAclName(methodName);
            handlers.put(aclName,
                    new InstanceMethodPair(aclHandler, method));
        }
    }
    // from reading the javadocs for IntrospectionException,
    // dont' really expect to get this one
    catch (IntrospectionException e) {
        IllegalArgumentException exc = new IllegalArgumentException();
        exc.initCause(e);
        throw exc;
    }

}