assert target != null;
store.compare(fromState, toState, new NodeStateDiff() {
@Override
public void propertyAdded(PropertyState after) {
Resolution resolution;
PropertyState p = target.getProperty(after.getName());
if (p == null) {
resolution = OURS;
}
else {
resolution = conflictHandler.addExistingProperty(target, after, p);
}
switch (resolution) {
case OURS:
setProperty(target, after);
break;
case THEIRS:
case MERGED:
break;
}
}
@Override
public void propertyChanged(PropertyState before, PropertyState after) {
assert before.getName().equals(after.getName());
Resolution resolution;
PropertyState p = target.getProperty(after.getName());
if (p == null) {
resolution = conflictHandler.changeDeletedProperty(target, after);
}
else if (before.equals(p)) {
resolution = OURS;
}
else {
resolution = conflictHandler.changeChangedProperty(target, after, p);
}
switch (resolution) {
case OURS:
setProperty(target, after);
break;
case THEIRS:
case MERGED:
break;
}
}
@Override
public void propertyDeleted(PropertyState before) {
Resolution resolution;
PropertyState p = target.getProperty(before.getName());
if (before.equals(p)) {
resolution = OURS;
}
else if (p == null) {
resolution = conflictHandler.deleteDeletedProperty(target, before);
}
else {
resolution = conflictHandler.deleteChangedProperty(target, p);
}
switch (resolution) {
case OURS:
target.removeProperty(before.getName());
break;
case THEIRS:
case MERGED:
break;
}
}
@Override
public void childNodeAdded(String name, NodeState after) {
Resolution resolution;
TreeImpl n = target.getChild(name);
if (n == null) {
resolution = OURS;
}
else {
resolution = conflictHandler.addExistingNode(target, name, after, n.getNodeState());
}
switch (resolution) {
case OURS:
addChild(target, name, after);
break;
case THEIRS:
case MERGED:
break;
}
}
@Override
public void childNodeChanged(String name, NodeState before, NodeState after) {
Resolution resolution;
TreeImpl n = target.getChild(name);
if (n == null) {
resolution = conflictHandler.changeDeletedNode(target, name, after);
}
else {
merge(before, after, n, conflictHandler);
resolution = MERGED;
}
switch (resolution) {
case OURS:
addChild(target, name, after);
break;
case THEIRS:
case MERGED:
break;
}
}
@Override
public void childNodeDeleted(String name, NodeState before) {
Resolution resolution;
TreeImpl n = target.getChild(name);
if (n == null) {
resolution = conflictHandler.deleteDeletedNode(target, name);
}