List of usage examples for org.apache.commons.beanutils PropertyUtils setProperty
public static void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:org.kuali.kfs.gl.web.TestDataGenerator.java
/** * If the actual transaction implementation has a "setUniversityFiscalYear" method, use that to set the * fiscal year to the value of TestUtils.getFiscalYearForTesting() * @param transaction transaction to try to set fiscal year on *///from ww w . ja va 2 s .c o m protected void setFiscalYear(Transaction transaction) { try { final PropertyDescriptor propertyDescriptor = PropertyUtils.getPropertyDescriptor(transaction, KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR); if (propertyDescriptor.getReadMethod() != null) { PropertyUtils.setProperty(transaction, KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, TestUtils.getFiscalYearForTesting()); } } catch (IllegalAccessException iae) { LOG.info("Could test universityFiscalYear property on fixture of transaction type: " + transaction.getClass().getName(), iae); } catch (InvocationTargetException ite) { LOG.info("Could test universityFiscalYear property on fixture of transaction type: " + transaction.getClass().getName(), ite); } catch (NoSuchMethodException nsme) { LOG.info("Could test universityFiscalYear property on fixture of transaction type: " + transaction.getClass().getName(), nsme); } }
From source file:org.kuali.kfs.sys.batch.AbstractFlatFilePropertySpecificationBase.java
/** * Sets the property on the business object * @param value the substring of the parsed line to set * @param businessObject the business object to set the parsed line on * @param lineNumber the parsed line number */// w w w. j av a 2 s.c o m @Override public void setProperty(String value, Object businessObject, int lineNumber) { if (leftTrim) { value = StringUtils.trimLeadingWhitespace(value); } if (rightTrim) { value = StringUtils.trimTrailingWhitespace(value); } try { PropertyUtils.setProperty(businessObject, propertyName, getFormattedObject(value, businessObject)); } catch (Exception e) { throw new RuntimeException("Exception occurred on line " + lineNumber + " while setting value " + value + " for property " + propertyName + ".", e); } }
From source file:org.kuali.kfs.sys.batch.FlatFileParseTrackerImpl.java
/** * Called when a line has completed parsing. Throws an exception if a proper parent * is not found for the line being parsed *///from w w w . j ava 2s. co m @Override @SuppressWarnings("unchecked") public void completeLineParse() { completedLineCount += 1; if (LOG.isDebugEnabled()) { LOG.debug("Completing parse of line: " + completedLineCount); } Object currentObject = parseStack.pop(); final FlatFileChildMapEntry entry = getEntryForParsedIntoObject(currentObject); final Class<?> parentClass = (entry == null) ? null : entry.getParentBeanClass(); final String propertyName = (entry == null) ? null : entry.getPropertyName(); while (!parseStack.isEmpty()) { Object checkingObject = parseStack.pop(); if (parentClass != null && parentClass.isAssignableFrom(checkingObject.getClass())) { try { if (Collection.class .isAssignableFrom(PropertyUtils.getPropertyType(checkingObject, propertyName))) { Collection childrenList = ((Collection) PropertyUtils.getProperty(checkingObject, propertyName)); childrenList.add(currentObject); } else { PropertyUtils.setProperty(checkingObject, propertyName, currentObject); } parseStack.push(checkingObject); parseStack.push(currentObject); return; } catch (Exception e) { LOG.error( e.getMessage() + "occured when completing line parse; attempting to set object of type " + currentObject.getClass().getName() + " to the following parent: " + parentClass.getName() + "#" + propertyName, e); throw new RuntimeException( e.getMessage() + "occured when completing line parse; attempting to set object of type " + currentObject.getClass().getName() + " to the following parent: " + parentClass.getName() + "#" + propertyName, e); } } } if (parentClass == null) { parseStack.push(currentObject); parsedParentObjects.add(currentObject); } else { throw new IllegalStateException("A line of class " + currentObject.getClass().getName() + " cannot exist without a proper parent"); } }
From source file:org.kuali.kfs.sys.ObjectUtil.java
/** * Populate the property of the target object with the counterpart of the source object * /*from w w w. j a va2 s. c o m*/ * @param targetObject the target object * @param sourceObject the source object * @param property the specified propety of the target object * @param skipReferenceFields determine whether the referencing fields need to be populated */ public static void setProperty(Object targetObject, Object sourceObject, DynaProperty property, boolean skipReferenceFields) { String propertyName = property.getName(); try { if (skipReferenceFields) { @SuppressWarnings("rawtypes") Class propertyType = property.getType(); if (propertyType == null || PersistableBusinessObjectBase.class.isAssignableFrom(propertyType) || List.class.isAssignableFrom(propertyType)) { return; } } if (PropertyUtils.isReadable(sourceObject, propertyName) && PropertyUtils.isWriteable(targetObject, propertyName)) { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); PropertyUtils.setProperty(targetObject, propertyName, propertyValue); } } catch (IllegalAccessException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (InvocationTargetException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (NoSuchMethodException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (IllegalArgumentException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } }
From source file:org.kuali.maven.plugins.graph.dot.html.HtmlUtils.java
public void setProperty(HtmlTag element, String property, Object value) { try {/*www. j a v a2s . co m*/ PropertyUtils.setProperty(element, property, value); } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:org.kuali.maven.plugins.graph.util.Helper.java
/** * If the property from "orig" is not null and that property from * "dest is null, copy the property from "orig" to "dest" *///from w w w .jav a2 s . c om public static final void copyPropertyIfNull(Object dest, String name, Object orig) { try { Object oldValue = PropertyUtils.getProperty(dest, name); if (oldValue != null) { return; } Object newValue = PropertyUtils.getProperty(orig, name); logger.trace("name={} value={}", name, newValue); PropertyUtils.setProperty(dest, name, newValue); } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:org.kuali.rice.core.framework.resourceloader.ObjectDefinitionResolver.java
protected static void invokeProperty(Object object, PropertyDefinition definition) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { PropertyUtils.setProperty(object, definition.getName(), definition.getData().getValue()); }
From source file:org.kuali.rice.devtools.pdle.PostDataLoadEncryptionServiceImpl.java
@Override public void encrypt(PersistableBusinessObject businessObject, Set<String> attributeNames) { for (String attributeName : attributeNames) { try {//ww w .j av a2s . co m if (CoreApiServiceLocator.getEncryptionService().isEnabled()) { PropertyUtils.setProperty(businessObject, attributeName, encryptionService.encrypt(PropertyUtils.getProperty(businessObject, attributeName))); } } catch (Exception e) { throw new RuntimeException(new StringBuffer( "PostDataLoadEncryptionServiceImpl caught exception while attempting to encrypt attribute ") .append(attributeName).append(" of Class ").append(businessObject.getClass()) .toString(), e); } } businessObjectService.save(businessObject); }
From source file:org.kuali.rice.kns.service.impl.BusinessObjectDictionaryServiceImpl.java
/** * Handles recursion for performForceUppercase in a cycle-safe manner, * keeping track of visited BusinessObjects to prevent infinite recursion. *//*from w w w .j ava 2 s . c o m*/ protected void performForceUppercaseCycleSafe(BusinessObject bo, Set<BusinessObject> visited) { if (visited.contains(bo)) { return; } else { visited.add(bo); } PropertyDescriptor descriptors[] = PropertyUtils.getPropertyDescriptors(bo); for (int i = 0; i < descriptors.length; ++i) { try { if (descriptors[i] instanceof IndexedPropertyDescriptor) { // Skip this case because PropertyUtils.getProperty(bo, // descriptors[i].getName()) will throw a // NoSuchMethodException on those. These // fields are usually convenience methods in the BO and in // the below code we anyway wouldn't know which index // .toUpperCase(). } else { Object nestedObject = ObjectUtils.getPropertyValue(bo, descriptors[i].getName()); if (ObjectUtils.isNotNull(nestedObject) && nestedObject instanceof BusinessObject) { if (persistenceStructureService.isPersistable(nestedObject.getClass())) { try { if (persistenceStructureService.hasReference(bo.getClass(), descriptors[i].getName())) { if (persistenceStructureService.isReferenceUpdatable(bo.getClass(), descriptors[i].getName())) { if (persistenceStructureService .getForeignKeyFieldsPopulationState((PersistableBusinessObject) bo, descriptors[i].getName()) .isAllFieldsPopulated()) { // check FKs to prevent probs caused // by referential integrity problems performForceUppercaseCycleSafe((BusinessObject) nestedObject, visited); } } } } catch (org.kuali.rice.krad.exception.ReferenceAttributeNotAnOjbReferenceException ranaore) { LOG.debug( "Propery " + descriptors[i].getName() + " is not a foreign key reference."); } } } else if (nestedObject instanceof String) { if (dataDictionaryService.isAttributeDefined(bo.getClass(), descriptors[i].getName()) .booleanValue() && dataDictionaryService .getAttributeForceUppercase(bo.getClass(), descriptors[i].getName()) .booleanValue()) { String curValue = (String) nestedObject; PropertyUtils.setProperty(bo, descriptors[i].getName(), curValue.toUpperCase()); } } else { if (ObjectUtils.isNotNull(nestedObject) && nestedObject instanceof Collection) { if (persistenceStructureService.hasCollection(bo.getClass(), descriptors[i].getName())) { if (persistenceStructureService.isCollectionUpdatable(bo.getClass(), descriptors[i].getName())) { Iterator iter = ((Collection) nestedObject).iterator(); while (iter.hasNext()) { Object collElem = iter.next(); if (collElem instanceof BusinessObject) { if (persistenceStructureService.isPersistable(collElem.getClass())) { performForceUppercaseCycleSafe((BusinessObject) collElem, visited); } } } } } } } } } catch (IllegalAccessException e) { throw new IntrospectionException("unable to performForceUppercase", e); } catch (InvocationTargetException e) { throw new IntrospectionException("unable to performForceUppercase", e); } catch (NoSuchMethodException e) { // if the getter/setter does not exist, just skip over // throw new // IntrospectionException("unable to performForceUppercase", e); } } }
From source file:org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm.java
private void setAttachmentProperty(Object boClass, String propertyName, Object propertyValue) { try {// w ww . ja v a 2 s .co m PropertyUtils.setProperty(boClass, propertyName, propertyValue); } catch (InvocationTargetException e) { throw new RuntimeException( "no setter for property '" + boClass.getClass().getName() + "." + propertyName + "'", e); } catch (NoSuchMethodException e) { throw new RuntimeException( "no setter for property '" + boClass.getClass().getName() + "." + propertyName + "'", e); } catch (IllegalAccessException e) { throw new RuntimeException( "problem accessing property '" + boClass.getClass().getName() + "." + propertyName + "'", e); } }