~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/impl/validation/ValidationState.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
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.
 
16
 */
 
17
 
 
18
package org.apache.xerces.impl.validation;
 
19
 
 
20
import org.apache.xerces.util.SymbolTable;
 
21
import org.apache.xerces.impl.dv.ValidationContext;
 
22
 
 
23
import org.apache.xerces.xni.NamespaceContext;
 
24
import java.util.Hashtable;
 
25
import java.util.Enumeration;
 
26
 
 
27
/**
 
28
 * Implementation of ValidationContext inteface. Used to establish an
 
29
 * environment for simple type validation.
 
30
 * 
 
31
 * @xerces.internal
 
32
 *
 
33
 * @author Elena Litani, IBM
 
34
 * @version $Id: ValidationState.java,v 1.2 2009/12/10 03:18:42 matthewoliver Exp $
 
35
 */
 
36
public class ValidationState implements ValidationContext {
 
37
 
 
38
    //
 
39
    // private data
 
40
    //
 
41
    private boolean fExtraChecking              = true;
 
42
    private boolean fFacetChecking              = true;
 
43
    private boolean fNormalize                  = true;
 
44
    private boolean fNamespaces                 = true;
 
45
 
 
46
    private EntityState fEntityState            = null;
 
47
    private NamespaceContext fNamespaceContext  = null;
 
48
    private SymbolTable fSymbolTable            = null;
 
49
 
 
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();
 
54
 
 
55
    //
 
56
    // public methods
 
57
    //
 
58
    public void setExtraChecking(boolean newValue) {
 
59
        fExtraChecking = newValue;
 
60
    }
 
61
 
 
62
    public void setFacetChecking(boolean newValue) {
 
63
        fFacetChecking = newValue;
 
64
    }
 
65
 
 
66
    public void setNormalizationRequired (boolean newValue) {
 
67
          fNormalize = newValue;
 
68
    }
 
69
 
 
70
    public void setUsingNamespaces (boolean newValue) {
 
71
          fNamespaces = newValue;
 
72
    }
 
73
 
 
74
    public void setEntityState(EntityState state) {
 
75
        fEntityState = state;
 
76
    }
 
77
 
 
78
    public void setNamespaceSupport(NamespaceContext namespace) {
 
79
        fNamespaceContext = namespace;
 
80
    }
 
81
 
 
82
    public void setSymbolTable(SymbolTable sTable) {
 
83
        fSymbolTable = sTable;
 
84
    }
 
85
 
 
86
    /**
 
87
     * return null if all IDREF values have a corresponding ID value;
 
88
     * otherwise return the first IDREF value without a matching ID value.
 
89
     */
 
90
    public String checkIDRefID () {
 
91
        Enumeration en = fIdRefTable.keys();
 
92
 
 
93
        String key;
 
94
        while (en.hasMoreElements()) {
 
95
            key = (String)en.nextElement();
 
96
            if (!fIdTable.containsKey(key)) {
 
97
                  return key;
 
98
            }
 
99
        }
 
100
        return null;
 
101
    }
 
102
 
 
103
    public void reset () {
 
104
        fExtraChecking = true;
 
105
        fFacetChecking = true;
 
106
        fNamespaces = true;
 
107
        fIdTable.clear();
 
108
        fIdRefTable.clear();
 
109
        fEntityState = null;
 
110
        fNamespaceContext = null;
 
111
        fSymbolTable = null;
 
112
    }
 
113
 
 
114
    /**
 
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
 
118
     * the two tables.
 
119
     */
 
120
    public void resetIDTables() {
 
121
        fIdTable.clear();
 
122
        fIdRefTable.clear();
 
123
    }
 
124
 
 
125
    //
 
126
    // implementation of ValidationContext methods
 
127
    //
 
128
 
 
129
    // whether to do extra id/idref/entity checking
 
130
    public boolean needExtraChecking() {
 
131
        return fExtraChecking;
 
132
    }
 
133
 
 
134
    // whether to validate against facets
 
135
    public boolean needFacetChecking() {
 
136
        return fFacetChecking;
 
137
    }
 
138
 
 
139
    public boolean needToNormalize (){
 
140
        return fNormalize;
 
141
    }
 
142
 
 
143
    public boolean useNamespaces() {
 
144
        return fNamespaces;
 
145
    }
 
146
 
 
147
    // entity
 
148
    public boolean isEntityDeclared (String name) {
 
149
        if (fEntityState !=null) {
 
150
            return fEntityState.isEntityDeclared(getSymbol(name));
 
151
        }
 
152
        return false;
 
153
    }
 
154
    public boolean isEntityUnparsed (String name) {
 
155
        if (fEntityState !=null) {
 
156
            return fEntityState.isEntityUnparsed(getSymbol(name));
 
157
        }
 
158
        return false;
 
159
    }
 
160
 
 
161
    // id
 
162
    public boolean isIdDeclared(String name) {
 
163
        return fIdTable.containsKey(name);
 
164
    }
 
165
    public void addId(String name) {
 
166
        fIdTable.put(name, fNullValue);
 
167
    }
 
168
 
 
169
    // idref
 
170
    public void addIdRef(String name) {
 
171
        fIdRefTable.put(name, fNullValue);
 
172
    }
 
173
    // get symbols
 
174
 
 
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();
 
183
    }
 
184
    // qname, notation
 
185
    public String getURI(String prefix) {
 
186
        if (fNamespaceContext !=null) {
 
187
            return fNamespaceContext.getURI(prefix);
 
188
        }
 
189
        return null;
 
190
    }
 
191
 
 
192
}