Java Code Examples for java.beans.PropertyDescriptor#getValue()

The following examples show how to use java.beans.PropertyDescriptor#getValue() . 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: TestBooleanBeanProperties.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void test(Class<?> cls, boolean isBound, boolean isExpert,
                         boolean isHidden, boolean isPref, boolean isReq,
                         boolean isVS) {
    PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(cls, "value");
    if (pd.isBound() != isBound) {
        throw new RuntimeException("isBound should be: " + isBound);
    }
    if (pd.isExpert() != isExpert || getValue(pd, "expert") != isExpert) {
        throw new RuntimeException("isExpert should be:" + isExpert);
    }
    if (pd.isHidden() != isHidden || getValue(pd, "hidden") != isHidden) {
        throw new RuntimeException("isHidden should be: " + isHidden);
    }
    if (pd.isPreferred() != isPref) {
        throw new RuntimeException("isPreferred should be: " + isPref);
    }
    if (getValue(pd, "required") != isReq) {
        throw new RuntimeException("required should be: " + isReq);
    }
    if (getValue(pd, "visualUpdate") != isVS) {
        throw new RuntimeException("required should be: " + isVS);
    }
    if (pd.getValue("enumerationValues") == null) {
        throw new RuntimeException("enumerationValues should be empty array");
    }
}
 
Example 2
Source File: InheritanceBeanPropertyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean checkDefault(BeanInfo i) {

        System.out.println("checking default info...");

        PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
        int nd = descriptors.length;
        if (nd != 1) {
            System.out.println("invalid number of descriptors: " + nd);
            return false;
        }

        PropertyDescriptor d = descriptors[0];

        String descr = d.getShortDescription();
        boolean ok = descr.equals("x");
        if (!ok) { System.out.println("invalid description: " + descr +
                ", expected: x"); }

        ok &= check("isBound",  d.isBound(),  false);
        ok &= check("isExpert", d.isExpert(), false);
        ok &= check("isHidden", d.isHidden(), false);
        ok &= check("isPreferred", d.isPreferred(), false);
        ok &= check("required", (boolean) d.getValue("required"), false);
        ok &= check("visualUpdate",
            (boolean) d.getValue("visualUpdate"), false);

        Object vals[] = (Object[]) d.getValue("enumerationValues");
        if (vals != null && vals.length > 0) {
            System.out.println("non-empty enumerationValues");
            ok = false;
        }

        return ok;
    }
 
Example 3
Source File: BeanPropertyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean checkAlternativeInfo(BeanInfo i) {

        System.out.println("checking alternative info...");

        PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
        int nd = descriptors.length;
        if (nd != 1) {
            System.out.println("invalid number of descriptors: " + nd);
            return false;
        }

        PropertyDescriptor d = descriptors[0];

        String descr = d.getShortDescription();
        boolean ok = descr.equals(DESCRIPTION_2);
        if (!ok) { System.out.println("invalid alternative description: " +
            descr + ", expected: " + DESCRIPTION_2); }

        ok &= check("isBound",  d.isBound(),  !BOUND);
        ok &= check("isExpert", d.isExpert(), !EXPERT);
        ok &= check("isHidden", d.isHidden(), !HIDDEN);
        ok &= check("isPreferred", d.isPreferred(), !PREFERRED);
        ok &= check("required", (boolean) d.getValue("required"), !REQUIRED);
        ok &= check("visualUpdate",
            (boolean) d.getValue("visualUpdate"), !UPDATE);

        Object vals[] = (Object[]) d.getValue("enumerationValues");
        if (vals != null || vals.length > 0) {
            System.out.println("non-null enumerationValues");
            return false;
        }

        return ok;
    }
 
Example 4
Source File: AnonymousClassBeanPropertyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean checkAlternativeInfo(Class<?> c, String what) {

        BeanInfo i;
        try { i = Introspector.getBeanInfo(c, Object.class); }
        catch (IntrospectionException e) { throw new RuntimeException(e); }

        System.out.println("checking alternative info for " + what);

        PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
        int nd = descriptors.length;
        if (nd != 1) {
            System.out.println("invalid number of descriptors: " + nd);
            return false;
        }

        PropertyDescriptor d = descriptors[0];

        String descr = d.getShortDescription();
        boolean ok = descr.equals(DESCRIPTION_2);
        if (!ok) { System.out.println("invalid alternative description: " +
            descr + ", expected: " + DESCRIPTION_2); }

        ok &= check("isBound",  d.isBound(),  !BOUND);
        ok &= check("isExpert", d.isExpert(), !EXPERT);
        ok &= check("isHidden", d.isHidden(), !HIDDEN);
        ok &= check("isPreferred", d.isPreferred(), !PREFERRED);
        ok &= check("required", (boolean) d.getValue("required"), !REQUIRED);
        ok &= check("visualUpdate",
            (boolean) d.getValue("visualUpdate"), !UPDATE);

        Object vals[] = (Object[]) d.getValue("enumerationValues");
        if (vals != null && vals.length > 0) {
            System.out.println("non-empty enumerationValues:");
            for (Object v: vals) { System.out.print(v.toString()); }
            System.out.println();
            return false;
        }

        return ok;
    }
 
Example 5
Source File: EntityInfo.java    From mongo-mapper with Apache License 2.0 5 votes vote down vote up
private void setDescriptors(List<PropertyDescriptor> descriptors) {
    for (PropertyDescriptor descriptor : descriptors) {
        // Skip fields annotated with java.beans.Transient
        Boolean tran = (Boolean) descriptor.getValue("transient");
        if (tran != null && tran) {
            continue;
        }

        if (!"class".equals(descriptor.getName())) {
            fields.put(descriptor.getDisplayName(), descriptor);
        }
    }
}
 
Example 6
Source File: TestBeanProperty.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Class<?>[] types =
            {B.class, BL.class, BLF.class, E.class, H.class, P.class,
             VU.class, D.class, EVD.class, EVE.class, EV.class, EVL.class,
             EVX.class, R.class};
    for (Class<?> type : types) {
        PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "value");
        if (((B.class == type) || (BLF.class == type)) && pd.isBound()) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("not bound");
        }
        if ((BL.class == type) == !pd.isBound()) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("bound");
        }
        if ((E.class == type) == !pd.isExpert()) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("expert");
        }
        if ((H.class == type) == !pd.isHidden()) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("hidden");
        }
        if ((P.class == type) == !pd.isPreferred()) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("preferred");
        }
        if ((R.class == type) == !Boolean.TRUE.equals(pd.getValue("required"))) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("required");
        }
        if ((D.class == type) == !"getter".equals(pd.getShortDescription())) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("shortDescription");
        }
        if ((VU.class == type) == !Boolean.TRUE.equals(pd.getValue("visualUpdate"))) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("visualUpdate");
        }
        if ((EV.class == type) == !isEV(pd, "LEFT", 2, "javax.swing.SwingConstants.LEFT", "RIGHT", 4, "javax.swing.SwingConstants.RIGHT")) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("enumerationValues from another package");
        }
        if ((EVL.class == type) == !isEV(pd, "ZERO", 0, "ZERO", "ONE", 1, "ONE")) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("enumerationValues from another package");
        }
        if ((EVX.class == type) == !isEV(pd, "ZERO", 0, "X.ZERO", "ONE", 1, "X.ONE")) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("enumerationValues from another package");
        }
        if (EVD.class == type && !isEV(pd)) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("EV:"+ pd.getValue("enumerationValues"));
        }
        if (EVE.class == type && !isEV(pd)) {
            BeanUtils.reportPropertyDescriptor(pd);
            throw new Error("EV:"+ pd.getValue("enumerationValues"));
        }
    }
}
 
Example 7
Source File: TestBeanProperty.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isEV(PropertyDescriptor pd, Object... expected) {
    Object value = pd.getValue("enumerationValues");
    return value instanceof Object[] && Arrays.equals((Object[]) value, expected);
}
 
Example 8
Source File: InheritanceBeanPropertyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean checkInfo(BeanInfo i, boolean ignoreValsCheck) {

        System.out.println("checking info...");

        PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
        int nd = descriptors.length;
        if (nd != 1) {
            System.out.println("invalid number of descriptors: " + nd);
            return false;
        }

        PropertyDescriptor d = descriptors[0];

        String descr = d.getShortDescription();
        boolean ok = descr.equals(DESCRIPTION);
        if (!ok) { System.out.println("invalid description: " + descr +
                ", expected: " + DESCRIPTION); }

        ok &= check("isBound",  d.isBound(),  BOUND);
        ok &= check("isExpert", d.isExpert(), EXPERT);
        ok &= check("isHidden", d.isHidden(), HIDDEN);
        ok &= check("isPreferred", d.isPreferred(), PREFERRED);
        ok &= check("required", (boolean) d.getValue("required"), REQUIRED);
        ok &= check("visualUpdate",
            (boolean) d.getValue("visualUpdate"), UPDATE);

        if (ignoreValsCheck) { return ok; }

        Object vals[] = (Object[]) d.getValue("enumerationValues");
        if (vals == null) {
            System.out.println("null enumerationValues");
            return false;
        }

        boolean okVals = (
            (vals.length == 3) &&
             vals[0].toString().equals(V_SHORT) &&
             vals[1].toString().equals(V)       &&
             vals[2].toString().equals(V_NAME));

        if (!okVals) { System.out.println("invalid enumerationValues"); }

        return (ok && okVals);
    }
 
Example 9
Source File: TestBooleanBeanProperties.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean getValue(PropertyDescriptor pd, String value) {
    return (boolean) pd.getValue(value);
}
 
Example 10
Source File: BeanPropertyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean checkInfo(BeanInfo i, boolean checkVals) {

        System.out.println("checking info...");

        PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
        int nd = descriptors.length;
        if (nd != 1) {
            System.out.println("invalid number of descriptors: " + nd);
            return false;
        }

        PropertyDescriptor d = descriptors[0];

        String descr = d.getShortDescription();
        boolean ok = descr.equals(DESCRIPTION);
        if (!ok) { System.out.println("invalid description: " + descr +
                ", expected: " + DESCRIPTION); }

        ok &= check("isBound",  d.isBound(),  BOUND);
        ok &= check("isExpert", d.isExpert(), EXPERT);
        ok &= check("isHidden", d.isHidden(), HIDDEN);
        ok &= check("isPreferred", d.isPreferred(), PREFERRED);
        ok &= check("required", (boolean) d.getValue("required"), REQUIRED);
        ok &= check("visualUpdate",
            (boolean) d.getValue("visualUpdate"), UPDATE);

        if (!checkVals) { return ok; }

        Object vals[] = (Object[]) d.getValue("enumerationValues");
        if (vals == null) {
            System.out.println("null enumerationValues");
            return false;
        }

        boolean okVals = (
            (vals.length == 3) &&
             vals[0].toString().equals(V_SHORT) &&
             vals[1].toString().equals(V)       &&
             vals[2].toString().equals(V_NAME));

        if (!okVals) { System.out.println("invalid enumerationValues"); }

        return (ok && okVals);
    }
 
Example 11
Source File: AnonymousClassBeanPropertyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean checkInfo(Class<?> c, String what, boolean checkVals) {

        BeanInfo i;
        try { i = Introspector.getBeanInfo(c, Object.class); }
        catch (IntrospectionException e) { throw new RuntimeException(e); }

        System.out.println("\nchecking info for " + what);

        PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
        int nd = descriptors.length;
        if (nd != 1) {
            System.out.println("invalid number of descriptors: " + nd);
            return false;
        }

        PropertyDescriptor d = descriptors[0];

        String descr = d.getShortDescription();
        boolean ok = descr.equals(DESCRIPTION);
        if (!ok) { System.out.println("invalid description: " + descr +
                ", expected: " + DESCRIPTION); }

        ok &= check("isBound",  d.isBound(),  BOUND);
        ok &= check("isExpert", d.isExpert(), EXPERT);
        ok &= check("isHidden", d.isHidden(), HIDDEN);
        ok &= check("isPreferred", d.isPreferred(), PREFERRED);
        ok &= check("required", (boolean) d.getValue("required"), REQUIRED);
        ok &= check("visualUpdate",
            (boolean) d.getValue("visualUpdate"), UPDATE);

        if (!checkVals) { return ok; }

        Object vals[] = (Object[]) d.getValue("enumerationValues");
        if (vals == null) {
            System.out.println("null enumerationValues");
            return false;
        }

        if (vals.length == 0) {
            System.out.println("empty enumerationValues");
            return false;
        }

        boolean okVals = (
            (vals.length == 3) &&
             vals[0].toString().equals(V_SHORT) &&
             vals[1].toString().equals(V)       &&
             vals[2].toString().equals(V_NAME));

        if (!okVals) {
            System.out.println("invalid enumerationValues:");
            for (Object v: vals) { System.out.println(v.toString()); }
        }

        return (ok && okVals);
    }