Пример #1
0
 public void setValue(Attribute attribute, Object value) {
   checkWritable();
   if (value != null && !(value instanceof Collection<?>)) {
     value = Collections.singleton(value);
   }
   setValues(attribute, (Collection<?>) value);
 }
Пример #2
0
  public void commitChange(DynamicType type) {
    if (!hasType(type)) {
      return;
    }

    Collection<String> removedKeys = new ArrayList<String>();
    Map<Attribute, Attribute> attributeMapping = new HashMap<Attribute, Attribute>();
    for (String key : data.keySet()) {
      Attribute attribute = getType().getAttribute(key);
      Attribute attribute2 = type.getAttribute(key);
      // key now longer availabe so remove it
      if (attribute2 == null) {
        removedKeys.add(key);
      }
      if (attribute == null) {
        continue;
      }
      String attId = attribute.getId();
      Attribute newAtt = findAttributeById(type, attId);
      if (newAtt != null) {
        attributeMapping.put(attribute, newAtt);
      }
    }
    for (Attribute attribute : attributeMapping.keySet()) {
      Collection<Object> convertedValues = new ArrayList<Object>();
      Collection<?> valueCollection = getValues(attribute);
      Attribute newAttribute = attributeMapping.get(attribute);
      for (Object oldValue : valueCollection) {
        Object newValue = newAttribute.convertValue(oldValue);
        if (newValue != null) {
          convertedValues.add(newValue);
        }
      }
      setValues(newAttribute, convertedValues);
    }

    for (String key : removedKeys) {
      data.remove(key);
    }
    this.type = type.getKey();
    name = null;
  }