source: icXML/icXML-devel/src/xercesc/validators/schema/SchemaValidationContextImpl.cpp

Last change on this file was 3563, checked in by cameron, 6 years ago

Update icxmlc files

File size: 5.2 KB
Line 
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/*
19 * $Id: SchemaValidationContextImpl.cpp 903149 2010-01-26 09:58:40Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/validators/schema/SchemaValidationContextImpl.hpp>
27#include <xercesc/framework/XMLRefInfo.hpp>
28#include <icxercesc/validators/DTD/DTDEntityDecl.hpp>
29#include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
30#include <icxercesc/validators/schema/NamespaceScope.hpp>
31#include <icxercesc/internal/XMLScanner.hpp>
32
33XERCES_CPP_NAMESPACE_BEGIN
34
35// ---------------------------------------------------------------------------
36//  Constructor and Destructor
37// ---------------------------------------------------------------------------
38
39SchemaValidationContextImpl::SchemaValidationContextImpl(XMLScanner * scanner, NamespaceScope* nsStack, MemoryManager* const manager)
40:ValidationContext(manager)
41,fIdRefList(new (fMemoryManager) RefHashTableOf<XMLRefInfo>(109, fMemoryManager))
42,fEntityDeclPool(0)
43,fToCheckIdRefList(true)
44,fScanner(scanner)
45,fNamespaceScope(nsStack)
46{
47
48}
49
50SchemaValidationContextImpl::~SchemaValidationContextImpl()
51{
52    delete fIdRefList;
53}
54
55/**
56 * IdRefList
57 *
58 */
59RefHashTableOf<XMLRefInfo>* SchemaValidationContextImpl::getIdRefList() const
60{
61    return fIdRefList;
62}
63
64void SchemaValidationContextImpl::setIdRefList(RefHashTableOf<XMLRefInfo>* const newIdRefList)
65{
66    delete fIdRefList;
67    fIdRefList = newIdRefList;
68}
69
70void SchemaValidationContextImpl::clearIdRefList()
71{
72    if (fIdRefList)
73        fIdRefList->removeAll();
74
75}
76
77void SchemaValidationContextImpl::addId(const XMLCh * const content)
78{
79    if (!fIdRefList || !fToCheckIdRefList)
80        return;
81
82    XMLRefInfo* idEntry = fIdRefList->get(content);
83
84    if (idEntry)
85    {
86        if (idEntry->getDeclared())
87        {
88            ThrowXMLwithMemMgr1(InvalidDatatypeValueException
89                    , XMLExcepts::VALUE_ID_Not_Unique
90                    , content
91                    , fMemoryManager);
92        }
93    }
94    else
95    {
96        idEntry = new (fMemoryManager) XMLRefInfo(content, false, false, fMemoryManager);
97        fIdRefList->put((void*)idEntry->getRefName(), idEntry);
98    }
99
100    //
101    //  Mark it declared
102    //
103    idEntry->setDeclared(true);
104
105}
106
107void SchemaValidationContextImpl::addIdRef(const XMLCh * const content)
108{
109    if (!fIdRefList || !fToCheckIdRefList)
110        return;
111
112    XMLRefInfo* idEntry = fIdRefList->get(content);
113
114    if (!idEntry)
115    {
116        idEntry = new (fMemoryManager) XMLRefInfo(content, false, false, fMemoryManager);
117        fIdRefList->put((void*)idEntry->getRefName(), idEntry);
118    }
119
120    //
121    //  Mark it used
122    //
123    idEntry->setUsed(true);
124
125}
126void SchemaValidationContextImpl::toCheckIdRefList(bool toCheck)
127{
128    fToCheckIdRefList = toCheck;
129}
130
131/**
132 * EntityDeclPool
133 *
134 */
135const NameIdPool<DTDEntityDecl>* SchemaValidationContextImpl::getEntityDeclPool() const
136{
137    return fEntityDeclPool;
138}
139
140const NameIdPool<DTDEntityDecl>* SchemaValidationContextImpl::setEntityDeclPool(const NameIdPool<DTDEntityDecl>* const newEntityDeclPool)
141{
142    // we don't own it so we return the existing one for the owner to delete
143    const NameIdPool<DTDEntityDecl>* tempPool = fEntityDeclPool;
144    fEntityDeclPool = newEntityDeclPool;
145    return tempPool;
146
147}
148
149void SchemaValidationContextImpl::checkEntity(const XMLCh * const content) const
150{
151
152    const DTDEntityDecl* decl = 0;
153
154    if (likely(fEntityDeclPool != 0))
155    {
156        decl = fEntityDeclPool->getByKey(content);
157    }
158
159    if (unlikely(!decl || !decl->isUnparsed()))
160    {
161        ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_ENTITY_Invalid, content, fMemoryManager);
162    }
163
164}
165
166bool SchemaValidationContextImpl::isPrefixUnknown(XMLCh* prefix)
167{
168    bool unknown;
169
170    if (unlikely(XMLString::equals(prefix, XMLUni::fgXMLNSString)))
171    {
172        unknown = true;
173    }
174    else if (unlikely(XMLString::equals(prefix, XMLUni::fgXMLString)))
175    {
176        unknown = false;
177    }
178    else
179    {
180        unknown = (fNamespaceScope->getNamespaceForPrefix(prefix) == XMLNamespaceResolver::fEmptyUriId);
181    }
182
183    return unknown;
184}
185
186const XMLCh* SchemaValidationContextImpl::getURIForPrefix(XMLCh* prefix)
187{
188    unsigned int uriId = fNamespaceScope->getNamespaceForPrefix(prefix);
189    if (likely(uriId != XMLNamespaceResolver::fEmptyUriId))
190    {
191        return fScanner->getURIText(uriId);
192    }
193    return XMLUni::fgZeroLenString;
194}
195
196XERCES_CPP_NAMESPACE_END
197
Note: See TracBrowser for help on using the repository browser.