public Classification newClassification(Classification original) { if (!isReadOnly()) { throw new IllegalStateException( "You can only create Classifications from a persistant Version of DynamicType"); } final ClassificationImpl newClassification = (ClassificationImpl) newClassification(true); { Attribute[] attributes = original.getAttributes(); for (int i = 0; i < attributes.length; i++) { Attribute originalAttribute = attributes[i]; String attributeKey = originalAttribute.getKey(); Attribute newAttribute = newClassification.getAttribute(attributeKey); Object defaultValue = originalAttribute.defaultValue(); Object originalValue = original.getValue(attributeKey); if (newAttribute != null && newAttribute.getType().equals(originalAttribute.getType())) { Object newDefaultValue = newAttribute.defaultValue(); // If the default value of the new type differs from the old one and the value is the same // as the old default then use the new default if (newDefaultValue != null && ((defaultValue == null && originalValue == null) || (defaultValue != null && originalValue != null && !newDefaultValue.equals(defaultValue) && (originalValue.equals(defaultValue))))) { newClassification.setValue(newAttribute, newDefaultValue); } else { newClassification.setValue(newAttribute, newAttribute.convertValue(originalValue)); } } } return newClassification; } }
public Classification newClassificationWithoutCheck(boolean useDefaults) { final ClassificationImpl classification = new ClassificationImpl(this); if (resolver != null) { classification.setResolver(resolver); } // Array could not be up todate final Attribute[] attributes2 = getAttributes(); if (useDefaults) { for (Attribute att : attributes2) { final Object defaultValue = att.defaultValue(); if (defaultValue != null) { classification.setValue(att, defaultValue); } } } return classification; }
public ClassificationImpl clone() { ClassificationImpl clone = new ClassificationImpl((DynamicTypeImpl) getType()); // clone.referenceHandler = (ReferenceHandler) referenceHandler.clone((Map<String, // List<String>>) ((HashMap<String, List<String>>)data).clone()); // clone.attributeValueMap = (HashMap<String,Object>) attributeValueMap.clone(); for (Map.Entry<String, List<String>> entry : data.entrySet()) { String key = entry.getKey(); List<String> value = new ArrayList<String>(entry.getValue()); clone.data.put(key, value); } clone.resolver = resolver; clone.typeId = getParentId(); clone.type = type; clone.name = null; clone.readOnly = false; // clones are always writable return clone; }