List of usage examples for org.springframework.util ReflectionUtils COPYABLE_FIELDS
FieldFilter COPYABLE_FIELDS
To view the source code for org.springframework.util ReflectionUtils COPYABLE_FIELDS.
Click Source Link
From source file:org.web4thejob.orm.AbstractHibernateEntity.java
@SuppressWarnings("CloneDoesntCallSuperClone") @Override// w ww . j ava 2 s . c o m public Entity clone() { try { final Entity clone = (Entity) ReflectHelper.getDefaultConstructor(getClass()) .newInstance((Object[]) null); clone.addDirtyListener(dirtyListener); ReflectionUtils.doWithFields(getClass(), new ReflectionUtils.FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { ReflectionUtils.makeAccessible(field); if (!Collection.class.isAssignableFrom(field.getType())) { // don't clone one-to-many fields field.set(clone, field.get(AbstractHibernateEntity.this)); } } }, ReflectionUtils.COPYABLE_FIELDS); return clone; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Clone failed for " + toString(), e); } }
From source file:org.web4thejob.orm.AbstractHibernateEntity.java
@Override public void merge(final Entity source) { ReflectionUtils.doWithFields(getClass(), new ReflectionUtils.FieldCallback() { @Override//from ww w.j a v a 2s. c o m public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { ReflectionUtils.makeAccessible(field); if (!Collection.class.isAssignableFrom(field.getType())) { // don't merge one-to-many fields field.set(AbstractHibernateEntity.this, field.get(source)); } } }, ReflectionUtils.COPYABLE_FIELDS); }
From source file:py.una.pol.karaku.services.ReflectionConverter.java
/** * /* w w w . j a v a 2 s . c o m*/ * @param source * @param targetClass * @param depth * @param dtoToEntity * @return */ protected Object map(final Object source, final Class<?> targetClass, final int depth, final boolean dtoToEntity) { if (source == null) { return null; } try { final Object toRet = targetClass.newInstance(); ReflectionUtils.doWithFields(source.getClass(), new FieldCallback() { @Override public void doWith(Field field) throws IllegalAccessException { mapField(source, targetClass, depth, dtoToEntity, toRet, field); } }, ReflectionUtils.COPYABLE_FIELDS); return toRet; } catch (Exception e) { throw new KarakuRuntimeException( String.format("Can't copy from %s to %s", source.getClass(), targetClass), e); } }