if (!isModelAffected()) {
takeWriteLock();
model = model.clone();
}
affectsModel.put(absoluteAddress, NULL);
Resource model = this.model;
final Iterator<PathElement> i = absoluteAddress.iterator();
while (i.hasNext()) {
final PathElement element = i.next();
if (element.isMultiTarget()) {
throw MESSAGES.cannotWriteTo("*");
}
if (! i.hasNext()) {
final String key = element.getKey();
if(model.hasChild(element)) {
throw MESSAGES.duplicateResourceAddress(absoluteAddress);
} else {
final PathAddress parent = absoluteAddress.subAddress(0, absoluteAddress.size() -1);
final Set<String> childrenNames = modelController.getRootRegistration().getChildNames(parent);
if(!childrenNames.contains(key)) {
throw MESSAGES.noChildType(key);
}
model.registerChild(element, toAdd);
model = toAdd;
}
} else {
model = model.getChild(element);
if (model == null) {
PathAddress ancestor = PathAddress.EMPTY_ADDRESS;
for (PathElement pe : absoluteAddress) {
ancestor = ancestor.append(pe);
if (element.equals(pe)) {