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);
}
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());
}
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);
}
}
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);
}
}
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));
}
}
Aggregations