下面列出了java.beans.MethodDescriptor#getMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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;
}
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;
}
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());
}
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;
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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;
}
/** 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;
}
}
/** 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;
}
}