if (prop.get(namePropLocator) == null) {
throw new IllegalArgumentException("There is no element in the map with the name " + namePropLocator);
}
String key = ((PropertySimple) prop.get(namePropLocator)).getStringValue();
Operation operation;
Address addr = new Address(address);
addr.add(type, key);
if (!addNewChildren || existingPropNames.contains(key)) {
// update existing entry
if (addDeleteModifiedChildren) {
operation = new Remove(addr);
cop.addStep(operation);
operation = new Operation("add", addr);
for (Map.Entry<String, Object> entry : results.entrySet()) {
String key1 = entry.getKey();
Object value = getValueWithType(entry, propDef);
if (key1.endsWith(":expr")) {
key1 = key1.substring(0, key1.indexOf(':'));
Map<String, Object> tmp = new HashMap<String, Object>();
tmp.put("EXPRESSION_VALUE", value);
operation.addAdditionalProperty(key1, tmp);
} else {
operation.addAdditionalProperty(key1, value);
}
}
cop.addStep(operation);
} else {
for (Map.Entry<String, Object> entry : results.entrySet()) {
String key1 = entry.getKey();
Object value = getValueWithType(entry, propDef);
if (key1.endsWith(":expr")) {
key1 = key1.substring(0, key1.indexOf(':'));
Map<String, Object> tmp = new HashMap<String, Object>();
tmp.put("EXPRESSION_VALUE", value);
operation = new WriteAttribute(addr, key1, tmp);
} else {
operation = new WriteAttribute(addr, key1, value);
}
cop.addStep(operation);
}
}
} else {
// write new child ( :name+ case )
operation = new Operation("add", addr);
for (Map.Entry<String, Object> entry : results.entrySet()) {
String key1 = entry.getKey();
Object value = getValueWithType(entry, propDef);
if (key1.endsWith(":expr")) {
key1 = key1.substring(0, key1.indexOf(':'));
Map<String, Object> tmp = new HashMap<String, Object>();
tmp.put("EXPRESSION_VALUE", value);
operation.addAdditionalProperty(key1, tmp);
} else {
operation.addAdditionalProperty(key1, value);
}
}
cop.addStep(operation);
}