Search in sources :

Example 1 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project ACS by ACS-Community.

the class BeanNode method computeProperties.

/** 
   * Computes a descriptor for properties from a bean info.
   * @param bean bean to create properties for
   * @param info about the bean
   * @param ignoreHiddenProperties true if hidden property should be ignored completely
   * @param propertyInfo extra information of some properties (possibly null)
   * @return three property lists
   */
private static Descriptor computeProperties(Object bean, BeanInfo info, boolean ignoreHiddenProperties, Boolean nodePropertiesCacheable, PropertyInfo[] propertyInfo) {
    java.util.List property = null;
    java.util.List expert = null;
    java.util.List hidden = null;
    PropertyDescriptor[] propertyDescriptor = info.getPropertyDescriptors();
    int k = propertyDescriptor.length;
    for (int i = 0; i < k; i++) {
        if (propertyDescriptor[i].getPropertyType() == null)
            continue;
        String propName = propertyDescriptor[i].getName();
        // we first update the PropertyDescriptor with the PropertyInfo
        // that update may make non hidden a property that was hidden
        PropertyInfo propInfo = findPropertyInfoByName(propertyInfo, propName);
        if (propInfo != null)
            propInfo.updatePropertyDescriptor(propertyDescriptor[i]);
        // after the update we can test whether the property is hidden or not
        if (ignoreHiddenProperties && propertyDescriptor[i].isHidden()) {
            continue;
        }
        CachingStrategy strategy = createCachingStrategy(nodePropertiesCacheable, BeanTagger.isCacheable(propertyDescriptor[i]));
        Node.Property prop;
        if (propertyDescriptor[i] instanceof IndexedPropertyDescriptor) {
            prop = createIndexedNodeProperty(bean, (IndexedPropertyDescriptor) propertyDescriptor[i], strategy);
        } else {
            prop = createNodeProperty(bean, propertyDescriptor[i], strategy);
        }
        if (prop == null)
            continue;
        if (propertyDescriptor[i].isHidden()) {
            if (hidden == null)
                hidden = new java.util.ArrayList();
            hidden.add(prop);
        } else if (propertyDescriptor[i].isExpert()) {
            if (expert == null)
                expert = new java.util.ArrayList();
            expert.add(prop);
        } else {
            if (property == null)
                property = new java.util.ArrayList();
            property.add(prop);
        }
    }
    // for    
    return new Descriptor(property, expert, hidden);
}
Also used : IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) PropertyDescriptor(java.beans.PropertyDescriptor) Node(org.openide.nodes.Node) CachingStrategy(cern.gp.nodes.cache.CachingStrategy) TimeLimitedCachingStrategy(cern.gp.nodes.cache.TimeLimitedCachingStrategy) StickyCachingStrategy(cern.gp.nodes.cache.StickyCachingStrategy) NoCachingStrategy(cern.gp.nodes.cache.NoCachingStrategy) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) PropertyInfo(cern.gp.beans.PropertyInfo)

Example 2 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project jdk8u_jdk by JetBrains.

the class Test7172865 method main.

public static void main(String[] args) throws Exception {
    int errors = 0;
    MethodDescriptor md = new MethodDescriptor(Test7172865.class.getMethod("getGood"));
    errors += test(PropertyDescriptor.class, "good", true);
    PropertyDescriptor pdGoodString = new PropertyDescriptor("good", Test7172865.class, "getGood", "setGood");
    PropertyDescriptor pdGoodMethod = new PropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()));
    errors += test(PropertyDescriptor.class, "bad", false);
    PropertyDescriptor pdBadString = new PropertyDescriptor("bad", Test7172865.class, "getBad", null);
    PropertyDescriptor pdBadMethod = new PropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()));
    errors += test(IndexedPropertyDescriptor.class, "good", true);
    IndexedPropertyDescriptor ipdGoodString = new IndexedPropertyDescriptor("good", Test7172865.class, "getGood", "setGood", "getGood", "setGood");
    IndexedPropertyDescriptor ipdGoodMethod = new IndexedPropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()), Test7172865.class.getMethod("getGood", Integer.TYPE), Test7172865.class.getMethod("setGood", Integer.TYPE, String.class));
    errors += test(IndexedPropertyDescriptor.class, "bad", false);
    IndexedPropertyDescriptor ipdBadString = new IndexedPropertyDescriptor("bad", Test7172865.class, "getBad", null, "getBad", null);
    IndexedPropertyDescriptor ipdBadMethod = new IndexedPropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()), Test7172865.class.getMethod("getBad", Integer.TYPE), Test7172865.class.getMethod("setBad", Integer.TYPE, String.class));
    for (int i = 1; i <= 2; i++) {
        System.out.println("STEP: " + i);
        errors += test("md", null != md.getMethod());
        errors += test("pdGoodString", pdGoodString, true, true);
        errors += test("pdGoodMethod", pdGoodMethod, true, true);
        errors += test("pdBadString", pdBadString, true, false);
        errors += test("pdBadMethod", pdBadMethod, true, true);
        errors += test("ipdGoodString", ipdGoodString, true, true, true, true);
        errors += test("ipdGoodMethod", ipdGoodMethod, true, true, true, true);
        errors += test("ipdBadString", ipdBadString, true, false, true, false);
        errors += test("ipdBadMethod", ipdBadMethod, true, true, true, true);
        try {
            int[] array = new int[1024];
            while (true) {
                array = new int[array.length << 1];
            }
        } catch (OutOfMemoryError error) {
            System.gc();
        }
    }
    if (errors > 0) {
        throw new Error("found " + errors + " errors");
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) MethodDescriptor(java.beans.MethodDescriptor)

Example 3 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project jdk8u_jdk by JetBrains.

the class Test6194788 method main.

public static void main(String[] args) throws IntrospectionException {
    test(Grand.class, new PropertyDescriptor("index", Grand.class));
    test(Grand.class, new IndexedPropertyDescriptor("name", Grand.class, null, null, "getName", "setName"));
    test(Parent.class, new PropertyDescriptor("parentIndex", Parent.class));
    test(Parent.class, new IndexedPropertyDescriptor("parentName", Parent.class));
    test(Child.class, new PropertyDescriptor("childIndex", Child.class));
    test(Child.class, new IndexedPropertyDescriptor("childName", Child.class));
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 4 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project jdk8u_jdk by JetBrains.

the class BeanUtils method reportPropertyDescriptor.

/**
     * Reports all the interesting information in an Indexed/PropertyDescrptor.
     */
public static void reportPropertyDescriptor(PropertyDescriptor pd) {
    System.out.println("property name:  " + pd.getName());
    System.out.println("         type:  " + pd.getPropertyType());
    System.out.println("         read:  " + pd.getReadMethod());
    System.out.println("         write: " + pd.getWriteMethod());
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        System.out.println(" indexed type: " + ipd.getIndexedPropertyType());
        System.out.println(" indexed read: " + ipd.getIndexedReadMethod());
        System.out.println(" indexed write: " + ipd.getIndexedWriteMethod());
    }
}
Also used : IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 5 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project spring-framework by spring-projects.

the class ExtendedBeanInfo method findExistingPropertyDescriptor.

private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
    for (PropertyDescriptor pd : this.propertyDescriptors) {
        final Class<?> candidateType;
        final String candidateName = pd.getName();
        if (pd instanceof IndexedPropertyDescriptor) {
            IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
            candidateType = ipd.getIndexedPropertyType();
            if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
                return pd;
            }
        } else {
            candidateType = pd.getPropertyType();
            if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) {
                return pd;
            }
        }
    }
    return null;
}
Also used : IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Aggregations

IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)201 Method (java.lang.reflect.Method)171 PropertyDescriptor (java.beans.PropertyDescriptor)144 BeanInfo (java.beans.BeanInfo)127 SimpleBeanInfo (java.beans.SimpleBeanInfo)126 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)126 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)49 IntrospectionException (java.beans.IntrospectionException)21 EventSetDescriptor (java.beans.EventSetDescriptor)3 MethodDescriptor (java.beans.MethodDescriptor)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 PropertyInfo (cern.gp.beans.PropertyInfo)1 CachingStrategy (cern.gp.nodes.cache.CachingStrategy)1 NoCachingStrategy (cern.gp.nodes.cache.NoCachingStrategy)1 StickyCachingStrategy (cern.gp.nodes.cache.StickyCachingStrategy)1 TimeLimitedCachingStrategy (cern.gp.nodes.cache.TimeLimitedCachingStrategy)1 BugException (freemarker.core.BugException)1 KeyEvent (java.awt.event.KeyEvent)1