com.thaiopensource.relaxng.pattern.DuplicateAttributeDetector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wicketstuff-jing Show documentation
Show all versions of wicketstuff-jing Show documentation
Jing is a validator for RELAX NG and other schema languages. This
project was taken from http://code.google.com/p/jing-trang and
mavenized for inclusion in the Wicket Stuff HTML Validator.
The code was taken from the 20091111 release.
package com.thaiopensource.relaxng.pattern;
import java.util.ArrayList;
import java.util.List;
class DuplicateAttributeDetector {
private final List nameClasses = new ArrayList();
private Alternative alternatives = null;
private static class Alternative {
private final int startIndex;
private int endIndex;
private final Alternative parent;
private Alternative(int startIndex, Alternative parent) {
this.startIndex = startIndex;
this.endIndex = startIndex;
this.parent = parent;
}
}
void addAttribute(NameClass nc) throws RestrictionViolationException {
int lim = nameClasses.size();
for (Alternative a = alternatives; a != null; a = a.parent) {
for (int i = a.endIndex; i < lim; i++)
checkAttributeOverlap(nc, nameClasses.get(i));
lim = a.startIndex;
}
for (int i = 0; i < lim; i++)
checkAttributeOverlap(nc, nameClasses.get(i));
nameClasses.add(nc);
}
static private void checkAttributeOverlap(NameClass nc1, NameClass nc2) throws RestrictionViolationException {
OverlapDetector.checkOverlap(nc1, nc2,
"duplicate_attribute_name",
"duplicate_attribute_ns",
"duplicate_attribute");
}
void startChoice() {
alternatives = new Alternative(nameClasses.size(), alternatives);
}
void alternative() {
alternatives.endIndex = nameClasses.size();
}
void endChoice() {
alternatives = alternatives.parent;
}
}