aboutsummaryrefslogtreecommitdiff
path: root/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java')
-rw-r--r--src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java100
1 files changed, 47 insertions, 53 deletions
diff --git a/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java b/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java
index f7fc09a..c138b7f 100644
--- a/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java
+++ b/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java
@@ -1,15 +1,15 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,16 +20,6 @@
package com.sun.org.apache.xerces.internal.impl.xs;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Stack;
-import java.util.Vector;
-import java.util.ArrayList;
-import javax.xml.XMLConstants;
import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
@@ -51,13 +41,14 @@ import com.sun.org.apache.xerces.internal.impl.xs.identity.XPathMatcher;
import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder;
import com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory;
import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator;
+import com.sun.org.apache.xerces.internal.parsers.XMLParser;
import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
import com.sun.org.apache.xerces.internal.util.IntStack;
import com.sun.org.apache.xerces.internal.util.SymbolTable;
+import com.sun.org.apache.xerces.internal.util.URI.MalformedURIException;
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
import com.sun.org.apache.xerces.internal.util.XMLChar;
import com.sun.org.apache.xerces.internal.util.XMLSymbols;
-import com.sun.org.apache.xerces.internal.util.URI.MalformedURIException;
import com.sun.org.apache.xerces.internal.xni.Augmentations;
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
import com.sun.org.apache.xerces.internal.xni.QName;
@@ -83,7 +74,13 @@ import com.sun.org.apache.xerces.internal.xs.StringList;
import com.sun.org.apache.xerces.internal.xs.XSConstants;
import com.sun.org.apache.xerces.internal.xs.XSObjectList;
import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
-import com.sun.org.apache.xerces.internal.parsers.XMLParser;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+import java.util.Vector;
/**
* The XML Schema validator. The validator implements a document
@@ -308,9 +305,6 @@ public class XMLSchemaValidator
protected static final int ID_CONSTRAINT_NUM = 1;
//
- private static final Hashtable EMPTY_TABLE = new Hashtable();
-
- //
// Data
//
@@ -495,7 +489,7 @@ public class XMLSchemaValidator
/** Schema Grammar Description passed, to give a chance to application to supply the Grammar */
protected final XSDDescription fXSDDescription = new XSDDescription();
- protected final Hashtable fLocationPairs = new Hashtable();
+ protected final Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = new HashMap<>();
// handlers
@@ -2358,8 +2352,7 @@ public class XMLSchemaValidator
}
}
if (nsLocation != null) {
- XMLSchemaLoader.LocationArray la =
- ((XMLSchemaLoader.LocationArray) fLocationPairs.get(XMLSymbols.EMPTY_STRING));
+ XMLSchemaLoader.LocationArray la = fLocationPairs.get(XMLSymbols.EMPTY_STRING);
if (la == null) {
la = new XMLSchemaLoader.LocationArray();
fLocationPairs.put(XMLSymbols.EMPTY_STRING, la);
@@ -2414,11 +2407,11 @@ public class XMLSchemaValidator
fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId());
}
- Hashtable locationPairs = fLocationPairs;
- Object locationArray =
+ Map<String, XMLSchemaLoader.LocationArray> locationPairs = fLocationPairs;
+ XMLSchemaLoader.LocationArray locationArray =
locationPairs.get(namespace == null ? XMLSymbols.EMPTY_STRING : namespace);
if (locationArray != null) {
- String[] temp = ((XMLSchemaLoader.LocationArray) locationArray).getLocationArray();
+ String[] temp = locationArray.getLocationArray();
if (temp.length != 0) {
setLocationHints(fXSDDescription, temp, grammar);
}
@@ -2428,7 +2421,7 @@ public class XMLSchemaValidator
boolean toParseSchema = true;
if (grammar != null) {
// use location hints instead
- locationPairs = EMPTY_TABLE;
+ locationPairs = Collections.emptyMap();
}
// try to parse the grammar using location hints from that namespace..
@@ -3688,7 +3681,7 @@ public class XMLSchemaValidator
protected void checkDuplicateValues() {
// no-op
- } // duplicateValue(Hashtable)
+ } // duplicateValue(Map)
/** Returns a string of the specified values. */
protected String toString(Object[] values) {
@@ -3861,7 +3854,7 @@ public class XMLSchemaValidator
String cName = fIdentityConstraint.getIdentityConstraintName();
reportSchemaError(code, new Object[] { value, eName, cName });
}
- } // duplicateValue(Hashtable)
+ } // duplicateValue(Map)
} // class UniqueValueStore
@@ -3898,7 +3891,7 @@ public class XMLSchemaValidator
String cName = fIdentityConstraint.getIdentityConstraintName();
reportSchemaError(code, new Object[] { value, eName, cName });
}
- } // duplicateValue(Hashtable)
+ } // duplicateValue(Map)
} // class KeyValueStore
@@ -3990,14 +3983,15 @@ public class XMLSchemaValidator
/**
* Values stores associated to specific identity constraints.
- * This hashtable maps IdentityConstraints and
+ * This map maps IdentityConstraints and
* the 0-based element on which their selectors first matched to
* a corresponding ValueStore. This should take care
* of all cases, including where ID constraints with
* descendant-or-self axes occur on recursively-defined
* elements.
*/
- protected final Hashtable fIdentityConstraint2ValueStoreMap = new Hashtable();
+ protected final Map<LocalIDKey, ValueStoreBase>
+ fIdentityConstraint2ValueStoreMap = new HashMap<>();
// sketch of algorithm:
// - when a constraint is first encountered, its
@@ -4010,7 +4004,7 @@ public class XMLSchemaValidator
// The fGlobalIDMapStack has the following structure:
// - validation always occurs against the fGlobalIDConstraintMap
// (which comprises all the "eligible" id constraints);
- // When an endElement is found, this Hashtable is merged with the one
+ // When an endElement is found, this Map is merged with the one
// below in the stack.
// When a start tag is encountered, we create a new
// fGlobalIDConstraintMap.
@@ -4018,8 +4012,10 @@ public class XMLSchemaValidator
// the preceding siblings' eligible id constraints;
// the fGlobalIDConstraintMap contains descendants+self.
// keyrefs can only match descendants+self.
- protected final Stack fGlobalMapStack = new Stack();
- protected final Hashtable fGlobalIDConstraintMap = new Hashtable();
+ protected final Stack<Map<IdentityConstraint, ValueStoreBase>>
+ fGlobalMapStack = new Stack<>();
+ protected final Map<IdentityConstraint, ValueStoreBase>
+ fGlobalIDConstraintMap = new HashMap<>();
//
// Constructors
@@ -4046,7 +4042,8 @@ public class XMLSchemaValidator
public void startElement() {
// only clone the hashtable when there are elements
if (fGlobalIDConstraintMap.size() > 0)
- fGlobalMapStack.push(fGlobalIDConstraintMap.clone());
+ fGlobalMapStack.push((Map<IdentityConstraint, ValueStoreBase>)
+ ((HashMap)fGlobalIDConstraintMap).clone());
else
fGlobalMapStack.push(null);
fGlobalIDConstraintMap.clear();
@@ -4059,19 +4056,17 @@ public class XMLSchemaValidator
if (fGlobalMapStack.isEmpty()) {
return; // must be an invalid doc!
}
- Hashtable oldMap = (Hashtable) fGlobalMapStack.pop();
+ Map<IdentityConstraint, ValueStoreBase> oldMap = fGlobalMapStack.pop();
// return if there is no element
if (oldMap == null) {
return;
}
- Iterator entries = oldMap.entrySet().iterator();
- while (entries.hasNext()) {
- Map.Entry entry = (Map.Entry) entries.next();
- IdentityConstraint id = (IdentityConstraint) entry.getKey();
- ValueStoreBase oldVal = (ValueStoreBase) entry.getValue();
+ for (Map.Entry<IdentityConstraint, ValueStoreBase> entry : oldMap.entrySet()) {
+ IdentityConstraint id = entry.getKey();
+ ValueStoreBase oldVal = entry.getValue();
if (oldVal != null) {
- ValueStoreBase currVal = (ValueStoreBase) fGlobalIDConstraintMap.get(id);
+ ValueStoreBase currVal = fGlobalIDConstraintMap.get(id);
if (currVal == null) {
fGlobalIDConstraintMap.put(id, oldVal);
}
@@ -4145,26 +4140,25 @@ public class XMLSchemaValidator
public ValueStoreBase getValueStoreFor(IdentityConstraint id, int initialDepth) {
fLocalId.fDepth = initialDepth;
fLocalId.fId = id;
- return (ValueStoreBase) fIdentityConstraint2ValueStoreMap.get(fLocalId);
+ return fIdentityConstraint2ValueStoreMap.get(fLocalId);
} // getValueStoreFor(IdentityConstraint, int):ValueStoreBase
/** Returns the global value store associated to the specified IdentityConstraint. */
public ValueStoreBase getGlobalValueStoreFor(IdentityConstraint id) {
- return (ValueStoreBase) fGlobalIDConstraintMap.get(id);
+ return fGlobalIDConstraintMap.get(id);
} // getValueStoreFor(IdentityConstraint):ValueStoreBase
// This method takes the contents of the (local) ValueStore
// associated with id and moves them into the global
- // hashtable, if id is a <unique> or a <key>.
+ // map, if id is a <unique> or a <key>.
// If it's a <keyRef>, then we leave it for later.
public void transplant(IdentityConstraint id, int initialDepth) {
fLocalId.fDepth = initialDepth;
fLocalId.fId = id;
- ValueStoreBase newVals =
- (ValueStoreBase) fIdentityConstraint2ValueStoreMap.get(fLocalId);
+ ValueStoreBase newVals = fIdentityConstraint2ValueStoreMap.get(fLocalId);
if (id.getCategory() == IdentityConstraint.IC_KEYREF)
return;
- ValueStoreBase currVals = (ValueStoreBase) fGlobalIDConstraintMap.get(id);
+ ValueStoreBase currVals = fGlobalIDConstraintMap.get(id);
if (currVals != null) {
currVals.append(newVals);
fGlobalIDConstraintMap.put(id, currVals);
@@ -4205,7 +4199,7 @@ public class XMLSchemaValidator
} // class ValueStoreCache
// the purpose of this class is to enable IdentityConstraint,int
- // pairs to be used easily as keys in Hashtables.
+ // pairs to be used easily as keys in Maps.
protected class LocalIDKey {
public IdentityConstraint fId;