Refine search
BeanUtils.setProperty( obj, property, val ); } catch ( Exception e ) { throw new KettleConfigException( e );
/** * Attempts to obtain the given property value from the dynamic property map first, and then an actual bean property * via a getter * * @param propertyName * @return */ public Object getPropertyValue(String propertyName) { try { return getValues().containsKey(propertyName) ? getValues().get(propertyName) : BeanUtils.getProperty(this, propertyName); } catch (Exception e) { return null; } }
/** * 对象间的属性值拷贝 * * @param dest 目标对象 * @param src 源对象 */ public static void copyProperties(Object dest, Object src) { if (src == null || dest == null) { return; } try { BeanUtils.copyProperties(dest, src); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } }
private static Object cloneBean(Object object, Object cloneOriginalBean, Object originalBean) { try { // Object cloneBean = object.getClass().newInstance(); Object cloneBean = object.getClass().getConstructor().newInstance(); Object bean = retornarObjeto(object); Map<?, ?> describe = BeanUtils.describe(bean); for (Map.Entry<?, ?> entry : describe.entrySet()) { Object propertyValue = PropertyUtils.getProperty(bean, entry.getKey().toString()); if (propertyValue != null && !propertyValue.getClass().isAssignableFrom(Class.class) && PropertyUtils.isWriteable(cloneBean, entry.getKey().toString())) { setProperty(cloneOriginalBean, originalBean, cloneBean, entry, propertyValue); } } return cloneBean; } catch (Exception ex) { throw new RuntimeException(ex); } }
((DynaBean) top).getDynaClass().getDynaProperty(property); if (desc == null) { throw new NoSuchMethodException PropertyUtils.getPropertyDescriptor(top, property); if (desc == null) { throw new NoSuchMethodException BeanUtils.setProperty(top, property, bodyText);
protected void set(Object obj, String property, Object value) { try { if (BeanUtils.getProperty(obj, property) == null) { BeanUtils.setProperty(obj, property, value); } } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } }
private static void addPropertyWithReflection( SearchableQuery query, String propName, String propValue ) throws Exception { Method getter = PropertyUtils.getReadMethod( new PropertyDescriptor( propName, query.getClass() ) ); Class returnType = getter.getReturnType(); Object objPhrase; if ( returnType.equals( QueryPhrase.class ) ) { objPhrase = new StandardQueryPhraseConverter().objectToPhrase( propValue ); } else if ( returnType.getName().equals( "boolean" ) ) { objPhrase = Boolean.valueOf( propValue ).booleanValue(); } else { throw new IntactException( "Unexpected type " + returnType.getName() + " for property name: " + propName ); } BeanUtils.setProperty( query, propName, objPhrase ); }
@Override public T fromHash(Map<String, String> hash) { T instance = org.springframework.beans.BeanUtils.instantiateClass(type); try { BeanUtils.populate(instance, hash); return instance; } catch (Exception ex) { throw new RuntimeException(ex); } }
private void writeValue(String property, Object value) { try { if (PropertyUtils.getPropertyDescriptor(model, property) != null) { BeanUtils.setProperty(model, property, value); } } catch (Exception e) { logger.warn("Error modifying object '{}': cannot set value '{}' to property '{}'", model, value, property); logger.warn("Caused by:", e); } }
@Override public Map<String, String> toHash(T object) { try { Map<String, String> map = BeanUtils.describe(object); Map<String, String> result = new LinkedHashMap<>(); for (Entry<String, String> entry : map.entrySet()) { if (entry.getValue() != null) { result.put(entry.getKey(), entry.getValue()); } } return result; } catch (Exception ex) { throw new IllegalArgumentException("Cannot describe object " + object, ex); } } }
boolean test = PropertyUtils.isWriteable(top, name); if (!test) throw new NoSuchMethodException("Property " + name + " can't be set"); BeanUtils.populate(top, values);
public T mapToDomainObject(Case ccCase) { T instance = null; try { instance = clazz.newInstance(); BeanUtils.copyProperties(instance, ccCase); BeanUtils.populate(instance, ccCase.getFieldValues()); } catch (Exception e) { e.printStackTrace(); } return instance; }
/** * Creates a copy of a conceptName * * @param conceptName the conceptName to be cloned * @return the cloned conceptName */ private ConceptName cloneConceptName(ConceptName conceptName) { ConceptName copy = new ConceptName(); try { copy = (ConceptName) BeanUtils.cloneBean(conceptName); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException e) { log.warn(errorMessage, e); } return copy; }
private <T> boolean merge(T target, T object) { if (object != null) { try { Map<String, Object> objectValues = PropertyUtils.describe(object); Map<String, Object> targetValues = PropertyUtils.describe(target); if (merge(targetValues, objectValues)) { BeanUtils.populate(target, targetValues); return true; } } catch (ReflectiveOperationException e) { logger.error("Cannot merge properties", e); } } return false; }
/** * @see Obs#isDirty() */ @Test public void isDirty_shouldReturnFalseWhenNoChangeHasBeenMade() throws Exception { assertFalse(new Obs().isDirty()); //Should also work if setters are called with same values as the original Obs obs = createObs(2); obs.setGroupMembers(new LinkedHashSet<>()); obs.getConcept().setDatatype(new ConceptDatatype()); assertFalse(obs.isDirty()); BeanUtils.copyProperties(obs, BeanUtils.cloneBean(obs)); assertFalse(obs.isDirty()); obs = createObs(null); obs.setGroupMembers(new LinkedHashSet<>()); obs.getConcept().setDatatype(new ConceptDatatype()); assertFalse(obs.isDirty()); BeanUtils.copyProperties(obs, BeanUtils.cloneBean(obs)); assertFalse(obs.isDirty()); }
@SuppressWarnings("unchecked") public void copyProperties(Object dest, Object origin) throws PropertyHandlingException { try { Map<String, Object> description = BeanUtils.describe(origin); StringFilter filterer = new StringFilter(getIncludeProperties(), getExcludeProperties()); filterer.filter(description.keySet().iterator()); for (String property : description.keySet()) { BeanUtils.copyProperty(dest, property, description.get(property)); } } catch (Exception e) { throw new PropertyHandlingException("Error copying properties", e); } } }
private static Object cloneBean(Object object, Object cloneOriginalBean, Object originalBean) { try { // Object cloneBean = object.getClass().newInstance(); Object cloneBean = object.getClass().getConstructor().newInstance(); Object bean = retornarObjeto(object); Map<?, ?> describe = BeanUtils.describe(bean); for (Map.Entry<?, ?> entry : describe.entrySet()) { Object propertyValue = PropertyUtils.getProperty(bean, entry.getKey().toString()); if (propertyValue != null && !propertyValue.getClass().isAssignableFrom(Class.class) && PropertyUtils.isWriteable(cloneBean, entry.getKey().toString())) { setProperty(cloneOriginalBean, originalBean, cloneBean, entry, propertyValue); } } return cloneBean; } catch (Exception ex) { throw new RuntimeException(ex); } }
((DynaBean) top).getDynaClass().getDynaProperty(actualName); if (desc == null) { throw new NoSuchMethodException PropertyUtils.getPropertyDescriptor(top, actualName); if (desc == null) { throw new NoSuchMethodException BeanUtils.setProperty(top, actualName, actualValue);
protected void set(Object obj, String property, Object value) { try { if (BeanUtils.getProperty(obj, property) == null) { BeanUtils.setProperty(obj, property, value); } } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } }
private static void addPropertyWithReflection( SearchableQuery query, String propName, String propValue ) throws Exception { Method getter = PropertyUtils.getReadMethod( new PropertyDescriptor( propName, query.getClass() ) ); Class returnType = getter.getReturnType(); Object objPhrase; if ( returnType.equals( QueryPhrase.class ) ) { objPhrase = new StandardQueryPhraseConverter().objectToPhrase( propValue ); } else if ( returnType.getName().equals( "boolean" ) ) { objPhrase = Boolean.valueOf( propValue ).booleanValue(); } else { throw new IntactException( "Unexpected type " + returnType.getName() + " for property name: " + propName ); } BeanUtils.setProperty( query, propName, objPhrase ); }