コード例 #1
0
 @Override
 public void run() {
   JsonElement element = parser.parse(line);
   DynamicModelObject object =
       DynamicModelUtils.getObjectByAdress(
           element.getAsJsonObject().get("@src").getAsString(), model);
   String propertyName = element.getAsJsonObject().get("@prop").getAsString();
   JsonElement nv = element.getAsJsonObject().get("@nv");
   JsonElement ov = element.getAsJsonObject().get("@ov");
   Object value = null;
   boolean isList = object.getCollection().getAsListProperties().contains(propertyName);
   if (nv != null) {
     String raw = nv.getAsString();
     if (OBJECT_ADDRESS_PATTERN.matcher(raw).matches()) {
       value = DynamicModelUtils.getObjectByAdress(nv.getAsString(), model);
     } else if (DOUBLE_VALUE_PATTERN.matcher(raw).matches()) {
       value = nv.getAsDouble();
     } else if (INTEGER_VALUE_PATTERN.matcher(raw).matches()) {
       value = nv.getAsInt();
     } else if (BOOLEAN_VALUE_PATTERN.matcher(raw).matches()) {
       value = nv.getAsBoolean();
     } else {
       value = raw;
     }
   } else if (ov != null) { // is a deletion
     value = null;
     if (isList) {
       value = model.getObject(ov.getAsString());
     }
   }
   if (!isList) {
     Property<Object> prop = (Property<Object>) object.getProperties().get(propertyName);
     if (prop != null) {
       if (prop.getValue() != null
           && (value == null || prop.getValue().getClass().isAssignableFrom(value.getClass()))) {
         prop.setValue(value);
       } else {
         SettlersApplication.NET.warning(
             "Received invalid property update - types don't match.");
       }
     } else {
       if (value == null) {
         return;
       }
       ((Property<Object>) object.getProperty(propertyName, value.getClass())).setValue(value);
     }
   } else {
     ListProperty<DynamicModelObject> list =
         (ListProperty<DynamicModelObject>) object.getProperty(propertyName, List.class);
     if (nv != null) {
       list.add((DynamicModelObject) value);
     } else if (ov != null) {
       list.remove(value);
     }
   }
 }
コード例 #2
0
 public boolean addValidator(Validator validator) {
   return validators.add(validator);
 }