2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.xerces.impl.validation;
20
import org.apache.xerces.util.SymbolTable;
21
import org.apache.xerces.impl.dv.ValidationContext;
23
import org.apache.xerces.xni.NamespaceContext;
24
import java.util.Hashtable;
25
import java.util.Enumeration;
28
* Implementation of ValidationContext inteface. Used to establish an
29
* environment for simple type validation.
33
* @author Elena Litani, IBM
34
* @version $Id: ValidationState.java,v 1.2 2009/12/10 03:18:42 matthewoliver Exp $
36
public class ValidationState implements ValidationContext {
41
private boolean fExtraChecking = true;
42
private boolean fFacetChecking = true;
43
private boolean fNormalize = true;
44
private boolean fNamespaces = true;
46
private EntityState fEntityState = null;
47
private NamespaceContext fNamespaceContext = null;
48
private SymbolTable fSymbolTable = null;
50
//REVISIT: Should replace with a lighter structure.
51
private final Hashtable fIdTable = new Hashtable();
52
private final Hashtable fIdRefTable = new Hashtable();
53
private final static Object fNullValue = new Object();
58
public void setExtraChecking(boolean newValue) {
59
fExtraChecking = newValue;
62
public void setFacetChecking(boolean newValue) {
63
fFacetChecking = newValue;
66
public void setNormalizationRequired (boolean newValue) {
67
fNormalize = newValue;
70
public void setUsingNamespaces (boolean newValue) {
71
fNamespaces = newValue;
74
public void setEntityState(EntityState state) {
78
public void setNamespaceSupport(NamespaceContext namespace) {
79
fNamespaceContext = namespace;
82
public void setSymbolTable(SymbolTable sTable) {
83
fSymbolTable = sTable;
87
* return null if all IDREF values have a corresponding ID value;
88
* otherwise return the first IDREF value without a matching ID value.
90
public String checkIDRefID () {
91
Enumeration en = fIdRefTable.keys();
94
while (en.hasMoreElements()) {
95
key = (String)en.nextElement();
96
if (!fIdTable.containsKey(key)) {
103
public void reset () {
104
fExtraChecking = true;
105
fFacetChecking = true;
110
fNamespaceContext = null;
115
* The same validation state can be used to validate more than one (schema)
116
* validation roots. Entity/Namespace/Symbol are shared, but each validation
117
* root needs its own id/idref tables. So we need this method to reset only
120
public void resetIDTables() {
126
// implementation of ValidationContext methods
129
// whether to do extra id/idref/entity checking
130
public boolean needExtraChecking() {
131
return fExtraChecking;
134
// whether to validate against facets
135
public boolean needFacetChecking() {
136
return fFacetChecking;
139
public boolean needToNormalize (){
143
public boolean useNamespaces() {
148
public boolean isEntityDeclared (String name) {
149
if (fEntityState !=null) {
150
return fEntityState.isEntityDeclared(getSymbol(name));
154
public boolean isEntityUnparsed (String name) {
155
if (fEntityState !=null) {
156
return fEntityState.isEntityUnparsed(getSymbol(name));
162
public boolean isIdDeclared(String name) {
163
return fIdTable.containsKey(name);
165
public void addId(String name) {
166
fIdTable.put(name, fNullValue);
170
public void addIdRef(String name) {
171
fIdRefTable.put(name, fNullValue);
175
public String getSymbol (String symbol) {
176
if (fSymbolTable != null)
177
return fSymbolTable.addSymbol(symbol);
178
// if there is no symbol table, we return java-internalized string,
179
// because symbol table strings are also java-internalzied.
180
// this guarantees that the returned string from this method can be
181
// compared by reference with other symbol table string. -SG
182
return symbol.intern();
185
public String getURI(String prefix) {
186
if (fNamespaceContext !=null) {
187
return fNamespaceContext.getURI(prefix);