// System.out.println("Restriction: " + r.keys.get("name") +
// " restriction " + r.keys.get("restriction"));
r.clearErrors();
Way fromWay = null;
Way toWay = null;
OsmPrimitive via = null;
/* find the "from", "via" and "to" elements */
for (RelationMember m : r.members) {
// if(restrictionDebug)
// System.out.println("member " + m.member + " selected " +
// r.selected);
if (m.member == null)
r.putError(tr("Empty member in relation."), true);
else if (m.member.deleted)
r.putError(tr("Deleted member ''{0}'' in relation.", m.member
.getName()), true);
else if (m.member.incomplete) {
return;
} else {
if (m.member instanceof Way) {
Way w = (Way) m.member;
if (w.nodes.size() < 2) {
r.putError(tr("Way ''{0}'' with less than two points.",
w.getName()), true);
} else if ("from".equals(m.role)) {
if (fromWay != null)
r.putError(tr("More than one \"from\" way found."),
true);
else {
fromWay = w;
}
} else if ("to".equals(m.role)) {
if (toWay != null)
r.putError(tr("More than one \"to\" way found."),
true);
else {
toWay = w;
}
} else if ("via".equals(m.role)) {
if (via != null)
r
.putError(
tr("More than one \"via\" found."),
true);
else
via = w;
} else
r.putError(tr("Unknown role ''{0}''.", m.role), true);
} else if (m.member instanceof Node) {
Node n = (Node) m.member;
if ("via".equals(m.role)) {
if (via != null)
r
.putError(
tr("More than one \"via\" found."),
true);
else
via = n;
} else
r.putError(tr("Unknown role ''{0}''.", m.role), true);
} else
r.putError(tr("Unknown member type for ''{0}''.", m.member
.getName()), true);
}
}
if (fromWay == null) {
r.putError(tr("No \"from\" way found."), true);
return;
}
if (toWay == null) {
r.putError(tr("No \"to\" way found."), true);
return;
}
if (via == null) {
r.putError(tr("No \"via\" node or way found."), true);
return;
}
Node viaNode;
if (via instanceof Node) {
viaNode = (Node) via;
if (!fromWay.isFirstLastNode(viaNode)) {
r
.putError(
tr("The \"from\" way doesn't start or end at a \"via\" node."),
true);
return;
}
if (!toWay.isFirstLastNode(viaNode))
r
.putError(
tr("The \"to\" way doesn't start or end at a \"via\" node."),
true);
} else {
Way viaWay = (Way) via;
Node firstNode = viaWay.firstNode();
Node lastNode = viaWay.lastNode();
if (fromWay.isFirstLastNode(firstNode))
viaNode = firstNode;
else if (fromWay.isFirstLastNode(lastNode))
viaNode = firstNode;
else {