Search in sources :

Example 1 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project tomcat by apache.

the class ImplicitObjectELResolver method getFeatureDescriptors.

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    List<FeatureDescriptor> feats = new ArrayList<>(SCOPE_NAMES.length);
    FeatureDescriptor feat;
    for (int i = 0; i < SCOPE_NAMES.length; i++) {
        feat = new FeatureDescriptor();
        feat.setDisplayName(SCOPE_NAMES[i]);
        feat.setExpert(false);
        feat.setHidden(false);
        feat.setName(SCOPE_NAMES[i]);
        feat.setPreferred(true);
        feat.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
        feat.setValue(TYPE, String.class);
        feats.add(feat);
    }
    return feats.iterator();
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor) ArrayList(java.util.ArrayList)

Example 2 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project tomcat by apache.

the class MapELResolver method getFeatureDescriptors.

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    if (base instanceof Map<?, ?>) {
        Iterator<?> itr = ((Map<?, ?>) base).keySet().iterator();
        List<FeatureDescriptor> feats = new ArrayList<>();
        Object key;
        FeatureDescriptor desc;
        while (itr.hasNext()) {
            key = itr.next();
            desc = new FeatureDescriptor();
            desc.setDisplayName(key.toString());
            desc.setShortDescription("");
            desc.setExpert(false);
            desc.setHidden(false);
            desc.setName(key.toString());
            desc.setPreferred(true);
            desc.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
            desc.setValue(TYPE, key.getClass());
            feats.add(desc);
        }
        return feats.iterator();
    }
    return null;
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project tomcat by apache.

the class TestBeanELResolver method testGetFeatureDescriptors02.

/**
     * Tests that a valid FeatureDescriptors are returned.
     */
@Test
public void testGetFeatureDescriptors02() {
    BeanELResolver resolver = new BeanELResolver();
    ELContext context = new StandardELContext(ELManager.getExpressionFactory());
    Iterator<FeatureDescriptor> result = resolver.getFeatureDescriptors(context, new Bean());
    while (result.hasNext()) {
        PropertyDescriptor featureDescriptor = (PropertyDescriptor) result.next();
        Assert.assertEquals(featureDescriptor.getPropertyType(), featureDescriptor.getValue(ELResolver.TYPE));
        Assert.assertEquals(Boolean.TRUE, featureDescriptor.getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME));
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) FeatureDescriptor(java.beans.FeatureDescriptor) Test(org.junit.Test)

Example 4 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project j2objc by google.

the class FeatureDescriptorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    fd = new FeatureDescriptor();
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor)

Example 5 with FeatureDescriptor

use of java.beans.FeatureDescriptor in project Activiti by Activiti.

the class JsonNodeELResolver method getFeatureDescriptors.

/**
	 * If the base object is not null, returns an Iterator containing the set of JavaBeans
	 * properties available on the given object. Otherwise, returns null. The Iterator returned must
	 * contain zero or more instances of java.beans.FeatureDescriptor. Each info object contains
	 * information about a property in the bean, as obtained by calling the
	 * BeanInfo.getPropertyDescriptors method. The FeatureDescriptor is initialized using the same
	 * fields as are present in the PropertyDescriptor, with the additional required named
	 * attributes "type" and "resolvableAtDesignTime" set as follows:
	 * <ul>
	 * <li>{@link ELResolver#TYPE} - The runtime type of the property, from
	 * PropertyDescriptor.getPropertyType().</li>
	 * <li>{@link ELResolver#RESOLVABLE_AT_DESIGN_TIME} - true.</li>
	 * </ul>
	 * 
	 * @param context
	 *            The context of this evaluation.
	 * @param base
	 *            The bean to analyze.
	 * @return An Iterator containing zero or more FeatureDescriptor objects, each representing a
	 *         property on this bean, or null if the base object is null.
	 */
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    if (isResolvable(base)) {
        JsonNode node = (JsonNode) base;
        final Iterator<String> keys = node.fieldNames();
        return new Iterator<FeatureDescriptor>() {

            public boolean hasNext() {
                return keys.hasNext();
            }

            public FeatureDescriptor next() {
                Object key = keys.next();
                FeatureDescriptor feature = new FeatureDescriptor();
                feature.setDisplayName(key == null ? "null" : key.toString());
                feature.setName(feature.getDisplayName());
                feature.setShortDescription("");
                feature.setExpert(true);
                feature.setHidden(false);
                feature.setPreferred(true);
                feature.setValue(TYPE, key == null ? "null" : key.getClass());
                feature.setValue(RESOLVABLE_AT_DESIGN_TIME, true);
                return feature;
            }

            public void remove() {
                throw new UnsupportedOperationException("cannot remove");
            }
        };
    }
    return null;
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor) Iterator(java.util.Iterator) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

FeatureDescriptor (java.beans.FeatureDescriptor)15 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 PropertyDescriptor (java.beans.PropertyDescriptor)3 ResourceBundle (java.util.ResourceBundle)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 BeanDescriptor (java.beans.BeanDescriptor)1 EventSetDescriptor (java.beans.EventSetDescriptor)1 IndexedPropertyChangeEvent (java.beans.IndexedPropertyChangeEvent)1 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)1 IntrospectionException (java.beans.IntrospectionException)1 MethodDescriptor (java.beans.MethodDescriptor)1 ParameterDescriptor (java.beans.ParameterDescriptor)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1