java.beans.BeanInfo#getMethodDescriptors ( )源码实例Demo

下面列出了java.beans.BeanInfo#getMethodDescriptors ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: IntrospectorTest.java
public void testBeanInfo_1() throws IntrospectionException {
    Class<FakeFox011> beanClass = FakeFox011.class;
    BeanInfo info = Introspector.getBeanInfo(beanClass);
    assertNull(info.getAdditionalBeanInfo());
    BeanDescriptor beanDesc = info.getBeanDescriptor();
    assertEquals("FakeFox011", beanDesc.getName());
    assertEquals(0, info.getEventSetDescriptors().length);
    assertEquals(-1, info.getDefaultEventIndex());
    assertEquals(0, info.getDefaultPropertyIndex());

    MethodDescriptor[] methodDesc = info.getMethodDescriptors();

    assertEquals(4, methodDesc.length);

    PropertyDescriptor[] propertyDesc = info.getPropertyDescriptors();
    assertEquals(2, propertyDesc.length);
    for (PropertyDescriptor element : propertyDesc) {
        if (element.getName().equals("class")) {
            assertNull(element.getWriteMethod());
            assertNotNull(element.getReadMethod());
        }
    }
}
 
源代码2 项目: tsml   文件: ClusterEvaluation.java
/**
 * Return the global info (if it exists) for the supplied clusterer
 * 
 * @param clusterer the clusterer to get the global info for
 * @return the global info (synopsis) for the clusterer
 * @throws Exception if there is a problem reflecting on the clusterer
 */
protected static String getGlobalInfo(Clusterer clusterer) throws Exception {
  BeanInfo bi = Introspector.getBeanInfo(clusterer.getClass());
  MethodDescriptor[] methods;
  methods = bi.getMethodDescriptors();
  Object[] args = {};
  String result = "\nSynopsis for " + clusterer.getClass().getName()
    + ":\n\n";
  
  for (int i = 0; i < methods.length; i++) {
    String name = methods[i].getDisplayName();
    Method meth = methods[i].getMethod();
    if (name.equals("globalInfo")) {
      String globalInfo = (String)(meth.invoke(clusterer, args));
      result += globalInfo;
      break;
    }
  }
  
  return result;
}
 
源代码3 项目: tsml   文件: Evaluation.java
/**
 * Return the global info (if it exists) for the supplied classifier.
 * 
 * @param classifier the classifier to get the global info for
 * @return the global info (synopsis) for the classifier
 * @throws Exception if there is a problem reflecting on the classifier
 */
protected static String getGlobalInfo(Classifier classifier) throws Exception {
  BeanInfo bi = Introspector.getBeanInfo(classifier.getClass());
  MethodDescriptor[] methods;
  methods = bi.getMethodDescriptors();
  Object[] args = {};
  String result = "\nSynopsis for " + classifier.getClass().getName()
      + ":\n\n";

  for (int i = 0; i < methods.length; i++) {
    String name = methods[i].getDisplayName();
    Method meth = methods[i].getMethod();
    if (name.equals("globalInfo")) {
      String globalInfo = (String) (meth.invoke(classifier, args));
      result += globalInfo;
      break;
    }
  }

  return result;
}
 
源代码4 项目: nebula   文件: DefaultWidgetIntrospector.java
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
	Introspector.flushFromCaches(beanClass);
	BeanInfo bi = Introspector.getBeanInfo(beanClass);
	BeanDescriptor bd = bi.getBeanDescriptor();
	MethodDescriptor mds[] = bi.getMethodDescriptors();
	EventSetDescriptor esds[] = bi.getEventSetDescriptors();
	PropertyDescriptor pds[] = bi.getPropertyDescriptors();

	List<PropertyDescriptor> filteredPDList = new ArrayList<PropertyDescriptor>();
	
	List<String> nonPropList = Arrays.asList(getNonProperties());
	for(PropertyDescriptor pd : pds){
		if(!nonPropList.contains(pd.getName()) && pd.getWriteMethod() != null && pd.getReadMethod() != null)
			filteredPDList.add(pd);
	}
	
	int defaultEvent = bi.getDefaultEventIndex();
	int defaultProperty = bi.getDefaultPropertyIndex();

     return new GenericBeanInfo(bd, esds, defaultEvent, 
    		 filteredPDList.toArray(new PropertyDescriptor[filteredPDList.size()]),
			defaultProperty, mds, null);
	
}
 
源代码5 项目: j2objc   文件: IntrospectorTest.java
public void testGetBeanInfoClassint_IGNORE_ALL_Method()
        throws IntrospectionException {
    BeanInfo info = Introspector.getBeanInfo(MockFooSub.class,
            Introspector.IGNORE_ALL_BEANINFO);
    MethodDescriptor[] mds = info.getMethodDescriptors();
    int getMethod = 0;
    int setMethod = 0;
    for (MethodDescriptor element : mds) {
        String name = element.getName();
        if (name.startsWith("getText")) {
            getMethod++;
            assertEquals("getText", name);
        }
        if (name.startsWith("setText")) {
            setMethod++;
            assertEquals("setText", name);
        }
    }

    assertEquals(1, getMethod);
    assertEquals(1, setMethod);
}
 
源代码6 项目: dragonwell8_jdk   文件: UnloadClassBeanInfo.java
public static void main(final String[] args) throws Exception {
    Class cl = getStub();
    System.out.println("cl.getClassLoader() = " + cl.getClassLoader());
    final BeanInfo beanInfo = Introspector.getBeanInfo(cl, Object.class);
    MethodDescriptor[] mds = beanInfo.getMethodDescriptors();
    System.out.println("mds = " + Arrays.toString(mds));
    loader.close();
    loader=null;
    cl=null;
    Util.generateOOME();
    mds = beanInfo.getMethodDescriptors();
    System.out.println("mds = " + Arrays.toString(mds));
}
 
源代码7 项目: jdk8u-dev-jdk   文件: Test6277246.java
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");
        }
    }
}
 
源代码8 项目: openjdk-8   文件: Test6277246.java
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");
        }
    }
}
 
源代码9 项目: hottub   文件: Test6277246.java
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");
        }
    }
}
 
源代码10 项目: jdk8u60   文件: Test6277246.java
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");
        }
    }
}
 
源代码11 项目: jdk8u-jdk   文件: Test6277246.java
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");
        }
    }
}
 
源代码12 项目: blog_demos   文件: ExtendedBeanInfo.java
/**
 * Wrap the given {@link BeanInfo} instance; copy all its existing property descriptors
 * locally, wrapping each in a custom {@link SimpleIndexedPropertyDescriptor indexed}
 * or {@link SimplePropertyDescriptor non-indexed} {@code PropertyDescriptor}
 * variant that bypasses default JDK weak/soft reference management; then search
 * through its method descriptors to find any non-void returning write methods and
 * update or create the corresponding {@link PropertyDescriptor} for each one found.
 * @param delegate the wrapped {@code BeanInfo}, which is never modified
 * @throws IntrospectionException if any problems occur creating and adding new
 * property descriptors
 * @see #getPropertyDescriptors()
 */
public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException {
	this.delegate = delegate;
	for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
		this.propertyDescriptors.add(pd instanceof IndexedPropertyDescriptor ?
				new SimpleIndexedPropertyDescriptor((IndexedPropertyDescriptor) pd) :
				new SimplePropertyDescriptor(pd));
	}
	MethodDescriptor[] methodDescriptors = delegate.getMethodDescriptors();
	if (methodDescriptors != null) {
		for (Method method : findCandidateWriteMethods(methodDescriptors)) {
			handleCandidateWriteMethod(method);
		}
	}
}
 
源代码13 项目: openjdk-8-source   文件: Test6277246.java
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");
        }
    }
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: UnloadClassBeanInfo.java
public static void main(final String[] args) throws Exception {
    Class cl = getStub();
    System.out.println("cl.getClassLoader() = " + cl.getClassLoader());
    final BeanInfo beanInfo = Introspector.getBeanInfo(cl, Object.class);
    MethodDescriptor[] mds = beanInfo.getMethodDescriptors();
    System.out.println("mds = " + Arrays.toString(mds));
    loader.close();
    loader=null;
    cl=null;
    Util.generateOOME();
    mds = beanInfo.getMethodDescriptors();
    System.out.println("mds = " + Arrays.toString(mds));
}
 
源代码15 项目: dragonwell8_jdk   文件: BeanInfoFinder.java
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码16 项目: TencentKona-8   文件: BeanInfoFinder.java
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码17 项目: jdk8u60   文件: BeanInfoFinder.java
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码18 项目: hottub   文件: BeanInfoFinder.java
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码19 项目: jdk8u-jdk   文件: BeanInfoFinder.java
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码20 项目: Bytecoder   文件: BeanInfoFinder.java
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
    if (DEFAULT.equals(prefix)) {
        prefix = DEFAULT_NEW;
    }
    // this optimization will only use the BeanInfo search path
    // if is has changed from the original
    // or trying to get the ComponentBeanInfo
    BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
            ? super.instantiate(type, prefix, name)
            : null;

    if (info != null) {
        // make sure that the returned BeanInfo matches the class
        BeanDescriptor bd = info.getBeanDescriptor();
        if (bd != null) {
            if (type.equals(bd.getBeanClass())) {
                return info;
            }
        }
        else {
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            if (pds != null) {
                for (PropertyDescriptor pd : pds) {
                    Method method = pd.getReadMethod();
                    if (method == null) {
                        method = pd.getWriteMethod();
                    }
                    if (isValid(type, method)) {
                        return info;
                    }
                }
            }
            else {
                MethodDescriptor[] mds = info.getMethodDescriptors();
                if (mds != null) {
                    for (MethodDescriptor md : mds) {
                        if (isValid(type, md.getMethod())) {
                            return info;
                        }
                    }
                }
            }
        }
    }
    return null;
}