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.jsecurity.web.servlet.JSecurityFilter.java
protected void applyFilterConfig(WebConfiguration conf) { if (log.isDebugEnabled()) { String msg = "Attempting to inject the FilterConfig (using 'setFilterConfig' method) into the " + "instantiated WebConfiguration for any wrapped Filter initialization..."; log.debug(msg);//from w ww .j a v a 2 s .c om } try { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(conf, "filterConfig"); if (pd != null) { PropertyUtils.setProperty(conf, "filterConfig", getFilterConfig()); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Error setting FilterConfig on WebConfiguration instance.", e); } } }
From source file:org.jsecurity.web.servlet.JSecurityFilter.java
protected void applyEmbeddedConfig(WebConfiguration conf) { if (this.config != null) { try {// w w w . ja v a 2 s . c o m PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(conf, "config"); if (pd != null) { PropertyUtils.setProperty(conf, "config", this.config); } else { String msg = "The 'config' filter param was specified, but there is no " + "'setConfig(String)' method on the Configuration instance [" + conf + "]. If you do " + "not require the 'config' filter param, please comment it out, or if you do need it, " + "please ensure your Configuration instance has a 'setConfig(String)' method to receive it."; throw new ConfigurationException(msg); } } catch (Exception e) { String msg = "There was an error setting the 'config' property of the Configuration object."; throw new ConfigurationException(msg, e); } } }
From source file:org.jsecurity.web.servlet.JSecurityFilter.java
protected void applyUrlConfig(WebConfiguration conf) { if (this.configUrl != null) { try {/*from w w w .ja v a 2 s. c o m*/ PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(conf, "configUrl"); if (pd != null) { PropertyUtils.setProperty(conf, "configUrl", this.configUrl); } else { String msg = "The 'configUrl' filter param was specified, but there is no " + "'setConfigUrl(String)' method on the Configuration instance [" + conf + "]. If you do " + "not require the 'configUrl' filter param, please comment it out, or if you do need it, " + "please ensure your Configuration instance has a 'setConfigUrl(String)' method to receive it."; throw new ConfigurationException(msg); } } catch (Exception e) { String msg = "There was an error setting the 'configUrl' property of the Configuration object."; throw new ConfigurationException(msg, e); } } }
From source file:org.kineticsystem.commons.data.model.swing.adapters.BeanTableStructure.java
/** {@inheritDoc} */ public Object setColumnValue(Object modifiedObject, Object modifiedValue, int column) { try {//from w w w . ja va2s.c o m PropertyUtils.setProperty(modifiedObject, propertyNames[column], modifiedValue); } catch (Exception ex) { logger.error(ex); } return modifiedObject; }
From source file:org.kordamp.ezmorph.bean.BeanMorpher.java
private void setProperty(Object targetBean, String name, Class<?> sourceType, Class<?> targetType, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (targetType.isAssignableFrom(sourceType)) { if (value == null && targetType.isPrimitive()) { value = morpherRegistry.morph(targetType, value); }//from w w w . j a v a 2 s . c o m PropertyUtils.setProperty(targetBean, name, value); } else { if (targetType.equals(Object.class)) { // no conversion PropertyUtils.setProperty(targetBean, name, value); } else { if (value == null) { if (targetType.isPrimitive()) { PropertyUtils.setProperty(targetBean, name, morpherRegistry.morph(targetType, value)); } } else { if (IdentityObjectMorpher.getInstance() == morpherRegistry.getMorpherFor(targetType)) { if (!lenient) { throw new MorphException("Can't find a morpher for target class " + targetType.getName() + " (" + name + ")"); } else { log.info("Can't find a morpher for target class " + targetType.getName() + " (" + name + ") SKIPPED"); } } else { PropertyUtils.setProperty(targetBean, name, morpherRegistry.morph(targetType, value)); } } } } }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * Populate the given fields of the target object with the corresponding field values of source object * * @param targetObject the target object * @param sourceObject the source object * @param keyFields the given fields of the target object that need to be popluated *//* www. j a va2s. c o m*/ public static void buildObject(Object targetObject, Object sourceObject, List<String> keyFields) { if (sourceObject.getClass().isArray()) { buildObject(targetObject, sourceObject, keyFields); return; } for (String propertyName : keyFields) { if (PropertyUtils.isReadable(sourceObject, propertyName) && PropertyUtils.isWriteable(targetObject, propertyName)) { try { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); PropertyUtils.setProperty(targetObject, propertyName, propertyValue); } catch (Exception e) { LOG.debug(e); } } } }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * Populate the given fields of the target object with the values of an array * * @param targetObject the target object * @param sourceObject the given array/*from ww w .j ava2s . c om*/ * @param keyFields the given fields of the target object that need to be popluated */ public static void buildObject(Object targetObject, Object[] sourceObject, List<String> keyFields) { int indexOfArray = 0; for (String propertyName : keyFields) { if (PropertyUtils.isWriteable(targetObject, propertyName) && indexOfArray < sourceObject.length) { try { Object value = sourceObject[indexOfArray]; String propertyValue = value != null ? value.toString() : StringUtils.EMPTY; String type = getSimpleTypeName(targetObject, propertyName); Object realPropertyValue = valueOf(type, propertyValue); if (realPropertyValue != null && !StringUtils.isEmpty(realPropertyValue.toString())) { PropertyUtils.setProperty(targetObject, propertyName, realPropertyValue); } else { PropertyUtils.setProperty(targetObject, propertyName, null); } } catch (Exception e) { LOG.debug(e); } } indexOfArray++; } }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * Populate the property of the target object with the counterpart of the source object * * @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 */// ww w.j av a2 s. c om public static void setProperty(Object targetObject, Object sourceObject, DynaProperty property, boolean skipReferenceFields) { String propertyName = property.getName(); try { if (skipReferenceFields) { 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) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (InvocationTargetException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (NoSuchMethodException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (IllegalArgumentException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (Exception e) { LOG.debug(e.getMessage() + ":" + propertyName); } }
From source file:org.kuali.ext.mm.TestDataPreparator.java
/** * Generates transaction data for a business object from properties * /*from www.j a v a 2s . co m*/ * @param businessObject the transction business object * @return the transction business object with data * @throws Exception thrown if an exception is encountered for any reason */ public static <T> T buildTestDataObject(Class<? extends T> clazz, Properties properties) { T testData = null; try { testData = clazz.newInstance(); Iterator propsIter = properties.keySet().iterator(); while (propsIter.hasNext()) { String propertyName = (String) propsIter.next(); String propertyValue = (String) properties.get(propertyName); // if searchValue is empty and the key is not a valid property ignore if (StringUtils.isBlank(propertyValue) || !(PropertyUtils.isWriteable(testData, propertyName))) { continue; } String propertyType = PropertyUtils.getPropertyType(testData, propertyName).getSimpleName(); Object finalPropertyValue = ObjectUtil.valueOf(propertyType, propertyValue); if (finalPropertyValue != null) { PropertyUtils.setProperty(testData, propertyName, finalPropertyValue); } } } catch (Exception e) { throw new RuntimeException("Cannot build a test data object with the given data. " + e); } return testData; }
From source file:org.kuali.kfs.gl.web.TestDataGenerator.java
/** * Generates transaction data for a business object from properties * /*from w ww. j av a2s . co m*/ * @param businessObject the transction business object * @return the transction business object with data * @throws Exception thrown if an exception is encountered for any reason */ public Transaction generateTransactionData(Transaction businessObject) throws Exception { Iterator propsIter = properties.keySet().iterator(); while (propsIter.hasNext()) { String propertyName = (String) propsIter.next(); String propertyValue = (String) properties.get(propertyName); // if searchValue is empty and the key is not a valid property ignore if (StringUtils.isBlank(propertyValue) || !(PropertyUtils.isWriteable(businessObject, propertyName))) { continue; } Object finalPropertyValue = getPropertyValue(businessObject, propertyName, propertyValue); if (finalPropertyValue != null) { PropertyUtils.setProperty(businessObject, propertyName, finalPropertyValue); } } setFiscalYear(businessObject); return businessObject; }