Search in sources :

Example 71 with BeanInfo

use of java.beans.BeanInfo in project gate-core by GateNLP.

the class CorpusAnnotationDiff method setParameterValue.

/**
 * Sets the value for a specified parameter.
 *
 * @param paramaterName the name for the parameteer
 * @param parameterValue the value the parameter will receive
 */
@Override
public void setParameterValue(String paramaterName, Object parameterValue) throws ResourceInstantiationException {
    // get the beaninfo for the resource bean, excluding data about Object
    BeanInfo resBeanInf = null;
    try {
        resBeanInf = Introspector.getBeanInfo(this.getClass(), Object.class);
    } catch (Exception e) {
        throw new ResourceInstantiationException("Couldn't get bean info for resource " + this.getClass().getName() + Strings.getNl() + "Introspector exception was: " + e);
    }
    AbstractResource.setParameterValue(this, resBeanInf, paramaterName, parameterValue);
}
Also used : BeanInfo(java.beans.BeanInfo) ResourceInstantiationException(gate.creole.ResourceInstantiationException) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

Example 72 with BeanInfo

use of java.beans.BeanInfo in project HotswapAgent by HotswapProjects.

the class JdkPluginTest method introspectorTest.

/**
 * Switch method implementation (using bean definition or interface).
 */
// @Test
public void introspectorTest() throws Exception {
    BeanInfo beanInfo1 = Introspector.getBeanInfo(TestBean1.class);
    assertTrue(containsMethod(beanInfo1, "helloWorld1"));
    swapClasses(TestBean1.class, TestBean2.class.getName());
    BeanInfo beanInfo2 = Introspector.getBeanInfo(TestBean1.class);
    assertTrue(!containsMethod(beanInfo2, "helloWorld1"));
    assertTrue(containsMethod(beanInfo2, "helloWorld2"));
    swapClasses(TestBean1.class, TestBean1.class.getName());
}
Also used : BeanInfo(java.beans.BeanInfo)

Example 73 with BeanInfo

use of java.beans.BeanInfo in project ma-core-public by infiniteautomation.

the class BeanConverter method getPropertyMapFromClass.

/* (non-Javadoc)
     * @see org.directwebremoting.extend.NamedConverter#getPropertyMap(java.lang.Class, boolean, boolean)
     */
public Map getPropertyMapFromClass(Class type, boolean readRequired, boolean writeRequired) throws MarshallException {
    try {
        BeanInfo info = Introspector.getBeanInfo(type);
        PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
        Map properties = new HashMap();
        for (int i = 0; i < descriptors.length; i++) {
            PropertyDescriptor descriptor = descriptors[i];
            String name = descriptor.getName();
            // We don't marshall getClass()
            if (name.equals("class")) {
                continue;
            }
            // Access rules mean we might not want to do this one
            if (!isAllowedByIncludeExcludeRules(name)) {
                continue;
            }
            if (readRequired && descriptor.getReadMethod() == null) {
                continue;
            }
            if (writeRequired && descriptor.getWriteMethod() == null) {
                continue;
            }
            properties.put(name, new PropertyDescriptorProperty(descriptor));
        }
        return properties;
    } catch (IntrospectionException ex) {
        throw new MarshallException(type, ex);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) MarshallException(org.directwebremoting.extend.MarshallException) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) PropertyDescriptorProperty(org.directwebremoting.impl.PropertyDescriptorProperty) Map(java.util.Map) HashMap(java.util.HashMap)

Example 74 with BeanInfo

use of java.beans.BeanInfo in project ma-core-public by infiniteautomation.

the class H2BeanConverter method getPropertyMapFromObject.

/* (non-Javadoc)
     * @see org.directwebremoting.extend.NamedConverter#getPropertyMapFromObject(java.lang.Object, boolean, boolean)
     */
public Map getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws MarshallException {
    Class clazz = Hibernate.getClass(example);
    try {
        BeanInfo info = Introspector.getBeanInfo(clazz);
        PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
        Map properties = new HashMap();
        for (int i = 0; i < descriptors.length; i++) {
            PropertyDescriptor descriptor = descriptors[i];
            String name = descriptor.getName();
            // We don't marshall getClass()
            if (name.equals("class")) {
                continue;
            }
            // Access rules mean we might not want to do this one
            if (!isAllowedByIncludeExcludeRules(name)) {
                continue;
            }
            if (readRequired && descriptor.getReadMethod() == null) {
                continue;
            }
            if (writeRequired && descriptor.getWriteMethod() == null) {
                continue;
            }
            properties.put(name, new H2PropertyDescriptorProperty(descriptor));
        }
        return properties;
    } catch (Exception ex) {
        throw new MarshallException(clazz, ex);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) MarshallException(org.directwebremoting.extend.MarshallException) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) HashMap(java.util.HashMap) MarshallException(org.directwebremoting.extend.MarshallException) IntrospectionException(java.beans.IntrospectionException)

Example 75 with BeanInfo

use of java.beans.BeanInfo in project portfolio by buchen.

the class SecurityTest method testThatDeepCopyIncludesAllProperties.

@Test
public void testThatDeepCopyIncludesAllProperties() throws IntrospectionException, IllegalAccessException, InvocationTargetException {
    BeanInfo info = Introspector.getBeanInfo(Security.class);
    Security source = new Security();
    int skipped = 0;
    // set properties
    for (PropertyDescriptor p : info.getPropertyDescriptors()) {
        if (// $NON-NLS-1$
        "UUID".equals(p.getName()))
            continue;
        if (p.getPropertyType() == String.class && p.getWriteMethod() != null)
            p.getWriteMethod().invoke(source, UUID.randomUUID().toString());
        else if (p.getPropertyType() == boolean.class)
            p.getWriteMethod().invoke(source, true);
        else if (p.getPropertyType() == int.class)
            p.getWriteMethod().invoke(source, new Random().nextInt());
        else
            skipped++;
    }
    assertThat(skipped, equalTo(7));
    Security target = source.deepCopy();
    assertThat(target.getUUID(), not(equalTo(source.getUUID())));
    // compare
    for (PropertyDescriptor p : info.getPropertyDescriptors()) {
        if (// $NON-NLS-1$
        "UUID".equals(p.getName()))
            continue;
        if (p.getPropertyType() != String.class && p.getPropertyType() != boolean.class && p.getPropertyType() != int.class)
            continue;
        Object sourceValue = p.getReadMethod().invoke(source);
        Object targetValue = p.getReadMethod().invoke(target);
        assertThat(targetValue, equalTo(sourceValue));
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Random(java.util.Random) BeanInfo(java.beans.BeanInfo) Test(org.junit.Test)

Aggregations

BeanInfo (java.beans.BeanInfo)420 PropertyDescriptor (java.beans.PropertyDescriptor)328 Method (java.lang.reflect.Method)217 SimpleBeanInfo (java.beans.SimpleBeanInfo)167 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)161 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)148 IntrospectionException (java.beans.IntrospectionException)115 InvocationTargetException (java.lang.reflect.InvocationTargetException)38 HashMap (java.util.HashMap)33 Test (org.junit.jupiter.api.Test)33 ArrayList (java.util.ArrayList)30 Field (java.lang.reflect.Field)17 Map (java.util.Map)17 Test (org.junit.Test)13 EventSetDescriptor (java.beans.EventSetDescriptor)12 MethodDescriptor (java.beans.MethodDescriptor)12 List (java.util.List)11 BeanDescriptor (java.beans.BeanDescriptor)10 HashSet (java.util.HashSet)8 Introspector (java.beans.Introspector)7