personbeaninfo.java

来自「不管是测试驱动开发或者是其它的开发模式」· Java 代码 · 共 44 行

JAVA
44
字号
/*  Copyright (c) 2000-2004 jMock.org
 */
package org.jmock.examples.website;

import java.beans.IntrospectionException;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.util.ArrayList;


public class PersonBeanInfo extends SimpleBeanInfo
{
    ArrayList properties = new ArrayList();
    ArrayList methods = new ArrayList();

    public PersonBeanInfo() throws IntrospectionException {
        Class beanClass = Person.class;

        properties.add(new PropertyDescriptor("name", beanClass, "name", null));
        properties.add(new PropertyDescriptor("age", beanClass, "age", null));
        properties.add(new PropertyDescriptor("spouse", beanClass, "spouse", null));
        properties.add(new PropertyDescriptor("children", beanClass, "children", null));

        try {
            methods.add(new MethodDescriptor(beanClass.getMethod("birth", new Class[0])));
            methods.add(new MethodDescriptor(beanClass.getMethod("school", new Class[0])));
            methods.add(new MethodDescriptor(beanClass.getMethod("work", new Class[0])));
            methods.add(new MethodDescriptor(beanClass.getMethod("death", new Class[0])));
        }
        catch (NoSuchMethodException ex) {
            throw new IntrospectionException(ex.getMessage());
        }
    }

    public MethodDescriptor[] getMethodDescriptors() {
        return (MethodDescriptor[])methods.toArray(new MethodDescriptor[methods.size()]);
    }

    public PropertyDescriptor[] getPropertyDescriptors() {
        return (PropertyDescriptor[])properties.toArray(new PropertyDescriptor[properties.size()]);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?