List of usage examples for org.springframework.beans BeanWrapperImpl getRootInstance
public final Object getRootInstance()
From source file:com.predic8.membrane.annot.bean.MCUtil.java
@SuppressWarnings("unchecked") public static <T> T clone(T object, boolean deep) { try {/*from w w w. j a v a 2 s . c o m*/ if (object == null) throw new InvalidParameterException("'object' must not be null."); Class<? extends Object> clazz = object.getClass(); MCElement e = clazz.getAnnotation(MCElement.class); if (e == null) throw new IllegalArgumentException("'object' must be @MCElement-annotated."); BeanWrapperImpl dst = new BeanWrapperImpl(clazz); BeanWrapperImpl src = new BeanWrapperImpl(object); for (Method m : clazz.getMethods()) { if (!m.getName().startsWith("set")) continue; String propertyName = AnnotUtils.dejavaify(m.getName().substring(3)); MCAttribute a = m.getAnnotation(MCAttribute.class); if (a != null) { dst.setPropertyValue(propertyName, src.getPropertyValue(propertyName)); } MCChildElement c = m.getAnnotation(MCChildElement.class); if (c != null) { if (deep) { dst.setPropertyValue(propertyName, cloneInternal(src.getPropertyValue(propertyName), deep)); } else { dst.setPropertyValue(propertyName, src.getPropertyValue(propertyName)); } } MCOtherAttributes o = m.getAnnotation(MCOtherAttributes.class); if (o != null) { dst.setPropertyValue(propertyName, src.getPropertyValue(propertyName)); } MCTextContent t = m.getAnnotation(MCTextContent.class); if (t != null) { dst.setPropertyValue(propertyName, src.getPropertyValue(propertyName)); } } return (T) dst.getRootInstance(); } catch (Exception e) { throw new RuntimeException(e); } }