summaryrefslogtreecommitdiff
path: root/gnu/xml/validation/relaxng/FullSyntaxBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/xml/validation/relaxng/FullSyntaxBuilder.java')
-rw-r--r--gnu/xml/validation/relaxng/FullSyntaxBuilder.java148
1 files changed, 75 insertions, 73 deletions
diff --git a/gnu/xml/validation/relaxng/FullSyntaxBuilder.java b/gnu/xml/validation/relaxng/FullSyntaxBuilder.java
index bb73c4f38..da24362fe 100644
--- a/gnu/xml/validation/relaxng/FullSyntaxBuilder.java
+++ b/gnu/xml/validation/relaxng/FullSyntaxBuilder.java
@@ -78,53 +78,55 @@ class FullSyntaxBuilder
/**
* Complete vocabulary (elements and attributes) of the full syntax.
*/
- static final Map VOCABULARY = new HashMap();
- static final Set STRIPPED_ATTRIBUTES = new HashSet();
- static final Set PATTERN_ELEMENTS = new HashSet();
+ static final Map<String,Set<String>> VOCABULARY = new HashMap<String,Set<String>>();
+ static final Set<String> STRIPPED_ATTRIBUTES = new HashSet<String>();
+ static final Set<String> PATTERN_ELEMENTS = new HashSet<String>();
+ static final Set<String> EMPTY_STRING_SET = Collections.emptySet();
+
static
{
- Set elementAttrs = Collections.singleton("name");
- Set dataAttrs = new HashSet();
+ Set<String> elementAttrs = Collections.singleton("name");
+ Set<String> dataAttrs = new HashSet<String>();
dataAttrs.add("type");
dataAttrs.add("datatypeLibrary");
- Set valueAttrs = new HashSet();
+ Set<String> valueAttrs = new HashSet<String>();
valueAttrs.add("type");
valueAttrs.add("datatypeLibrary");
valueAttrs.add("ns");
- Set externalAttrs = Collections.singleton("href");
- Set startAttrs = Collections.singleton("combine");
- Set defineAttrs = new HashSet();
+ Set<String> externalAttrs = Collections.singleton("href");
+ Set<String> startAttrs = Collections.singleton("combine");
+ Set<String> defineAttrs = new HashSet<String>();
defineAttrs.add("name");
defineAttrs.add("combine");
- Set nsAttrs = Collections.singleton("ns");
+ Set<String> nsAttrs = Collections.singleton("ns");
VOCABULARY.put("element", elementAttrs);
VOCABULARY.put("attribute", elementAttrs);
- VOCABULARY.put("group", Collections.EMPTY_SET);
- VOCABULARY.put("interleave", Collections.EMPTY_SET);
- VOCABULARY.put("choice", Collections.EMPTY_SET);
- VOCABULARY.put("optional", Collections.EMPTY_SET);
- VOCABULARY.put("zeroOrMore", Collections.EMPTY_SET);
- VOCABULARY.put("oneOrMore", Collections.EMPTY_SET);
- VOCABULARY.put("list", Collections.EMPTY_SET);
- VOCABULARY.put("mixed", Collections.EMPTY_SET);
+ VOCABULARY.put("group", EMPTY_STRING_SET);
+ VOCABULARY.put("interleave", EMPTY_STRING_SET);
+ VOCABULARY.put("choice", EMPTY_STRING_SET);
+ VOCABULARY.put("optional", EMPTY_STRING_SET);
+ VOCABULARY.put("zeroOrMore", EMPTY_STRING_SET);
+ VOCABULARY.put("oneOrMore", EMPTY_STRING_SET);
+ VOCABULARY.put("list", EMPTY_STRING_SET);
+ VOCABULARY.put("mixed", EMPTY_STRING_SET);
VOCABULARY.put("ref", elementAttrs);
VOCABULARY.put("parentRef", elementAttrs);
- VOCABULARY.put("empty", Collections.EMPTY_SET);
- VOCABULARY.put("text", Collections.EMPTY_SET);
+ VOCABULARY.put("empty", EMPTY_STRING_SET);
+ VOCABULARY.put("text", EMPTY_STRING_SET);
VOCABULARY.put("value", valueAttrs);
VOCABULARY.put("data", dataAttrs);
- VOCABULARY.put("notAllowed", Collections.EMPTY_SET);
+ VOCABULARY.put("notAllowed", EMPTY_STRING_SET);
VOCABULARY.put("externalRef", externalAttrs);
- VOCABULARY.put("grammar", Collections.EMPTY_SET);
+ VOCABULARY.put("grammar", EMPTY_STRING_SET);
VOCABULARY.put("param", elementAttrs);
- VOCABULARY.put("except", Collections.EMPTY_SET);
- VOCABULARY.put("div", Collections.EMPTY_SET);
+ VOCABULARY.put("except", EMPTY_STRING_SET);
+ VOCABULARY.put("div", EMPTY_STRING_SET);
VOCABULARY.put("include", externalAttrs);
VOCABULARY.put("start", startAttrs);
VOCABULARY.put("define", defineAttrs);
VOCABULARY.put("name", nsAttrs);
- VOCABULARY.put("anyName", Collections.EMPTY_SET);
+ VOCABULARY.put("anyName", EMPTY_STRING_SET);
VOCABULARY.put("nsName", nsAttrs);
STRIPPED_ATTRIBUTES.add("name");
@@ -152,9 +154,9 @@ class FullSyntaxBuilder
PATTERN_ELEMENTS.add("grammar");
}
- private Set urls; // recursion checking
+ private Set<String> urls; // recursion checking
private int refCount; // creation of ref names
- private Map datatypeLibraries;
+ private Map<String,DatatypeLibrary> datatypeLibraries;
/**
* Parse the specified document into a grammar.
@@ -162,7 +164,7 @@ class FullSyntaxBuilder
synchronized Grammar parse(Document doc)
throws IOException
{
- urls = new HashSet();
+ urls = new HashSet<String>();
refCount = 1;
doc.normalizeDocument(); // Normalize XML document
@@ -195,24 +197,24 @@ class FullSyntaxBuilder
}
// 4.19. define and ref elements
- Set allDefines = new HashSet(), reachableDefines = new HashSet();
+ Set<Element> allDefines = new HashSet<Element>(), reachableDefines = new HashSet<Element>();
getDefines(allDefines, grammar, grammar, false);
getDefines(reachableDefines, grammar, start, true);
allDefines.removeAll(reachableDefines);
- for (Iterator i = allDefines.iterator(); i.hasNext(); )
+ for (Iterator<Element> i = allDefines.iterator(); i.hasNext(); )
{
// remove unreachable defines
- Element d = (Element) i.next();
+ Element d = i.next();
Node parent = d.getParentNode();
parent.removeChild(d);
}
// replace all elements that are not children of defines by refs to new
// defines
- Set elements = new HashSet();
+ Set<Element> elements = new HashSet<Element>();
getElements(elements, grammar, grammar);
- for (Iterator i = elements.iterator(); i.hasNext(); )
+ for (Iterator<Element> i = elements.iterator(); i.hasNext(); )
{
- Element element = (Element) i.next();
+ Element element = i.next();
Node parent = element.getParentNode();
if (!reachableDefines.contains(parent))
{
@@ -230,9 +232,9 @@ class FullSyntaxBuilder
}
}
// Get defines that don't have element children
- for (Iterator i = reachableDefines.iterator(); i.hasNext(); )
+ for (Iterator<Element> i = reachableDefines.iterator(); i.hasNext(); )
{
- Element d = (Element) i.next();
+ Element d = i.next();
Element child = getFirstChildElement(d);
if (child != null && "element".equals(child.getLocalName()))
i.remove();
@@ -240,9 +242,9 @@ class FullSyntaxBuilder
// Expand refs that refer to these defines
expandRefs(reachableDefines, grammar);
// Remove any defines that don't have element children
- for (Iterator i = reachableDefines.iterator(); i.hasNext(); )
+ for (Iterator<Element> i = reachableDefines.iterator(); i.hasNext(); )
{
- Element d = (Element) i.next();
+ Element d = i.next();
Node parent = d.getParentNode();
parent.removeChild(d);
}
@@ -254,7 +256,7 @@ class FullSyntaxBuilder
return ret;
}
- private void getDefines(Set defines, Element grammar, Element node,
+ private void getDefines(Set<Element> defines, Element grammar, Element node,
boolean followRefs)
{
String elementName = node.getLocalName();
@@ -281,7 +283,7 @@ class FullSyntaxBuilder
getDefines(defines, grammar, child, followRefs);
}
- private void getElements(Set elements, Element grammar, Element node)
+ private void getElements(Set<Element> elements, Element grammar, Element node)
{
String elementName = node.getLocalName();
if ("element".equals(elementName))
@@ -291,16 +293,16 @@ class FullSyntaxBuilder
getElements(elements, grammar, child);
}
- private void expandRefs(Set defines, Element node)
+ private void expandRefs(Set<Element> defines, Element node)
throws GrammarException
{
String elementName = node.getLocalName();
if ("ref".equals(elementName))
{
String rname = node.getAttribute("name");
- for (Iterator i = defines.iterator(); i.hasNext(); )
+ for (Iterator<Element> i = defines.iterator(); i.hasNext(); )
{
- Element define = (Element) i.next();
+ Element define = i.next();
String dname = define.getAttribute("name");
if (rname.equals(dname))
{
@@ -351,7 +353,7 @@ class FullSyntaxBuilder
parent.removeChild(node);
else
{
- Set allowedAttrs = (Set) VOCABULARY.get(elementName);
+ Set<String> allowedAttrs = VOCABULARY.get(elementName);
NamedNodeMap attrs = node.getAttributes();
int len = attrs.getLength();
for (int i = len - 1; i >= 0; i--)
@@ -467,19 +469,19 @@ class FullSyntaxBuilder
transform(element);
urls.remove(href);
// handle components
- List includeComponents = getComponents(include);
- List grammarComponents = getComponents(element);
- for (Iterator i = includeComponents.iterator(); i.hasNext(); )
+ List<Element> includeComponents = getComponents(include);
+ List<Element> grammarComponents = getComponents(element);
+ for (Iterator<Element> i = includeComponents.iterator(); i.hasNext(); )
{
- Element comp = (Element) i.next();
+ Element comp = i.next();
String compName = comp.getLocalName();
if ("start".equals(compName))
{
boolean found = false;
- for (Iterator j = grammarComponents.iterator();
+ for (Iterator<Element> j = grammarComponents.iterator();
j.hasNext(); )
{
- Element c2 = (Element) j.next();
+ Element c2 = j.next();
if ("start".equals(c2.getLocalName()))
{
c2.getParentNode().removeChild(c2);
@@ -494,10 +496,10 @@ class FullSyntaxBuilder
{
String name = comp.getAttribute("name");
boolean found = false;
- for (Iterator j = grammarComponents.iterator();
+ for (Iterator<Element> j = grammarComponents.iterator();
j.hasNext(); )
{
- Element c2 = (Element) j.next();
+ Element c2 = j.next();
if ("define".equals(c2.getLocalName()) &&
name.equals(c2.getAttribute("name")))
{
@@ -706,7 +708,7 @@ class FullSyntaxBuilder
forbidDescendants(node, Collections.singleton("anyName"));
else if ("nsName".equals(parentName))
{
- Set names = new HashSet();
+ Set<String> names = new HashSet<String>();
names.add("nsName");
names.add("anyName");
forbidDescendants(node, names);
@@ -748,7 +750,7 @@ class FullSyntaxBuilder
else if ("grammar".equals(elementName))
{
String combine = null;
- List nodes = new LinkedList();
+ List<Node> nodes = new LinkedList<Node>();
Node ctx = node.getFirstChild();
while (ctx != null)
{
@@ -767,8 +769,8 @@ class FullSyntaxBuilder
if (!nodes.isEmpty())
combineNodes(node, combine, "start", nodes);
// defines
- Map defines = new HashMap();
- Map defineCombines = new HashMap();
+ Map<String,List<Node>> defines = new HashMap<String,List<Node>>();
+ Map<String,String> defineCombines = new HashMap<String,String>();
ctx = node.getFirstChild();
while (ctx != null)
{
@@ -776,7 +778,7 @@ class FullSyntaxBuilder
if ("define".equals(ctx.getLocalName()))
{
String name = ((Element) ctx).getAttribute("name");
- combine = (String) defineCombines.get(name);
+ combine = defineCombines.get(name);
String c = ((Element) ctx).getAttribute("combine");
if (combine != null && !combine.equals(c))
throw new GrammarException("multiple define " +
@@ -784,21 +786,21 @@ class FullSyntaxBuilder
name + "' but no " +
"combine attribute");
defineCombines.put(name, c);
- nodes = (List) defines.get(name);
+ nodes = defines.get(name);
if (nodes == null)
{
- nodes = new LinkedList();
+ nodes = new LinkedList<Node>();
defines.put(name, nodes);
}
nodes.add(ctx);
}
ctx = next;
}
- for (Iterator i = defines.keySet().iterator(); i.hasNext(); )
+ for (Iterator<String> i = defines.keySet().iterator(); i.hasNext(); )
{
- String name = (String) i.next();
- combine = (String) defineCombines.get(name);
- nodes = (List) defines.get(name);
+ String name = i.next();
+ combine = defineCombines.get(name);
+ nodes = defines.get(name);
if (!nodes.isEmpty())
combineNodes(node, combine, "define", nodes);
}
@@ -937,7 +939,7 @@ class FullSyntaxBuilder
grammar = grammar1;
String name = ((Element) node).getAttribute("name");
- if (name != null)
+ if (name == null)
throw new GrammarException("no name attribute on " +
elementName);
Node define = null;
@@ -1205,9 +1207,9 @@ class FullSyntaxBuilder
/**
* Returns the "components" of an element, as described in section 4.7.
*/
- private List getComponents(Node node)
+ private List<Element> getComponents(Node node)
{
- List ret = new LinkedList();
+ List<Element> ret = new LinkedList<Element>();
for (Node ctx = node.getFirstChild(); ctx != null;
ctx = ctx.getNextSibling())
{
@@ -1220,7 +1222,7 @@ class FullSyntaxBuilder
if ("div".equals(name))
ret.addAll(getComponents(ctx));
else if (VOCABULARY.containsKey(name))
- ret.add(ctx);
+ ret.add((Element) ctx);
}
return ret;
}
@@ -1257,7 +1259,7 @@ class FullSyntaxBuilder
return (Element) ctx;
}
- private static void forbidDescendants(Node node, Set names)
+ private static void forbidDescendants(Node node, Set<String> names)
throws GrammarException
{
for (Node ctx = node.getFirstChild(); ctx != null;
@@ -1289,7 +1291,7 @@ class FullSyntaxBuilder
}
private static void combineNodes(Node node, String combine, String name,
- List nodes)
+ List<Node> nodes)
{
Document doc = node.getOwnerDocument();
Node child =
@@ -1298,9 +1300,9 @@ class FullSyntaxBuilder
doc.createElementNS(XMLConstants.RELAXNG_NS_URI, combine);
child.appendChild(combineNode);
boolean inserted = false;
- for (Iterator i = nodes.iterator(); i.hasNext(); )
+ for (Iterator<Node> i = nodes.iterator(); i.hasNext(); )
{
- Node startNode = (Node) i.next();
+ Node startNode = i.next();
if (!inserted)
{
node.insertBefore(child, startNode);
@@ -1635,8 +1637,8 @@ class FullSyntaxBuilder
throws GrammarException
{
if (datatypeLibraries == null)
- datatypeLibraries = new HashMap();
- DatatypeLibrary library = (DatatypeLibrary) datatypeLibraries.get(uri);
+ datatypeLibraries = new HashMap<String,DatatypeLibrary>();
+ DatatypeLibrary library = datatypeLibraries.get(uri);
if (library == null)
{
library = new DatatypeLibraryLoader().createDatatypeLibrary(uri);