List of usage examples for org.apache.commons.beanutils MappedPropertyDescriptor getMappedReadMethod
public Method getMappedReadMethod()
From source file:no.sesat.search.datamodel.BeanDataObjectInvocationHandler.java
private Method findSupport(final String propertyName, final boolean setter) throws IntrospectionException { // If there's a support instance, use it first. Method m = null;/* w w w . j a v a2s . c om*/ if (null != support) { final PropertyDescriptor[] propDescriptors = Introspector .getBeanInfo(support.getClass().getInterfaces()[0]).getPropertyDescriptors(); for (PropertyDescriptor pd : propDescriptors) { if (propertyName.equalsIgnoreCase(pd.getName())) { if (pd instanceof MappedPropertyDescriptor) { final MappedPropertyDescriptor mpd = (MappedPropertyDescriptor) pd; m = setter ? mpd.getMappedWriteMethod() : mpd.getMappedReadMethod(); } else { m = setter ? pd.getWriteMethod() : pd.getReadMethod(); } break; } } } return m; }
From source file:no.sesat.search.datamodel.DataModelFactoryImplTest.java
/** * * @throws java.lang.Exception//from w w w . ja v a2s. c o m */ @Test public void testDataObjectGetters() throws Exception { LOG.info("testDataObjectGetters()"); scan(DataObject.class, DataModel.class, new Command() { public void execute(Object... args) { try { final Class<?> cls = (Class<?>) args[0]; final Object dataObject = testInstantiate(cls); final PropertyDescriptor[] properties = Introspector.getBeanInfo(cls).getPropertyDescriptors(); for (PropertyDescriptor property : properties) { if (null != property.getReadMethod()) { final Object value = invoke(property.getReadMethod(), dataObject, new Object[0]); LOG.info(" Getter on " + property.getName() + " returned " + value); } if (property instanceof MappedPropertyDescriptor) { final MappedPropertyDescriptor mappedProperty = (MappedPropertyDescriptor) property; if (null != mappedProperty.getReadMethod()) { final Object value = invoke(mappedProperty.getMappedReadMethod(), dataObject, ""); LOG.info(" Getter on " + mappedProperty.getName() + " returned " + value); } } } } catch (IntrospectionException ie) { LOG.info(ie.getMessage(), ie); throw new RuntimeException(ie.getMessage(), ie); } } }); }
From source file:no.sesat.search.datamodel.DataModelTest.java
private void handleMappedProperty(final Collection<Method> propertyMethods, final MappedPropertyDescriptor property) throws IntrospectionException { if (null != property.getMappedReadMethod()) { propertyMethods.add(property.getMappedReadMethod()); // recurse down the datamodel heirarchy if (null != property.getMappedPropertyType().getAnnotation(DataObject.class)) { ensureJavaBeanAPI(property.getMappedPropertyType()); }//from www .ja v a 2 s.c om } if (null != property.getMappedWriteMethod()) { propertyMethods.add(property.getMappedWriteMethod()); } }