public void checkCloneable(OrderItemAttribute itemAttribute) throws CloneNotSupportedException, SecurityException, NoSuchMethodException { Method cloneMethod = itemAttribute.getClass().getMethod("clone", new Class[] {}); if (cloneMethod.getDeclaringClass().getName().startsWith("org.broadleafcommerce") && !itemAttribute.getClass().getName().startsWith("org.broadleafcommerce")) { // subclass is not implementing the clone method throw new CloneNotSupportedException( "Custom extensions and implementations should implement clone in order to guarantee split and merge operations are performed accurately"); } }
@Override public OrderItemAttribute clone() { // instantiate from the fully qualified name via reflection OrderItemAttribute itemAttribute; try { itemAttribute = (OrderItemAttribute) Class.forName(this.getClass().getName()).newInstance(); try { checkCloneable(itemAttribute); } catch (CloneNotSupportedException e) { LOG.warn( "Clone implementation missing in inheritance hierarchy outside of Broadleaf: " + itemAttribute.getClass().getName(), e); } itemAttribute.setName(name); itemAttribute.setOrderItem(orderItem); itemAttribute.setValue(value); } catch (Exception e) { throw new RuntimeException(e); } return itemAttribute; }