// There is only a single source ...
SelectorName viewName = mapping.getOriginalName();
SelectorName sourceName = mapping.getSingleMappedSelectorName();
if (joinCondition instanceof SameNodeJoinCondition) {
SameNodeJoinCondition condition = (SameNodeJoinCondition)joinCondition;
SelectorName replacement1 = condition.selector1Name();
SelectorName replacement2 = condition.selector2Name();
if (replacement1.equals(viewName)) replacement1 = sourceName;
if (replacement2.equals(viewName)) replacement2 = sourceName;
if (replacement1 == condition.selector1Name() && replacement2 == condition.selector2Name()) return condition;
node.addSelector(replacement1, replacement2);
if (condition.getSelector2Path() == null) return new SameNodeJoinCondition(replacement1, replacement2);
return new SameNodeJoinCondition(replacement1, replacement2, condition.getSelector2Path());
}
if (joinCondition instanceof ChildNodeJoinCondition) {
ChildNodeJoinCondition condition = (ChildNodeJoinCondition)joinCondition;
SelectorName childSelector = condition.childSelectorName();
SelectorName parentSelector = condition.parentSelectorName();
if (childSelector.equals(viewName)) childSelector = sourceName;
if (parentSelector.equals(viewName)) parentSelector = sourceName;
if (childSelector == condition.childSelectorName() && parentSelector == condition.parentSelectorName()) return condition;
node.addSelector(childSelector, parentSelector);
return new ChildNodeJoinCondition(parentSelector, childSelector);
}
if (joinCondition instanceof DescendantNodeJoinCondition) {
DescendantNodeJoinCondition condition = (DescendantNodeJoinCondition)joinCondition;
SelectorName ancestor = condition.ancestorSelectorName();
SelectorName descendant = condition.descendantSelectorName();
if (ancestor.equals(viewName)) ancestor = sourceName;
if (descendant.equals(viewName)) descendant = sourceName;
if (ancestor == condition.ancestorSelectorName() && descendant == condition.descendantSelectorName()) return condition;
node.addSelector(ancestor, descendant);
return new DescendantNodeJoinCondition(ancestor, descendant);
}
return joinCondition;
}