List of usage examples for org.apache.commons.beanutils PropertyUtils getReadMethod
public static Method getReadMethod(PropertyDescriptor descriptor)
Return an accessible property getter method for this property, if there is one; otherwise return null
.
For more details see PropertyUtilsBean
.
From source file:org.kuali.coeus.sys.framework.model.KcPersistableBusinessObjectBase.java
@Override protected void postPersist() { if (temporaryExtension != null) { @SuppressWarnings("unchecked") final List<String> fieldNames = getPersistenceStructureService().listPrimaryKeyFieldNames(getClass()); try {// ww w. ja v a 2s . c o m for (String fieldName : fieldNames) { try { Method thisGetter = PropertyUtils .getReadMethod(PropertyUtils.getPropertyDescriptor(this, fieldName)); Method extensionSetter = PropertyUtils .getWriteMethod(PropertyUtils.getPropertyDescriptor(temporaryExtension, fieldName)); extensionSetter.invoke(temporaryExtension, thisGetter.invoke(this)); } catch (NoSuchMethodException nsme) { throw new PersistenceBrokerException( "Could not find accessor for " + fieldName + " in an extension object", nsme); } catch (InvocationTargetException ite) { throw new PersistenceBrokerException( "Could not invoke accessor for " + fieldName + " on an extension object", ite); } catch (IllegalAccessException iae) { throw new PersistenceBrokerException( "Illegal access when invoking " + fieldName + " accessor on an extension object", iae); } } } finally { extension = temporaryExtension; temporaryExtension = null; } } }
From source file:org.kuali.kfs.sys.KualiTestAssertionUtils.java
/** * Asserts that the non-null non-BO properties of the expected bean are equal to those of the actual bean. Any null or * BusinessObject expected properties are ignored. Attributes are reflected bean-style via any public no-argument methods * starting with "get" (or "is" for booleans), including inherited methods. The expected and actual beans do not need to be of * the same class.//from w w w . j a v a2s .c om * <p> * Reflection wraps primitives, so differences in primitiveness are ignored. Properties that are BusinessObjects (generally * relations based on foreign key properties) are also ignored, because this method is not testing OJB foreign key resolution * (e.g., via the <code>refresh</code> method), we do not want to have to put all the related BOs into the test fixture * (redundant with the foreign keys), and many (all?) of our BOs implement the <code>equals</code> method in terms of identity * so would fail this assertion anyway. This is a data-oriented assertion, for our data-oriented tests and persistence layer. * * @param message a description of this test assertion * @param expectedBean a java bean containing expected properties * @param actualBean a java bean containing actual properties * @throws InvocationTargetException if a getter method throws an exception (the cause) * @throws NoSuchMethodException if an expected property does not exist in the actualBean */ public static void assertSparselyEqualBean(String message, Object expectedBean, Object actualBean) throws InvocationTargetException, NoSuchMethodException { if (message == null) { message = ""; } else { message = message + " "; } assertNotNull(message + "actual bean is null", actualBean); PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(expectedBean); for (int i = 0; i < descriptors.length; i++) { PropertyDescriptor descriptor = descriptors[i]; if (PropertyUtils.getReadMethod(descriptor) != null) { try { Object expectedValue = PropertyUtils.getSimpleProperty(expectedBean, descriptor.getName()); if (expectedValue != null && !(expectedValue instanceof BusinessObject)) { assertEquals(message + descriptor.getName(), expectedValue, PropertyUtils.getSimpleProperty(actualBean, descriptor.getName())); } } catch (IllegalAccessException e) { throw new AssertionError(e); // can't happen because getReadMethod() returns only public methods } } } }
From source file:org.kuali.kra.bo.KraPersistableBusinessObjectBase.java
/** * {@inheritDoc}// w ww. ja v a2 s. c om * @see org.kuali.rice.kns.bo.PersistableBusinessObjectBase#afterInsert(org.apache.ojb.broker.PersistenceBroker) */ @Override @SuppressWarnings("unchecked") public void afterInsert(PersistenceBroker persistenceBroker) throws PersistenceBrokerException { if (temporaryExtension != null) { List<String> fieldNames = getPersistenceStructureService().listPrimaryKeyFieldNames(getClass()); try { for (String fieldName : fieldNames) { try { Method thisGetter = PropertyUtils .getReadMethod(PropertyUtils.getPropertyDescriptor(this, fieldName)); Method extensionSetter = PropertyUtils .getWriteMethod(PropertyUtils.getPropertyDescriptor(temporaryExtension, fieldName)); extensionSetter.invoke(temporaryExtension, thisGetter.invoke(this)); } catch (NoSuchMethodException nsme) { throw new PersistenceBrokerException( "Could not find accessor for " + fieldName + " in an extension object", nsme); } catch (InvocationTargetException ite) { throw new PersistenceBrokerException( "Could not invoke accessor for " + fieldName + " on an extension object", ite); } catch (IllegalAccessException iae) { throw new PersistenceBrokerException( "Illegal access when invoking " + fieldName + " accessor on an extension object", iae); } } } finally { extension = temporaryExtension; temporaryExtension = null; } } }
From source file:org.lunifera.runtime.web.vaadin.databinding.component.internal.SimpleAccessorProperty.java
public SimpleAccessorProperty(Class<?> componentClass, String property) { super();//from w w w .j a v a 2 s . co m PropertyDescriptor result = getPropertyDescriptor(componentClass, property); this.getter = PropertyUtils.getReadMethod(result); this.setter = PropertyUtils.getWriteMethod(result); this.type = getter.getReturnType(); }
From source file:us.mn.state.health.lims.common.provider.reports.toplink.QueryResultDataSource.java
public Object getFieldValue(JRField field) throws JRException { Object value = null;//from w w w.j a va 2 s. c om try { Method getter = PropertyUtils .getReadMethod(PropertyUtils.getPropertyDescriptor(currentValue, field.getName())); value = getter.invoke(currentValue, (Object[]) null); } catch (Exception ex) { //bugzilla 2154 LogEvent.logError("QueryResultDataSource", "getFieldValue()", ex.toString()); } return value; }
From source file:us.mn.state.health.lims.reports.valueholder.common.JRHibernateDataSource.java
private Object nestedFieldValue(Object object, String field) { Object value = null;/*from w w w . ja v a2 s .co m*/ if (field.indexOf("__") > -1) { try { Method nestedGetter = PropertyUtils.getReadMethod( PropertyUtils.getPropertyDescriptor(object, field.substring(0, field.indexOf("__")))); Object nestedObject = nestedGetter.invoke(object, (Object[]) null); value = nestedFieldValue(nestedObject, field.substring(field.indexOf("__") + 2, field.length())); } catch (Exception ex) { //bugzilla 2154 LogEvent.logError("JRHibernateDataSource", "nestedFieldValue()", ex.toString()); } } else { try { Method getter = PropertyUtils.getReadMethod(PropertyUtils.getPropertyDescriptor(object, field)); value = getter.invoke(object, (Object[]) null); if (Collection.class.isAssignableFrom(getter.getReturnType())) { return new JRHibernateDataSource((Collection) value); } if (Map.class.isAssignableFrom(getter.getReturnType())) { return new JRHibernateDataSource((Map) value); } } catch (Exception ex) { //bugzilla 2154 LogEvent.logError("JRHibernateDataSource", "nestedFieldValue()", ex.toString()); } } return value; }