示例#1
0
 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;
   }
 }
示例#2
0
 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;
 }