Added Xerces-C++ 3.1.2

This commit is contained in:
sippeangelo
2015-12-01 10:23:50 +01:00
parent 65d3f3bc31
commit 1b478d3159
815 changed files with 262638 additions and 0 deletions
@@ -0,0 +1,911 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ComplexTypeInfo.cpp 901107 2010-01-20 08:45:02Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/validators/schema/ComplexTypeInfo.hpp>
#include <xercesc/validators/schema/SchemaAttDefList.hpp>
#include <xercesc/validators/common/AllContentModel.hpp>
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/common/DFAContentModel.hpp>
#include <xercesc/validators/common/MixedContentModel.hpp>
#include <xercesc/validators/common/SimpleContentModel.hpp>
#include <xercesc/validators/schema/XSDLocator.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
#include <xercesc/util/XMLInitializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Static member data
// ---------------------------------------------------------------------------
ComplexTypeInfo* ComplexTypeInfo::fAnyType = 0;
void XMLInitializer::initializeComplexTypeInfo()
{
// create type name
XMLCh typeName[128];
XMLSize_t nsLen = XMLString::stringLen(SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
XMLString::copyString(typeName, SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
typeName[nsLen] = chComma;
XMLString::copyString(typeName + nsLen + 1, SchemaSymbols::fgATTVAL_ANYTYPE);
// Create and initialize 'anyType'
ComplexTypeInfo::fAnyType = new ComplexTypeInfo();
ContentSpecNode* term = new ContentSpecNode
(
new QName
(
XMLUni::fgZeroLenString
, XMLUni::fgZeroLenString
, 1
)
, false
);
term->setType(ContentSpecNode::Any_Lax);
term->setMinOccurs(0);
term->setMaxOccurs(SchemaSymbols::XSD_UNBOUNDED);
ContentSpecNode* particle = new ContentSpecNode
(
ContentSpecNode::ModelGroupSequence
, term
, 0
);
SchemaAttDef* attWildCard = new SchemaAttDef
(
XMLUni::fgZeroLenString
, XMLUni::fgZeroLenString
, 1
, XMLAttDef::Any_Any
, XMLAttDef::ProcessContents_Lax
);
ComplexTypeInfo::fAnyType->setTypeName(typeName);
ComplexTypeInfo::fAnyType->setBaseComplexTypeInfo(ComplexTypeInfo::fAnyType);
ComplexTypeInfo::fAnyType->setDerivedBy(SchemaSymbols::XSD_RESTRICTION);
ComplexTypeInfo::fAnyType->setContentType(SchemaElementDecl::Mixed_Complex);
ComplexTypeInfo::fAnyType->setContentSpec(particle);
ComplexTypeInfo::fAnyType->setAttWildCard(attWildCard);
}
void XMLInitializer::terminateComplexTypeInfo()
{
delete ComplexTypeInfo::fAnyType;
ComplexTypeInfo::fAnyType = 0;
}
ComplexTypeInfo* ComplexTypeInfo::getAnyType(unsigned int /*emptyNSId*/)
{
return fAnyType;
}
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Constructors and Destructor
// ---------------------------------------------------------------------------
ComplexTypeInfo::ComplexTypeInfo(MemoryManager* const manager)
: fAnonymous(false)
, fAbstract(false)
, fAdoptContentSpec(true)
, fAttWithTypeId(false)
, fPreprocessed(false)
, fDerivedBy(0)
, fBlockSet(0)
, fFinalSet(0)
, fScopeDefined(Grammar::TOP_LEVEL_SCOPE)
, fContentType(SchemaElementDecl::Empty)
, fElementId(XMLElementDecl::fgInvalidElemId)
, fUniqueURI(0)
, fContentSpecOrgURISize(16)
, fTypeName(0)
, fTypeLocalName(0)
, fTypeUri(0)
, fBaseDatatypeValidator(0)
, fDatatypeValidator(0)
, fBaseComplexTypeInfo(0)
, fContentSpec(0)
, fAttWildCard(0)
, fAttList(0)
, fElements(0)
, fAttDefs(0)
, fContentModel(0)
, fFormattedModel(0)
, fContentSpecOrgURI(0)
, fLocator(0)
, fMemoryManager(manager)
{
fAttDefs = new (fMemoryManager) RefHash2KeysTableOf<SchemaAttDef>(29, true, fMemoryManager);
fAttList = new (fMemoryManager) SchemaAttDefList(fAttDefs,fMemoryManager);
}
ComplexTypeInfo::~ComplexTypeInfo()
{
fMemoryManager->deallocate(fTypeName); //delete [] fTypeName;
fMemoryManager->deallocate(fTypeLocalName); //delete [] fTypeLocalName;
fMemoryManager->deallocate(fTypeUri); //delete [] fTypeUri;
if (fAdoptContentSpec) {
delete fContentSpec;
}
delete fAttWildCard;
delete fAttDefs;
delete fAttList;
delete fElements;
delete fLocator;
delete fContentModel;
fMemoryManager->deallocate(fFormattedModel); //delete [] fFormattedModel;
fMemoryManager->deallocate(fContentSpecOrgURI); //delete [] fContentSpecOrgURI;
}
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Setter methods
// ---------------------------------------------------------------------------
void ComplexTypeInfo::addAttDef(SchemaAttDef* const toAdd) {
// Tell this guy the element id of its parent (us)
toAdd->setElemId(getElementId());
fAttDefs->put((void*)(toAdd->getAttName()->getLocalPart()),
toAdd->getAttName()->getURI(), toAdd);
// update and/or create fAttList
fAttList->addAttDef(toAdd);
}
void ComplexTypeInfo::setContentSpec(ContentSpecNode* const toAdopt) {
if (fContentSpec && fAdoptContentSpec) {
delete fContentSpec;
}
fContentSpec = toAdopt;
}
void ComplexTypeInfo::setLocator(XSDLocator* const aLocator) {
if (fLocator)
delete fLocator;
fLocator = aLocator;
}
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Getter methods
// ---------------------------------------------------------------------------
XMLAttDefList& ComplexTypeInfo::getAttDefList() const
{
// NOTE: if users plan on using nextElement() to access attributes
// they need to call Reset() explicitly (i.e attList.Reset()).
// It's better to get the attribute count and use an index to
// access attributes (especially if same grammar is used in
// multiple threads).
return *fAttList;
}
const XMLCh*
ComplexTypeInfo::getFormattedContentModel() const
{
//
// If its not already built, then call the protected virtual method
// to allow the derived class to build it (since only it knows.)
// Otherwise, just return the previously formatted methods.
//
// Since we are faulting this in, within a const getter, we have to
// cast off the const-ness.
//
if (!fFormattedModel)
((ComplexTypeInfo*)this)->fFormattedModel = formatContentModel();
return fFormattedModel;
}
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Helper methods
// ---------------------------------------------------------------------------
void ComplexTypeInfo::checkUniqueParticleAttribution (SchemaGrammar* const pGrammar,
GrammarResolver* const pGrammarResolver,
XMLStringPool* const pStringPool,
XMLValidator* const pValidator)
{
if (fContentSpec && !fContentModel)
{
fContentModel = makeContentModel(true);
if (fContentModel) {
fContentModel->checkUniqueParticleAttribution(pGrammar, pGrammarResolver, pStringPool, pValidator, fContentSpecOrgURI, fTypeLocalName);
}
}
}
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Private Helper methods
// ---------------------------------------------------------------------------
void ComplexTypeInfo::faultInAttDefList() const
{
// Use a hash modulus of 29 and tell it owns its elements
((ComplexTypeInfo*)this)->fAttDefs =
new (fMemoryManager) RefHash2KeysTableOf<SchemaAttDef>(29, true, fMemoryManager);
}
XMLCh* ComplexTypeInfo::formatContentModel() const
{
XMLCh* newValue = 0;
if (fContentType == SchemaElementDecl::Any)
{
newValue = XMLString::replicate(XMLUni::fgAnyString, fMemoryManager);
}
else if (fContentType == SchemaElementDecl::Empty ||
fContentType == SchemaElementDecl::ElementOnlyEmpty)
{
newValue = XMLString::replicate(XMLUni::fgEmptyString, fMemoryManager);
}
else
{
//
// Use a temp XML buffer to format into. Content models could be
// pretty long, but very few will be longer than one K. The buffer
// will expand to handle the more pathological ones.
//
const ContentSpecNode* specNode = fContentSpec;
if (specNode) {
XMLBuffer bufFmt(1023, fMemoryManager);
specNode->formatSpec(bufFmt);
newValue = XMLString::replicate
(
bufFmt.getRawBuffer()
, fMemoryManager
);
}
}
return newValue;
}
bool ComplexTypeInfo::useRepeatingLeafNodes(ContentSpecNode* particle)
{
int maxOccurs = particle->getMaxOccurs();
int minOccurs = particle->getMinOccurs();
ContentSpecNode::NodeTypes type = particle->getType();
if (((type & 0x0f) == ContentSpecNode::Choice) || ((type & 0x0f) == ContentSpecNode::Sequence))
{
if (minOccurs != 1 || maxOccurs != 1) {
if(particle->getFirst()!=0 && particle->getSecond()==0)
{
ContentSpecNode* particle2 = particle->getFirst();
ContentSpecNode::NodeTypes type2 = particle2->getType();
return (((type2 == ContentSpecNode::Leaf) ||
((type2 & 0x0f) == ContentSpecNode::Any) ||
((type2 & 0x0f) == ContentSpecNode::Any_Other) ||
((type2 & 0x0f) == ContentSpecNode::Any_NS)) &&
particle2->getMinOccurs() == 1 &&
particle2->getMaxOccurs() == 1);
}
return (particle->getFirst()==0 && particle->getSecond()==0);
}
if(particle->getFirst()!=0 && !useRepeatingLeafNodes(particle->getFirst()))
return false;
if(particle->getSecond()!=0 && !useRepeatingLeafNodes(particle->getSecond()))
return false;
}
return true;
}
XMLContentModel* ComplexTypeInfo::makeContentModel(bool checkUPA)
{
ContentSpecNode* aSpecNode = new (fMemoryManager) ContentSpecNode(*fContentSpec);
if (checkUPA) {
fContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate
(
fContentSpecOrgURISize * sizeof(unsigned int)
); //new unsigned int[fContentSpecOrgURISize];
}
aSpecNode = convertContentSpecTree(aSpecNode, checkUPA, useRepeatingLeafNodes(aSpecNode));
Janitor<ContentSpecNode> janSpecNode(aSpecNode);
XMLContentModel* cmRet = 0;
if (fContentType == SchemaElementDecl::Simple ||
fContentType == SchemaElementDecl::ElementOnlyEmpty) {
// just return nothing
}
else if (fContentType == SchemaElementDecl::Mixed_Simple)
{
//
// Just create a mixel content model object. This type of
// content model is optimized for mixed content validation.
//
cmRet = new (fMemoryManager) MixedContentModel(false, aSpecNode, false, fMemoryManager);
}
else if (fContentType == SchemaElementDecl::Mixed_Complex ||
fContentType == SchemaElementDecl::Children)
{
bool isMixed = (fContentType == SchemaElementDecl::Mixed_Complex);
//
// This method will create an optimal model for the complexity
// of the element's defined model. If its simple, it will create
// a SimpleContentModel object. If its a simple list, it will
// create a SimpleListContentModel object. If its complex, it
// will create a DFAContentModel object.
//
if(!aSpecNode)
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, fMemoryManager);
ContentSpecNode::NodeTypes specType = aSpecNode->getType();
//
// Do a sanity check that the node is does not have a PCDATA id. Since,
// if it was, it should have already gotten taken by the Mixed model.
//
if (aSpecNode->getElement() && aSpecNode->getElement()->getURI() == XMLElementDecl::fgPCDataElemId)
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_NoPCDATAHere, fMemoryManager);
//
// According to the type of node, we will create the correct type of
// content model.
//
if (((specType & 0x0f) == ContentSpecNode::Any) ||
((specType & 0x0f) == ContentSpecNode::Any_Other) ||
((specType & 0x0f) == ContentSpecNode::Any_NS) ||
specType == ContentSpecNode::Loop) {
// let fall through to build a DFAContentModel
}
else if (isMixed)
{
if (specType == ContentSpecNode::All) {
// All the nodes under an ALL must be additional ALL nodes and
// ELEMENTs (or ELEMENTs under ZERO_OR_ONE nodes.)
// We collapse the ELEMENTs into a single vector.
cmRet = new (fMemoryManager) AllContentModel(aSpecNode, true, fMemoryManager);
}
else if (specType == ContentSpecNode::ZeroOrOne) {
// An ALL node can appear under a ZERO_OR_ONE node.
if (aSpecNode->getFirst()->getType() == ContentSpecNode::All) {
cmRet = new (fMemoryManager) AllContentModel(aSpecNode->getFirst(), true, fMemoryManager);
}
}
// otherwise, let fall through to build a DFAContentModel
}
else if (specType == ContentSpecNode::Leaf)
{
// Create a simple content model
cmRet = new (fMemoryManager) SimpleContentModel
(
false
, aSpecNode->getElement()
, 0
, ContentSpecNode::Leaf
, fMemoryManager
);
}
else if (((specType & 0x0f) == ContentSpecNode::Choice)
|| ((specType & 0x0f) == ContentSpecNode::Sequence))
{
//
// Lets see if both of the children are leafs. If so, then it has to
// be a simple content model
//
if ((aSpecNode->getFirst()->getType() == ContentSpecNode::Leaf)
&& (aSpecNode->getSecond())
&& (aSpecNode->getSecond()->getType() == ContentSpecNode::Leaf))
{
cmRet = new (fMemoryManager) SimpleContentModel
(
false
, aSpecNode->getFirst()->getElement()
, aSpecNode->getSecond()->getElement()
, specType
, fMemoryManager
);
}
}
else if ((specType == ContentSpecNode::OneOrMore)
|| (specType == ContentSpecNode::ZeroOrMore)
|| (specType == ContentSpecNode::ZeroOrOne))
{
//
// Its a repetition, so see if its one child is a leaf. If so its a
// repetition of a single element, so we can do a simple content
// model for that.
//
if (aSpecNode->getFirst()->getType() == ContentSpecNode::Leaf)
{
cmRet = new (fMemoryManager) SimpleContentModel
(
false
, aSpecNode->getFirst()->getElement()
, 0
, specType
, fMemoryManager
);
}
else if (aSpecNode->getFirst()->getType() == ContentSpecNode::All)
cmRet = new (fMemoryManager) AllContentModel(aSpecNode->getFirst(), false, fMemoryManager);
}
else if (specType == ContentSpecNode::All)
cmRet = new (fMemoryManager) AllContentModel(aSpecNode, false, fMemoryManager);
else
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, fMemoryManager);
}
// Its not any simple type of content, so create a DFA based content model
if(cmRet==0)
cmRet = new (fMemoryManager) DFAContentModel(false, aSpecNode, isMixed, fMemoryManager);
}
else
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_MustBeMixedOrChildren, fMemoryManager);
}
return cmRet;
}
// ---------------------------------------------------------------------------
// SchemaElementDecl: Private helper methods
// ---------------------------------------------------------------------------
ContentSpecNode*
ComplexTypeInfo::convertContentSpecTree(ContentSpecNode* const curNode,
bool checkUPA,
bool bAllowCompactSyntax) {
if (!curNode)
return 0;
const ContentSpecNode::NodeTypes curType = curNode->getType();
// When checking Unique Particle Attribution, rename leaf elements
if (checkUPA) {
if (curNode->getElement()) {
if (fUniqueURI == fContentSpecOrgURISize) {
resizeContentSpecOrgURI();
}
fContentSpecOrgURI[fUniqueURI] = curNode->getElement()->getURI();
curNode->getElement()->setURI(fUniqueURI);
fUniqueURI++;
}
}
// Get the spec type of the passed node
int minOccurs = curNode->getMinOccurs();
int maxOccurs = curNode->getMaxOccurs();
ContentSpecNode* retNode = curNode;
if ((curType & 0x0f) == ContentSpecNode::Any
|| (curType & 0x0f) == ContentSpecNode::Any_Other
|| (curType & 0x0f) == ContentSpecNode::Any_NS
|| curType == ContentSpecNode::Leaf)
{
retNode = expandContentModel(curNode, minOccurs, maxOccurs, bAllowCompactSyntax);
}
else if (((curType & 0x0f) == ContentSpecNode::Choice)
|| (curType == ContentSpecNode::All)
|| ((curType & 0x0f) == ContentSpecNode::Sequence))
{
ContentSpecNode* childNode = curNode->getFirst();
ContentSpecNode* leftNode = convertContentSpecTree(childNode, checkUPA, bAllowCompactSyntax);
ContentSpecNode* rightNode = curNode->getSecond();
if (!rightNode) {
retNode = expandContentModel(leftNode, minOccurs, maxOccurs, bAllowCompactSyntax);
curNode->setAdoptFirst(false);
delete curNode;
return retNode;
}
if (leftNode != childNode) {
curNode->setAdoptFirst(false);
curNode->setFirst(leftNode);
curNode->setAdoptFirst(true);
}
childNode = rightNode;
rightNode = convertContentSpecTree(childNode, checkUPA, bAllowCompactSyntax);
if (rightNode != childNode) {
curNode->setAdoptSecond(false);
curNode->setSecond(rightNode);
curNode->setAdoptSecond(true);
}
retNode = expandContentModel(curNode, minOccurs, maxOccurs, bAllowCompactSyntax);
}
return retNode;
}
ContentSpecNode* ComplexTypeInfo::expandContentModel(ContentSpecNode* const specNode,
int minOccurs,
int maxOccurs,
bool bAllowCompactSyntax)
{
if (!specNode) {
return 0;
}
ContentSpecNode* saveNode = specNode;
ContentSpecNode* retNode = specNode;
if (minOccurs == 1 && maxOccurs == 1) {
}
else if (minOccurs == 0 && maxOccurs == 1) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::ZeroOrOne
, retNode
, 0
, true
, true
, fMemoryManager
);
}
else if (minOccurs == 0 && maxOccurs == -1) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::ZeroOrMore
, retNode
, 0
, true
, true
, fMemoryManager
);
}
else if (minOccurs == 1 && maxOccurs == -1) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::OneOrMore
, retNode
, 0
, true
, true
, fMemoryManager
);
}
// if what is being repeated is a leaf avoid expanding the tree
else if(bAllowCompactSyntax &&
(saveNode->getType()==ContentSpecNode::Leaf ||
(saveNode->getType() & 0x0f)==ContentSpecNode::Any ||
(saveNode->getType() & 0x0f)==ContentSpecNode::Any_Other ||
(saveNode->getType() & 0x0f)==ContentSpecNode::Any_NS))
{
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::Loop
, retNode
, 0
, true
, true
, fMemoryManager
);
retNode->setMinOccurs(minOccurs);
retNode->setMaxOccurs(maxOccurs);
if(minOccurs==0)
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::ZeroOrMore
, retNode
, 0
, true
, true
, fMemoryManager
);
else
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::OneOrMore
, retNode
, 0
, true
, true
, fMemoryManager
);
}
else if (maxOccurs == -1) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::OneOrMore
, retNode
, 0
, true
, true
, fMemoryManager
);
for (int i=0; i < (minOccurs-1); i++) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::Sequence
, saveNode
, retNode
, false
, true
, fMemoryManager
);
}
}
else {
if (minOccurs == 0) {
ContentSpecNode* optional = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::ZeroOrOne
, saveNode
, 0
, true
, true
, fMemoryManager
);
retNode = optional;
for (int i=0; i < (maxOccurs-1); i++) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::Sequence
, retNode
, optional
, true
, false
, fMemoryManager
);
}
}
else {
if (minOccurs > 1) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::Sequence
, retNode
, saveNode
, true
, false
, fMemoryManager
);
for (int i=1; i < (minOccurs-1); i++) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::Sequence
, retNode
, saveNode
, true
, false
, fMemoryManager
);
}
}
int counter = maxOccurs-minOccurs;
if (counter > 0) {
ContentSpecNode* optional = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::ZeroOrOne
, saveNode
, 0
, false
, true
, fMemoryManager
);
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::Sequence
, retNode
, optional
, true
, true
, fMemoryManager
);
for (int j=1; j < counter; j++) {
retNode = new (fMemoryManager) ContentSpecNode
(
ContentSpecNode::Sequence
, retNode
, optional
, true
, false
, fMemoryManager
);
}
}
}
}
return retNode;
}
void ComplexTypeInfo::resizeContentSpecOrgURI() {
unsigned int newSize = fContentSpecOrgURISize * 2;
unsigned int* newContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate
(
newSize * sizeof(unsigned int)
); //new unsigned int[newSize];
// Copy the existing values
unsigned int index = 0;
for (; index < fContentSpecOrgURISize; index++)
newContentSpecOrgURI[index] = fContentSpecOrgURI[index];
for (; index < newSize; index++)
newContentSpecOrgURI[index] = 0;
// Delete the old array and udpate our members
fMemoryManager->deallocate(fContentSpecOrgURI); //delete [] fContentSpecOrgURI;
fContentSpecOrgURI = newContentSpecOrgURI;
fContentSpecOrgURISize = newSize;
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(ComplexTypeInfo)
void ComplexTypeInfo::serialize(XSerializeEngine& serEng)
{
if (serEng.isStoring())
{
serEng<<fAnonymous;
serEng<<fAbstract;
serEng<<fAdoptContentSpec;
serEng<<fAttWithTypeId;
serEng<<fPreprocessed;
serEng<<fDerivedBy;
serEng<<fBlockSet;
serEng<<fFinalSet;
serEng<<fScopeDefined;
serEng<<fContentType;
serEng<<fElementId;
serEng.writeString(fTypeName);
serEng.writeString(fTypeLocalName);
serEng.writeString(fTypeUri);
DatatypeValidator::storeDV(serEng, fBaseDatatypeValidator);
DatatypeValidator::storeDV(serEng, fDatatypeValidator);
serEng<<fBaseComplexTypeInfo;
serEng<<fContentSpec;
serEng<<fAttWildCard;
serEng<<fAttList;
/***
*
* Serialize RefVectorOf<SchemaElementDecl>* fElements;
* Serialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
***/
XTemplateSerializer::storeObject(fElements, serEng);
XTemplateSerializer::storeObject(fAttDefs, serEng);
/***
* Don't serialize
*
* fContentModel;
* fFormattedModel;
* fLocator;
*
* fContentSpecOrgURI: start of the array
* fContentSpecOrgURISize: size of the array
* fUniqueURI: the current last element in the array
***/
}
else
{
serEng>>fAnonymous;
serEng>>fAbstract;
serEng>>fAdoptContentSpec;
serEng>>fAttWithTypeId;
serEng>>fPreprocessed;
serEng>>fDerivedBy;
serEng>>fBlockSet;
serEng>>fFinalSet;
serEng>>fScopeDefined;
serEng>>fContentType;
serEng>>fElementId;
serEng.readString(fTypeName);
serEng.readString(fTypeLocalName);
serEng.readString(fTypeUri);
fBaseDatatypeValidator = DatatypeValidator::loadDV(serEng);
fDatatypeValidator = DatatypeValidator::loadDV(serEng);
serEng>>fBaseComplexTypeInfo;
serEng>>fContentSpec;
serEng>>fAttWildCard;
delete fAttList; // will recreate it next...
serEng>>fAttList;
/***
*
* Deserialize RefVectorOf<SchemaElementDecl>* fElements;
* Deserialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
***/
XTemplateSerializer::loadObject(&fElements, 8, false, serEng);
delete fAttDefs; // will recreate it next...
XTemplateSerializer::loadObject(&fAttDefs, 29, true, serEng);
/***
* Don't deserialize
*
* fFormattedModel;
* fLocator;
*
* fContentSpecOrgURI: start of the array
* fContentSpecOrgURISize: size of the array
* fUniqueURI: the current last element in the array
***/
fFormattedModel = 0;
fLocator = 0;
fContentSpecOrgURI = 0;
fContentSpecOrgURISize = 0;
fUniqueURI = 0;
// Create the content model by calling getContentModel(). This
// will ensure the grammar can be used concurrently by multiple
// parsers.
// Don't bother to do check unique particle attribution, since
// this will already have been done when the grammar was first
// created (if full schema checking was enabled).
getContentModel(false);
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file ComplexTypeInfo.cpp
*/
@@ -0,0 +1,531 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ComplexTypeInfo.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_COMPLEXTYPEINFO_HPP)
#define XERCESC_INCLUDE_GUARD_COMPLEXTYPEINFO_HPP
/**
* The class act as a place holder to store complex type information.
*
* The class is intended for internal use.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/RefHash2KeysTableOf.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/framework/XMLElementDecl.hpp>
#include <xercesc/framework/XMLContentModel.hpp>
#include <xercesc/validators/schema/SchemaAttDef.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class DatatypeValidator;
class ContentSpecNode;
class SchemaAttDefList;
class SchemaElementDecl;
class XSDLocator;
class VALIDATORS_EXPORT ComplexTypeInfo : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Public Constructors/Destructor
// -----------------------------------------------------------------------
ComplexTypeInfo(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~ComplexTypeInfo();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
bool getAbstract() const;
bool getAdoptContentSpec() const;
bool containsAttWithTypeId() const;
bool getPreprocessed() const;
int getDerivedBy() const;
int getBlockSet() const;
int getFinalSet() const;
unsigned int getScopeDefined() const;
unsigned int getElementId() const;
int getContentType() const;
XMLSize_t elementCount() const;
XMLCh* getTypeName() const;
DatatypeValidator* getBaseDatatypeValidator() const;
DatatypeValidator* getDatatypeValidator() const;
ComplexTypeInfo* getBaseComplexTypeInfo() const;
ContentSpecNode* getContentSpec() const;
const SchemaAttDef* getAttWildCard() const;
SchemaAttDef* getAttWildCard();
const SchemaAttDef* getAttDef(const XMLCh* const baseName,
const int uriId) const;
SchemaAttDef* getAttDef(const XMLCh* const baseName,
const int uriId);
XMLAttDefList& getAttDefList() const;
const SchemaElementDecl* elementAt(const XMLSize_t index) const;
SchemaElementDecl* elementAt(const XMLSize_t index);
XMLContentModel* getContentModel(const bool checkUPA = false);
const XMLCh* getFormattedContentModel () const;
XSDLocator* getLocator() const;
const XMLCh* getTypeLocalName() const;
const XMLCh* getTypeUri() const;
/**
* returns true if this type is anonymous
**/
bool getAnonymous() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setAbstract(const bool isAbstract);
void setAdoptContentSpec(const bool toAdopt);
void setAttWithTypeId(const bool value);
void setPreprocessed(const bool aValue = true);
void setDerivedBy(const int derivedBy);
void setBlockSet(const int blockSet);
void setFinalSet(const int finalSet);
void setScopeDefined(const unsigned int scopeDefined);
void setElementId(const unsigned int elemId);
void setTypeName(const XMLCh* const typeName);
void setContentType(const int contentType);
void setBaseDatatypeValidator(DatatypeValidator* const baseValidator);
void setDatatypeValidator(DatatypeValidator* const validator);
void setBaseComplexTypeInfo(ComplexTypeInfo* const typeInfo);
void setContentSpec(ContentSpecNode* const toAdopt);
void setAttWildCard(SchemaAttDef* const toAdopt);
void addAttDef(SchemaAttDef* const toAdd);
void addElement(SchemaElementDecl* const toAdd);
void setLocator(XSDLocator* const aLocator);
/**
* sets this type to be anonymous
**/
void setAnonymous();
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
bool hasAttDefs() const;
bool contains(const XMLCh* const attName);
void checkUniqueParticleAttribution
(
SchemaGrammar* const pGrammar
, GrammarResolver* const pGrammarResolver
, XMLStringPool* const pStringPool
, XMLValidator* const pValidator
) ;
/**
* Return a singleton that represents 'anyType'
*
* @param emptyNSId the uri id of the empty namespace
*/
static ComplexTypeInfo* getAnyType(unsigned int emptyNSId);
/**
* Notification that lazy data has been deleted
*/
static void reinitAnyType();
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(ComplexTypeInfo)
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
ComplexTypeInfo(const ComplexTypeInfo& elemInfo);
ComplexTypeInfo& operator= (const ComplexTypeInfo& other);
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void faultInAttDefList() const;
bool useRepeatingLeafNodes(ContentSpecNode* particle);
XMLContentModel* makeContentModel(bool checkUPA = false);
XMLCh* formatContentModel () const ;
ContentSpecNode* expandContentModel(ContentSpecNode* const curNode, int minOccurs, int maxOccurs, bool bAllowCompactSyntax);
ContentSpecNode* convertContentSpecTree(ContentSpecNode* const curNode, bool checkUPA, bool bAllowCompactSyntax);
void resizeContentSpecOrgURI();
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
bool fAnonymous;
bool fAbstract;
bool fAdoptContentSpec;
bool fAttWithTypeId;
bool fPreprocessed;
int fDerivedBy;
int fBlockSet;
int fFinalSet;
unsigned int fScopeDefined;
int fContentType;
unsigned int fElementId;
unsigned int fUniqueURI;
unsigned int fContentSpecOrgURISize;
XMLCh* fTypeName;
XMLCh* fTypeLocalName;
XMLCh* fTypeUri;
DatatypeValidator* fBaseDatatypeValidator;
DatatypeValidator* fDatatypeValidator;
ComplexTypeInfo* fBaseComplexTypeInfo;
ContentSpecNode* fContentSpec;
SchemaAttDef* fAttWildCard;
SchemaAttDefList* fAttList;
RefVectorOf<SchemaElementDecl>* fElements;
RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
XMLContentModel* fContentModel;
XMLCh* fFormattedModel;
unsigned int* fContentSpecOrgURI;
XSDLocator* fLocator;
MemoryManager* fMemoryManager;
static ComplexTypeInfo* fAnyType;
friend class XMLInitializer;
};
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Getter methods
// ---------------------------------------------------------------------------
inline bool ComplexTypeInfo::getAbstract() const {
return fAbstract;
}
inline bool ComplexTypeInfo::getAdoptContentSpec() const {
return fAdoptContentSpec;
}
inline bool ComplexTypeInfo::containsAttWithTypeId() const {
return fAttWithTypeId;
}
inline bool ComplexTypeInfo::getPreprocessed() const {
return fPreprocessed;
}
inline int ComplexTypeInfo::getDerivedBy() const {
return fDerivedBy;
}
inline int ComplexTypeInfo::getBlockSet() const {
return fBlockSet;
}
inline int ComplexTypeInfo::getFinalSet() const {
return fFinalSet;
}
inline unsigned int ComplexTypeInfo::getScopeDefined() const {
return fScopeDefined;
}
inline unsigned int ComplexTypeInfo::getElementId() const {
return fElementId;
}
inline int ComplexTypeInfo::getContentType() const {
return fContentType;
}
inline XMLSize_t ComplexTypeInfo::elementCount() const {
if (fElements) {
return fElements->size();
}
return 0;
}
inline XMLCh* ComplexTypeInfo::getTypeName() const {
return fTypeName;
}
inline DatatypeValidator* ComplexTypeInfo::getBaseDatatypeValidator() const {
return fBaseDatatypeValidator;
}
inline DatatypeValidator* ComplexTypeInfo::getDatatypeValidator() const {
return fDatatypeValidator;
}
inline ComplexTypeInfo* ComplexTypeInfo::getBaseComplexTypeInfo() const {
return fBaseComplexTypeInfo;
}
inline ContentSpecNode* ComplexTypeInfo::getContentSpec() const {
return fContentSpec;
}
inline const SchemaAttDef* ComplexTypeInfo::getAttWildCard() const {
return fAttWildCard;
}
inline SchemaAttDef* ComplexTypeInfo::getAttWildCard() {
return fAttWildCard;
}
inline const SchemaAttDef* ComplexTypeInfo::getAttDef(const XMLCh* const baseName,
const int uriId) const {
return fAttDefs->get(baseName, uriId);
}
inline SchemaAttDef* ComplexTypeInfo::getAttDef(const XMLCh* const baseName,
const int uriId)
{
return fAttDefs->get(baseName, uriId);
}
inline SchemaElementDecl*
ComplexTypeInfo::elementAt(const XMLSize_t index) {
if (!fElements) {
return 0; // REVISIT - need to throw an exception
}
return fElements->elementAt(index);
}
inline const SchemaElementDecl*
ComplexTypeInfo::elementAt(const XMLSize_t index) const {
if (!fElements) {
return 0; // REVISIT - need to throw an exception
}
return fElements->elementAt(index);
}
inline XMLContentModel* ComplexTypeInfo::getContentModel(const bool checkUPA)
{
if (!fContentModel && fContentSpec)
fContentModel = makeContentModel(checkUPA);
return fContentModel;
}
inline XSDLocator* ComplexTypeInfo::getLocator() const
{
return fLocator;
}
inline bool ComplexTypeInfo::getAnonymous() const {
return fAnonymous;
}
inline const XMLCh* ComplexTypeInfo::getTypeLocalName() const
{
return fTypeLocalName;
}
inline const XMLCh* ComplexTypeInfo::getTypeUri() const
{
return fTypeUri;
}
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Setter methods
// ---------------------------------------------------------------------------
inline void ComplexTypeInfo::setAbstract(const bool isAbstract) {
fAbstract = isAbstract;
}
inline void ComplexTypeInfo::setAdoptContentSpec(const bool toAdopt) {
fAdoptContentSpec = toAdopt;
}
inline void ComplexTypeInfo::setAttWithTypeId(const bool value) {
fAttWithTypeId = value;
}
inline void ComplexTypeInfo::setPreprocessed(const bool aValue) {
fPreprocessed = aValue;
}
inline void ComplexTypeInfo::setDerivedBy(const int derivedBy) {
fDerivedBy = derivedBy;
}
inline void ComplexTypeInfo::setBlockSet(const int blockSet) {
fBlockSet = blockSet;
}
inline void ComplexTypeInfo::setFinalSet(const int finalSet) {
fFinalSet = finalSet;
}
inline void ComplexTypeInfo::setScopeDefined(const unsigned int scopeDefined) {
fScopeDefined = scopeDefined;
}
inline void ComplexTypeInfo::setElementId(const unsigned int elemId) {
fElementId = elemId;
}
inline void
ComplexTypeInfo::setContentType(const int contentType) {
fContentType = contentType;
}
inline void ComplexTypeInfo::setTypeName(const XMLCh* const typeName) {
fMemoryManager->deallocate(fTypeName);//delete [] fTypeName;
fMemoryManager->deallocate(fTypeLocalName);//delete [] fTypeLocalName;
fMemoryManager->deallocate(fTypeUri);//delete [] fTypeUri;
if (typeName)
{
fTypeName = XMLString::replicate(typeName, fMemoryManager);
int index = XMLString::indexOf(fTypeName, chComma);
XMLSize_t length = XMLString::stringLen(fTypeName);
fTypeLocalName = (XMLCh*) fMemoryManager->allocate
(
(length - index + 1) * sizeof(XMLCh)
); //new XMLCh[length - index + 1];
XMLString::subString(fTypeLocalName, fTypeName, index + 1, length, fMemoryManager);
fTypeUri = (XMLCh*) fMemoryManager->allocate
(
(index + 1) * sizeof(XMLCh)
); //new XMLCh[index + 1];
XMLString::subString(fTypeUri, fTypeName, 0, index, fMemoryManager);
}
else
{
fTypeName = fTypeLocalName = fTypeUri = 0;
}
}
inline void
ComplexTypeInfo::setBaseDatatypeValidator(DatatypeValidator* const validator) {
fBaseDatatypeValidator = validator;
}
inline void
ComplexTypeInfo::setDatatypeValidator(DatatypeValidator* const validator) {
fDatatypeValidator = validator;
}
inline void
ComplexTypeInfo::setBaseComplexTypeInfo(ComplexTypeInfo* const typeInfo) {
fBaseComplexTypeInfo = typeInfo;
}
inline void ComplexTypeInfo::addElement(SchemaElementDecl* const elem) {
if (!fElements) {
fElements = new (fMemoryManager) RefVectorOf<SchemaElementDecl>(8, false, fMemoryManager);
}
else if (fElements->containsElement(elem)) {
return;
}
fElements->addElement(elem);
}
inline void ComplexTypeInfo::setAttWildCard(SchemaAttDef* const toAdopt) {
if (fAttWildCard) {
delete fAttWildCard;
}
fAttWildCard = toAdopt;
}
inline void ComplexTypeInfo::setAnonymous() {
fAnonymous = true;
}
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Helper methods
// ---------------------------------------------------------------------------
inline bool ComplexTypeInfo::hasAttDefs() const
{
return !fAttDefs->isEmpty();
}
inline bool ComplexTypeInfo::contains(const XMLCh* const attName) {
RefHash2KeysTableOfEnumerator<SchemaAttDef> enumDefs(fAttDefs, false, fMemoryManager);
while (enumDefs.hasMoreElements()) {
if (XMLString::equals(attName, enumDefs.nextElement().getAttName()->getLocalPart())) {
return true;
}
}
return false;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file ComplexTypeInfo.hpp
*/
@@ -0,0 +1,798 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/GeneralAttributeCheck.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp>
#include <xercesc/validators/schema/TraverseSchema.hpp>
#include <xercesc/validators/datatype/DatatypeValidatorFactory.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/framework/XMLErrorCodes.hpp>
#include <xercesc/framework/psvi/XSAnnotation.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Local const data
// ---------------------------------------------------------------------------
static const XMLCh fgValueZero[] =
{
chDigit_0, chNull
};
static const XMLCh fgValueOne[] =
{
chDigit_1, chNull
};
static const XMLCh fgUnbounded[] =
{
chLatin_u, chLatin_n, chLatin_b, chLatin_o, chLatin_u, chLatin_n, chLatin_d,
chLatin_e, chLatin_d, chNull
};
// ---------------------------------------------------------------------------
// Static member data initialization
// ---------------------------------------------------------------------------
ValueHashTableOf<unsigned short>* GeneralAttributeCheck::fAttMap = 0;
ValueHashTableOf<unsigned short>* GeneralAttributeCheck::fFacetsMap = 0;
DatatypeValidator* GeneralAttributeCheck::fNonNegIntDV = 0;
DatatypeValidator* GeneralAttributeCheck::fBooleanDV = 0;
DatatypeValidator* GeneralAttributeCheck::fAnyURIDV = 0;
void XMLInitializer::initializeGeneralAttributeCheck()
{
GeneralAttributeCheck::initialize ();
}
void XMLInitializer::terminateGeneralAttributeCheck()
{
delete GeneralAttributeCheck::fFacetsMap;
delete GeneralAttributeCheck::fAttMap;
GeneralAttributeCheck::fAttMap = 0;
GeneralAttributeCheck::fFacetsMap = 0;
GeneralAttributeCheck::fNonNegIntDV = 0;
GeneralAttributeCheck::fBooleanDV = 0;
GeneralAttributeCheck::fAnyURIDV = 0;
}
void GeneralAttributeCheck::initialize()
{
// Set up validators.
//
DatatypeValidatorFactory dvFactory;
fNonNegIntDV = dvFactory.getDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER);
fBooleanDV = dvFactory.getDatatypeValidator(SchemaSymbols::fgDT_BOOLEAN);
fAnyURIDV = dvFactory.getDatatypeValidator(SchemaSymbols::fgDT_ANYURI);
// TODO - add remaining valdiators
// Map attributes.
//
fAttMap = new ValueHashTableOf<unsigned short>(A_Count);
fAttMap->put((void*)SchemaSymbols::fgATT_ABSTRACT, A_Abstract);
fAttMap->put((void*)SchemaSymbols::fgATT_ATTRIBUTEFORMDEFAULT, A_AttributeFormDefault);
fAttMap->put((void*)SchemaSymbols::fgATT_BASE, A_Base);
fAttMap->put((void*)SchemaSymbols::fgATT_BLOCK, A_Block);
fAttMap->put((void*)SchemaSymbols::fgATT_BLOCKDEFAULT, A_BlockDefault);
fAttMap->put((void*)SchemaSymbols::fgATT_DEFAULT, A_Default);
fAttMap->put((void*)SchemaSymbols::fgATT_ELEMENTFORMDEFAULT, A_ElementFormDefault);
fAttMap->put((void*)SchemaSymbols::fgATT_FINAL, A_Final);
fAttMap->put((void*)SchemaSymbols::fgATT_FINALDEFAULT, A_FinalDefault);
fAttMap->put((void*)SchemaSymbols::fgATT_FIXED, A_Fixed);
fAttMap->put((void*)SchemaSymbols::fgATT_FORM, A_Form);
fAttMap->put((void*)SchemaSymbols::fgATT_ID, A_ID);
fAttMap->put((void*)SchemaSymbols::fgATT_ITEMTYPE, A_ItemType);
fAttMap->put((void*)SchemaSymbols::fgATT_MAXOCCURS, A_MaxOccurs);
fAttMap->put((void*)SchemaSymbols::fgATT_MEMBERTYPES, A_MemberTypes);
fAttMap->put((void*)SchemaSymbols::fgATT_MINOCCURS, A_MinOccurs);
fAttMap->put((void*)SchemaSymbols::fgATT_MIXED, A_Mixed);
fAttMap->put((void*)SchemaSymbols::fgATT_NAME, A_Name);
fAttMap->put((void*)SchemaSymbols::fgATT_NAMESPACE, A_Namespace);
fAttMap->put((void*)SchemaSymbols::fgATT_NILLABLE, A_Nillable);
fAttMap->put((void*)SchemaSymbols::fgATT_PROCESSCONTENTS, A_ProcessContents);
fAttMap->put((void*)SchemaSymbols::fgATT_PUBLIC, A_Public);
fAttMap->put((void*)SchemaSymbols::fgATT_REF, A_Ref);
fAttMap->put((void*)SchemaSymbols::fgATT_REFER, A_Refer);
fAttMap->put((void*)SchemaSymbols::fgATT_SCHEMALOCATION, A_SchemaLocation);
fAttMap->put((void*)SchemaSymbols::fgATT_SOURCE, A_Source);
fAttMap->put((void*)SchemaSymbols::fgATT_SUBSTITUTIONGROUP, A_SubstitutionGroup);
fAttMap->put((void*)SchemaSymbols::fgATT_SYSTEM, A_System);
fAttMap->put((void*)SchemaSymbols::fgATT_TARGETNAMESPACE, A_TargetNamespace);
fAttMap->put((void*)SchemaSymbols::fgATT_TYPE, A_Type);
fAttMap->put((void*)SchemaSymbols::fgATT_USE, A_Use);
fAttMap->put((void*)SchemaSymbols::fgATT_VALUE, A_Value);
fAttMap->put((void*)SchemaSymbols::fgATT_VERSION, A_Version);
fAttMap->put((void*)SchemaSymbols::fgATT_XPATH, A_XPath);
fFacetsMap = new ValueHashTableOf<unsigned short>(13);
fFacetsMap->put((void*) SchemaSymbols::fgELT_MINEXCLUSIVE, E_MinExclusive);
fFacetsMap->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, E_MinInclusive);
fFacetsMap->put((void*) SchemaSymbols::fgELT_MAXEXCLUSIVE, E_MaxExclusive);
fFacetsMap->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, E_MaxInclusive);
fFacetsMap->put((void*) SchemaSymbols::fgELT_TOTALDIGITS, E_TotalDigits);
fFacetsMap->put((void*) SchemaSymbols::fgELT_FRACTIONDIGITS, E_FractionDigits);
fFacetsMap->put((void*) SchemaSymbols::fgELT_LENGTH, E_Length);
fFacetsMap->put((void*) SchemaSymbols::fgELT_MINLENGTH, E_MinLength);
fFacetsMap->put((void*) SchemaSymbols::fgELT_MAXLENGTH, E_MaxLength);
fFacetsMap->put((void*) SchemaSymbols::fgELT_ENUMERATION, E_Enumeration);
fFacetsMap->put((void*) SchemaSymbols::fgELT_WHITESPACE, E_WhiteSpace);
fFacetsMap->put((void*) SchemaSymbols::fgELT_PATTERN, E_Pattern);
}
// ---------------------------------------------------------------------------
// GeneralAttributeCheck: Constructors and Destructor
// ---------------------------------------------------------------------------
GeneralAttributeCheck::GeneralAttributeCheck(MemoryManager* const manager)
: fMemoryManager(manager)
, fIDValidator(manager)
{
}
GeneralAttributeCheck::~GeneralAttributeCheck()
{
}
// ---------------------------------------------------------------------------
// GeneralAttributeCheck: Validation methods
// ---------------------------------------------------------------------------
void
GeneralAttributeCheck::checkAttributes(const DOMElement* const elem,
const unsigned short elemContext,
TraverseSchema* const schema,
const bool isTopLevel,
ValueVectorOf<DOMNode*>* const nonXSAttList)
{
if (nonXSAttList)
nonXSAttList->removeAllElements();
if (elem == 0 || !fAttMap || elemContext>=E_Count)
return;
const XMLCh* elemName = elem->getLocalName();
if (!XMLString::equals(SchemaSymbols::fgURI_SCHEMAFORSCHEMA, elem->getNamespaceURI())) {
schema->reportSchemaError
(
elem
, XMLUni::fgXMLErrDomain
, XMLErrs::ELTSchemaNS
, elemName
);
}
DOMNamedNodeMap* eltAttrs = elem->getAttributes();
const XMLSize_t attrCount = eltAttrs->getLength();
XMLByte attList[A_Count];
memset(attList, 0, sizeof(attList));
for (XMLSize_t i = 0; i < attrCount; i++) {
DOMNode* attribute = eltAttrs->item(i);
const XMLCh* attName = attribute->getNodeName();
// skip namespace declarations
if (XMLString::equals(attName, XMLUni::fgXMLNSString)
|| XMLString::startsWith(attName, XMLUni::fgXMLNSColonString))
continue;
// Bypass attributes that start with xml
// add this to the list of "non-schema" attributes
if ((*attName == chLatin_X || *attName == chLatin_x)
&& (*(attName+1) == chLatin_M || *(attName+1) == chLatin_m)
&& (*(attName+2) == chLatin_L || *(attName+2) == chLatin_l)) {
if (nonXSAttList)
nonXSAttList->addElement(attribute);
continue;
}
// for attributes with namespace prefix
const XMLCh* attrURI = attribute->getNamespaceURI();
if (attrURI != 0 && *attrURI) {
// attributes with schema namespace are not allowed
// and not allowed on "documentation" and "appInfo"
if (XMLString::equals(attrURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) ||
XMLString::equals(elemName, SchemaSymbols::fgELT_APPINFO) ||
XMLString::equals(elemName, SchemaSymbols::fgELT_DOCUMENTATION)) {
schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain,
isTopLevel?XMLErrs::AttributeDisallowedGlobal:XMLErrs::AttributeDisallowedLocal,
attName, elemName);
}
else if (nonXSAttList)
{
nonXSAttList->addElement(attribute);
}
continue;
}
int attNameId = A_Invalid;
attName = attribute->getLocalName();
bool bContinue=false; // workaround for Borland bug with 'continue' in 'catch'
try {
attNameId= fAttMap->get(attName, fMemoryManager);
}
catch(const OutOfMemoryException&)
{
throw;
}
catch(...) {
schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain,
isTopLevel?XMLErrs::AttributeDisallowedGlobal:XMLErrs::AttributeDisallowedLocal,
attName, elemName);
bContinue=true;
}
if(bContinue)
continue;
if (fgElemAttTable[elemContext][attNameId] & Att_Mask) {
attList[attNameId] = 1;
validate
(
elem
, attName
, attribute->getNodeValue()
, fgElemAttTable[elemContext][attNameId] & DV_Mask
, schema
);
}
else {
schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain,
isTopLevel?XMLErrs::AttributeDisallowedGlobal:XMLErrs::AttributeDisallowedLocal,
attName, elemName);
}
}
// ------------------------------------------------------------------
// Check for required attributes
// ------------------------------------------------------------------
for (unsigned int j=0; j < A_Count; j++) {
if ((fgElemAttTable[elemContext][j] & Att_Required) && attList[j] == 0) {
schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain,
isTopLevel?XMLErrs::AttributeRequiredGlobal:XMLErrs::AttributeRequiredLocal,
fAttNames[j], elemName);
}
}
}
void GeneralAttributeCheck::validate(const DOMElement* const elem,
const XMLCh* const attName,
const XMLCh* const attValue,
const short dvIndex,
TraverseSchema* const schema)
{
bool isInvalid = false;
DatatypeValidator* dv = 0;
ValidationContext* fValidationContext = schema->fSchemaInfo->getValidationContext();
switch (dvIndex) {
case DV_Form:
if (!XMLString::equals(attValue, SchemaSymbols::fgATTVAL_QUALIFIED)
&& !XMLString::equals(attValue, SchemaSymbols::fgATTVAL_UNQUALIFIED)) {
isInvalid = true;
}
break;
case DV_MaxOccurs:
// maxOccurs = (nonNegativeInteger | unbounded)
if (!XMLString::equals(attValue, fgUnbounded)) {
dv = fNonNegIntDV;
}
break;
case DV_MaxOccurs1:
if (!XMLString::equals(attValue, fgValueOne)) {
isInvalid = true;
}
break;
case DV_MinOccurs1:
if (!XMLString::equals(attValue, fgValueZero)
&& !XMLString::equals(attValue, fgValueOne)) {
isInvalid = true;
}
break;
case DV_ProcessContents:
if (!XMLString::equals(attValue, SchemaSymbols::fgATTVAL_SKIP)
&& !XMLString::equals(attValue, SchemaSymbols::fgATTVAL_LAX)
&& !XMLString::equals(attValue, SchemaSymbols::fgATTVAL_STRICT)) {
isInvalid = true;
}
break;
case DV_Use:
if (!XMLString::equals(attValue, SchemaSymbols::fgATTVAL_OPTIONAL)
&& !XMLString::equals(attValue, SchemaSymbols::fgATTVAL_PROHIBITED)
&& !XMLString::equals(attValue, SchemaSymbols::fgATTVAL_REQUIRED)) {
isInvalid = true;
}
break;
case DV_WhiteSpace:
if (!XMLString::equals(attValue, SchemaSymbols::fgWS_PRESERVE)
&& !XMLString::equals(attValue, SchemaSymbols::fgWS_REPLACE)
&& !XMLString::equals(attValue, SchemaSymbols::fgWS_COLLAPSE)) {
isInvalid = true;
}
break;
case DV_Boolean:
dv = fBooleanDV;
break;
case DV_NonNegInt:
dv = fNonNegIntDV;
break;
case DV_AnyURI:
dv = fAnyURIDV;
break;
case DV_ID:
if (fValidationContext)
{
dv = &fIDValidator;
}
break;
}
if (dv) {
try {
dv->validate(attValue, fValidationContext, fMemoryManager);
}
catch(const XMLException& excep) {
schema->reportSchemaError(elem, excep);
}
catch(const OutOfMemoryException&)
{
throw;
}
catch(...) {
isInvalid = true;
}
}
if (isInvalid) {
schema->reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidAttValue,
attValue, attName);
}
}
// ---------------------------------------------------------------------------
// Conditional methods for building the table
// ---------------------------------------------------------------------------
//
// This code will set up the character flags table. Its defined out since
// this table is now written out and hard coded (at the bottom of this
// file) into the code itself. This code is retained in case there is
// any need to recreate it later.
//
#if defined(NEED_TO_GEN_ELEM_ATT_MAP_TABLE)
#include <stdio.h>
void GeneralAttributeCheck::initCharFlagTable()
{
unsigned short attList[E_Count][A_Count];
for (unsigned int i=0; i < E_Count; i++) {
for (unsigned int j=0; j < A_Count; j++) {
attList[i][j] = 0;
}
}
//
// Write it out to a temp file to be read back into this source later.
//
FILE* outFl = fopen("ea_table.out", "wt+");
fprintf(outFl, "unsigned short GeneralAttributeCheck::fgElemAttTable[GeneralAttributeCheck::E_Count][GeneralAttributeCheck::A_Count] =\n{\n {");
//"all"
attList[E_All][A_ID] = Att_Optional | DV_ID;
attList[E_All][A_MaxOccurs] = Att_Optional | DV_MaxOccurs1;
attList[E_All][A_MinOccurs] = Att_Optional | DV_MinOccurs1;
// "annotation"
attList[E_Annotation][A_ID] = Att_Optional | DV_ID;
// "any"
attList[E_Any][A_ID] = Att_Optional | DV_ID;
attList[E_Any][A_MaxOccurs] = Att_Optional | DV_MaxOccurs;
attList[E_Any][A_MinOccurs] = Att_Optional | DV_NonNegInt;
attList[E_Any][A_Namespace] = Att_Optional;
attList[E_Any][A_ProcessContents] = Att_Optional | DV_ProcessContents;
// "anyAttribute"
attList[E_AnyAttribute][A_ID] = Att_Optional | DV_ID;
attList[E_AnyAttribute][A_Namespace] = Att_Optional;
attList[E_AnyAttribute][A_ProcessContents] = Att_Optional | DV_ProcessContents;
// "appinfo"
attList[E_Appinfo][A_Source]= Att_Optional | DV_AnyURI;
// attribute - global"
attList[E_AttributeGlobal][A_Default] = Att_Optional;
attList[E_AttributeGlobal][A_Fixed] = Att_Optional;
attList[E_AttributeGlobal][A_ID] = Att_Optional | DV_ID;
attList[E_AttributeGlobal][A_Name] = Att_Required;
attList[E_AttributeGlobal][A_Type] = Att_Optional;
// "attribute - local"
attList[E_AttributeLocal][A_Default] = Att_Optional;
attList[E_AttributeLocal][A_Fixed] = Att_Optional;
attList[E_AttributeLocal][A_Form]= Att_Optional | DV_Form;
attList[E_AttributeLocal][A_ID] = Att_Optional | DV_ID;
attList[E_AttributeLocal][A_Name] = Att_Required;
attList[E_AttributeLocal][A_Type] = Att_Optional;
attList[E_AttributeLocal][A_Use] = Att_Optional | DV_Use;
// "attribute - ref"
attList[E_AttributeRef][A_Default] = Att_Optional;
attList[E_AttributeRef][A_Fixed] = Att_Optional;
attList[E_AttributeRef][A_ID] = Att_Optional | DV_ID;
attList[E_AttributeRef][A_Ref]= Att_Required;
attList[E_AttributeRef][A_Use] = Att_Optional | DV_Use;
// "attributeGroup - global"
attList[E_AttributeGroupGlobal][A_ID] = Att_Optional | DV_ID;
attList[E_AttributeGroupGlobal][A_Name] = Att_Required;
// "attributeGroup - ref"
attList[E_AttributeGroupRef][A_ID] = Att_Optional | DV_ID;
attList[E_AttributeGroupRef][A_Ref]= Att_Required;
// "choice"
attList[E_Choice][A_ID] = Att_Optional | DV_ID;
attList[E_Choice][A_MaxOccurs] = Att_Optional | DV_MaxOccurs;
attList[E_Choice][A_MinOccurs] = Att_Optional | DV_NonNegInt;
// "complexContent"
attList[E_ComplexContent][A_ID] = Att_Optional | DV_ID;
attList[E_ComplexContent][A_Mixed] = Att_Optional | DV_Boolean;
// "complexType - global"
attList[E_ComplexTypeGlobal][A_Abstract] = Att_Optional | DV_Boolean;
attList[E_ComplexTypeGlobal][A_Block] = Att_Optional;
attList[E_ComplexTypeGlobal][A_Final] = Att_Optional;
attList[E_ComplexTypeGlobal][A_ID] = Att_Optional | DV_ID;
attList[E_ComplexTypeGlobal][A_Mixed] = Att_Optional | DV_Boolean;
attList[E_ComplexTypeGlobal][A_Name] = Att_Required;
// "complexType - local"
attList[E_ComplexTypeLocal][A_ID] = Att_Optional | DV_ID;
attList[E_ComplexTypeLocal][A_Mixed] = Att_Optional | DV_Boolean;
// "documentation"
attList[E_Documentation][A_Source] = Att_Optional | DV_AnyURI;
// "element - global"
attList[E_ElementGlobal][A_Abstract] = Att_Optional | DV_Boolean;
attList[E_ElementGlobal][A_Block] = Att_Optional;
attList[E_ElementGlobal][A_Default] = Att_Optional;
attList[E_ElementGlobal][A_Final] = Att_Optional;
attList[E_ElementGlobal][A_Fixed] = Att_Optional;
attList[E_ElementGlobal][A_ID] = Att_Optional | DV_ID;
attList[E_ElementGlobal][A_Name] = Att_Required;
attList[E_ElementGlobal][A_Nillable] = Att_Optional | DV_Boolean;
attList[E_ElementGlobal][A_SubstitutionGroup] = Att_Optional;
attList[E_ElementGlobal][A_Type] = Att_Optional;
// "element - local"
attList[E_ElementLocal][A_Block]= Att_Optional;
attList[E_ElementLocal][A_Default] = Att_Optional;
attList[E_ElementLocal][A_Fixed] = Att_Optional;
attList[E_ElementLocal][A_Form] = Att_Optional | DV_Form;
attList[E_ElementLocal][A_ID] = Att_Optional | DV_ID;
attList[E_ElementLocal][A_MaxOccurs] = Att_Optional | DV_MaxOccurs;
attList[E_ElementLocal][A_MinOccurs] = Att_Optional | DV_NonNegInt;
attList[E_ElementLocal][A_Name] = Att_Required;
attList[E_ElementLocal][A_Nillable] = Att_Optional | DV_Boolean;
attList[E_ElementLocal][A_Type] = Att_Optional;
//"element - ref"
attList[E_ElementRef][A_ID] = Att_Optional | DV_ID;
attList[E_ElementRef][A_MaxOccurs] = Att_Optional | DV_MaxOccurs;
attList[E_ElementRef][A_MinOccurs] = Att_Optional | DV_NonNegInt;
attList[E_ElementRef][A_Ref] = Att_Required;
// "enumeration"
attList[E_Enumeration][A_ID] = Att_Optional | DV_ID;
attList[E_Enumeration][A_Value] = Att_Optional;
// "extension"
attList[E_Extension][A_Base] = Att_Required;
attList[E_Extension][A_ID] = Att_Optional | DV_ID;
//"field"
attList[E_Field][A_ID] = Att_Optional | DV_ID;
attList[E_Field][A_XPath] = Att_Required;
// "fractionDigits"
attList[E_FractionDigits][A_ID] = Att_Optional | DV_ID;
attList[E_FractionDigits][A_Value] = Att_Optional | DV_NonNegInt;
attList[E_FractionDigits][A_Fixed] = Att_Optional | DV_Boolean;
// "group - global"
attList[E_GroupGlobal][A_ID] = Att_Optional | DV_ID;
attList[E_GroupGlobal][A_Name] = Att_Required;
// "group - ref"
attList[E_GroupRef][A_ID] = Att_Optional | DV_ID;
attList[E_GroupRef][A_MaxOccurs] = Att_Optional | DV_MaxOccurs;
attList[E_GroupRef][A_MinOccurs] = Att_Optional | DV_NonNegInt;
attList[E_GroupRef][A_Ref] = Att_Required;
// "import"
attList[E_Import][A_ID] = Att_Optional | DV_ID;
attList[E_Import][A_Namespace] = Att_Optional;
attList[E_Import][A_SchemaLocation] = Att_Optional;
// "include"
attList[E_Include][A_ID] = Att_Optional | DV_ID;
attList[E_Include][A_SchemaLocation] = Att_Required;
// "key"
attList[E_Key][A_ID] = Att_Optional | DV_ID;
attList[E_Key][A_Name] = Att_Required;
// "keyref"
attList[E_KeyRef][A_ID] = Att_Optional | DV_ID;
attList[E_KeyRef][A_Name] = Att_Required;
attList[E_KeyRef][A_Refer] = Att_Required;
// "length"
attList[E_Length][A_ID] = Att_Optional | DV_ID;
attList[E_Length][A_Value] = Att_Optional | DV_NonNegInt;
attList[E_Length][A_Fixed] = Att_Optional | DV_Boolean;
// "list"
attList[E_List][A_ID] = Att_Optional | DV_ID;
attList[E_List][A_ItemType] = Att_Optional;
// "maxExclusive"
attList[E_MaxExclusive][A_ID] = Att_Optional | DV_ID;
attList[E_MaxExclusive][A_Value] = Att_Optional;
attList[E_MaxExclusive][A_Fixed] = Att_Optional | DV_Boolean;
// "maxInclusive"
attList[E_MaxInclusive][A_ID] = Att_Optional | DV_ID;
attList[E_MaxInclusive][A_Value] = Att_Optional;
attList[E_MaxInclusive][A_Fixed] = Att_Optional | DV_Boolean;
// "maxLength"
attList[E_MaxLength][A_ID] = Att_Optional | DV_ID;
attList[E_MaxLength][A_Value] = Att_Optional | DV_NonNegInt;
attList[E_MaxLength][A_Fixed] = Att_Optional | DV_Boolean;
// "minExclusive"
attList[E_MinExclusive][A_ID] = Att_Optional | DV_ID;
attList[E_MinExclusive][A_Value] = Att_Optional;
attList[E_MinExclusive][A_Fixed] = Att_Optional | DV_Boolean;
// "minInclusive"
attList[E_MinInclusive][A_ID] = Att_Optional | DV_ID;
attList[E_MinInclusive][A_Value] = Att_Optional;
attList[E_MinInclusive][A_Fixed] = Att_Optional | DV_Boolean;
// "minLength"
attList[E_MinLength][A_ID] = Att_Optional | DV_ID;
attList[E_MinLength][A_Value] = Att_Optional | DV_NonNegInt;
attList[E_MinLength][A_Fixed] = Att_Optional | DV_Boolean;
// "notation"
attList[E_Notation][A_ID] = Att_Optional | DV_ID;
attList[E_Notation][A_Name] = Att_Required;
attList[E_Notation][A_Public] = Att_Optional;
attList[E_Notation][A_System] = Att_Optional | DV_AnyURI;
// "pattern"
attList[E_Pattern][A_ID] = Att_Optional;
attList[E_Pattern][A_Value] = Att_Optional;
// "redefine"
attList[E_Redefine][A_ID] = Att_Optional | DV_ID;
attList[E_Redefine][A_SchemaLocation] = Att_Required;
// "restriction"
attList[E_Restriction][A_Base] = Att_Optional;
attList[E_Restriction][A_ID] = Att_Optional | DV_ID;
// "schema"
attList[E_Schema][A_AttributeFormDefault] = Att_Optional | DV_Form;
attList[E_Schema][A_BlockDefault] = Att_Optional;
attList[E_Schema][A_ElementFormDefault] = Att_Optional | DV_Form;
attList[E_Schema][A_FinalDefault] = Att_Optional;
attList[E_Schema][A_ID] = Att_Optional | DV_ID;
attList[E_Schema][A_TargetNamespace] = Att_Optional;
attList[E_Schema][A_Version] = Att_Optional;
// "selector"
attList[E_Selector][A_ID] = Att_Optional | DV_ID;
attList[E_Selector][A_XPath] = Att_Required;
// "sequence"
attList[E_Sequence][A_ID] = Att_Optional | DV_ID;
attList[E_Sequence][A_MaxOccurs] = Att_Optional | DV_MaxOccurs;
attList[E_Sequence][A_MinOccurs] = Att_Optional | DV_NonNegInt;
// "simpleContent"
attList[E_SimpleContent][A_ID] = Att_Optional | DV_ID;
// "simpleType - global"
attList[E_SimpleTypeGlobal][A_Final] = Att_Optional;
attList[E_SimpleTypeGlobal][A_ID] = Att_Optional | DV_ID;
attList[E_SimpleTypeGlobal][A_Name] = Att_Required;
// "simpleType - local"
attList[E_SimpleTypeLocal][A_Final] = Att_Optional;
attList[E_SimpleTypeLocal][A_ID] = Att_Optional | DV_ID;
// "totalDigits"
attList[E_TotalDigits][A_ID] = Att_Optional | DV_ID;
attList[E_TotalDigits][A_Value] = Att_Optional | DV_NonNegInt;
attList[E_TotalDigits][A_Fixed] = Att_Optional | DV_Boolean;
// "union"
attList[E_Union][A_ID] = Att_Optional | DV_ID;
attList[E_Union][A_MemberTypes] = Att_Optional;
// "unique"
attList[E_Unique][A_ID] = Att_Optional | DV_ID;
attList[E_Unique][A_Name] = Att_Required;
// "whitespace"
attList[E_WhiteSpace][A_ID] = Att_Optional | DV_ID;
attList[E_WhiteSpace][A_Value] = Att_Optional | DV_WhiteSpace;
attList[E_WhiteSpace][A_Fixed] = Att_Optional | DV_Boolean;
for (unsigned int j=0; j < E_Count; j++) {
for (unsigned int index = 0; index < A_Count-1; index++)
{
fprintf(outFl, " %d,", attList[j][index]);
}
fprintf(outFl, " %d", attList[j][A_Count - 1]);
if (j + 1 == E_Count)
fprintf(outFl, "}\n};");
else
fprintf(outFl, "},\n {");
}
fclose(outFl);
}
#endif
unsigned short GeneralAttributeCheck::fgElemAttTable[GeneralAttributeCheck::E_Count][GeneralAttributeCheck::A_Count] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 258, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 130, 0, 10, 0, 0, 2, 0, 1026, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 2, 0, 1026, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 66, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2050, 0, 0, 0},
{ 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2050, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 130, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 18, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 34, 0, 0, 0, 0, 18, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0},
{ 18, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 34, 0, 0, 0, 0, 0, 1, 0, 18, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0},
{ 0, 0, 0, 2, 0, 2, 0, 0, 0, 2, 66, 34, 0, 130, 0, 10, 0, 1, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 130, 0, 10, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 130, 0, 10, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 66, 0, 0, 2, 0, 66, 0, 2, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 130, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4098, 0, 0}
};
const XMLCh* GeneralAttributeCheck::fAttNames[GeneralAttributeCheck::A_Count] =
{
SchemaSymbols::fgATT_ABSTRACT,
SchemaSymbols::fgATT_ATTRIBUTEFORMDEFAULT,
SchemaSymbols::fgATT_BASE,
SchemaSymbols::fgATT_BLOCK,
SchemaSymbols::fgATT_BLOCKDEFAULT,
SchemaSymbols::fgATT_DEFAULT,
SchemaSymbols::fgATT_ELEMENTFORMDEFAULT,
SchemaSymbols::fgATT_FINAL,
SchemaSymbols::fgATT_FINALDEFAULT,
SchemaSymbols::fgATT_FIXED,
SchemaSymbols::fgATT_FORM,
SchemaSymbols::fgATT_ID,
SchemaSymbols::fgATT_ITEMTYPE,
SchemaSymbols::fgATT_MAXOCCURS,
SchemaSymbols::fgATT_MEMBERTYPES,
SchemaSymbols::fgATT_MINOCCURS,
SchemaSymbols::fgATT_MIXED,
SchemaSymbols::fgATT_NAME,
SchemaSymbols::fgATT_NAMESPACE,
SchemaSymbols::fgATT_NILLABLE,
SchemaSymbols::fgATT_PROCESSCONTENTS,
SchemaSymbols::fgATT_PUBLIC,
SchemaSymbols::fgATT_REF,
SchemaSymbols::fgATT_REFER,
SchemaSymbols::fgATT_SCHEMALOCATION,
SchemaSymbols::fgATT_SOURCE,
SchemaSymbols::fgATT_SUBSTITUTIONGROUP,
SchemaSymbols::fgATT_SYSTEM,
SchemaSymbols::fgATT_TARGETNAMESPACE,
SchemaSymbols::fgATT_TYPE,
SchemaSymbols::fgATT_USE,
SchemaSymbols::fgATT_VALUE,
SchemaSymbols::fgATT_VERSION,
SchemaSymbols::fgATT_XPATH,
};
XERCES_CPP_NAMESPACE_END
/**
* End of file GeneralAttributeCheck.cpp
*/
@@ -0,0 +1,258 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: GeneralAttributeCheck.hpp 729944 2008-12-29 17:03:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_GENERALATTRIBUTECHECK_HPP)
#define XERCESC_INCLUDE_GUARD_GENERALATTRIBUTECHECK_HPP
/**
* A general purpose class to check for valid values of attributes, as well
* as check for proper association with corresponding schema elements.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/ValueHashTableOf.hpp>
#include <xercesc/validators/datatype/IDDatatypeValidator.hpp>
#include <xercesc/framework/ValidationContext.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward declaration
// ---------------------------------------------------------------------------
class TraverseSchema;
class DOMElement;
class DOMNode;
class VALIDATORS_EXPORT GeneralAttributeCheck : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------
//Elements
enum
{
E_All,
E_Annotation,
E_Any,
E_AnyAttribute,
E_Appinfo,
E_AttributeGlobal,
E_AttributeLocal,
E_AttributeRef,
E_AttributeGroupGlobal,
E_AttributeGroupRef,
E_Choice,
E_ComplexContent,
E_ComplexTypeGlobal,
E_ComplexTypeLocal,
E_Documentation,
E_ElementGlobal,
E_ElementLocal,
E_ElementRef,
E_Enumeration,
E_Extension,
E_Field,
E_FractionDigits,
E_GroupGlobal,
E_GroupRef,
E_Import,
E_Include,
E_Key,
E_KeyRef,
E_Length,
E_List,
E_MaxExclusive,
E_MaxInclusive,
E_MaxLength,
E_MinExclusive,
E_MinInclusive,
E_MinLength,
E_Notation,
E_Pattern,
E_Redefine,
E_Restriction,
E_Schema,
E_Selector,
E_Sequence,
E_SimpleContent,
E_SimpleTypeGlobal,
E_SimpleTypeLocal,
E_TotalDigits,
E_Union,
E_Unique,
E_WhiteSpace,
E_Count,
E_Invalid = -1
};
//Attributes
enum
{
A_Abstract,
A_AttributeFormDefault,
A_Base,
A_Block,
A_BlockDefault,
A_Default,
A_ElementFormDefault,
A_Final,
A_FinalDefault,
A_Fixed,
A_Form,
A_ID,
A_ItemType,
A_MaxOccurs,
A_MemberTypes,
A_MinOccurs,
A_Mixed,
A_Name,
A_Namespace,
A_Nillable,
A_ProcessContents,
A_Public,
A_Ref,
A_Refer,
A_SchemaLocation,
A_Source,
A_SubstitutionGroup,
A_System,
A_TargetNamespace,
A_Type,
A_Use,
A_Value,
A_Version,
A_XPath,
A_Count,
A_Invalid = -1
};
//Validators
enum {
DV_String = 0,
DV_AnyURI = 4,
DV_NonNegInt = 8,
DV_Boolean = 16,
DV_ID = 32,
DV_Form = 64,
DV_MaxOccurs = 128,
DV_MaxOccurs1 = 256,
DV_MinOccurs1 = 512,
DV_ProcessContents = 1024,
DV_Use = 2048,
DV_WhiteSpace = 4096,
DV_Mask = (DV_AnyURI | DV_NonNegInt | DV_Boolean | DV_ID | DV_Form |
DV_MaxOccurs | DV_MaxOccurs1 | DV_MinOccurs1 |
DV_ProcessContents | DV_Use | DV_WhiteSpace)
};
// generate element-attributes map table
#if defined(NEED_TO_GEN_ELEM_ATT_MAP_TABLE)
static void initCharFlagTable();
#endif
// -----------------------------------------------------------------------
// Constructor/Destructor
// -----------------------------------------------------------------------
GeneralAttributeCheck(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~GeneralAttributeCheck();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
unsigned short getFacetId(const XMLCh* const facetName, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// -----------------------------------------------------------------------
// Validation methods
// -----------------------------------------------------------------------
void checkAttributes(const DOMElement* const elem,
const unsigned short elemContext,
TraverseSchema* const schema,
const bool isTopLevel = false,
ValueVectorOf<DOMNode*>* const nonXSAttList = 0);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
GeneralAttributeCheck(const GeneralAttributeCheck&);
GeneralAttributeCheck& operator=(const GeneralAttributeCheck&);
// -----------------------------------------------------------------------
// Validation methods
// -----------------------------------------------------------------------
void validate(const DOMElement* const elem, const XMLCh* const attName, const XMLCh* const attValue,
const short dvIndex, TraverseSchema* const schema);
// -----------------------------------------------------------------------
// Private Constants
// -----------------------------------------------------------------------
// optional vs. required attribute
enum {
Att_Required = 1,
Att_Optional = 2,
Att_Mask = 3
};
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
static ValueHashTableOf<unsigned short>* fAttMap;
static ValueHashTableOf<unsigned short>* fFacetsMap;
static DatatypeValidator* fNonNegIntDV;
static DatatypeValidator* fBooleanDV;
static DatatypeValidator* fAnyURIDV;
static unsigned short fgElemAttTable[E_Count][A_Count];
static const XMLCh* fAttNames[A_Count];
MemoryManager* fMemoryManager;
IDDatatypeValidator fIDValidator;
private:
static void initialize();
friend class XMLInitializer;
};
// ---------------------------------------------------------------------------
// GeneralAttributeCheck: Getter methods
// ---------------------------------------------------------------------------
inline unsigned short
GeneralAttributeCheck::getFacetId(const XMLCh* const facetName, MemoryManager* const manager) {
return fFacetsMap->get(facetName, manager);
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file GeneralAttributeCheck.hpp
*/
@@ -0,0 +1,317 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: NamespaceScope.cpp 729944 2008-12-29 17:03:32Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <string.h>
#include <xercesc/util/EmptyStackException.hpp>
#include <xercesc/validators/schema/NamespaceScope.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// NamespaceScope: Constructors and Destructor
// ---------------------------------------------------------------------------
NamespaceScope::NamespaceScope(MemoryManager* const manager /*= XMLPlatformUtils::fgMemoryManager*/) :
fEmptyNamespaceId(0)
, fStackCapacity(8)
, fStackTop(0)
, fPrefixPool(109, manager)
, fStack(0)
, fMemoryManager(manager)
{
// Do an initial allocation of the stack and zero it out
fStack = (StackElem**) fMemoryManager->allocate
(
fStackCapacity * sizeof(StackElem*)
);//new StackElem*[fStackCapacity];
memset(fStack, 0, fStackCapacity * sizeof(StackElem*));
}
NamespaceScope::NamespaceScope(const NamespaceScope* const initialize, MemoryManager* const manager /*= XMLPlatformUtils::fgMemoryManager*/) :
fEmptyNamespaceId(0)
, fStackCapacity(8)
, fStackTop(0)
, fPrefixPool(109, manager)
, fStack(0)
, fMemoryManager(manager)
{
// Do an initial allocation of the stack and zero it out
fStack = (StackElem**) fMemoryManager->allocate
(
fStackCapacity * sizeof(StackElem*)
);//new StackElem*[fStackCapacity];
memset(fStack, 0, fStackCapacity * sizeof(StackElem*));
if(initialize)
{
reset(initialize->fEmptyNamespaceId);
// copy the existing bindings
for (unsigned int index = initialize->fStackTop; index > 0; index--)
{
// Get a convenience pointer to the current element
StackElem* curRow = initialize->fStack[index-1];
// If no prefixes mapped at this level, then go the next one
if (!curRow->fMapCount)
continue;
for (unsigned int mapIndex = 0; mapIndex < curRow->fMapCount; mapIndex++)
{
// go from the id to the prefix
const XMLCh* prefix = initialize->fPrefixPool.getValueForId(curRow->fMap[mapIndex].fPrefId);
// if the prefix is not already known, add it
if(getNamespaceForPrefix(prefix)==fEmptyNamespaceId)
addPrefix(prefix, curRow->fMap[mapIndex].fURIId);
}
}
}
}
NamespaceScope::~NamespaceScope()
{
//
// Start working from the bottom of the stack and clear it out as we
// go up. Once we hit an uninitialized one, we can break out.
//
for (unsigned int stackInd = 0; stackInd < fStackCapacity; stackInd++)
{
// If this entry has been set, then lets clean it up
if (!fStack[stackInd])
break;
// Delete the row for this entry, then delete the row structure
fMemoryManager->deallocate(fStack[stackInd]->fMap);//delete [] fStack[stackInd]->fMap;
delete fStack[stackInd];
}
// Delete the stack array itself now
fMemoryManager->deallocate(fStack);//delete [] fStack;
}
// ---------------------------------------------------------------------------
// NamespaceScope: Stack access
// ---------------------------------------------------------------------------
unsigned int NamespaceScope::increaseDepth()
{
// See if we need to expand the stack
if (fStackTop == fStackCapacity)
expandStack();
// If this element has not been initialized yet, then initialize it
if (!fStack[fStackTop])
{
fStack[fStackTop] = new (fMemoryManager) StackElem;
fStack[fStackTop]->fMapCapacity = 0;
fStack[fStackTop]->fMap = 0;
}
// Set up the new top row
fStack[fStackTop]->fMapCount = 0;
// Bump the top of stack
fStackTop++;
return fStackTop-1;
}
unsigned int NamespaceScope::decreaseDepth()
{
if (!fStackTop)
ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::ElemStack_StackUnderflow, fMemoryManager);
fStackTop--;
return fStackTop;
}
// ---------------------------------------------------------------------------
// NamespaceScope: Prefix map methods
// ---------------------------------------------------------------------------
void NamespaceScope::addPrefix(const XMLCh* const prefixToAdd,
const unsigned int uriId) {
if (!fStackTop)
ThrowXMLwithMemMgr(EmptyStackException, XMLExcepts::ElemStack_EmptyStack, fMemoryManager);
// Get a convenience pointer to the stack top row
StackElem* curRow = fStack[fStackTop - 1];
// Map the prefix to its unique id
const unsigned int prefId = fPrefixPool.addOrFind(prefixToAdd);
// Search the map at this level for the passed prefix
for (unsigned int mapIndex = 0; mapIndex < curRow->fMapCount; mapIndex++)
{
if (curRow->fMap[mapIndex].fPrefId == prefId)
{
curRow->fMap[mapIndex].fURIId = uriId;
return;
}
}
//
// Add a new element to the prefix map for this element. If its full,
// then expand it out.
//
if (curRow->fMapCount == curRow->fMapCapacity)
expandMap(curRow);
//
// And now add a new element for this prefix.
//
curRow->fMap[curRow->fMapCount].fPrefId = prefId;
curRow->fMap[curRow->fMapCount].fURIId = uriId;
// Bump the map count now
curRow->fMapCount++;
}
unsigned int
NamespaceScope::getNamespaceForPrefix(const XMLCh* const prefixToMap) const {
//
// Map the prefix to its unique id, from the prefix string pool. If its
// not a valid prefix, then its a failure.
//
unsigned int prefixId = fPrefixPool.getId(prefixToMap);
if (!prefixId){
return fEmptyNamespaceId;
}
//
// Start at the stack top and work backwards until we come to some
// element that mapped this prefix.
//
for (unsigned int index = fStackTop; index > 0; index--)
{
// Get a convenience pointer to the current element
StackElem* curRow = fStack[index-1];
// If no prefixes mapped at this level, then go the next one
if (!curRow->fMapCount)
continue;
// Search the map at this level for the passed prefix
for (unsigned int mapIndex = 0; mapIndex < curRow->fMapCount; mapIndex++)
{
if (curRow->fMap[mapIndex].fPrefId == prefixId)
return curRow->fMap[mapIndex].fURIId;
}
}
return fEmptyNamespaceId;
}
// ---------------------------------------------------------------------------
// NamespaceScope: Miscellaneous methods
// ---------------------------------------------------------------------------
void NamespaceScope::reset(const unsigned int emptyId)
{
// Flush the prefix pool and put back in the standard prefixes
fPrefixPool.flushAll();
// Reset the stack top to clear the stack
fStackTop = 0;
// And store the new special URI ids
fEmptyNamespaceId = emptyId;
// add the first storage
increaseDepth();
}
// ---------------------------------------------------------------------------
// Namespace: Private helpers
// ---------------------------------------------------------------------------
void NamespaceScope::expandMap(StackElem* const toExpand)
{
// For convenience get the old map size
const unsigned int oldCap = toExpand->fMapCapacity;
//
// Expand the capacity by 25%, or initialize it to 16 if its currently
// empty. Then allocate a new temp buffer.
//
const unsigned int newCapacity = oldCap ?
(unsigned int)(oldCap * 1.25) : 16;
PrefMapElem* newMap = (PrefMapElem*) fMemoryManager->allocate
(
newCapacity * sizeof(PrefMapElem)
);//new PrefMapElem[newCapacity];
//
// Copy over the old stuff. We DON'T have to zero out the new stuff
// since this is a by value map and the current map index controls what
// is relevant.
//
memcpy(newMap, toExpand->fMap, oldCap * sizeof(PrefMapElem));
// Delete the old map and store the new stuff
fMemoryManager->deallocate(toExpand->fMap);//delete [] toExpand->fMap;
toExpand->fMap = newMap;
toExpand->fMapCapacity = newCapacity;
}
void NamespaceScope::expandStack()
{
// Expand the capacity by 25% and allocate a new buffer
const unsigned int newCapacity = (unsigned int)(fStackCapacity * 1.25);
StackElem** newStack = (StackElem**) fMemoryManager->allocate
(
newCapacity * sizeof(StackElem*)
);//new StackElem*[newCapacity];
// Copy over the old stuff
memcpy(newStack, fStack, fStackCapacity * sizeof(StackElem*));
//
// And zero out the new stuff. Though we use a stack top, we reuse old
// stack contents so we need to know if elements have been initially
// allocated or not as we push new stuff onto the stack.
//
memset
(
&newStack[fStackCapacity]
, 0
, (newCapacity - fStackCapacity) * sizeof(StackElem*)
);
// Delete the old array and update our members
fMemoryManager->deallocate(fStack);//delete [] fStack;
fStack = newStack;
fStackCapacity = newCapacity;
}
XERCES_CPP_NAMESPACE_END
/**
* End of file NamespaceScope.cpp
*/
@@ -0,0 +1,169 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: NamespaceScope.hpp 729944 2008-12-29 17:03:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_NAMESPACESCOPE_HPP)
#define XERCESC_INCLUDE_GUARD_NAMESPACESCOPE_HPP
#include <xercesc/util/StringPool.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// Define a pure interface to allow XercesXPath to work on both NamespaceScope and DOMXPathNSResolver
class VALIDATORS_EXPORT XercesNamespaceResolver
{
public:
virtual unsigned int getNamespaceForPrefix(const XMLCh* const prefix) const = 0;
};
//
// NamespaceScope provides a data structure for mapping namespace prefixes
// to their URI's. The mapping accurately reflects the scoping of namespaces
// at a particular instant in time.
//
class VALIDATORS_EXPORT NamespaceScope : public XMemory,
public XercesNamespaceResolver
{
public :
// -----------------------------------------------------------------------
// Class specific data types
//
// These really should be private, but some of the compilers we have to
// support are too dumb to deal with that.
//
// PrefMapElem
// fURIId is the id of the URI from the validator's URI map. The
// fPrefId is the id of the prefix from our own prefix pool. The
// namespace stack consists of these elements.
//
// StackElem
// The fMapCapacity is how large fMap has grown so far. fMapCount
// is how many of them are valid right now.
// -----------------------------------------------------------------------
struct PrefMapElem : public XMemory
{
unsigned int fPrefId;
unsigned int fURIId;
};
struct StackElem : public XMemory
{
PrefMapElem* fMap;
unsigned int fMapCapacity;
unsigned int fMapCount;
};
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
NamespaceScope(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
NamespaceScope(const NamespaceScope* const initialize, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~NamespaceScope();
// -----------------------------------------------------------------------
// Stack access
// -----------------------------------------------------------------------
unsigned int increaseDepth();
unsigned int decreaseDepth();
// -----------------------------------------------------------------------
// Prefix map methods
// -----------------------------------------------------------------------
void addPrefix(const XMLCh* const prefixToAdd,
const unsigned int uriId);
virtual unsigned int getNamespaceForPrefix(const XMLCh* const prefixToMap) const;
// -----------------------------------------------------------------------
// Miscellaneous methods
// -----------------------------------------------------------------------
bool isEmpty() const;
void reset(const unsigned int emptyId);
unsigned int getEmptyNamespaceId() const;
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
NamespaceScope(const NamespaceScope&);
NamespaceScope& operator=(const NamespaceScope&);
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void expandMap(StackElem* const toExpand);
void expandStack();
// -----------------------------------------------------------------------
// Data members
//
// fEmptyNamespaceId
// This is the special URI id for the "" namespace, which is magic
// because of the xmlns="" operation.
//
// fPrefixPool
// This is the prefix pool where prefixes are hashed and given unique
// ids. These ids are used to track prefixes in the element stack.
//
// fStack
// fStackCapacity
// fStackTop
// This the stack array. Its an array of pointers to StackElem
// structures. The capacity is the current high water mark of the
// stack. The top is the current top of stack (i.e. the part of it
// being used.)
// -----------------------------------------------------------------------
unsigned int fEmptyNamespaceId;
unsigned int fStackCapacity;
unsigned int fStackTop;
XMLStringPool fPrefixPool;
StackElem** fStack;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// NamespaceScope: Miscellaneous methods
// ---------------------------------------------------------------------------
inline bool NamespaceScope::isEmpty() const
{
return (fStackTop == 0);
}
inline unsigned int NamespaceScope::getEmptyNamespaceId() const
{
return fEmptyNamespaceId;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file NameSpaceScope.hpp
*/
@@ -0,0 +1,40 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: PSVIDefs.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_PSVIDEFS_HPP)
#define XERCESC_INCLUDE_GUARD_PSVIDEFS_HPP
XERCES_CPP_NAMESPACE_BEGIN
class VALIDATORS_EXPORT PSVIDefs
{
public:
enum PSVIScope
{
SCP_ABSENT // declared in group/attribute group
, SCP_GLOBAL // global declaration or ref
, SCP_LOCAL // local declaration
};
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,178 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaAttDef.cpp 679359 2008-07-24 11:15:19Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/framework/XMLElementDecl.hpp>
#include <xercesc/validators/schema/SchemaAttDef.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// SchemaAttDef: Implementation of the XMLAttDef interface
// ---------------------------------------------------------------------------
const XMLCh* SchemaAttDef::getFullName() const
{
return fAttName->getRawName();
}
// ---------------------------------------------------------------------------
// SchemaAttDef: Constructors and Destructor
// ---------------------------------------------------------------------------
SchemaAttDef::SchemaAttDef(MemoryManager* const manager) :
XMLAttDef(XMLAttDef::CData, XMLAttDef::Implied, manager)
, fElemId(XMLElementDecl::fgInvalidElemId)
, fPSVIScope(PSVIDefs::SCP_ABSENT)
, fAttName(0)
, fDatatypeValidator(0)
, fNamespaceList(0)
, fBaseAttDecl(0)
{
}
SchemaAttDef::SchemaAttDef( const XMLCh* const prefix
, const XMLCh* const localPart
, const int uriId
, const XMLAttDef::AttTypes type
, const XMLAttDef::DefAttTypes defType
, MemoryManager* const manager) :
XMLAttDef(type, defType, manager)
, fElemId(XMLElementDecl::fgInvalidElemId)
, fPSVIScope(PSVIDefs::SCP_ABSENT)
, fDatatypeValidator(0)
, fNamespaceList(0)
, fBaseAttDecl(0)
{
fAttName = new (manager) QName(prefix, localPart, uriId, manager);
}
SchemaAttDef::SchemaAttDef( const XMLCh* const prefix
, const XMLCh* const localPart
, const int uriId
, const XMLCh* const attValue
, const XMLAttDef::AttTypes type
, const XMLAttDef::DefAttTypes defType
, const XMLCh* const enumValues
, MemoryManager* const manager) :
XMLAttDef(attValue, type, defType, enumValues, manager)
, fElemId(XMLElementDecl::fgInvalidElemId)
, fPSVIScope(PSVIDefs::SCP_ABSENT)
, fDatatypeValidator(0)
, fNamespaceList(0)
, fBaseAttDecl(0)
{
fAttName = new (manager) QName(prefix, localPart, uriId, manager);
}
SchemaAttDef::SchemaAttDef(const SchemaAttDef* other) :
XMLAttDef(other->getValue(), other->getType(),
other->getDefaultType(), other->getEnumeration(),
other->getMemoryManager())
, fElemId(XMLElementDecl::fgInvalidElemId)
, fPSVIScope(other->fPSVIScope)
, fAttName(0)
, fDatatypeValidator(other->fDatatypeValidator)
, fNamespaceList(0)
, fBaseAttDecl(other->fBaseAttDecl)
{
QName* otherName = other->getAttName();
fAttName = new (getMemoryManager()) QName(otherName->getPrefix(),
otherName->getLocalPart(), otherName->getURI(),
getMemoryManager());
if (other->fNamespaceList && other->fNamespaceList->size()) {
fNamespaceList = new (getMemoryManager()) ValueVectorOf<unsigned int>(*(other->fNamespaceList));
}
}
SchemaAttDef::~SchemaAttDef()
{
delete fAttName;
delete fNamespaceList;
}
// ---------------------------------------------------------------------------
// SchemaAttDef: Setter methods
// ---------------------------------------------------------------------------
void SchemaAttDef::setAttName(const XMLCh* const prefix
, const XMLCh* const localPart
, const int uriId )
{
fAttName->setName(prefix, localPart, uriId);
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(SchemaAttDef)
void SchemaAttDef::serialize(XSerializeEngine& serEng)
{
XMLAttDef::serialize(serEng);
if (serEng.isStoring())
{
serEng.writeSize (fElemId);
serEng<<(int)fPSVIScope;
serEng<<fAttName;
DatatypeValidator::storeDV(serEng, fDatatypeValidator);
/***
* Serialize ValueVectorOf<unsigned int>
***/
XTemplateSerializer::storeObject(fNamespaceList, serEng);
serEng<<fBaseAttDecl;
}
else
{
serEng.readSize (fElemId);
int i;
serEng>>i;
fPSVIScope = (PSVIDefs::PSVIScope)i;
serEng>>fAttName;
fDatatypeValidator = DatatypeValidator::loadDV(serEng);
/***
* Deserialize ValueVectorOf<unsigned int>
***/
XTemplateSerializer::loadObject(&fNamespaceList, 8, false, serEng);
serEng>>fBaseAttDecl;
}
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,252 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaAttDef.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SCHEMAATTDEF_HPP)
#define XERCESC_INCLUDE_GUARD_SCHEMAATTDEF_HPP
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/XMLAttDef.hpp>
#include <xercesc/util/ValueVectorOf.hpp>
#include <xercesc/validators/datatype/DatatypeValidator.hpp>
#include <xercesc/validators/datatype/UnionDatatypeValidator.hpp>
#include <xercesc/validators/schema/PSVIDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DatatypeValidator;
class QName;
class ComplexTypeInfo;
//
// This class is a derivative of the core XMLAttDef class. This class adds
// any Schema specific data members and provides Schema specific implementations
// of any underlying attribute def virtual methods.
//
class VALIDATORS_EXPORT SchemaAttDef : public XMLAttDef
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructors
// -----------------------------------------------------------------------
SchemaAttDef(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
SchemaAttDef
(
const XMLCh* const prefix
, const XMLCh* const localPart
, const int uriId
, const XMLAttDef::AttTypes type = CData
, const XMLAttDef::DefAttTypes defType = Implied
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
SchemaAttDef
(
const XMLCh* const prefix
, const XMLCh* const localPart
, const int uriId
, const XMLCh* const attValue
, const XMLAttDef::AttTypes type
, const XMLAttDef::DefAttTypes defType
, const XMLCh* const enumValues = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
SchemaAttDef
(
const SchemaAttDef* other
);
virtual ~SchemaAttDef();
// -----------------------------------------------------------------------
// Implementation of the XMLAttDef interface
// -----------------------------------------------------------------------
virtual const XMLCh* getFullName() const;
virtual void reset();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
XMLSize_t getElemId() const;
QName* getAttName() const;
DatatypeValidator* getDatatypeValidator() const;
ValueVectorOf<unsigned int>* getNamespaceList() const;
const SchemaAttDef* getBaseAttDecl() const;
SchemaAttDef* getBaseAttDecl();
PSVIDefs::PSVIScope getPSVIScope() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setElemId(const XMLSize_t newId);
void setAttName
(
const XMLCh* const prefix
,const XMLCh* const localPart
,const int uriId = -1
);
void setDatatypeValidator(DatatypeValidator* newDatatypeValidator);
void setBaseAttDecl(SchemaAttDef* const attDef);
void setPSVIScope(const PSVIDefs::PSVIScope toSet);
void setNamespaceList(const ValueVectorOf<unsigned int>* const toSet);
void resetNamespaceList();
void setEnclosingCT(ComplexTypeInfo* complexTypeInfo);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(SchemaAttDef)
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SchemaAttDef(const SchemaAttDef&);
SchemaAttDef& operator=(const SchemaAttDef&);
// -----------------------------------------------------------------------
// Private data members
//
// fElemId
// This is the id of the element (the id is into the element decl
// pool) of the element this attribute def said it belonged to.
// This is used later to link back to the element, mostly for
// validation purposes.
//
// fAttName
// This is the name of the attribute.
//
// fDatatypeValidator
// The DatatypeValidator used to validate this attribute type.
//
// fNamespaceList
// The list of namespace values for a wildcard attribute
//
// fBaseAttDecl
// The base attribute declaration that this attribute is based on
// NOTE: we do not have a notion of attribute use, so in the case
// of ref'd attributes and inherited attributes, we make a copy
// of the actual attribute declaration. The fBaseAttDecl stores that
// declaration, and will be helpful when we build the XSModel (i.e
// easy access the XSAnnotation object).
// -----------------------------------------------------------------------
XMLSize_t fElemId;
PSVIDefs::PSVIScope fPSVIScope;
QName* fAttName;
DatatypeValidator* fDatatypeValidator;
ValueVectorOf<unsigned int>* fNamespaceList;
SchemaAttDef* fBaseAttDecl;
};
// ---------------------------------------------------------------------------
// SchemaAttDef: Getter methods
// ---------------------------------------------------------------------------
inline XMLSize_t SchemaAttDef::getElemId() const
{
return fElemId;
}
inline QName* SchemaAttDef::getAttName() const
{
return fAttName;
}
inline DatatypeValidator* SchemaAttDef::getDatatypeValidator() const
{
return fDatatypeValidator;
}
inline ValueVectorOf<unsigned int>*
SchemaAttDef::getNamespaceList() const {
return fNamespaceList;
}
inline SchemaAttDef* SchemaAttDef::getBaseAttDecl()
{
return fBaseAttDecl;
}
inline const SchemaAttDef* SchemaAttDef::getBaseAttDecl() const
{
return fBaseAttDecl;
}
inline PSVIDefs::PSVIScope SchemaAttDef::getPSVIScope() const
{
return fPSVIScope;
}
// ---------------------------------------------------------------------------
// SchemaAttDef: Setter methods
// ---------------------------------------------------------------------------
inline void SchemaAttDef::setElemId(const XMLSize_t newId)
{
fElemId = newId;
}
inline void SchemaAttDef::setDatatypeValidator(DatatypeValidator* newDatatypeValidator)
{
fDatatypeValidator = newDatatypeValidator;
}
inline void SchemaAttDef::resetNamespaceList() {
if (fNamespaceList && fNamespaceList->size()) {
fNamespaceList->removeAllElements();
}
}
inline void SchemaAttDef::setNamespaceList(const ValueVectorOf<unsigned int>* const toSet) {
if (toSet && toSet->size()) {
if (fNamespaceList) {
*fNamespaceList = *toSet;
}
else {
fNamespaceList = new (getMemoryManager()) ValueVectorOf<unsigned int>(*toSet);
}
}
else {
resetNamespaceList();
}
}
inline void SchemaAttDef::reset() {
}
inline void SchemaAttDef::setEnclosingCT(ComplexTypeInfo*)
{
}
inline void SchemaAttDef::setBaseAttDecl(SchemaAttDef* const attDef)
{
fBaseAttDecl = attDef;
}
inline void SchemaAttDef::setPSVIScope(const PSVIDefs::PSVIScope toSet)
{
fPSVIScope = toSet;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,201 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaAttDefList.cpp 679359 2008-07-24 11:15:19Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/SchemaAttDefList.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// SchemaAttDefList: Constructors and Destructor
// ---------------------------------------------------------------------------
SchemaAttDefList::SchemaAttDefList(RefHash2KeysTableOf<SchemaAttDef>* const listToUse, MemoryManager* const manager)
: XMLAttDefList(manager)
,fEnum(0)
,fList(listToUse)
,fArray(0)
,fSize(0)
,fCount(0)
{
fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(listToUse, false, getMemoryManager());
fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) << 1));
fSize = 2;
}
SchemaAttDefList::~SchemaAttDefList()
{
delete fEnum;
(getMemoryManager())->deallocate(fArray);
}
// ---------------------------------------------------------------------------
// SchemaAttDefList: Implementation of the virtual interface
// ---------------------------------------------------------------------------
bool SchemaAttDefList::isEmpty() const
{
return fList->isEmpty();
}
XMLAttDef* SchemaAttDefList::findAttDef(const unsigned int uriID
, const XMLCh* const attName)
{
const int colonInd = XMLString::indexOf(attName, chColon);
// An index of 0 is really an error, but the QName class doesn't check for
// that case either...
const XMLCh* const localPart = colonInd >= 0 ? attName + colonInd + 1 : attName;
return fList->get((void*)localPart, uriID);
}
const XMLAttDef*
SchemaAttDefList::findAttDef( const unsigned int uriID
, const XMLCh* const attName) const
{
const int colonInd = XMLString::indexOf(attName, chColon);
// An index of 0 is really an error, but the QName class doesn't check for
// that case either...
const XMLCh* const localPart = colonInd >= 0 ? attName + colonInd + 1 : attName;
return fList->get((void*)localPart, uriID);
}
XMLAttDef* SchemaAttDefList::findAttDef( const XMLCh* const
, const XMLCh* const)
{
//need numeric URI id to locate the attribute, that's how it was stored
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_InvalidId, getMemoryManager());
return 0;
}
const XMLAttDef*
SchemaAttDefList::findAttDef( const XMLCh* const
, const XMLCh* const) const
{
//need numeric URI id to locate the attribute, that's how it was stored
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_InvalidId, getMemoryManager());
return 0;
}
/**
* return total number of attributes in this list
*/
XMLSize_t SchemaAttDefList::getAttDefCount() const
{
return fCount;
}
/**
* return attribute at the index-th position in the list.
*/
XMLAttDef &SchemaAttDefList::getAttDef(XMLSize_t index)
{
if(index >= fCount)
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
return *(fArray[index]);
}
/**
* return attribute at the index-th position in the list.
*/
const XMLAttDef &SchemaAttDefList::getAttDef(XMLSize_t index) const
{
if(index >= fCount)
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
return *(fArray[index]);
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(SchemaAttDefList)
void SchemaAttDefList::serialize(XSerializeEngine& serEng)
{
XMLAttDefList::serialize(serEng);
if (serEng.isStoring())
{
/***
*
* Serialize RefHash2KeysTableOf<SchemaAttDef>
*
***/
XTemplateSerializer::storeObject(fList, serEng);
serEng.writeSize (fCount);
// do not serialize fEnum
}
else
{
/***
*
* Deserialize RefHash2KeysTableOf<SchemaAttDef>
*
***/
XTemplateSerializer::loadObject(&fList, 29, true, serEng);
// assume empty so we can size fArray just right
serEng.readSize (fSize);
if (!fEnum && fList)
{
fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(fList, false, getMemoryManager());
}
if(fSize)
{
(getMemoryManager())->deallocate(fArray);
fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize));
fCount = 0;
while(fEnum->hasMoreElements())
{
fArray[fCount++] = &fEnum->nextElement();
}
}
}
}
SchemaAttDefList::SchemaAttDefList(MemoryManager* const manager)
: XMLAttDefList(manager)
,fEnum(0)
,fList(0)
,fArray(0)
,fSize(0)
,fCount(0)
{
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,181 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaAttDefList.hpp 673679 2008-07-03 13:50:10Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SCHEMAATTDEFLIST_HPP)
#define XERCESC_INCLUDE_GUARD_SCHEMAATTDEFLIST_HPP
#include <xercesc/util/RefHash2KeysTableOf.hpp>
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This is a derivative of the framework abstract class which defines the
// interface to a list of attribute defs that belong to a particular
// element. The scanner needs to be able to get a list of the attributes
// that an element supports, for use during the validation process and for
// fixed/default attribute processing.
//
// For us, we just wrap the RefHash2KeysTableOf collection that the SchemaElementDecl
// class uses to store the attributes that belong to it.
//
// This class does not adopt the hash table, it just references it. The
// hash table is owned by the element decl it is a member of.
//
class VALIDATORS_EXPORT SchemaAttDefList : public XMLAttDefList
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
SchemaAttDefList
(
RefHash2KeysTableOf<SchemaAttDef>* const listToUse,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
~SchemaAttDefList();
// -----------------------------------------------------------------------
// Implementation of the virtual interface
// -----------------------------------------------------------------------
virtual bool isEmpty() const;
virtual XMLAttDef* findAttDef
(
const unsigned int uriID
, const XMLCh* const attName
);
virtual const XMLAttDef* findAttDef
(
const unsigned int uriID
, const XMLCh* const attName
) const;
virtual XMLAttDef* findAttDef
(
const XMLCh* const attURI
, const XMLCh* const attName
);
virtual const XMLAttDef* findAttDef
(
const XMLCh* const attURI
, const XMLCh* const attName
) const;
XMLAttDef* findAttDefLocalPart
(
const unsigned int uriID
, const XMLCh* const attLocalPart
);
const XMLAttDef* findAttDefLocalPart
(
const unsigned int uriID
, const XMLCh* const attLocalPart
) const;
/**
* return total number of attributes in this list
*/
virtual XMLSize_t getAttDefCount() const ;
/**
* return attribute at the index-th position in the list.
*/
virtual XMLAttDef &getAttDef(XMLSize_t index) ;
/**
* return attribute at the index-th position in the list.
*/
virtual const XMLAttDef &getAttDef(XMLSize_t index) const ;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(SchemaAttDefList)
SchemaAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SchemaAttDefList(const SchemaAttDefList&);
SchemaAttDefList& operator=(const SchemaAttDefList&);
void addAttDef(SchemaAttDef *toAdd);
// -----------------------------------------------------------------------
// Private data members
//
// fEnum
// This is an enumerator for the list that we use to do the enumerator
// type methods of this class.
//
// fList
// The list of SchemaAttDef objects that represent the attributes that
// a particular element supports.
// fArray
// vector of pointers to the DTDAttDef objects contained in this list
// fSize
// size of fArray
// fCount
// number of DTDAttDef objects currently stored in this list
// -----------------------------------------------------------------------
RefHash2KeysTableOfEnumerator<SchemaAttDef>* fEnum;
RefHash2KeysTableOf<SchemaAttDef>* fList;
SchemaAttDef** fArray;
XMLSize_t fSize;
XMLSize_t fCount;
friend class ComplexTypeInfo;
};
inline void SchemaAttDefList::addAttDef(SchemaAttDef *toAdd)
{
if(fCount == fSize)
{
// need to grow fArray
fSize <<= 1;
SchemaAttDef** newArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize ));
memcpy(newArray, fArray, fCount * sizeof(SchemaAttDef *));
(getMemoryManager())->deallocate(fArray);
fArray = newArray;
}
fArray[fCount++] = toAdd;
}
inline XMLAttDef* SchemaAttDefList::findAttDefLocalPart(const unsigned int uriID
, const XMLCh* const attLocalPart)
{
return fList->get((void*)attLocalPart, uriID);
}
inline const XMLAttDef* SchemaAttDefList::findAttDefLocalPart(const unsigned int uriID
, const XMLCh* const attLocalPart) const
{
return fList->get((void*)attLocalPart, uriID);
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,277 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaElementDecl.cpp 609971 2008-01-08 13:30:47Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/validators/schema/SchemaAttDefList.hpp>
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// SchemaElementDecl: Constructors and Destructor
// ---------------------------------------------------------------------------
SchemaElementDecl::SchemaElementDecl(MemoryManager* const manager) :
XMLElementDecl(manager)
, fModelType(Any)
, fPSVIScope(PSVIDefs::SCP_ABSENT)
, fEnclosingScope(Grammar::TOP_LEVEL_SCOPE)
, fFinalSet(0)
, fBlockSet(0)
, fMiscFlags(0)
, fDefaultValue(0)
, fComplexTypeInfo(0)
, fAttDefs(0)
, fIdentityConstraints(0)
, fAttWildCard(0)
, fSubstitutionGroupElem(0)
, fDatatypeValidator(0)
{
}
SchemaElementDecl::SchemaElementDecl(const XMLCh* const prefix
, const XMLCh* const localPart
, const int uriId
, const SchemaElementDecl::ModelTypes type
, const unsigned int enclosingScope
, MemoryManager* const manager) :
XMLElementDecl(manager)
, fModelType(type)
, fPSVIScope(PSVIDefs::SCP_ABSENT)
, fEnclosingScope(enclosingScope)
, fFinalSet(0)
, fBlockSet(0)
, fMiscFlags(0)
, fDefaultValue(0)
, fComplexTypeInfo(0)
, fAttDefs(0)
, fIdentityConstraints(0)
, fAttWildCard(0)
, fSubstitutionGroupElem(0)
, fDatatypeValidator(0)
{
setElementName(prefix, localPart, uriId);
}
SchemaElementDecl::SchemaElementDecl(const QName* const elementName
, const SchemaElementDecl::ModelTypes type
, const unsigned int enclosingScope
, MemoryManager* const manager) :
XMLElementDecl(manager)
, fModelType(type)
, fPSVIScope(PSVIDefs::SCP_ABSENT)
, fEnclosingScope(enclosingScope)
, fFinalSet(0)
, fBlockSet(0)
, fMiscFlags(0)
, fDefaultValue(0)
, fComplexTypeInfo(0)
, fAttDefs(0)
, fIdentityConstraints(0)
, fAttWildCard(0)
, fSubstitutionGroupElem(0)
, fDatatypeValidator(0)
{
setElementName(elementName);
}
SchemaElementDecl::~SchemaElementDecl()
{
getMemoryManager()->deallocate(fDefaultValue);//delete [] fDefaultValue;
delete fAttDefs;
delete fIdentityConstraints;
delete fAttWildCard;
}
// ---------------------------------------------------------------------------
// SchemaElementDecl: XMLElementDecl virtual interface implementation
// ---------------------------------------------------------------------------
XMLAttDefList& SchemaElementDecl::getAttDefList() const
{
if (!fComplexTypeInfo)
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::DV_InvalidOperation, getMemoryManager());
}
return fComplexTypeInfo->getAttDefList();
}
XMLElementDecl::CharDataOpts SchemaElementDecl::getCharDataOpts() const
{
SchemaElementDecl::ModelTypes modelType = fModelType;
if (fComplexTypeInfo) {
modelType = (SchemaElementDecl::ModelTypes) fComplexTypeInfo->getContentType();
}
XMLElementDecl::CharDataOpts retVal;
switch(modelType)
{
case Children :
case ElementOnlyEmpty :
retVal = XMLElementDecl::SpacesOk;
break;
case Empty :
retVal = XMLElementDecl::NoCharData;
break;
default :
retVal = XMLElementDecl::AllCharData;
break;
}
return retVal;
}
bool SchemaElementDecl::hasAttDefs() const
{
if (fComplexTypeInfo) {
return fComplexTypeInfo->hasAttDefs();
}
// If the collection hasn't been faulted in, then no att defs
return false;
}
const XMLCh*
SchemaElementDecl::getFormattedContentModel() const
{
if (fComplexTypeInfo) {
return fComplexTypeInfo->getFormattedContentModel();
}
return 0;
}
// ---------------------------------------------------------------------------
// SchemaElementDecl: Getter methods
// ---------------------------------------------------------------------------
const SchemaAttDef* SchemaElementDecl::getAttDef(const XMLCh* const baseName, const int uriId) const
{
if (fComplexTypeInfo) {
return fComplexTypeInfo->getAttDef(baseName, uriId);
}
// If no complex type, then return a null
return 0;
}
SchemaAttDef* SchemaElementDecl::getAttDef(const XMLCh* const baseName, const int uriId)
{
if (fComplexTypeInfo) {
return fComplexTypeInfo->getAttDef(baseName, uriId);
}
// If no complex type, then return a null
return 0;
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(SchemaElementDecl)
void SchemaElementDecl::serialize(XSerializeEngine& serEng)
{
XMLElementDecl::serialize(serEng);
if (serEng.isStoring())
{
serEng<<(int)fModelType;
serEng<<(int)fPSVIScope;
serEng<<fEnclosingScope;
serEng<<fFinalSet;
serEng<<fBlockSet;
serEng<<fMiscFlags;
serEng.writeString(fDefaultValue);
serEng<<fComplexTypeInfo;
/***
* Serialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
***/
XTemplateSerializer::storeObject(fAttDefs, serEng);
/***
* Serialize RefVectorOf<IdentityConstraint>* fIdentityConstraints;
***/
XTemplateSerializer::storeObject(fIdentityConstraints, serEng);
serEng<<fAttWildCard;
serEng<<fSubstitutionGroupElem;
DatatypeValidator::storeDV(serEng, fDatatypeValidator);
}
else
{
int i;
serEng>>i;
fModelType = (ModelTypes)i;
serEng>>i;
fPSVIScope = (PSVIDefs::PSVIScope)i;
serEng>>fEnclosingScope;
serEng>>fFinalSet;
serEng>>fBlockSet;
serEng>>fMiscFlags;
serEng.readString(fDefaultValue);
serEng>>fComplexTypeInfo;
/***
* DeSerialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
***/
XTemplateSerializer::loadObject(&fAttDefs, 29, true, serEng);
/***
* DeSerialize RefVectorOf<IdentityConstraint>* fIdentityConstraints;
***/
XTemplateSerializer::loadObject(&fIdentityConstraints, 16, true, serEng);
serEng>>fAttWildCard;
serEng>>fSubstitutionGroupElem;
fDatatypeValidator = DatatypeValidator::loadDV(serEng);
}
}
XMLElementDecl::objectType SchemaElementDecl::getObjectType() const
{
return Schema;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,438 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaElementDecl.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SCHEMAELEMENTDECL_HPP)
#define XERCESC_INCLUDE_GUARD_SCHEMAELEMENTDECL_HPP
#include <xercesc/util/QName.hpp>
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/validators/schema/ComplexTypeInfo.hpp>
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
#include <xercesc/validators/datatype/DatatypeValidator.hpp>
#include <xercesc/validators/schema/PSVIDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class ContentSpecNode;
class SchemaAttDefList;
//
// This class is a derivative of the basic element decl. This one implements
// the virtuals so that they work for a Schema.
//
class VALIDATORS_EXPORT SchemaElementDecl : public XMLElementDecl
{
public :
// -----------------------------------------------------------------------
// Class specific types
//
// ModelTypes
// Indicates the type of content model that an element has. This
// indicates how the content model is represented and validated.
// -----------------------------------------------------------------------
enum ModelTypes
{
Empty
, Any
, Mixed_Simple
, Mixed_Complex
, Children
, Simple
, ElementOnlyEmpty
, ModelTypes_Count
};
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
SchemaElementDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
SchemaElementDecl
(
const XMLCh* const prefix
, const XMLCh* const localPart
, const int uriId
, const ModelTypes modelType = Any
, const unsigned int enclosingScope = Grammar::TOP_LEVEL_SCOPE
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
SchemaElementDecl
(
const QName* const elementName
, const ModelTypes modelType = Any
, const unsigned int enclosingScope = Grammar::TOP_LEVEL_SCOPE
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
~SchemaElementDecl();
// -----------------------------------------------------------------------
// The virtual element decl interface
// -----------------------------------------------------------------------
virtual XMLAttDefList& getAttDefList() const;
virtual CharDataOpts getCharDataOpts() const;
virtual bool hasAttDefs() const;
virtual const ContentSpecNode* getContentSpec() const;
virtual ContentSpecNode* getContentSpec();
virtual void setContentSpec(ContentSpecNode* toAdopt);
virtual XMLContentModel* getContentModel();
virtual void setContentModel(XMLContentModel* const newModelToAdopt);
virtual const XMLCh* getFormattedContentModel () const;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const SchemaAttDef* getAttDef(const XMLCh* const baseName, const int uriId) const;
SchemaAttDef* getAttDef(const XMLCh* const baseName, const int uriId);
const SchemaAttDef* getAttWildCard() const;
SchemaAttDef* getAttWildCard();
ModelTypes getModelType() const;
PSVIDefs::PSVIScope getPSVIScope() const;
DatatypeValidator* getDatatypeValidator() const;
unsigned int getEnclosingScope() const;
int getFinalSet() const;
int getBlockSet() const;
int getMiscFlags() const;
XMLCh* getDefaultValue() const;
ComplexTypeInfo* getComplexTypeInfo() const;
virtual bool isGlobalDecl() const;
SchemaElementDecl* getSubstitutionGroupElem() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setModelType(const SchemaElementDecl::ModelTypes toSet);
void setPSVIScope(const PSVIDefs::PSVIScope toSet);
void setDatatypeValidator(DatatypeValidator* newDatatypeValidator);
void setEnclosingScope(const unsigned int enclosingScope);
void setFinalSet(const int finalSet);
void setBlockSet(const int blockSet);
void setMiscFlags(const int flags);
void setDefaultValue(const XMLCh* const value);
void setComplexTypeInfo(ComplexTypeInfo* const typeInfo);
void setAttWildCard(SchemaAttDef* const attWildCard);
void setSubstitutionGroupElem(SchemaElementDecl* const elemDecl);
// -----------------------------------------------------------------------
// IC methods
// -----------------------------------------------------------------------
void addIdentityConstraint(IdentityConstraint* const ic);
XMLSize_t getIdentityConstraintCount() const;
IdentityConstraint* getIdentityConstraintAt(XMLSize_t index) const;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(SchemaElementDecl)
virtual XMLElementDecl::objectType getObjectType() const;
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SchemaElementDecl(const SchemaElementDecl&);
SchemaElementDecl& operator=(const SchemaElementDecl&);
// -----------------------------------------------------------------------
// Private data members
//
// fModelType
// The content model type of this element. This tells us what kind
// of content model to create.
//
// fDatatypeValidator
// The DatatypeValidator used to validate this element type.
//
// fEnclosingScope
// The enclosing scope where this element is declared.
//
// fFinalSet
// The value set of the 'final' attribute.
//
// fBlockSet
// The value set of the 'block' attribute.
//
// fMiscFlags
// Stores 'abstract/nullable' values
//
// fDefaultValue
// The default/fixed value
//
// fComplexTypeInfo
// Stores complex type information
// (no need to delete - handled by schema grammar)
//
// fAttDefs
// The list of attributes that are faulted in for this element
// when ComplexTypeInfo does not exist. We want to keep track
// of these faulted in attributes to avoid duplicate redundant
// error.
//
// fIdentityConstraints
// Store information about an element identity constraints.
//
// fAttWildCard
// Store wildcard attribute in the case of an element with a type of
// 'anyType'.
//
// fSubstitutionGroupElem
// The substitution group element declaration.
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
ModelTypes fModelType;
PSVIDefs::PSVIScope fPSVIScope;
unsigned int fEnclosingScope;
int fFinalSet;
int fBlockSet;
int fMiscFlags;
XMLCh* fDefaultValue;
ComplexTypeInfo* fComplexTypeInfo;
RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
RefVectorOf<IdentityConstraint>* fIdentityConstraints;
SchemaAttDef* fAttWildCard;
SchemaElementDecl* fSubstitutionGroupElem;
DatatypeValidator* fDatatypeValidator;
};
// ---------------------------------------------------------------------------
// SchemaElementDecl: XMLElementDecl virtual interface implementation
// ---------------------------------------------------------------------------
inline ContentSpecNode* SchemaElementDecl::getContentSpec()
{
if (fComplexTypeInfo != 0) {
return fComplexTypeInfo->getContentSpec();
}
return 0;
}
inline const ContentSpecNode* SchemaElementDecl::getContentSpec() const
{
if (fComplexTypeInfo != 0) {
return fComplexTypeInfo->getContentSpec();
}
return 0;
}
inline void
SchemaElementDecl::setContentSpec(ContentSpecNode*)
{
//Handled by complexType
}
inline XMLContentModel* SchemaElementDecl::getContentModel()
{
if (fComplexTypeInfo != 0) {
return fComplexTypeInfo->getContentModel();
}
return 0;
}
inline void
SchemaElementDecl::setContentModel(XMLContentModel* const)
{
//Handled by complexType
}
// ---------------------------------------------------------------------------
// SchemaElementDecl: Getter methods
// ---------------------------------------------------------------------------
inline SchemaElementDecl::ModelTypes SchemaElementDecl::getModelType() const
{
if (fComplexTypeInfo) {
return (SchemaElementDecl::ModelTypes) fComplexTypeInfo->getContentType();
}
return fModelType;
}
inline PSVIDefs::PSVIScope SchemaElementDecl::getPSVIScope() const
{
return fPSVIScope;
}
inline DatatypeValidator* SchemaElementDecl::getDatatypeValidator() const
{
return fDatatypeValidator;
}
inline unsigned int SchemaElementDecl::getEnclosingScope() const
{
return fEnclosingScope;
}
inline int SchemaElementDecl::getFinalSet() const
{
return fFinalSet;
}
inline int SchemaElementDecl::getBlockSet() const
{
return fBlockSet;
}
inline int SchemaElementDecl::getMiscFlags() const
{
return fMiscFlags;
}
inline XMLCh* SchemaElementDecl::getDefaultValue() const
{
return fDefaultValue;
}
inline ComplexTypeInfo* SchemaElementDecl::getComplexTypeInfo() const
{
return fComplexTypeInfo;
}
inline const SchemaAttDef* SchemaElementDecl::getAttWildCard() const {
return fAttWildCard;
}
inline SchemaAttDef* SchemaElementDecl::getAttWildCard() {
return fAttWildCard;
}
inline bool SchemaElementDecl::isGlobalDecl() const {
return (fEnclosingScope == Grammar::TOP_LEVEL_SCOPE);
}
inline SchemaElementDecl*
SchemaElementDecl::getSubstitutionGroupElem() const {
return fSubstitutionGroupElem;
}
// ---------------------------------------------------------------------------
// SchemaElementDecl: Setter methods
// ---------------------------------------------------------------------------
inline void
SchemaElementDecl::setModelType(const SchemaElementDecl::ModelTypes toSet)
{
fModelType = toSet;
}
inline void
SchemaElementDecl::setPSVIScope(const PSVIDefs::PSVIScope toSet)
{
fPSVIScope = toSet;
}
inline void SchemaElementDecl::setDatatypeValidator(DatatypeValidator* newDatatypeValidator)
{
fDatatypeValidator = newDatatypeValidator;
}
inline void SchemaElementDecl::setEnclosingScope(const unsigned int newEnclosingScope)
{
fEnclosingScope = newEnclosingScope;
}
inline void SchemaElementDecl::setFinalSet(const int finalSet)
{
fFinalSet = finalSet;
}
inline void SchemaElementDecl::setBlockSet(const int blockSet)
{
fBlockSet = blockSet;
}
inline void SchemaElementDecl::setMiscFlags(const int flags)
{
fMiscFlags = flags;
}
inline void SchemaElementDecl::setDefaultValue(const XMLCh* const value)
{
if (fDefaultValue) {
getMemoryManager()->deallocate(fDefaultValue);//delete[] fDefaultValue;
}
fDefaultValue = XMLString::replicate(value, getMemoryManager());
}
inline void
SchemaElementDecl::setComplexTypeInfo(ComplexTypeInfo* const typeInfo)
{
fComplexTypeInfo = typeInfo;
}
inline void
SchemaElementDecl::setAttWildCard(SchemaAttDef* const attWildCard) {
if (fAttWildCard)
delete fAttWildCard;
fAttWildCard = attWildCard;
}
inline void
SchemaElementDecl::setSubstitutionGroupElem(SchemaElementDecl* const elemDecl) {
fSubstitutionGroupElem = elemDecl;
}
// ---------------------------------------------------------------------------
// SchemaElementDecl: IC methods
// ---------------------------------------------------------------------------
inline void
SchemaElementDecl::addIdentityConstraint(IdentityConstraint* const ic) {
if (!fIdentityConstraints) {
fIdentityConstraints = new (getMemoryManager()) RefVectorOf<IdentityConstraint>(16, true, getMemoryManager());
}
fIdentityConstraints->addElement(ic);
}
inline XMLSize_t SchemaElementDecl::getIdentityConstraintCount() const {
if (fIdentityConstraints) {
return fIdentityConstraints->size();
}
return 0;
}
inline IdentityConstraint*
SchemaElementDecl::getIdentityConstraintAt(XMLSize_t index) const {
if (fIdentityConstraints) {
return fIdentityConstraints->elementAt(index);
}
return 0;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,369 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaGrammar.cpp 883376 2009-11-23 15:45:23Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/SchemaGrammar.hpp>
#include <xercesc/validators/schema/ComplexTypeInfo.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp>
#include <xercesc/validators/schema/XercesGroupInfo.hpp>
#include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
#include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/framework/psvi/XSAnnotation.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
#include <xercesc/internal/ValidationContextImpl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
typedef JanitorMemFunCall<SchemaGrammar> CleanupType;
// ---------------------------------------------------------------------------
// SchemaGrammar: Constructors and Destructor
// ---------------------------------------------------------------------------
SchemaGrammar::SchemaGrammar(MemoryManager* const manager) :
fTargetNamespace(0)
, fElemDeclPool(0)
, fElemNonDeclPool(0)
, fGroupElemDeclPool(0)
, fNotationDeclPool(0)
, fAttributeDeclRegistry(0)
, fComplexTypeRegistry(0)
, fGroupInfoRegistry(0)
, fAttGroupInfoRegistry(0)
, fValidSubstitutionGroups(0)
, fValidationContext(0)
, fMemoryManager(manager)
, fGramDesc(0)
, fAnnotations(0)
, fValidated(false)
, fDatatypeRegistry(manager)
, fScopeCount (0)
, fAnonTypeCount (0)
{
CleanupType cleanup(this, &SchemaGrammar::cleanUp);
//
// Init all the pool members.
//
// <TBD> Investigate what the optimum values would be for the various
// pools.
//
fElemDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(109, true, 128, fMemoryManager);
try {
// should not be necessary now that grammars, once built,
// are read-only
// fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager);
fGroupElemDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(109, false, 128, fMemoryManager);
fNotationDeclPool = new (fMemoryManager) NameIdPool<XMLNotationDecl>(109, 128, fMemoryManager);
fValidationContext = new (fMemoryManager) ValidationContextImpl(fMemoryManager);
//REVISIT: use grammarPool to create
fGramDesc = new (fMemoryManager) XMLSchemaDescriptionImpl(XMLUni::fgXMLNSURIName, fMemoryManager);
// Create annotation table
fAnnotations = new (fMemoryManager) RefHashTableOf<XSAnnotation, PtrHasher>
(
29, true, fMemoryManager
);
//
// Call our own reset method. This lets us have the pool setup stuff
// done in just one place (because this stame setup stuff has to be
// done every time we are reset.)
//
reset();
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
SchemaGrammar::~SchemaGrammar()
{
cleanUp();
}
// -----------------------------------------------------------------------
// Virtual methods
// -----------------------------------------------------------------------
XMLElementDecl* SchemaGrammar::findOrAddElemDecl (const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const prefixName
, const XMLCh* const qName
, unsigned int scope
, bool& wasAdded )
{
// See it it exists
SchemaElementDecl* retVal = (SchemaElementDecl*) getElemDecl(uriId, baseName, qName, scope);
// if not, then add this in
if (!retVal)
{
retVal = new (fMemoryManager) SchemaElementDecl
(
prefixName
, baseName
, uriId
, SchemaElementDecl::Any
, Grammar::TOP_LEVEL_SCOPE
, fMemoryManager
);
if(!fElemNonDeclPool)
fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager);
const XMLSize_t elemId = fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal);
retVal->setId(elemId);
wasAdded = true;
}
else
{
wasAdded = false;
}
return retVal;
}
XMLElementDecl* SchemaGrammar::putElemDecl (const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const prefixName
, const XMLCh* const
, unsigned int scope
, const bool notDeclared)
{
SchemaElementDecl* retVal = new (fMemoryManager) SchemaElementDecl
(
prefixName
, baseName
, uriId
, SchemaElementDecl::Any
, Grammar::TOP_LEVEL_SCOPE
, fMemoryManager
);
if(notDeclared)
{
if(!fElemNonDeclPool)
fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager);
retVal->setId(fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal));
} else
{
retVal->setId(fElemDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal));
}
return retVal;
}
void SchemaGrammar::reset()
{
//
// We need to reset all of the pools.
//
fElemDeclPool->removeAll();
if(fElemNonDeclPool)
fElemNonDeclPool->removeAll();
fGroupElemDeclPool->removeAll();
fNotationDeclPool->removeAll();
fAnnotations->removeAll();
fValidated = false;
}
void SchemaGrammar::cleanUp()
{
delete fElemDeclPool;
if(fElemNonDeclPool)
delete fElemNonDeclPool;
delete fGroupElemDeclPool;
delete fNotationDeclPool;
fMemoryManager->deallocate(fTargetNamespace);//delete [] fTargetNamespace;
delete fAttributeDeclRegistry;
delete fComplexTypeRegistry;
delete fGroupInfoRegistry;
delete fAttGroupInfoRegistry;
delete fValidSubstitutionGroups;
delete fValidationContext;
delete fGramDesc;
delete fAnnotations;
}
void SchemaGrammar::setGrammarDescription(XMLGrammarDescription* gramDesc)
{
if ((!gramDesc) ||
(gramDesc->getGrammarType() != Grammar::SchemaGrammarType))
return;
if (fGramDesc)
delete fGramDesc;
//adopt the grammar Description
fGramDesc = (XMLSchemaDescription*) gramDesc;
}
// ---------------------------------------------------------------------------
// SchemaGrammar: Helper methods
// ---------------------------------------------------------------------------
void SchemaGrammar::putAnnotation(void* key, XSAnnotation* const annotation)
{
fAnnotations->put(key, annotation);
}
void SchemaGrammar::addAnnotation(XSAnnotation* const annotation)
{
XSAnnotation* lAnnot = fAnnotations->get(this);
if (lAnnot)
lAnnot->setNext(annotation);
else
fAnnotations->put(this, annotation);
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(SchemaGrammar)
void SchemaGrammar::serialize(XSerializeEngine& serEng)
{
/***
* don't serialize ValidationContext* fValidationContext;
* fElemNonDeclPool
***/
Grammar::serialize(serEng);
if (serEng.isStoring())
{
//serialize DatatypeValidatorFactory first
fDatatypeRegistry.serialize(serEng);
/***
*
* Serialize RefHash3KeysIdPool<SchemaElementDecl>* fElemDeclPool;
* Serialize RefHash3KeysIdPool<SchemaElementDecl>* fGroupElemDeclPool;
*
***/
XTemplateSerializer::storeObject(fElemDeclPool, serEng);
XTemplateSerializer::storeObject(fGroupElemDeclPool, serEng);
/***
* Serialize NameIdPool<XMLNotationDecl>* fNotationDeclPool;
***/
XTemplateSerializer::storeObject(fNotationDeclPool, serEng);
/***
*
* Serialize RefHashTableOf<XMLAttDef>* fAttributeDeclRegistry;
* Serialize RefHashTableOf<ComplexTypeInfo>* fComplexTypeRegistry;
* Serialize RefHashTableOf<XercesGroupInfo>* fGroupInfoRegistry;
* Serialize RefHashTableOf<XercesAttGroupInfo>* fAttGroupInfoRegistry;
* Serialize RefHashTableOf<XMLRefInfo>* fIDRefList;
*
***/
XTemplateSerializer::storeObject(fAttributeDeclRegistry, serEng);
XTemplateSerializer::storeObject(fComplexTypeRegistry, serEng);
XTemplateSerializer::storeObject(fGroupInfoRegistry, serEng);
XTemplateSerializer::storeObject(fAttGroupInfoRegistry, serEng);
/***
* Serialize RefHash2KeysTableOf<ElemVector>* fValidSubstitutionGroups;
***/
XTemplateSerializer::storeObject(fValidSubstitutionGroups, serEng);
/***
* Serialize RefHashTableOf<XSAnnotation>* fAnnotations;
***/
XTemplateSerializer::storeObject(fAnnotations, serEng);
serEng.writeString(fTargetNamespace);
serEng<<fValidated;
/***
* serialize() method shall be used to store object
* which has been created in ctor
***/
fGramDesc->serialize(serEng);
}
else
{
fDatatypeRegistry.serialize(serEng);
/***
*
* Deserialize RefHash3KeysIdPool<SchemaElementDecl>* fElemDeclPool;
* Deserialize RefHash3KeysIdPool<SchemaElementDecl>* fGroupElemDeclPool;
*
***/
XTemplateSerializer::loadObject(&fElemDeclPool, 109, true, 128, serEng);
XTemplateSerializer::loadObject(&fGroupElemDeclPool, 109, true, 128, serEng);
/***
* Deserialize NameIdPool<XMLNotationDecl>* fNotationDeclPool;
***/
XTemplateSerializer::loadObject(&fNotationDeclPool, 109, 128, serEng);
/***
*
* Deserialize RefHashTableOf<XMLAttDef>* fAttributeDeclRegistry;
* Deserialize RefHashTableOf<ComplexTypeInfo>* fComplexTypeRegistry;
* Deserialize RefHashTableOf<XercesGroupInfo>* fGroupInfoRegistry;
* Deserialize RefHashTableOf<XercesAttGroupInfo>* fAttGroupInfoRegistry;
* Deserialize RefHashTableOf<XMLRefInfo>* fIDRefList;
*
***/
XTemplateSerializer::loadObject(&fAttributeDeclRegistry, 29, true, serEng);
XTemplateSerializer::loadObject(&fComplexTypeRegistry, 29, true, serEng);
XTemplateSerializer::loadObject(&fGroupInfoRegistry, 13, true, serEng);
XTemplateSerializer::loadObject(&fAttGroupInfoRegistry, 13, true, serEng);
/***
* Deserialize RefHash2KeysTableOf<ElemVector>* fValidSubstitutionGroups;
***/
XTemplateSerializer::loadObject(&fValidSubstitutionGroups, 29, true, serEng);
/***
* Deserialize RefHashTableOf<XSAnnotation>* fAnnotations;
***/
XTemplateSerializer::loadObject(&fAnnotations, 29, true, serEng);
serEng.readString(fTargetNamespace);
serEng>>fValidated;
/***
* serialize() method shall be used to load object
* which has been created in ctor
***/
fGramDesc->serialize(serEng);
}
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,638 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaGrammar.hpp 883376 2009-11-23 15:45:23Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SCHEMAGRAMMAR_HPP)
#define XERCESC_INCLUDE_GUARD_SCHEMAGRAMMAR_HPP
#include <xercesc/framework/XMLNotationDecl.hpp>
#include <xercesc/util/RefHash3KeysIdPool.hpp>
#include <xercesc/util/NameIdPool.hpp>
#include <xercesc/util/StringPool.hpp>
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
#include <xercesc/util/ValueVectorOf.hpp>
#include <xercesc/validators/datatype/IDDatatypeValidator.hpp>
#include <xercesc/validators/datatype/DatatypeValidatorFactory.hpp>
#include <xercesc/framework/XMLSchemaDescription.hpp>
#include <xercesc/framework/ValidationContext.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This class stores the Schema information
// NOTE: Schemas are not namespace aware, so we just use regular NameIdPool
// data structures to store element and attribute decls. They are all set
// to be in the global namespace and the full QName is used as the base name
// of the decl. This means that all the URI parameters below are expected
// to be null pointers (and anything else will cause an exception.)
//
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class ComplexTypeInfo;
class XercesGroupInfo;
class XercesAttGroupInfo;
class XSAnnotation;
// ---------------------------------------------------------------------------
// typedef declaration
// ---------------------------------------------------------------------------
typedef ValueVectorOf<SchemaElementDecl*> ElemVector;
class VALIDATORS_EXPORT SchemaGrammar : public Grammar
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
SchemaGrammar(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
virtual ~SchemaGrammar();
// -----------------------------------------------------------------------
// Implementation of Virtual Interface
// -----------------------------------------------------------------------
virtual Grammar::GrammarType getGrammarType() const;
virtual const XMLCh* getTargetNamespace() const;
// this method should only be used while the grammar is being
// constructed, not while it is being used
// in a validation episode!
virtual XMLElementDecl* findOrAddElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const prefixName
, const XMLCh* const qName
, unsigned int scope
, bool& wasAdded
) ;
virtual XMLSize_t getElemId
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const qName
, unsigned int scope
) const ;
virtual const XMLElementDecl* getElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const qName
, unsigned int scope
) const ;
virtual XMLElementDecl* getElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const qName
, unsigned int scope
);
virtual const XMLElementDecl* getElemDecl
(
const unsigned int elemId
) const;
virtual XMLElementDecl* getElemDecl
(
const unsigned int elemId
);
virtual const XMLNotationDecl* getNotationDecl
(
const XMLCh* const notName
) const;
virtual XMLNotationDecl* getNotationDecl
(
const XMLCh* const notName
);
virtual bool getValidated() const;
virtual XMLElementDecl* putElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const prefixName
, const XMLCh* const qName
, unsigned int scope
, const bool notDeclared = false
);
virtual XMLSize_t putElemDecl
(
XMLElementDecl* const elemDecl
, const bool notDeclared = false
) ;
virtual XMLSize_t putNotationDecl
(
XMLNotationDecl* const notationDecl
) const;
virtual void setValidated(const bool newState);
virtual void reset();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
RefHash3KeysIdPoolEnumerator<SchemaElementDecl> getElemEnumerator() const;
NameIdPoolEnumerator<XMLNotationDecl> getNotationEnumerator() const;
RefHashTableOf<XMLAttDef>* getAttributeDeclRegistry() const;
RefHashTableOf<ComplexTypeInfo>* getComplexTypeRegistry() const;
RefHashTableOf<XercesGroupInfo>* getGroupInfoRegistry() const;
RefHashTableOf<XercesAttGroupInfo>* getAttGroupInfoRegistry() const;
DatatypeValidatorFactory* getDatatypeRegistry();
RefHash2KeysTableOf<ElemVector>* getValidSubstitutionGroups() const;
// @deprecated
ValidationContext* getValidationContext() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setTargetNamespace(const XMLCh* const targetNamespace);
void setAttributeDeclRegistry(RefHashTableOf<XMLAttDef>* const attReg);
void setComplexTypeRegistry(RefHashTableOf<ComplexTypeInfo>* const other);
void setGroupInfoRegistry(RefHashTableOf<XercesGroupInfo>* const other);
void setAttGroupInfoRegistry(RefHashTableOf<XercesAttGroupInfo>* const other);
void setValidSubstitutionGroups(RefHash2KeysTableOf<ElemVector>* const);
virtual void setGrammarDescription( XMLGrammarDescription*);
virtual XMLGrammarDescription* getGrammarDescription() const;
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
XMLSize_t putGroupElemDecl
(
XMLElementDecl* const elemDecl
) const;
// -----------------------------------------------------------------------
// Annotation management methods
// -----------------------------------------------------------------------
/**
* Add annotation to the list of annotations for a given key
*/
void putAnnotation(void* key, XSAnnotation* const annotation);
/**
* Add global annotation
*
* Note: XSAnnotation acts as a linked list
*/
void addAnnotation(XSAnnotation* const annotation);
/**
* Retrieve the annotation that is associated with the specified key
*
* @param key represents a schema component object (i.e. SchemaGrammar)
* @return XSAnnotation associated with the key object
*/
XSAnnotation* getAnnotation(const void* const key);
/**
* Retrieve the annotation that is associated with the specified key
*
* @param key represents a schema component object (i.e. SchemaGrammar)
* @return XSAnnotation associated with the key object
*/
const XSAnnotation* getAnnotation(const void* const key) const;
/**
* Get global annotation
*/
XSAnnotation* getAnnotation();
const XSAnnotation* getAnnotation() const;
/**
* Get annotation hash table, to enumerate through them
*/
RefHashTableOf<XSAnnotation, PtrHasher>* getAnnotations();
const RefHashTableOf<XSAnnotation, PtrHasher>* getAnnotations() const;
/**
* Get/set scope count.
*/
unsigned int getScopeCount () const;
void setScopeCount (unsigned int);
/**
* Get/set anonymous type count.
*/
unsigned int getAnonTypeCount () const;
void setAnonTypeCount (unsigned int);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(SchemaGrammar)
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SchemaGrammar(const SchemaGrammar&);
SchemaGrammar& operator=(const SchemaGrammar&);
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void cleanUp();
// -----------------------------------------------------------------------
// Private data members
//
// fElemDeclPool
// This is the element decl pool. It contains all of the elements
// declared in the Schema (and their associated attributes.)
//
// fElemNonDeclPool
// This is the element decl pool that is is populated as new elements
// are seen in the XML document (not declared in the Schema), and they
// are given default characteristics.
//
// fGroupElemDeclPool
// This is the element decl pool for elements in a group that are
// referenced in different scope. It contains all of the elements
// declared in the Schema (and their associated attributes.)
//
// fNotationDeclPool
// This is a pool of NotationDecl objects, which contains all of the
// notations declared in the Schema.
//
// fTargetNamespace
// Target name space for this grammar.
//
// fAttributeDeclRegistry
// Global attribute declarations
//
// fComplexTypeRegistry
// Stores complexType declaration info
//
// fGroupInfoRegistry
// Stores global <group> declaration info
//
// fAttGroupInfoRegistry
// Stores global <attributeGroup> declaration info
//
// fDatatypeRegistry
// Datatype validator factory
//
// fValidSubstitutionGroups
// Valid list of elements that can substitute a given element
//
// fIDRefList
// List of ids of schema declarations extracted during schema grammar
// traversal
//
// fValidated
// Indicates if the content of the Grammar has been pre-validated
// or not (UPA checking, etc.). When using a cached grammar, no need
// for pre content validation.
//
// fGramDesc: adopted
//
// -----------------------------------------------------------------------
XMLCh* fTargetNamespace;
RefHash3KeysIdPool<SchemaElementDecl>* fElemDeclPool;
RefHash3KeysIdPool<SchemaElementDecl>* fElemNonDeclPool;
RefHash3KeysIdPool<SchemaElementDecl>* fGroupElemDeclPool;
NameIdPool<XMLNotationDecl>* fNotationDeclPool;
RefHashTableOf<XMLAttDef>* fAttributeDeclRegistry;
RefHashTableOf<ComplexTypeInfo>* fComplexTypeRegistry;
RefHashTableOf<XercesGroupInfo>* fGroupInfoRegistry;
RefHashTableOf<XercesAttGroupInfo>* fAttGroupInfoRegistry;
RefHash2KeysTableOf<ElemVector>* fValidSubstitutionGroups;
// @deprecated
ValidationContext* fValidationContext;
MemoryManager* fMemoryManager;
XMLSchemaDescription* fGramDesc;
RefHashTableOf<XSAnnotation, PtrHasher>* fAnnotations;
bool fValidated;
DatatypeValidatorFactory fDatatypeRegistry;
unsigned int fScopeCount;
unsigned int fAnonTypeCount;
};
// ---------------------------------------------------------------------------
// SchemaGrammar: Getter methods
// ---------------------------------------------------------------------------
inline RefHash3KeysIdPoolEnumerator<SchemaElementDecl>
SchemaGrammar::getElemEnumerator() const
{
return RefHash3KeysIdPoolEnumerator<SchemaElementDecl>(fElemDeclPool, false, fMemoryManager);
}
inline NameIdPoolEnumerator<XMLNotationDecl>
SchemaGrammar::getNotationEnumerator() const
{
return NameIdPoolEnumerator<XMLNotationDecl>(fNotationDeclPool, fMemoryManager);
}
inline RefHashTableOf<XMLAttDef>* SchemaGrammar::getAttributeDeclRegistry() const {
return fAttributeDeclRegistry;
}
inline RefHashTableOf<ComplexTypeInfo>*
SchemaGrammar::getComplexTypeRegistry() const {
return fComplexTypeRegistry;
}
inline RefHashTableOf<XercesGroupInfo>*
SchemaGrammar::getGroupInfoRegistry() const {
return fGroupInfoRegistry;
}
inline RefHashTableOf<XercesAttGroupInfo>*
SchemaGrammar::getAttGroupInfoRegistry() const {
return fAttGroupInfoRegistry;
}
inline DatatypeValidatorFactory* SchemaGrammar::getDatatypeRegistry() {
return &fDatatypeRegistry;
}
inline RefHash2KeysTableOf<ElemVector>*
SchemaGrammar::getValidSubstitutionGroups() const {
return fValidSubstitutionGroups;
}
// @deprecated
inline ValidationContext* SchemaGrammar::getValidationContext() const {
return fValidationContext;
}
inline XMLGrammarDescription* SchemaGrammar::getGrammarDescription() const
{
return fGramDesc;
}
inline XSAnnotation* SchemaGrammar::getAnnotation(const void* const key)
{
return fAnnotations->get(key);
}
inline const XSAnnotation* SchemaGrammar::getAnnotation(const void* const key) const
{
return fAnnotations->get(key);
}
inline XSAnnotation* SchemaGrammar::getAnnotation()
{
return fAnnotations->get(this);
}
inline const XSAnnotation* SchemaGrammar::getAnnotation() const
{
return fAnnotations->get(this);
}
inline RefHashTableOf<XSAnnotation, PtrHasher>* SchemaGrammar::getAnnotations()
{
return fAnnotations;
}
inline const RefHashTableOf<XSAnnotation, PtrHasher>* SchemaGrammar::getAnnotations() const
{
return fAnnotations;
}
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
inline void SchemaGrammar::setTargetNamespace(const XMLCh* const targetNamespace)
{
if (fTargetNamespace)
fMemoryManager->deallocate(fTargetNamespace);//delete [] fTargetNamespace;
fTargetNamespace = XMLString::replicate(targetNamespace, fMemoryManager);
}
inline void
SchemaGrammar::setAttributeDeclRegistry(RefHashTableOf<XMLAttDef>* const attReg) {
fAttributeDeclRegistry = attReg;
}
inline void
SchemaGrammar::setComplexTypeRegistry(RefHashTableOf<ComplexTypeInfo>* const other) {
fComplexTypeRegistry = other;
}
inline void
SchemaGrammar::setGroupInfoRegistry(RefHashTableOf<XercesGroupInfo>* const other) {
fGroupInfoRegistry = other;
}
inline void
SchemaGrammar::setAttGroupInfoRegistry(RefHashTableOf<XercesAttGroupInfo>* const other) {
fAttGroupInfoRegistry = other;
}
inline void
SchemaGrammar::setValidSubstitutionGroups(RefHash2KeysTableOf<ElemVector>* const other) {
fValidSubstitutionGroups = other;
}
// ---------------------------------------------------------------------------
// SchemaGrammar: Virtual methods
// ---------------------------------------------------------------------------
inline Grammar::GrammarType SchemaGrammar::getGrammarType() const {
return Grammar::SchemaGrammarType;
}
inline const XMLCh* SchemaGrammar::getTargetNamespace() const {
return fTargetNamespace;
}
// Element Decl
inline XMLSize_t SchemaGrammar::getElemId (const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const
, unsigned int scope ) const
{
//
// In this case, we don't return zero to mean 'not found', so we have to
// map it to the official not found value if we don't find it.
//
const SchemaElementDecl* decl = fElemDeclPool->getByKey(baseName, uriId, scope);
if (!decl) {
decl = fGroupElemDeclPool->getByKey(baseName, uriId, scope);
if (!decl)
return XMLElementDecl::fgInvalidElemId;
}
return decl->getId();
}
inline const XMLElementDecl* SchemaGrammar::getElemDecl( const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const
, unsigned int scope ) const
{
const SchemaElementDecl* decl = fElemDeclPool->getByKey(baseName, uriId, scope);
if (!decl) {
decl = fGroupElemDeclPool->getByKey(baseName, uriId, scope);
if (!decl && fElemNonDeclPool)
decl = fElemNonDeclPool->getByKey(baseName, uriId, scope);
}
return decl;
}
inline XMLElementDecl* SchemaGrammar::getElemDecl (const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const
, unsigned int scope )
{
SchemaElementDecl* decl = fElemDeclPool->getByKey(baseName, uriId, scope);
if (!decl) {
decl = fGroupElemDeclPool->getByKey(baseName, uriId, scope);
if (!decl && fElemNonDeclPool)
decl = fElemNonDeclPool->getByKey(baseName, uriId, scope);
}
return decl;
}
inline const XMLElementDecl* SchemaGrammar::getElemDecl(const unsigned int elemId) const
{
// Look up this element decl by id
const SchemaElementDecl* decl = fElemDeclPool->getById(elemId);
if (!decl)
decl = fGroupElemDeclPool->getById(elemId);
return decl;
}
inline XMLElementDecl* SchemaGrammar::getElemDecl(const unsigned int elemId)
{
// Look up this element decl by id
SchemaElementDecl* decl = fElemDeclPool->getById(elemId);
if (!decl)
decl = fGroupElemDeclPool->getById(elemId);
return decl;
}
inline XMLSize_t
SchemaGrammar::putElemDecl(XMLElementDecl* const elemDecl,
const bool notDeclared)
{
if (notDeclared)
{
if(!fElemNonDeclPool)
fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager);
return fElemNonDeclPool->put(elemDecl->getBaseName(), elemDecl->getURI(), ((SchemaElementDecl* )elemDecl)->getEnclosingScope(), (SchemaElementDecl*) elemDecl);
}
return fElemDeclPool->put(elemDecl->getBaseName(), elemDecl->getURI(), ((SchemaElementDecl* )elemDecl)->getEnclosingScope(), (SchemaElementDecl*) elemDecl);
}
inline XMLSize_t SchemaGrammar::putGroupElemDecl (XMLElementDecl* const elemDecl) const
{
return fGroupElemDeclPool->put(elemDecl->getBaseName(), elemDecl->getURI(), ((SchemaElementDecl* )elemDecl)->getEnclosingScope(), (SchemaElementDecl*) elemDecl);
}
// Notation Decl
inline const XMLNotationDecl* SchemaGrammar::getNotationDecl(const XMLCh* const notName) const
{
return fNotationDeclPool->getByKey(notName);
}
inline XMLNotationDecl* SchemaGrammar::getNotationDecl(const XMLCh* const notName)
{
return fNotationDeclPool->getByKey(notName);
}
inline XMLSize_t SchemaGrammar::putNotationDecl(XMLNotationDecl* const notationDecl) const
{
return fNotationDeclPool->put(notationDecl);
}
inline bool SchemaGrammar::getValidated() const
{
return fValidated;
}
inline void SchemaGrammar::setValidated(const bool newState)
{
fValidated = newState;
}
inline unsigned int
SchemaGrammar::getScopeCount () const
{
return fScopeCount;
}
inline void
SchemaGrammar::setScopeCount (unsigned int scopeCount)
{
fScopeCount = scopeCount;
}
inline unsigned int
SchemaGrammar::getAnonTypeCount () const
{
return fAnonTypeCount;
}
inline void
SchemaGrammar::setAnonTypeCount (unsigned int count)
{
fAnonTypeCount = count;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,251 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaInfo.cpp 925236 2010-03-19 14:29:47Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/SchemaInfo.hpp>
#include <xercesc/validators/schema/XUtil.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp>
#include <xercesc/validators/schema/NamespaceScope.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/internal/ValidationContextImpl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// SchemaInfo: Constructors and Destructor
// ---------------------------------------------------------------------------
SchemaInfo::SchemaInfo(const unsigned short elemAttrDefaultQualified,
const int blockDefault,
const int finalDefault,
const int targetNSURI,
const NamespaceScope* const currNamespaceScope,
const XMLCh* const schemaURL,
const XMLCh* const targetNSURIString,
const DOMElement* const root,
XMLScanner* xmlScanner,
MemoryManager* const manager)
: fAdoptInclude(false)
, fProcessed(false)
, fElemAttrDefaultQualified(elemAttrDefaultQualified)
, fBlockDefault(blockDefault)
, fFinalDefault(finalDefault)
, fTargetNSURI(targetNSURI)
, fNamespaceScope(0)
, fSchemaRootElement(root)
, fIncludeInfoList(0)
, fImportedInfoList(0)
, fImportingInfoList(0)
, fFailedRedefineList(0)
, fRecursingAnonTypes(0)
, fRecursingTypeNames(0)
, fNonXSAttList(0)
, fValidationContext(0)
, fMemoryManager(manager)
{
fImportingInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(4, false, fMemoryManager);
memset(
fTopLevelComponents,
0,
sizeof(fTopLevelComponents[0]) * C_Count);
memset(
fLastTopLevelComponent,
0,
sizeof(fLastTopLevelComponent[0]) * C_Count);
fNonXSAttList = new (fMemoryManager) ValueVectorOf<DOMNode*>(2, fMemoryManager);
fValidationContext = new (fMemoryManager) ValidationContextImpl(fMemoryManager);
fNamespaceScope = new (fMemoryManager) NamespaceScope(currNamespaceScope, fMemoryManager);
fCurrentSchemaURL = XMLString::replicate(schemaURL, fMemoryManager);
fTargetNSURIString = XMLString::replicate(targetNSURIString, fMemoryManager);
fValidationContext->setScanner (xmlScanner);
fValidationContext->setNamespaceScope(fNamespaceScope);
}
SchemaInfo::~SchemaInfo()
{
fMemoryManager->deallocate(fCurrentSchemaURL);//delete [] fCurrentSchemaURL;
fMemoryManager->deallocate(fTargetNSURIString);
delete fImportedInfoList;
if (fAdoptInclude)
delete fIncludeInfoList;
delete fImportingInfoList;
delete fFailedRedefineList;
delete fRecursingAnonTypes;
delete fRecursingTypeNames;
for (unsigned int i = 0; i < C_Count; i++) {
delete fTopLevelComponents[i];
}
delete fNonXSAttList;
delete fValidationContext;
delete fNamespaceScope;
}
// ---------------------------------------------------------------------------
// SchemaInfo:
// ---------------------------------------------------------------------------
DOMElement*
SchemaInfo::getTopLevelComponent(const unsigned short compCategory,
const XMLCh* const compName,
const XMLCh* const name,
SchemaInfo** enclosingSchema) {
if (fSchemaRootElement == 0)
return 0;
SchemaInfo* currentInfo = this;
DOMElement* child = getTopLevelComponent(compCategory, compName, name);
if (child == 0) {
XMLSize_t listSize = (fIncludeInfoList) ? fIncludeInfoList->size() : 0;
for (XMLSize_t i=0; i < listSize; i++) {
currentInfo = fIncludeInfoList->elementAt(i);
if (currentInfo == this)
continue;
child = currentInfo->getTopLevelComponent(compCategory, compName, name);
if (child != 0) {
*enclosingSchema = currentInfo;
break;
}
}
}
return child;
}
DOMElement*
SchemaInfo::getTopLevelComponent(const unsigned short compCategory,
const XMLCh* const compName,
const XMLCh* const name) {
if (fSchemaRootElement == 0 || compCategory >= C_Count)
return 0;
DOMElement* child = XUtil::getFirstChildElement(fSchemaRootElement);
if (!child)
return 0;
RefHashTableOf<DOMElement>* compList = fTopLevelComponents[compCategory];
if (fTopLevelComponents[compCategory] == 0) {
compList= new (fMemoryManager) RefHashTableOf<DOMElement>(17, false, fMemoryManager);
fTopLevelComponents[compCategory] = compList;
}
else {
DOMElement* cachedChild = compList->get(name);
if(cachedChild)
return cachedChild;
child = fLastTopLevelComponent[compCategory];
}
DOMElement* redefParent = (DOMElement*) child->getParentNode();
// Parent is not "redefine"
if (!XMLString::equals(redefParent->getLocalName(),SchemaSymbols::fgELT_REDEFINE))
redefParent = 0;
while (child != 0) {
fLastTopLevelComponent[compCategory]=child;
if (XMLString::equals(child->getLocalName(), compName)) {
const XMLCh* cName=child->getAttribute(SchemaSymbols::fgATT_NAME);
compList->put((void*)cName, child);
if (XMLString::equals(cName, name))
return child;
}
else if (XMLString::equals(child->getLocalName(),SchemaSymbols::fgELT_REDEFINE)
&& (!fFailedRedefineList || !fFailedRedefineList->containsElement(child))) { // if redefine
DOMElement* redefineChild = XUtil::getFirstChildElement(child);
while (redefineChild != 0) {
fLastTopLevelComponent[compCategory]=redefineChild;
if ((!fFailedRedefineList || !fFailedRedefineList->containsElement(redefineChild))
&& XMLString::equals(redefineChild->getLocalName(), compName)) {
const XMLCh* rName=redefineChild->getAttribute(SchemaSymbols::fgATT_NAME);
compList->put((void*)rName, redefineChild);
if (XMLString::equals(rName, name))
return redefineChild;
}
redefineChild = XUtil::getNextSiblingElement(redefineChild);
}
}
child = XUtil::getNextSiblingElement(child);
if (child == 0 && redefParent) {
child = XUtil::getNextSiblingElement(redefParent);
redefParent = 0;
}
}
return child;
}
void SchemaInfo::updateImportingInfo(SchemaInfo* const importingInfo) {
if (!fImportingInfoList->containsElement(importingInfo)) {
fImportingInfoList->addElement(importingInfo);
}
XMLSize_t listSize = importingInfo->fImportingInfoList->size();
for (XMLSize_t i=0; i < listSize; i++) {
SchemaInfo* tmpInfo = importingInfo->fImportingInfoList->elementAt(i);
if (tmpInfo != this && !fImportingInfoList->containsElement(tmpInfo)) {
fImportingInfoList->addElement(tmpInfo);
}
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file SchemaInfo.cpp
*/
@@ -0,0 +1,432 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaInfo.hpp 925236 2010-03-19 14:29:47Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SCHEMAINFO_HPP)
#define XERCESC_INCLUDE_GUARD_SCHEMAINFO_HPP
/** When in a <redefine>, type definitions being used (and indeed
* refs to <group>'s and <attributeGroup>'s) may refer to info
* items either in the schema being redefined, in the <redefine>,
* or else in the schema doing the redefining. Because of this
* latter we have to be prepared sometimes to look for our type
* definitions outside the schema stored in fSchemaRootElement.
* This simple class does this; it's just a linked list that
* lets us look at the <schema>'s on the queue; note also that this
* should provide us with a mechanism to handle nested <redefine>'s.
* It's also a handy way of saving schema info when importing/including.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/util/ValueVectorOf.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class XMLScanner;
class ValidationContext;
class NamespaceScope;
class VALIDATORS_EXPORT SchemaInfo : public XMemory
{
public:
enum ListType {
// Redefine is treated as an include
IMPORT = 1,
INCLUDE = 2
};
enum {
C_ComplexType,
C_SimpleType,
C_Group,
C_Attribute,
C_AttributeGroup,
C_Element,
C_Notation,
C_Count
};
// -----------------------------------------------------------------------
// Constructor/Destructor
// -----------------------------------------------------------------------
SchemaInfo(const unsigned short fElemAttrDefaultQualified,
const int blockDefault,
const int finalDefault,
const int targetNSURI,
const NamespaceScope* const currNamespaceScope,
const XMLCh* const schemaURL,
const XMLCh* const targetNSURIString,
const DOMElement* const root,
XMLScanner* xmlScanner,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~SchemaInfo();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
XMLCh* getCurrentSchemaURL() const;
const XMLCh* getTargetNSURIString() const;
const DOMElement* getRoot() const;
bool getProcessed() const;
int getBlockDefault() const;
int getFinalDefault() const;
int getTargetNSURI() const;
NamespaceScope* getNamespaceScope() const;
unsigned short getElemAttrDefaultQualified() const;
BaseRefVectorEnumerator<SchemaInfo> getImportingListEnumerator() const;
ValueVectorOf<const DOMElement*>* getRecursingAnonTypes() const;
ValueVectorOf<const XMLCh*>* getRecursingTypeNames() const;
ValueVectorOf<DOMNode*>* getNonXSAttList() const;
ValidationContext* getValidationContext() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setProcessed(const bool aValue = true);
void setBlockDefault(const int aValue);
void setFinalDefault(const int aValue);
void setElemAttrDefaultQualified(const unsigned short aValue);
void resetRoot ();
// -----------------------------------------------------------------------
// Access methods
// -----------------------------------------------------------------------
void addSchemaInfo(SchemaInfo* const toAdd, const ListType aListType);
bool containsInfo(const SchemaInfo* const toCheck, const ListType aListType) const;
SchemaInfo* getImportInfo(const unsigned int namespaceURI) const;
DOMElement* getTopLevelComponent(const unsigned short compCategory,
const XMLCh* const compName,
const XMLCh* const name);
DOMElement* getTopLevelComponent(const unsigned short compCategory,
const XMLCh* const compName,
const XMLCh* const name,
SchemaInfo** enclosingSchema);
void updateImportingInfo(SchemaInfo* const importingInfo);
bool circularImportExist(const unsigned int nameSpaceURI);
bool isFailedRedefine(const DOMElement* const anElem);
void addFailedRedefine(const DOMElement* const anElem);
void addRecursingType(const DOMElement* const elem, const XMLCh* const name);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SchemaInfo(const SchemaInfo&);
SchemaInfo& operator=(const SchemaInfo&);
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void clearTopLevelComponents();
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
bool fAdoptInclude;
bool fProcessed;
unsigned short fElemAttrDefaultQualified;
int fBlockDefault;
int fFinalDefault;
int fTargetNSURI;
NamespaceScope* fNamespaceScope;
XMLCh* fCurrentSchemaURL;
XMLCh* fTargetNSURIString;
const DOMElement* fSchemaRootElement;
RefVectorOf<SchemaInfo>* fIncludeInfoList;
RefVectorOf<SchemaInfo>* fImportedInfoList;
RefVectorOf<SchemaInfo>* fImportingInfoList;
ValueVectorOf<const DOMElement*>* fFailedRedefineList;
ValueVectorOf<const DOMElement*>* fRecursingAnonTypes;
ValueVectorOf<const XMLCh*>* fRecursingTypeNames;
RefHashTableOf<DOMElement>* fTopLevelComponents[C_Count];
DOMElement* fLastTopLevelComponent[C_Count];
ValueVectorOf<DOMNode*>* fNonXSAttList;
ValidationContext* fValidationContext;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// SchemaInfo: Getter methods
// ---------------------------------------------------------------------------
inline unsigned short SchemaInfo::getElemAttrDefaultQualified() const {
return fElemAttrDefaultQualified;
}
inline bool SchemaInfo::getProcessed() const {
return fProcessed;
}
inline int SchemaInfo::getBlockDefault() const {
return fBlockDefault;
}
inline int SchemaInfo::getFinalDefault() const {
return fFinalDefault;
}
inline NamespaceScope* SchemaInfo::getNamespaceScope() const {
return fNamespaceScope;
}
inline XMLCh* SchemaInfo::getCurrentSchemaURL() const {
return fCurrentSchemaURL;
}
inline const XMLCh* SchemaInfo::getTargetNSURIString() const {
return fTargetNSURIString;
}
inline const DOMElement* SchemaInfo::getRoot() const {
return fSchemaRootElement;
}
inline int SchemaInfo::getTargetNSURI() const {
return fTargetNSURI;
}
inline BaseRefVectorEnumerator<SchemaInfo>
SchemaInfo::getImportingListEnumerator() const {
return BaseRefVectorEnumerator<SchemaInfo>(fImportingInfoList);
}
inline ValueVectorOf<const DOMElement*>*
SchemaInfo::getRecursingAnonTypes() const {
return fRecursingAnonTypes;
}
inline ValueVectorOf<const XMLCh*>*
SchemaInfo::getRecursingTypeNames() const {
return fRecursingTypeNames;
}
inline ValueVectorOf<DOMNode*>* SchemaInfo::getNonXSAttList() const
{
return fNonXSAttList;
}
// ---------------------------------------------------------------------------
// Setter methods
// ---------------------------------------------------------------------------
inline void SchemaInfo::setBlockDefault(const int aValue) {
fBlockDefault = aValue;
}
inline void SchemaInfo::setFinalDefault(const int aValue) {
fFinalDefault = aValue;
}
inline void SchemaInfo::setElemAttrDefaultQualified(const unsigned short aValue) {
fElemAttrDefaultQualified = aValue;
}
inline void SchemaInfo::setProcessed(const bool aValue) {
fProcessed = aValue;
/* if (fProcessed && fIncludeInfoList) {
unsigned int includeListLen = fIncludeInfoList->size());
for (unsigned int i = 0; i < includeListLen; i++) {
fIncludeInfoList->elementAt(i)->clearTopLevelComponents();
}
}*/
}
inline void SchemaInfo::resetRoot ()
{
fSchemaRootElement = 0;
}
// ---------------------------------------------------------------------------
// SchemaInfo: Access methods
// ---------------------------------------------------------------------------
inline void SchemaInfo::addSchemaInfo(SchemaInfo* const toAdd,
const ListType aListType) {
if (aListType == IMPORT) {
if (!fImportedInfoList)
fImportedInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(4, false, fMemoryManager);
if (!fImportedInfoList->containsElement(toAdd)) {
fImportedInfoList->addElement(toAdd);
toAdd->updateImportingInfo(this);
}
}
else {
if (!fIncludeInfoList) {
fIncludeInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(8, false, fMemoryManager);
fAdoptInclude = true;
}
if (!fIncludeInfoList->containsElement(toAdd)) {
fIncludeInfoList->addElement(toAdd);
//code was originally:
//toAdd->fIncludeInfoList = fIncludeInfoList;
//however for handling multiple imports this was causing
//to schemaInfo's to have the same fIncludeInfoList which they
//both owned so when it was deleted it crashed.
if (toAdd->fIncludeInfoList) {
if (toAdd->fIncludeInfoList != fIncludeInfoList) {
XMLSize_t size = toAdd->fIncludeInfoList->size();
for (XMLSize_t i=0; i<size; i++) {
if (!fIncludeInfoList->containsElement(toAdd->fIncludeInfoList->elementAt(i))) {
fIncludeInfoList->addElement(toAdd->fIncludeInfoList->elementAt(i));
}
}
size = fIncludeInfoList->size();
for (XMLSize_t j=0; j<size; j++) {
if (!toAdd->fIncludeInfoList->containsElement(fIncludeInfoList->elementAt(j))) {
toAdd->fIncludeInfoList->addElement(fIncludeInfoList->elementAt(j));
}
}
}
}
else {
toAdd->fIncludeInfoList = fIncludeInfoList;
}
}
}
}
inline SchemaInfo* SchemaInfo::getImportInfo(const unsigned int namespaceURI) const {
XMLSize_t importSize = (fImportedInfoList) ? fImportedInfoList->size() : 0;
SchemaInfo* currInfo = 0;
for (XMLSize_t i=0; i < importSize; i++) {
currInfo = fImportedInfoList->elementAt(i);
if (currInfo->getTargetNSURI() == (int) namespaceURI)
return currInfo;
}
return 0;
}
inline ValidationContext* SchemaInfo::getValidationContext() const {
return fValidationContext;
}
inline bool SchemaInfo::containsInfo(const SchemaInfo* const toCheck,
const ListType aListType) const {
if ((aListType == INCLUDE) && fIncludeInfoList) {
return fIncludeInfoList->containsElement(toCheck);
}
else if ((aListType == IMPORT) && fImportedInfoList) {
return fImportedInfoList->containsElement(toCheck);
}
return false;
}
inline bool SchemaInfo::circularImportExist(const unsigned int namespaceURI) {
XMLSize_t importSize = fImportingInfoList->size();
for (XMLSize_t i=0; i < importSize; i++) {
if (fImportingInfoList->elementAt(i)->getTargetNSURI() == (int) namespaceURI) {
return true;
}
}
return false;
}
inline bool SchemaInfo::isFailedRedefine(const DOMElement* const anElem) {
if (fFailedRedefineList)
return (fFailedRedefineList->containsElement(anElem));
return false;
}
inline void SchemaInfo::addFailedRedefine(const DOMElement* const anElem) {
if (!fFailedRedefineList) {
fFailedRedefineList = new (fMemoryManager) ValueVectorOf<const DOMElement*>(4, fMemoryManager);
}
fFailedRedefineList->addElement(anElem);
}
inline void SchemaInfo::addRecursingType(const DOMElement* const elem,
const XMLCh* const name) {
if (!fRecursingAnonTypes) {
fRecursingAnonTypes = new (fMemoryManager) ValueVectorOf<const DOMElement*>(8, fMemoryManager);
fRecursingTypeNames = new (fMemoryManager) ValueVectorOf<const XMLCh*>(8, fMemoryManager);
}
fRecursingAnonTypes->addElement(elem);
fRecursingTypeNames->addElement(name);
}
inline void SchemaInfo::clearTopLevelComponents() {
for (unsigned int i = 0; i < C_Count; i++) {
delete fTopLevelComponents[i];
fTopLevelComponents[i] = 0;
fLastTopLevelComponent[i] = 0;
}
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file SchemaInfo.hpp
*/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,254 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaSymbols.hpp 802804 2009-08-10 14:21:48Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SCHEMASYMBOLS_HPP)
#define XERCESC_INCLUDE_GUARD_SCHEMASYMBOLS_HPP
#include <xercesc/util/XercesDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/*
* Collection of symbols used to parse a Schema Grammar
*/
class VALIDATORS_EXPORT SchemaSymbols
{
public :
// -----------------------------------------------------------------------
// Constant data
// -----------------------------------------------------------------------
static const XMLCh fgURI_XSI[];
static const XMLCh fgURI_SCHEMAFORSCHEMA[];
// deprecated (typo)
static const XMLCh fgXSI_SCHEMALOCACTION[];
// deprecated (typo)
static const XMLCh fgXSI_NONAMESPACESCHEMALOCACTION[];
static const XMLCh fgXSI_SCHEMALOCATION[];
static const XMLCh fgXSI_NONAMESPACESCHEMALOCATION[];
static const XMLCh fgXSI_TYPE[];
static const XMLCh fgELT_ALL[];
static const XMLCh fgELT_ANNOTATION[];
static const XMLCh fgELT_ANY[];
static const XMLCh fgELT_WILDCARD[];
static const XMLCh fgELT_ANYATTRIBUTE[];
static const XMLCh fgELT_APPINFO[];
static const XMLCh fgELT_ATTRIBUTE[];
static const XMLCh fgELT_ATTRIBUTEGROUP[];
static const XMLCh fgELT_CHOICE[];
static const XMLCh fgELT_COMPLEXTYPE[];
static const XMLCh fgELT_CONTENT[];
static const XMLCh fgELT_DOCUMENTATION[];
static const XMLCh fgELT_DURATION[];
static const XMLCh fgELT_ELEMENT[];
static const XMLCh fgELT_ENCODING[];
static const XMLCh fgELT_ENUMERATION[];
static const XMLCh fgELT_FIELD[];
static const XMLCh fgELT_WHITESPACE[];
static const XMLCh fgELT_GROUP[];
static const XMLCh fgELT_IMPORT[];
static const XMLCh fgELT_INCLUDE[];
static const XMLCh fgELT_REDEFINE[];
static const XMLCh fgELT_KEY[];
static const XMLCh fgELT_KEYREF[];
static const XMLCh fgELT_LENGTH[];
static const XMLCh fgELT_MAXEXCLUSIVE[];
static const XMLCh fgELT_MAXINCLUSIVE[];
static const XMLCh fgELT_MAXLENGTH[];
static const XMLCh fgELT_MINEXCLUSIVE[];
static const XMLCh fgELT_MININCLUSIVE[];
static const XMLCh fgELT_MINLENGTH[];
static const XMLCh fgELT_NOTATION[];
static const XMLCh fgELT_PATTERN[];
static const XMLCh fgELT_PERIOD[];
static const XMLCh fgELT_TOTALDIGITS[];
static const XMLCh fgELT_FRACTIONDIGITS[];
static const XMLCh fgELT_SCHEMA[];
static const XMLCh fgELT_SELECTOR[];
static const XMLCh fgELT_SEQUENCE[];
static const XMLCh fgELT_SIMPLETYPE[];
static const XMLCh fgELT_UNION[];
static const XMLCh fgELT_LIST[];
static const XMLCh fgELT_UNIQUE[];
static const XMLCh fgELT_COMPLEXCONTENT[];
static const XMLCh fgELT_SIMPLECONTENT[];
static const XMLCh fgELT_RESTRICTION[];
static const XMLCh fgELT_EXTENSION[];
static const XMLCh fgATT_ABSTRACT[];
static const XMLCh fgATT_ATTRIBUTEFORMDEFAULT[];
static const XMLCh fgATT_BASE[];
static const XMLCh fgATT_ITEMTYPE[];
static const XMLCh fgATT_MEMBERTYPES[];
static const XMLCh fgATT_BLOCK[];
static const XMLCh fgATT_BLOCKDEFAULT[];
static const XMLCh fgATT_DEFAULT[];
static const XMLCh fgATT_ELEMENTFORMDEFAULT[];
static const XMLCh fgATT_SUBSTITUTIONGROUP[];
static const XMLCh fgATT_FINAL[];
static const XMLCh fgATT_FINALDEFAULT[];
static const XMLCh fgATT_FIXED[];
static const XMLCh fgATT_FORM[];
static const XMLCh fgATT_ID[];
static const XMLCh fgATT_MAXOCCURS[];
static const XMLCh fgATT_MINOCCURS[];
static const XMLCh fgATT_NAME[];
static const XMLCh fgATT_NAMESPACE[];
static const XMLCh fgATT_NILL[];
static const XMLCh fgATT_NILLABLE[];
static const XMLCh fgATT_PROCESSCONTENTS[];
static const XMLCh fgATT_REF[];
static const XMLCh fgATT_REFER[];
static const XMLCh fgATT_SCHEMALOCATION[];
static const XMLCh fgATT_SOURCE[];
static const XMLCh fgATT_SYSTEM[];
static const XMLCh fgATT_PUBLIC[];
static const XMLCh fgATT_TARGETNAMESPACE[];
static const XMLCh fgATT_TYPE[];
static const XMLCh fgATT_USE[];
static const XMLCh fgATT_VALUE[];
static const XMLCh fgATT_MIXED[];
static const XMLCh fgATT_VERSION[];
static const XMLCh fgATT_XPATH[];
static const XMLCh fgATTVAL_TWOPOUNDANY[];
static const XMLCh fgATTVAL_TWOPOUNDLOCAL[];
static const XMLCh fgATTVAL_TWOPOUNDOTHER[];
static const XMLCh fgATTVAL_TWOPOUNDTRAGETNAMESPACE[];
static const XMLCh fgATTVAL_POUNDALL[];
static const XMLCh fgATTVAL_BASE64[];
static const XMLCh fgATTVAL_BOOLEAN[];
static const XMLCh fgATTVAL_DEFAULT[];
static const XMLCh fgATTVAL_ELEMENTONLY[];
static const XMLCh fgATTVAL_EMPTY[];
static const XMLCh fgATTVAL_EXTENSION[];
static const XMLCh fgATTVAL_FALSE[];
static const XMLCh fgATTVAL_FIXED[];
static const XMLCh fgATTVAL_HEX[];
static const XMLCh fgATTVAL_ID[];
static const XMLCh fgATTVAL_LAX[];
static const XMLCh fgATTVAL_MAXLENGTH[];
static const XMLCh fgATTVAL_MINLENGTH[];
static const XMLCh fgATTVAL_MIXED[];
static const XMLCh fgATTVAL_NCNAME[];
static const XMLCh fgATTVAL_OPTIONAL[];
static const XMLCh fgATTVAL_PROHIBITED[];
static const XMLCh fgATTVAL_QNAME[];
static const XMLCh fgATTVAL_QUALIFIED[];
static const XMLCh fgATTVAL_REQUIRED[];
static const XMLCh fgATTVAL_RESTRICTION[];
static const XMLCh fgATTVAL_SKIP[];
static const XMLCh fgATTVAL_STRICT[];
static const XMLCh fgATTVAL_STRING[];
static const XMLCh fgATTVAL_TEXTONLY[];
static const XMLCh fgATTVAL_TIMEDURATION[];
static const XMLCh fgATTVAL_TRUE[];
static const XMLCh fgATTVAL_UNQUALIFIED[];
static const XMLCh fgATTVAL_URI[];
static const XMLCh fgATTVAL_URIREFERENCE[];
static const XMLCh fgATTVAL_SUBSTITUTIONGROUP[];
static const XMLCh fgATTVAL_SUBSTITUTION[];
static const XMLCh fgATTVAL_ANYTYPE[];
static const XMLCh fgWS_PRESERVE[];
static const XMLCh fgWS_COLLAPSE[];
static const XMLCh fgWS_REPLACE[];
static const XMLCh fgDT_STRING[];
static const XMLCh fgDT_TOKEN[];
static const XMLCh fgDT_LANGUAGE[];
static const XMLCh fgDT_NAME[];
static const XMLCh fgDT_NCNAME[];
static const XMLCh fgDT_INTEGER[];
static const XMLCh fgDT_DECIMAL[];
static const XMLCh fgDT_BOOLEAN[];
static const XMLCh fgDT_NONPOSITIVEINTEGER[];
static const XMLCh fgDT_NEGATIVEINTEGER[];
static const XMLCh fgDT_LONG[];
static const XMLCh fgDT_INT[];
static const XMLCh fgDT_SHORT[];
static const XMLCh fgDT_BYTE[];
static const XMLCh fgDT_NONNEGATIVEINTEGER[];
static const XMLCh fgDT_ULONG[];
static const XMLCh fgDT_UINT[];
static const XMLCh fgDT_USHORT[];
static const XMLCh fgDT_UBYTE[];
static const XMLCh fgDT_POSITIVEINTEGER[];
//datetime
static const XMLCh fgDT_DATETIME[];
static const XMLCh fgDT_DATE[];
static const XMLCh fgDT_TIME[];
static const XMLCh fgDT_DURATION[];
static const XMLCh fgDT_DAY[];
static const XMLCh fgDT_MONTH[];
static const XMLCh fgDT_MONTHDAY[];
static const XMLCh fgDT_YEAR[];
static const XMLCh fgDT_YEARMONTH[];
static const XMLCh fgDT_BASE64BINARY[];
static const XMLCh fgDT_HEXBINARY[];
static const XMLCh fgDT_FLOAT[];
static const XMLCh fgDT_DOUBLE[];
static const XMLCh fgDT_URIREFERENCE[];
static const XMLCh fgDT_ANYURI[];
static const XMLCh fgDT_QNAME[];
static const XMLCh fgDT_NORMALIZEDSTRING[];
static const XMLCh fgDT_ANYSIMPLETYPE[];
static const XMLCh fgRegEx_XOption[];
static const XMLCh fgRedefIdentifier[];
static const int fgINT_MIN_VALUE;
static const int fgINT_MAX_VALUE;
enum {
XSD_EMPTYSET = 0,
XSD_SUBSTITUTION = 1,
XSD_EXTENSION = 2,
XSD_RESTRICTION = 4,
XSD_LIST = 8,
XSD_UNION = 16,
XSD_ENUMERATION = 32
};
// group orders
enum {
XSD_CHOICE = 0,
XSD_SEQUENCE= 1,
XSD_ALL = 2
};
enum {
XSD_UNBOUNDED = -1,
XSD_NILLABLE = 1,
XSD_ABSTRACT = 2,
XSD_FIXED = 4
};
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SchemaSymbols();
};
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file SchemaSymbols.hpp
*/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,443 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SchemaValidator.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SCHEMAVALIDATOR_HPP)
#define XERCESC_INCLUDE_GUARD_SCHEMAVALIDATOR_HPP
#include <xercesc/framework/XMLValidator.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/util/ValueStackOf.hpp>
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/schema/SchemaGrammar.hpp>
#include <xercesc/validators/schema/XSDErrorReporter.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class GrammarResolver;
class DatatypeValidator;
class SchemaElementDecl;
//
// This is a derivative of the abstract validator interface. This class
// implements a validator that supports standard XML Schema semantics.
// This class handles scanning the of the schema, and provides
// the standard validation services against the Schema info it found.
//
class VALIDATORS_EXPORT SchemaValidator : public XMLValidator
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
SchemaValidator
(
XMLErrorReporter* const errReporter = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
virtual ~SchemaValidator();
// -----------------------------------------------------------------------
// Implementation of the XMLValidator interface
// -----------------------------------------------------------------------
virtual bool checkContent
(
XMLElementDecl* const elemDecl
, QName** const children
, XMLSize_t childCount
, XMLSize_t* indexFailingChild
);
virtual void faultInAttr
(
XMLAttr& toFill
, const XMLAttDef& attDef
) const;
virtual void preContentValidation(bool reuseGrammar,
bool validateDefAttr = false);
virtual void postParseValidation();
virtual void reset();
virtual bool requiresNamespaces() const;
virtual void validateAttrValue
(
const XMLAttDef* attDef
, const XMLCh* const attrValue
, bool preValidation = false
, const XMLElementDecl* elemDecl = 0
);
virtual void validateElement
(
const XMLElementDecl* elemDef
);
virtual Grammar* getGrammar() const;
virtual void setGrammar(Grammar* aGrammar);
// -----------------------------------------------------------------------
// Virtual DTD handler interface.
// -----------------------------------------------------------------------
virtual bool handlesDTD() const;
// -----------------------------------------------------------------------
// Virtual Schema handler interface. handlesSchema() always return false.
// -----------------------------------------------------------------------
virtual bool handlesSchema() const;
// -----------------------------------------------------------------------
// Schema Validator methods
// -----------------------------------------------------------------------
void normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* const value, XMLBuffer& toFill, bool bStandalone = false);
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setGrammarResolver(GrammarResolver* grammarResolver);
void setXsiType(const XMLCh* const prefix
, const XMLCh* const localPart
, const unsigned int uriId);
void setNillable(bool isNil);
void resetNillable();
void setErrorReporter(XMLErrorReporter* const errorReporter);
void setExitOnFirstFatal(const bool newValue);
void setDatatypeBuffer(const XMLCh* const value);
void clearDatatypeBuffer();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
ComplexTypeInfo* getCurrentTypeInfo() const;
DatatypeValidator *getCurrentDatatypeValidator() const;
DatatypeValidator *getMostRecentAttrValidator() const;
bool getErrorOccurred() const;
bool getIsElemSpecified() const;
bool getIsXsiTypeSet() const;
const XMLCh* getNormalizedValue() const;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SchemaValidator(const SchemaValidator&);
SchemaValidator& operator=(const SchemaValidator&);
// -----------------------------------------------------------------------
// Element Consistency Checking methods
// -----------------------------------------------------------------------
void checkRefElementConsistency(SchemaGrammar* const currentGrammar,
const ComplexTypeInfo* const curTypeInfo,
const XercesGroupInfo* const curGroup = 0);
// -----------------------------------------------------------------------
// Particle Derivation Checking methods
// -----------------------------------------------------------------------
void checkParticleDerivation(SchemaGrammar* const currentGrammar,
const ComplexTypeInfo* const typeInfo);
void checkParticleDerivationOk(SchemaGrammar* const currentGrammar,
ContentSpecNode* const curNode,
const int derivedScope,
ContentSpecNode* const baseNode,
const int baseScope,
const ComplexTypeInfo* const baseInfo = 0,
const bool toCheckOccurrence = true);
ContentSpecNode* checkForPointlessOccurrences(ContentSpecNode* const specNode,
const ContentSpecNode::NodeTypes nodeType,
ValueVectorOf<ContentSpecNode*>* const nodes);
void gatherChildren(const ContentSpecNode::NodeTypes parentNodeType,
ContentSpecNode* const specNode,
ValueVectorOf<ContentSpecNode*>* const nodes);
bool isOccurrenceRangeOK(const int min1, const int max1, const int min2, const int max2);
void checkNSCompat(const ContentSpecNode* const derivedSpecNode,
const ContentSpecNode* const baseSpecNode,
const bool toCheckOccurence);
bool wildcardEltAllowsNamespace(const ContentSpecNode* const baseSpecNode,
const unsigned int derivedURI);
void checkNameAndTypeOK(SchemaGrammar* const currentGrammar,
const ContentSpecNode* const derivedSpecNode,
const int derivedScope,
const ContentSpecNode* const baseSpecNode,
const int baseScope,
const ComplexTypeInfo* const baseInfo = 0);
SchemaElementDecl* findElement(const int scope,
const unsigned int uriIndex,
const XMLCh* const name,
SchemaGrammar* const grammar,
const ComplexTypeInfo* const typeInfo = 0);
void checkICRestriction(const SchemaElementDecl* const derivedElemDecl,
const SchemaElementDecl* const baseElemDecl,
const XMLCh* const derivedElemName,
const XMLCh* const baseElemName);
void checkTypesOK(const SchemaElementDecl* const derivedElemDecl,
const SchemaElementDecl* const baseElemDecl,
const XMLCh* const derivedElemName);
void checkRecurseAsIfGroup(SchemaGrammar* const currentGrammar,
ContentSpecNode* const derivedSpecNode,
const int derivedScope,
const ContentSpecNode* const baseSpecNode,
const int baseScope,
ValueVectorOf<ContentSpecNode*>* const nodes,
const ComplexTypeInfo* const baseInfo);
void checkRecurse(SchemaGrammar* const currentGrammar,
const ContentSpecNode* const derivedSpecNode,
const int derivedScope,
ValueVectorOf<ContentSpecNode*>* const derivedNodes,
const ContentSpecNode* const baseSpecNode,
const int baseScope,
ValueVectorOf<ContentSpecNode*>* const baseNodes,
const ComplexTypeInfo* const baseInfo,
const bool toLax = false);
void checkNSSubset(const ContentSpecNode* const derivedSpecNode,
const ContentSpecNode* const baseSpecNode);
bool checkNSSubsetChoiceRoot(const ContentSpecNode* const derivedSpecNode,
const ContentSpecNode* const baseSpecNode);
bool checkNSSubsetChoice(const ContentSpecNode* const derivedSpecNode,
const ContentSpecNode* const baseSpecNode);
bool isWildCardEltSubset(const ContentSpecNode* const derivedSpecNode,
const ContentSpecNode* const baseSpecNode);
void checkNSRecurseCheckCardinality(SchemaGrammar* const currentGrammar,
const ContentSpecNode* const derivedSpecNode,
ValueVectorOf<ContentSpecNode*>* const derivedNodes,
const int derivedScope,
ContentSpecNode* const baseSpecNode,
const bool toCheckOccurence);
void checkRecurseUnordered(SchemaGrammar* const currentGrammar,
const ContentSpecNode* const derivedSpecNode,
ValueVectorOf<ContentSpecNode*>* const derivedNodes,
const int derivedScope,
ContentSpecNode* const baseSpecNode,
ValueVectorOf<ContentSpecNode*>* const baseNodes,
const int baseScope,
const ComplexTypeInfo* const baseInfo);
void checkMapAndSum(SchemaGrammar* const currentGrammar,
const ContentSpecNode* const derivedSpecNode,
ValueVectorOf<ContentSpecNode*>* const derivedNodes,
const int derivedScope,
ContentSpecNode* const baseSpecNode,
ValueVectorOf<ContentSpecNode*>* const baseNodes,
const int baseScope,
const ComplexTypeInfo* const baseInfo);
ContentSpecNode* getNonUnaryGroup(ContentSpecNode* const pNode);
// -----------------------------------------------------------------------
// Private data members
//
// -----------------------------------------------------------------------
// The following comes from or set by the Scanner
// fSchemaGrammar
// The current schema grammar used by the validator
//
// fGrammarResolver
// All the schema grammar stored
//
// fXsiType
// Store the Schema Type Attribute Value if schema type is specified
//
// fNil
// Indicates if a nil value is acceptable
// fNilFound
// Indicates if Nillable has been set
// -----------------------------------------------------------------------
// The following used internally in the validator
//
// fCurrentDatatypeValidator
// The validator used for validating the content of elements
// with simple types
//
// fDatatypeBuffer
// Buffer for simple type element string content
//
// fTrailing
// Previous chunk had a trailing space
//
// fSeenNonWhiteSpace
// Seen a non-whitespace character in the previous chunk
//
// fSeenId
// Indicate if an attribute of ID type has been seen already, reset per element.
//
// fSchemaErrorReporter
// Report schema process errors
//
// fTypeStack
// Stack of complex type declarations.
//
// fMostRecentAttrValidator
// DatatypeValidator that validated attribute most recently processed
//
// fErrorOccurred
// whether an error occurred in the most recent operation
// -----------------------------------------------------------------------
MemoryManager* fMemoryManager;
SchemaGrammar* fSchemaGrammar;
GrammarResolver* fGrammarResolver;
QName* fXsiType;
bool fNil;
bool fNilFound;
DatatypeValidator* fCurrentDatatypeValidator;
XMLBuffer* fNotationBuf;
XMLBuffer fDatatypeBuffer;
bool fTrailing;
bool fSeenNonWhiteSpace;
bool fSeenId;
XSDErrorReporter fSchemaErrorReporter;
ValueStackOf<ComplexTypeInfo*>* fTypeStack;
DatatypeValidator * fMostRecentAttrValidator;
bool fErrorOccurred;
bool fElemIsSpecified;
};
// ---------------------------------------------------------------------------
// SchemaValidator: Setter methods
// ---------------------------------------------------------------------------
inline void SchemaValidator::setGrammarResolver(GrammarResolver* grammarResolver) {
fGrammarResolver = grammarResolver;
}
inline void SchemaValidator::setXsiType(const XMLCh* const prefix
, const XMLCh* const localPart
, const unsigned int uriId)
{
delete fXsiType;
fXsiType = new (fMemoryManager) QName(prefix, localPart, uriId, fMemoryManager);
}
inline void SchemaValidator::setNillable(bool isNil) {
fNil = isNil;
fNilFound = true;
}
inline void SchemaValidator::resetNillable() {
fNil = false;
fNilFound = false;
}
inline void SchemaValidator::setExitOnFirstFatal(const bool newValue) {
fSchemaErrorReporter.setExitOnFirstFatal(newValue);
}
inline void SchemaValidator::setDatatypeBuffer(const XMLCh* const value)
{
fDatatypeBuffer.append(value);
}
inline void SchemaValidator::clearDatatypeBuffer()
{
fDatatypeBuffer.reset();
}
// ---------------------------------------------------------------------------
// SchemaValidator: Getter methods
// ---------------------------------------------------------------------------
inline ComplexTypeInfo* SchemaValidator::getCurrentTypeInfo() const {
if (fTypeStack->empty())
return 0;
return fTypeStack->peek();
}
inline DatatypeValidator * SchemaValidator::getCurrentDatatypeValidator() const
{
return fCurrentDatatypeValidator;
}
inline DatatypeValidator *SchemaValidator::getMostRecentAttrValidator() const
{
return fMostRecentAttrValidator;
}
// ---------------------------------------------------------------------------
// Virtual interface
// ---------------------------------------------------------------------------
inline Grammar* SchemaValidator::getGrammar() const {
return fSchemaGrammar;
}
inline void SchemaValidator::setGrammar(Grammar* aGrammar) {
fSchemaGrammar = (SchemaGrammar*) aGrammar;
}
inline void SchemaValidator::setErrorReporter(XMLErrorReporter* const errorReporter) {
XMLValidator::setErrorReporter(errorReporter);
fSchemaErrorReporter.setErrorReporter(errorReporter);
}
// ---------------------------------------------------------------------------
// SchemaValidator: DTD handler interface
// ---------------------------------------------------------------------------
inline bool SchemaValidator::handlesDTD() const
{
// No DTD scanning
return false;
}
// ---------------------------------------------------------------------------
// SchemaValidator: Schema handler interface
// ---------------------------------------------------------------------------
inline bool SchemaValidator::handlesSchema() const
{
return true;
}
// ---------------------------------------------------------------------------
// SchemaValidator: Particle derivation checking
// ---------------------------------------------------------------------------
inline bool
SchemaValidator::isOccurrenceRangeOK(const int min1, const int max1,
const int min2, const int max2) {
if (min1 >= min2 &&
(max2 == SchemaSymbols::XSD_UNBOUNDED ||
(max1 != SchemaSymbols::XSD_UNBOUNDED && max1 <= max2))) {
return true;
}
return false;
}
inline bool SchemaValidator::getErrorOccurred() const
{
return fErrorOccurred;
}
inline bool SchemaValidator::getIsElemSpecified() const
{
return fElemIsSpecified;
}
inline const XMLCh* SchemaValidator::getNormalizedValue() const
{
return fDatatypeBuffer.getRawBuffer();
}
inline bool SchemaValidator::getIsXsiTypeSet() const
{
return (fXsiType!=0);
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,210 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SubstitutionGroupComparator.cpp 794273 2009-07-15 14:13:07Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/framework/XMLGrammarPool.hpp>
#include <xercesc/framework/XMLSchemaDescription.hpp>
#include <xercesc/framework/psvi/XSAnnotation.hpp>
#include <xercesc/validators/schema/SubstitutionGroupComparator.hpp>
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/validators/schema/SchemaGrammar.hpp>
#include <xercesc/validators/schema/ComplexTypeInfo.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp>
XERCES_CPP_NAMESPACE_BEGIN
bool SubstitutionGroupComparator::isEquivalentTo(const QName* const anElement
, const QName* const exemplar)
{
if (!anElement && !exemplar)
return true;
if ((!anElement && exemplar) || (anElement && !exemplar))
return false;
if (XMLString::equals(anElement->getLocalPart(), exemplar->getLocalPart()) &&
(anElement->getURI() == exemplar->getURI()))
return true; // they're the same!
if (!fGrammarResolver || !fStringPool )
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::SubGrpComparator_NGR, anElement->getMemoryManager());
}
unsigned int uriId = anElement->getURI();
if (uriId == XMLContentModel::gEOCFakeId ||
uriId == XMLContentModel::gEpsilonFakeId ||
uriId == XMLElementDecl::fgPCDataElemId ||
uriId == XMLElementDecl::fgInvalidElemId)
return false;
const XMLCh* uri = fStringPool->getValueForId(uriId);
const XMLCh* localpart = anElement->getLocalPart();
// In addition to simply trying to find a chain between anElement and exemplar,
// we need to make sure that no steps in the chain are blocked.
// That is, at every step, we need to make sure that the element
// being substituted for will permit being substituted
// for, and whether the type of the element will permit derivations in
// instance documents of this sort.
if (!uri)
return false;
SchemaGrammar *sGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(uri);
if (!sGrammar || sGrammar->getGrammarType() == Grammar::DTDGrammarType)
return false;
SchemaElementDecl* anElementDecl = (SchemaElementDecl*) sGrammar->getElemDecl(uriId, localpart, 0, Grammar::TOP_LEVEL_SCOPE);
if (!anElementDecl)
return false;
SchemaElementDecl* pElemDecl = anElementDecl->getSubstitutionGroupElem();
bool foundIt = false;
while (pElemDecl) //(substitutionGroupFullName)
{
if (XMLString::equals(pElemDecl->getBaseName(), exemplar->getLocalPart()) &&
(pElemDecl->getURI() == exemplar->getURI()))
{
// time to check for block value on element
if((pElemDecl->getBlockSet() & SchemaSymbols::XSD_SUBSTITUTION) != 0)
return false;
foundIt = true;
break;
}
pElemDecl = pElemDecl->getSubstitutionGroupElem();
}//while
if (!foundIt)
return false;
// this will contain anElement's complexType information.
ComplexTypeInfo *aComplexType = anElementDecl->getComplexTypeInfo();
int exemplarBlockSet = pElemDecl->getBlockSet();
if(!aComplexType)
{
// check on simpleType case
DatatypeValidator *anElementDV = anElementDecl->getDatatypeValidator();
DatatypeValidator *exemplarDV = pElemDecl->getDatatypeValidator();
return((anElementDV == 0) ||
((anElementDV == exemplarDV) ||
((exemplarBlockSet & SchemaSymbols::XSD_RESTRICTION) == 0)));
}
// 2.3 The set of all {derivation method}s involved in the derivation of D's {type definition} from C's {type definition} does not intersect with the union of the blocking constraint, C's {prohibited substitutions} (if C is complex, otherwise the empty set) and the {prohibited substitutions} (respectively the empty set) of any intermediate {type definition}s in the derivation of D's {type definition} from C's {type definition}.
// prepare the combination of {derivation method} and
// {disallowed substitution}
int devMethod = 0;
int blockConstraint = exemplarBlockSet;
ComplexTypeInfo *exemplarComplexType = pElemDecl->getComplexTypeInfo();
ComplexTypeInfo *tempType = aComplexType;;
while (tempType != 0 &&
tempType != exemplarComplexType)
{
devMethod |= tempType->getDerivedBy();
tempType = tempType->getBaseComplexTypeInfo();
if (tempType) {
blockConstraint |= tempType->getBlockSet();
}
}
if (tempType != exemplarComplexType) {
return false;
}
if ((devMethod & blockConstraint) != 0) {
return false;
}
return true;
}
bool SubstitutionGroupComparator::isAllowedByWildcard(SchemaGrammar* const pGrammar,
QName* const element,
unsigned int wuri, bool wother)
{
// whether the uri is allowed directly by the wildcard
unsigned int uriId = element->getURI();
// Here we assume that empty string has id 1.
//
if ((!wother && uriId == wuri) ||
(wother &&
uriId != 1 &&
uriId != wuri &&
uriId != XMLContentModel::gEOCFakeId &&
uriId != XMLContentModel::gEpsilonFakeId &&
uriId != XMLElementDecl::fgPCDataElemId &&
uriId != XMLElementDecl::fgInvalidElemId))
{
return true;
}
// get all elements that can substitute the current element
RefHash2KeysTableOf<ElemVector>* theValidSubstitutionGroups = pGrammar->getValidSubstitutionGroups();
if (!theValidSubstitutionGroups)
return false;
ValueVectorOf<SchemaElementDecl*>* subsElements = theValidSubstitutionGroups->get(element->getLocalPart(), uriId);
if (!subsElements)
return false;
// then check whether there exists one element that is allowed by the wildcard
XMLSize_t size = subsElements->size();
for (XMLSize_t i = 0; i < size; i++)
{
unsigned int subUriId = subsElements->elementAt(i)->getElementName()->getURI();
// Here we assume that empty string has id 1.
//
if ((!wother && subUriId == wuri) ||
(wother &&
subUriId != 1 &&
subUriId != wuri &&
subUriId != XMLContentModel::gEOCFakeId &&
subUriId != XMLContentModel::gEpsilonFakeId &&
subUriId != XMLElementDecl::fgPCDataElemId &&
subUriId != XMLElementDecl::fgInvalidElemId))
{
return true;
}
}
return false;
}
XERCES_CPP_NAMESPACE_END
/**
* End of file SubstitutionGroupComparator.cpp
*/
@@ -0,0 +1,126 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SubstitutionGroupComparator.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SUBSTITUTIONGROUPCOMPARATOR_HPP)
#define XERCESC_INCLUDE_GUARD_SUBSTITUTIONGROUPCOMPARATOR_HPP
#include <xercesc/util/StringPool.hpp>
#include <xercesc/util/QName.hpp>
#include <xercesc/validators/common/GrammarResolver.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class SchemaGrammar;
class VALIDATORS_EXPORT SubstitutionGroupComparator : public XMemory
{
public:
// -----------------------------------------------------------------------
// Public Constructor
// -----------------------------------------------------------------------
/** @name Constructor. */
//@{
SubstitutionGroupComparator(GrammarResolver* const pGrammarResolver
, XMLStringPool* const pStringPool);
//@}
// -----------------------------------------------------------------------
// Public Destructor
// -----------------------------------------------------------------------
/** @name Destructor. */
//@{
~SubstitutionGroupComparator();
//@}
// -----------------------------------------------------------------------
// Validation methods
// -----------------------------------------------------------------------
/** @name Validation Function */
//@{
/**
* Checks that the "anElement" is within the substitution group.
*
* @param anElement QName of the element
*
* @param exemplar QName of the head element in the group
*/
bool isEquivalentTo(const QName* const anElement
, const QName* const exemplar);
//@}
/*
* check whether one element or any element in its substitution group
* is allowed by a given wildcard uri
*
* @param pGrammar the grammar where the wildcard is declared
* @param element the QName of a given element
* @param wuri the uri of the wildcard
* @param wother whether the uri is from ##other, so wuri is excluded
*
* @return whether the element is allowed by the wildcard
*/
bool isAllowedByWildcard(SchemaGrammar* const pGrammar, QName* const element, unsigned int wuri, bool wother);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SubstitutionGroupComparator();
SubstitutionGroupComparator(const SubstitutionGroupComparator&);
SubstitutionGroupComparator& operator=(const SubstitutionGroupComparator&);
// -----------------------------------------------------------------------
// Private data members
//
//
// -----------------------------------------------------------------------
GrammarResolver *fGrammarResolver;
XMLStringPool *fStringPool;
};
// ---------------------------------------------------------------------------
// SubstitutionGroupComparator: Getters
// ---------------------------------------------------------------------------
inline SubstitutionGroupComparator::SubstitutionGroupComparator(GrammarResolver* const pGrammarResolver
, XMLStringPool* const pStringPool)
:fGrammarResolver(pGrammarResolver)
,fStringPool(pStringPool)
{}
inline SubstitutionGroupComparator::~SubstitutionGroupComparator()
{}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file SubstitutionGroupComparator.hpp
*/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,925 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: TraverseSchema.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_TRAVERSESCHEMA_HPP)
#define XERCESC_INCLUDE_GUARD_TRAVERSESCHEMA_HPP
/**
* Instances of this class get delegated to Traverse the Schema and
* to populate the SchemaGrammar internal representation.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/framework/XMLErrorCodes.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp>
#include <xercesc/util/ValueVectorOf.hpp>
#include <xercesc/util/RefHash2KeysTableOf.hpp>
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/schema/SchemaGrammar.hpp>
#include <xercesc/validators/schema/SchemaInfo.hpp>
#include <xercesc/validators/schema/GeneralAttributeCheck.hpp>
#include <xercesc/validators/schema/XSDErrorReporter.hpp>
#include <xercesc/util/XMLResourceIdentifier.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class GrammarResolver;
class XMLEntityHandler;
class XMLScanner;
class DatatypeValidator;
class DatatypeValidatorFactory;
class QName;
class ComplexTypeInfo;
class XMLAttDef;
class NamespaceScope;
class SchemaAttDef;
class InputSource;
class XercesGroupInfo;
class XercesAttGroupInfo;
class IdentityConstraint;
class XSDLocator;
class XSDDOMParser;
class XMLErrorReporter;
class VALIDATORS_EXPORT TraverseSchema : public XMemory
{
public:
// -----------------------------------------------------------------------
// Public Constructors/Destructor
// -----------------------------------------------------------------------
TraverseSchema
(
DOMElement* const schemaRoot
, XMLStringPool* const uriStringPool
, SchemaGrammar* const schemaGrammar
, GrammarResolver* const grammarResolver
, RefHash2KeysTableOf<SchemaInfo>* cachedSchemaInfoList
, RefHash2KeysTableOf<SchemaInfo>* schemaInfoList
, XMLScanner* const xmlScanner
, const XMLCh* const schemaURL
, XMLEntityHandler* const entityHandler
, XMLErrorReporter* const errorReporter
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
, bool multipleImport = false
);
~TraverseSchema();
private:
// This enumeration is defined here for compatibility with the CodeWarrior
// compiler, which apparently doesn't like to accept default parameter
// arguments that it hasn't yet seen. The Not_All_Context argument is
// used in the declaration of checkMinMax, below.
//
// Flags indicate any special restrictions on minOccurs and maxOccurs
// relating to "all".
// Not_All_Context - not processing an <all>
// All_Element - processing an <element> in an <all>
// Group_Ref_With_All - processing <group> reference that contained <all>
// All_Group - processing an <all> group itself
enum
{
Not_All_Context = 0
, All_Element = 1
, Group_Ref_With_All = 2
, All_Group = 4
};
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
TraverseSchema(const TraverseSchema&);
TraverseSchema& operator=(const TraverseSchema&);
// -----------------------------------------------------------------------
// Init/CleanUp methods
// -----------------------------------------------------------------------
void init();
void cleanUp();
// -----------------------------------------------------------------------
// Traversal methods
// -----------------------------------------------------------------------
/**
* Traverse the Schema DOM tree
*/
void doTraverseSchema(const DOMElement* const schemaRoot);
void preprocessSchema(DOMElement* const schemaRoot,
const XMLCh* const schemaURL,
bool multipleImport = false);
void traverseSchemaHeader(const DOMElement* const schemaRoot);
XSAnnotation* traverseAnnotationDecl(const DOMElement* const childElem,
ValueVectorOf<DOMNode*>* const nonXSAttList,
const bool topLevel = false);
void traverseInclude(const DOMElement* const childElem);
void traverseImport(const DOMElement* const childElem);
void traverseRedefine(const DOMElement* const childElem);
void traverseAttributeDecl(const DOMElement* const childElem,
ComplexTypeInfo* const typeInfo,
const bool topLevel = false);
void traverseSimpleContentDecl(const XMLCh* const typeName,
const XMLCh* const qualifiedName,
const DOMElement* const contentDecl,
ComplexTypeInfo* const typeInfo,
Janitor<XSAnnotation>* const janAnnot);
void traverseComplexContentDecl(const XMLCh* const typeName,
const DOMElement* const contentDecl,
ComplexTypeInfo* const typeInfo,
const bool isMixed,
Janitor<XSAnnotation>* const janAnnot);
DatatypeValidator* traverseSimpleTypeDecl(const DOMElement* const childElem,
const bool topLevel = true,
int baseRefContext = SchemaSymbols::XSD_EMPTYSET);
int traverseComplexTypeDecl(const DOMElement* const childElem,
const bool topLevel = true,
const XMLCh* const recursingTypeName = 0);
DatatypeValidator* traverseByList(const DOMElement* const rootElem,
const DOMElement* const contentElem,
const XMLCh* const typeName,
const XMLCh* const qualifiedName,
const int finalSet,
Janitor<XSAnnotation>* const janAnnot);
DatatypeValidator* traverseByRestriction(const DOMElement* const rootElem,
const DOMElement* const contentElem,
const XMLCh* const typeName,
const XMLCh* const qualifiedName,
const int finalSet,
Janitor<XSAnnotation>* const janAnnot);
DatatypeValidator* traverseByUnion(const DOMElement* const rootElem,
const DOMElement* const contentElem,
const XMLCh* const typeName,
const XMLCh* const qualifiedName,
const int finalSet,
int baseRefContext,
Janitor<XSAnnotation>* const janAnnot);
SchemaElementDecl* traverseElementDecl(const DOMElement* const childElem,
const bool topLevel = false);
const XMLCh* traverseNotationDecl(const DOMElement* const childElem);
const XMLCh* traverseNotationDecl(const DOMElement* const childElem,
const XMLCh* const name,
const XMLCh* const uriStr);
ContentSpecNode* traverseChoiceSequence(const DOMElement* const elemDecl,
const int modelGroupType,
bool& hasChildren);
ContentSpecNode* traverseAny(const DOMElement* const anyDecl);
ContentSpecNode* traverseAll(const DOMElement* const allElem,
bool& hasChildren);
XercesGroupInfo* traverseGroupDecl(const DOMElement* const childElem,
const bool topLevel = true);
XercesAttGroupInfo* traverseAttributeGroupDecl(const DOMElement* const elem,
ComplexTypeInfo* const typeInfo,
const bool topLevel = false);
XercesAttGroupInfo* traverseAttributeGroupDeclNS(const DOMElement* const elem,
const XMLCh* const uriStr,
const XMLCh* const name);
SchemaAttDef* traverseAnyAttribute(const DOMElement* const elem);
void traverseKey(const DOMElement* const icElem,
SchemaElementDecl* const elemDecl);
void traverseUnique(const DOMElement* const icElem,
SchemaElementDecl* const elemDecl);
void traverseKeyRef(const DOMElement* const icElem,
SchemaElementDecl* const elemDecl);
bool traverseIdentityConstraint(IdentityConstraint* const ic,
const DOMElement* const icElem);
// -----------------------------------------------------------------------
// Error Reporting methods
// -----------------------------------------------------------------------
void reportSchemaError(const XSDLocator* const aLocator,
const XMLCh* const msgDomain,
const int errorCode);
void reportSchemaError(const XSDLocator* const aLocator,
const XMLCh* const msgDomain,
const int errorCode,
const XMLCh* const text1,
const XMLCh* const text2 = 0,
const XMLCh* const text3 = 0,
const XMLCh* const text4 = 0);
void reportSchemaError(const DOMElement* const elem,
const XMLCh* const msgDomain,
const int errorCode);
void reportSchemaError(const DOMElement* const elem,
const XMLCh* const msgDomain,
const int errorCode,
const XMLCh* const text1,
const XMLCh* const text2 = 0,
const XMLCh* const text3 = 0,
const XMLCh* const text4 = 0);
void reportSchemaError(const DOMElement* const elem,
const XMLException& except);
// -----------------------------------------------------------------------
// Private Helper methods
// -----------------------------------------------------------------------
/**
* Keep track of the xs:import found
*/
bool isImportingNS(const int namespaceURI);
void addImportedNS(const int namespaceURI);
/**
* Retrieved the Namespace mapping from the schema element
*/
bool retrieveNamespaceMapping(const DOMElement* const elem);
/**
* Loop through the children, and traverse the corresponding schema type
* type declaration (simpleType, complexType, import, ....)
*/
void processChildren(const DOMElement* const root);
void preprocessChildren(const DOMElement* const root);
void preprocessImport(const DOMElement* const elemNode);
void preprocessInclude(const DOMElement* const elemNode);
void preprocessRedefine(const DOMElement* const elemNode);
/**
* Parameters:
* rootElem - top element for a given type declaration
* contentElem - content must be annotation? or some other simple content
* isEmpty: - true if (annotation?, smth_else), false if (annotation?)
* processAnnot - default is true, false if reprocessing a complex type
* since we have already processed the annotation.
*
* Check for Annotation if it is present, traverse it. If a sibling is
* found and it is not an annotation return it, otherwise return 0.
* Used by traverseSimpleTypeDecl.
*/
DOMElement* checkContent(const DOMElement* const rootElem,
DOMElement* const contentElem,
const bool isEmpty, bool processAnnot = true);
/**
* Parameters:
* contentElem - content element to check
*
* Check for identity constraints content.
*/
const DOMElement* checkIdentityConstraintContent(const DOMElement* const contentElem);
DatatypeValidator* getDatatypeValidator(const XMLCh* const uriStr,
const XMLCh* const localPartStr);
/**
* Process simpleType content of a list|restriction|union
* Return a dataype validator if valid type, otherwise 0.
*/
DatatypeValidator* checkForSimpleTypeValidator(const DOMElement* const content,
int baseRefContext = SchemaSymbols::XSD_EMPTYSET);
/**
* Process complexType content of an element
* Return a ComplexTypeInfo if valid type, otherwise 0.
*/
ComplexTypeInfo* checkForComplexTypeInfo(const DOMElement* const content);
/**
* Return DatatypeValidator available for the baseTypeStr.
*/
DatatypeValidator* findDTValidator(const DOMElement* const elem,
const XMLCh* const derivedTypeName,
const XMLCh* const baseTypeName,
const int baseRefContext);
const XMLCh* resolvePrefixToURI(const DOMElement* const elem,
const XMLCh* const prefix);
/**
* Return the prefix for a given rawname string
*
* Function allocated, caller managed (facm) - pointer to be deleted by
* caller.
*/
const XMLCh* getPrefix(const XMLCh* const rawName);
/**
* Return the local for a given rawname string
*
* caller allocated, caller managed (cacm)
*/
const XMLCh* getLocalPart(const XMLCh* const rawName);
/**
* Process a 'ref' of an Element declaration
*/
SchemaElementDecl* processElementDeclRef(const DOMElement* const elem,
const XMLCh* const refName);
void processElemDeclAttrs(const DOMElement* const elem,
SchemaElementDecl* const elemDecl,
const XMLCh*& valConstraint,
bool isTopLevel = false);
void processElemDeclIC(DOMElement* const elem,
SchemaElementDecl* const elemDecl);
bool checkElemDeclValueConstraint(const DOMElement* const elem,
SchemaElementDecl* const elemDecl,
const XMLCh* const valConstraint,
ComplexTypeInfo* const typeInfo,
DatatypeValidator* const validator);
/**
* Process a 'ref' of an Attribute declaration
*/
void processAttributeDeclRef(const DOMElement* const elem,
ComplexTypeInfo* const typeInfo,
const XMLCh* const refName,
const XMLCh* const useVal,
const XMLCh* const defaultVal,
const XMLCh* const fixedVal);
/**
* Process a 'ref' on a group
*/
XercesGroupInfo* processGroupRef(const DOMElement* const elem,
const XMLCh* const refName);
/**
* Process a 'ref' on a attributeGroup
*/
XercesAttGroupInfo* processAttributeGroupRef(const DOMElement* const elem,
const XMLCh* const refName,
ComplexTypeInfo* const typeInfo);
/**
* Parse block & final items
*/
int parseBlockSet(const DOMElement* const elem, const int blockType, const bool isRoot = false);
int parseFinalSet(const DOMElement* const elem, const int finalType, const bool isRoot = false);
/**
* Return true if a name is an identity constraint, otherwise false
*/
bool isIdentityConstraintName(const XMLCh* const constraintName);
/**
* If 'typeStr' belongs to a different schema, return that schema URI,
* otherwise return 0;
*/
const XMLCh* checkTypeFromAnotherSchema(const DOMElement* const elem,
const XMLCh* const typeStr);
/**
* Return the datatype validator for a given element type attribute if
* the type is a simple type
*/
DatatypeValidator* getElementTypeValidator(const DOMElement* const elem,
const XMLCh* const typeStr,
bool& noErrorDetected,
const XMLCh* const otherSchemaURI);
/**
* Return the complexType info for a given element type attribute if
* the type is a complex type
*/
ComplexTypeInfo* getElementComplexTypeInfo(const DOMElement* const elem,
const XMLCh* const typeStr,
const XMLCh* const otherSchemaURI);
/**
* Return global schema element declaration for a given element name
*/
SchemaElementDecl* getGlobalElemDecl(const DOMElement* const elem,
const XMLCh* const name);
/**
* Check validity constraint of a substitutionGroup attribute in
* an element declaration
*/
bool isSubstitutionGroupValid(const DOMElement* const elem,
const SchemaElementDecl* const elemDecl,
const ComplexTypeInfo* const typeInfo,
const DatatypeValidator* const validator,
const XMLCh* const elemName,
const bool toEmit = true);
bool isSubstitutionGroupCircular(SchemaElementDecl* const elemDecl,
SchemaElementDecl* const subsElemDecl);
void processSubstitutionGroup(const DOMElement* const elem,
SchemaElementDecl* const elemDecl,
ComplexTypeInfo*& typeInfo,
DatatypeValidator*& validator,
const XMLCh* const subsElemQName);
/**
* Create a 'SchemaElementDecl' object and add it to SchemaGrammar
*/
SchemaElementDecl* createSchemaElementDecl(const DOMElement* const elem,
const XMLCh* const name,
bool& isDuplicate,
const XMLCh*& valConstraint,
const bool topLevel);
/**
* Return the value of a given attribute name from an element node
*/
const XMLCh* getElementAttValue(const DOMElement* const elem,
const XMLCh* const attName,
const DatatypeValidator::ValidatorType attType = DatatypeValidator::UnKnown);
/* return minOccurs */
int checkMinMax(ContentSpecNode* const specNode,
const DOMElement* const elem,
const int allContext = Not_All_Context);
/**
* Process complex content for a complexType
*/
void processComplexContent(const DOMElement* const elem,
const XMLCh* const typeName,
const DOMElement* const childElem,
ComplexTypeInfo* const typeInfo,
const XMLCh* const baseLocalPart,
const bool isMixed,
const bool isBaseAnyType = false);
/**
* Process "base" information for a complexType
*/
void processBaseTypeInfo(const DOMElement* const elem,
const XMLCh* const baseName,
const XMLCh* const localPart,
const XMLCh* const uriStr,
ComplexTypeInfo* const typeInfo);
/**
* Check if base is from another schema
*/
bool isBaseFromAnotherSchema(const XMLCh* const baseURI);
/**
* Get complexType infp from another schema
*/
ComplexTypeInfo* getTypeInfoFromNS(const DOMElement* const elem,
const XMLCh* const uriStr,
const XMLCh* const localPart);
DatatypeValidator*
getAttrDatatypeValidatorNS(const DOMElement* const elem,
const XMLCh* localPart,
const XMLCh* typeURI);
/**
* Returns true if a DOM Element is an attribute or attribute group
*/
bool isAttrOrAttrGroup(const DOMElement* const elem);
/**
* Process attributes of a complex type
*/
void processAttributes(const DOMElement* const elem,
const DOMElement* const attElem,
ComplexTypeInfo* const typeInfo,
const bool isBaseAnyType = false);
/**
* Generate a name for an anonymous type
*/
const XMLCh* genAnonTypeName(const XMLCh* const prefix);
void defaultComplexTypeInfo(ComplexTypeInfo* const typeInfo);
/**
* Resolve a schema location attribute value to an input source.
* Caller to delete the returned object.
*/
InputSource* resolveSchemaLocation
(
const XMLCh* const loc
, const XMLResourceIdentifier::ResourceIdentifierType resourceIdentitiferType
, const XMLCh* const nameSpace=0
);
void restoreSchemaInfo(SchemaInfo* const toRestore,
SchemaInfo::ListType const aListType = SchemaInfo::INCLUDE,
const unsigned int saveScope = Grammar::TOP_LEVEL_SCOPE);
void popCurrentTypeNameStack();
/**
* Check whether a mixed content is emptiable or not.
* Needed to validate element constraint values (defualt, fixed)
*/
bool emptiableParticle(const ContentSpecNode* const specNode);
void checkFixedFacet(const DOMElement* const, const XMLCh* const,
const DatatypeValidator* const, unsigned int&);
void buildValidSubstitutionListF(const DOMElement* const elem,
SchemaElementDecl* const,
SchemaElementDecl* const);
void buildValidSubstitutionListB(const DOMElement* const elem,
SchemaElementDecl* const,
SchemaElementDecl* const);
void checkEnumerationRequiredNotation(const DOMElement* const elem,
const XMLCh* const name,
const XMLCh* const typeStr);
void processElements(const DOMElement* const elem,
ComplexTypeInfo* const baseTypeInfo,
ComplexTypeInfo* const newTypeInfo);
void processElements(const DOMElement* const elem,
XercesGroupInfo* const fromGroup,
ComplexTypeInfo* const typeInfo);
void copyGroupElements(const DOMElement* const elem,
XercesGroupInfo* const fromGroup,
XercesGroupInfo* const toGroup,
ComplexTypeInfo* const typeInfo);
void copyAttGroupAttributes(const DOMElement* const elem,
XercesAttGroupInfo* const fromAttGroup,
XercesAttGroupInfo* const toAttGroup,
ComplexTypeInfo* const typeInfo);
void checkForEmptyTargetNamespace(const DOMElement* const elem);
/**
* Attribute wild card intersection.
*
* Note:
* The first parameter will be the result of the intersection, so
* we need to make sure that first parameter is a copy of the
* actual attribute definition we need to intersect with.
*
* What we need to wory about is: type, defaultType, namespace,
* and URI. All remaining data members should be the same.
*/
void attWildCardIntersection(SchemaAttDef* const resultWildCart,
const SchemaAttDef* const toCompareWildCard);
/**
* Attribute wild card union.
*
* Note:
* The first parameter will be the result of the union, so
* we need to make sure that first parameter is a copy of the
* actual attribute definition we need to intersect with.
*
* What we need to wory about is: type, defaultType, namespace,
* and URI. All remaining data members should be the same.
*/
void attWildCardUnion(SchemaAttDef* const resultWildCart,
const SchemaAttDef* const toCompareWildCard);
void copyWildCardData(const SchemaAttDef* const srcWildCard,
SchemaAttDef* const destWildCard);
/**
* Check that the attributes of a type derived by restriction satisfy
* the constraints of derivation valid restriction
*/
void checkAttDerivationOK(const DOMElement* const elem,
const ComplexTypeInfo* const baseTypeInfo,
const ComplexTypeInfo* const childTypeInfo);
void checkAttDerivationOK(const DOMElement* const elem,
const XercesAttGroupInfo* const baseAttGrpInfo,
const XercesAttGroupInfo* const childAttGrpInfo);
/**
* Check whether a namespace value is valid with respect to wildcard
* constraint
*/
bool wildcardAllowsNamespace(const SchemaAttDef* const baseAttWildCard,
const unsigned int nameURI);
/**
* Check whether a namespace constraint is an intensional subset of
* another namespace constraint
*/
bool isWildCardSubset(const SchemaAttDef* const baseAttWildCard,
const SchemaAttDef* const childAttWildCard);
bool openRedefinedSchema(const DOMElement* const redefineElem);
/**
* The purpose of this method is twofold:
* 1. To find and appropriately modify all information items
* in redefinedSchema with names that are redefined by children of
* redefineElem.
* 2. To make sure the redefine element represented by
* redefineElem is valid as far as content goes and with regard to
* properly referencing components to be redefined.
*
* No traversing is done here!
* This method also takes actions to find and, if necessary, modify
* the names of elements in <redefine>'s in the schema that's being
* redefined.
*/
void renameRedefinedComponents(const DOMElement* const redefineElem,
SchemaInfo* const redefiningSchemaInfo,
SchemaInfo* const redefinedSchemaInfo);
/**
* This method returns true if the redefine component is valid, and if
* it was possible to revise it correctly.
*/
bool validateRedefineNameChange(const DOMElement* const redefineChildElem,
const XMLCh* const redefineChildElemName,
const XMLCh* const redefineChildDeclName,
const int redefineNameCounter,
SchemaInfo* const redefiningSchemaInfo);
/**
* This function looks among the children of 'redefineChildElem' for a
* component of type 'redefineChildComponentName'. If it finds one, it
* evaluates whether its ref attribute contains a reference to
* 'refChildTypeName'. If it does, it returns 1 + the value returned by
* calls to itself on all other children. In all other cases it returns
* 0 plus the sum of the values returned by calls to itself on
* redefineChildElem's children. It also resets the value of ref so that
* it will refer to the renamed type from the schema being redefined.
*/
int changeRedefineGroup(const DOMElement* const redefineChildElem,
const XMLCh* const redefineChildComponentName,
const XMLCh* const redefineChildTypeName,
const int redefineNameCounter);
/** This simple function looks for the first occurrence of a
* 'redefineChildTypeName' item in the redefined schema and appropriately
* changes the value of its name. If it turns out that what we're looking
* for is in a <redefine> though, then we just rename it--and it's
* reference--to be the same.
*/
void fixRedefinedSchema(const DOMElement* const elem,
SchemaInfo* const redefinedSchemaInfo,
const XMLCh* const redefineChildComponentName,
const XMLCh* const redefineChildTypeName,
const int redefineNameCounter);
void getRedefineNewTypeName(const XMLCh* const oldTypeName,
const int redefineCounter,
XMLBuffer& newTypeName);
/**
* This purpose of this method is threefold:
* 1. To extract the schema information of included/redefined schema.
* 2. Rename redefined components.
* 3. Process components of included/redefined schemas
*/
void preprocessRedefineInclude(SchemaInfo* const currSchemaInfo);
/**
* Update the list of valid substitution groups in the case of circular
* import.
*/
void updateCircularSubstitutionList(SchemaInfo* const aSchemaInfo);
void processKeyRefFor(SchemaInfo* const aSchemaInfo,
ValueVectorOf<SchemaInfo*>* const infoList);
void processAttValue(const XMLCh* const attVal, XMLBuffer& aBuf);
// routine to generate synthetic annotations
XSAnnotation* generateSyntheticAnnotation(const DOMElement* const elem
, ValueVectorOf<DOMNode*>* nonXSAttList);
// routine to validate annotations
void validateAnnotations();
// -----------------------------------------------------------------------
// Private constants
// -----------------------------------------------------------------------
enum
{
ES_Block
, C_Block
, S_Final
, EC_Final
, ECS_Final
};
enum ExceptionCodes
{
NoException = 0,
InvalidComplexTypeInfo = 1,
RecursingElement = 2
};
enum
{
Elem_Def_Qualified = 1,
Attr_Def_Qualified = 2
};
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
bool fFullConstraintChecking;
int fTargetNSURI;
int fEmptyNamespaceURI;
unsigned int fCurrentScope;
unsigned int fScopeCount;
unsigned int fAnonXSTypeCount;
XMLSize_t fCircularCheckIndex;
const XMLCh* fTargetNSURIString;
DatatypeValidatorFactory* fDatatypeRegistry;
GrammarResolver* fGrammarResolver;
SchemaGrammar* fSchemaGrammar;
XMLEntityHandler* fEntityHandler;
XMLErrorReporter* fErrorReporter;
XMLStringPool* fURIStringPool;
XMLStringPool* fStringPool;
XMLBuffer fBuffer;
XMLScanner* fScanner;
RefHashTableOf<XMLAttDef>* fAttributeDeclRegistry;
RefHashTableOf<ComplexTypeInfo>* fComplexTypeRegistry;
RefHashTableOf<XercesGroupInfo>* fGroupRegistry;
RefHashTableOf<XercesAttGroupInfo>* fAttGroupRegistry;
RefHashTableOf<ElemVector>* fIC_ElementsNS;
RefHashTableOf<SchemaInfo, PtrHasher>* fPreprocessedNodes;
SchemaInfo* fSchemaInfo;
XercesGroupInfo* fCurrentGroupInfo;
XercesAttGroupInfo* fCurrentAttGroupInfo;
ComplexTypeInfo* fCurrentComplexType;
ValueVectorOf<unsigned int>* fCurrentTypeNameStack;
ValueVectorOf<unsigned int>* fCurrentGroupStack;
ValueVectorOf<SchemaElementDecl*>* fIC_Elements;
ValueVectorOf<const DOMElement*>* fDeclStack;
ValueVectorOf<unsigned int>** fGlobalDeclarations;
ValueVectorOf<DOMNode*>* fNonXSAttList;
ValueVectorOf<int>* fImportedNSList;
RefHashTableOf<ValueVectorOf<DOMElement*>, PtrHasher>* fIC_NodeListNS;
RefHash2KeysTableOf<XMLCh>* fNotationRegistry;
RefHash2KeysTableOf<XMLCh>* fRedefineComponents;
RefHash2KeysTableOf<IdentityConstraint>* fIdentityConstraintNames;
RefHash2KeysTableOf<ElemVector>* fValidSubstitutionGroups;
RefHash2KeysTableOf<SchemaInfo>* fSchemaInfoList;
RefHash2KeysTableOf<SchemaInfo>* fCachedSchemaInfoList;
XSDDOMParser* fParser;
XSDErrorReporter fXSDErrorReporter;
XSDLocator* fLocator;
MemoryManager* fMemoryManager;
MemoryManager* fGrammarPoolMemoryManager;
XSAnnotation* fAnnotation;
GeneralAttributeCheck fAttributeCheck;
friend class GeneralAttributeCheck;
friend class NamespaceScopeManager;
};
// ---------------------------------------------------------------------------
// TraverseSchema: Helper methods
// ---------------------------------------------------------------------------
inline const XMLCh* TraverseSchema::getPrefix(const XMLCh* const rawName) {
int colonIndex = XMLString::indexOf(rawName, chColon);
if (colonIndex == -1 || colonIndex == 0) {
return XMLUni::fgZeroLenString;
}
fBuffer.set(rawName, colonIndex);
return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
}
inline const XMLCh* TraverseSchema::getLocalPart(const XMLCh* const rawName) {
int colonIndex = XMLString::indexOf(rawName, chColon);
XMLSize_t rawNameLen = XMLString::stringLen(rawName);
if (XMLSize_t(colonIndex + 1) == rawNameLen) {
return XMLUni::fgZeroLenString;
}
if (colonIndex == -1) {
fBuffer.set(rawName, rawNameLen);
}
else {
fBuffer.set(rawName + colonIndex + 1, rawNameLen - colonIndex - 1);
}
return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
}
inline void
TraverseSchema::checkForEmptyTargetNamespace(const DOMElement* const elem) {
const XMLCh* targetNS = getElementAttValue(elem, SchemaSymbols::fgATT_TARGETNAMESPACE);
if (targetNS && !*targetNS) {
reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidTargetNSValue);
}
}
inline bool TraverseSchema::isBaseFromAnotherSchema(const XMLCh* const baseURI)
{
if (!XMLString::equals(baseURI,fTargetNSURIString)
&& !XMLString::equals(baseURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA)
&& (baseURI && *baseURI)) {
//REVISIT, !!!! a hack: for schema that has no
//target namespace, e.g. personal-schema.xml
return true;
}
return false;
}
inline bool TraverseSchema::isAttrOrAttrGroup(const DOMElement* const elem) {
const XMLCh* elementName = elem->getLocalName();
if (XMLString::equals(elementName, SchemaSymbols::fgELT_ATTRIBUTE) ||
XMLString::equals(elementName, SchemaSymbols::fgELT_ATTRIBUTEGROUP) ||
XMLString::equals(elementName, SchemaSymbols::fgELT_ANYATTRIBUTE)) {
return true;
}
return false;
}
inline const XMLCh* TraverseSchema::genAnonTypeName(const XMLCh* const prefix) {
XMLCh anonCountStr[16]; // a count of 15 digits should be enough
XMLString::sizeToText(fAnonXSTypeCount++, anonCountStr, 15, 10, fMemoryManager);
fBuffer.set(prefix);
fBuffer.append(anonCountStr);
return fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
}
inline void TraverseSchema::popCurrentTypeNameStack() {
XMLSize_t stackSize = fCurrentTypeNameStack->size();
if (stackSize != 0) {
fCurrentTypeNameStack->removeElementAt(stackSize - 1);
}
}
inline void
TraverseSchema::copyWildCardData(const SchemaAttDef* const srcWildCard,
SchemaAttDef* const destWildCard) {
destWildCard->getAttName()->setURI(srcWildCard->getAttName()->getURI());
destWildCard->setType(srcWildCard->getType());
destWildCard->setDefaultType(srcWildCard->getDefaultType());
}
inline void TraverseSchema::getRedefineNewTypeName(const XMLCh* const oldTypeName,
const int redefineCounter,
XMLBuffer& newTypeName) {
newTypeName.set(oldTypeName);
for (int i=0; i < redefineCounter; i++) {
newTypeName.append(SchemaSymbols::fgRedefIdentifier);
}
}
inline bool TraverseSchema::isImportingNS(const int namespaceURI) {
if (!fImportedNSList)
return false;
return (fImportedNSList->containsElement(namespaceURI));
}
inline void TraverseSchema::addImportedNS(const int namespaceURI) {
if (!fImportedNSList) {
fImportedNSList = new (fMemoryManager) ValueVectorOf<int>(4, fMemoryManager);
}
if (!fImportedNSList->containsElement(namespaceURI))
fImportedNSList->addElement(namespaceURI);
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file TraverseSchema.hpp
*/
@@ -0,0 +1,235 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XMLSchemaDescriptionImpl.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
#include <xercesc/util/QName.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// XMLSchemaDescriptionImpl: constructor and destructor
// ---------------------------------------------------------------------------
XMLSchemaDescriptionImpl::XMLSchemaDescriptionImpl(const XMLCh* const targetNamespace
, MemoryManager* const memMgr)
:XMLSchemaDescription(memMgr)
,fContextType(CONTEXT_UNKNOWN)
,fNamespace(0)
,fLocationHints(0)
,fTriggeringComponent(0)
,fEnclosingElementName(0)
,fAttributes(0)
{
if (targetNamespace)
fNamespace = XMLString::replicate(targetNamespace, memMgr);
fLocationHints = new (memMgr) RefArrayVectorOf<XMLCh>(4, true, memMgr);
/***
fAttributes
***/
}
XMLSchemaDescriptionImpl::~XMLSchemaDescriptionImpl()
{
if (fNamespace)
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
if (fLocationHints)
delete fLocationHints;
if (fTriggeringComponent)
delete fTriggeringComponent;
if (fEnclosingElementName)
delete fEnclosingElementName;
}
const XMLCh* XMLSchemaDescriptionImpl::getGrammarKey() const
{
return getTargetNamespace();
}
XMLSchemaDescription::ContextType XMLSchemaDescriptionImpl::getContextType() const
{
return fContextType;
}
const XMLCh* XMLSchemaDescriptionImpl::getTargetNamespace() const
{
return fNamespace;
}
const RefArrayVectorOf<XMLCh>* XMLSchemaDescriptionImpl::getLocationHints() const
{
return fLocationHints;
}
const QName* XMLSchemaDescriptionImpl::getTriggeringComponent() const
{
return fTriggeringComponent;
}
const QName* XMLSchemaDescriptionImpl::getEnclosingElementName() const
{
return fEnclosingElementName;
}
const XMLAttDef* XMLSchemaDescriptionImpl::getAttributes() const
{
return fAttributes;
}
void XMLSchemaDescriptionImpl::setContextType(ContextType type)
{
fContextType = type;
}
void XMLSchemaDescriptionImpl::setTargetNamespace(const XMLCh* const newNamespace)
{
if (fNamespace) {
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
fNamespace = 0;
}
fNamespace = XMLString::replicate(newNamespace, XMLGrammarDescription::getMemoryManager());
}
void XMLSchemaDescriptionImpl::setLocationHints(const XMLCh* const hint)
{
fLocationHints->addElement(XMLString::replicate(hint, XMLGrammarDescription::getMemoryManager()));
}
void XMLSchemaDescriptionImpl::setTriggeringComponent(QName* const trigComponent)
{
if ( fTriggeringComponent) {
delete fTriggeringComponent;
fTriggeringComponent = 0;
}
fTriggeringComponent = new (trigComponent->getMemoryManager()) QName(*trigComponent);
}
void XMLSchemaDescriptionImpl::setEnclosingElementName(QName* const encElement)
{
if (fEnclosingElementName) {
delete fEnclosingElementName;
fEnclosingElementName = 0;
}
fEnclosingElementName = new (encElement->getMemoryManager()) QName(*encElement);
}
void XMLSchemaDescriptionImpl::setAttributes(XMLAttDef* const attDefs)
{
// XMLAttDef is part of the grammar that this description refers to
// so we reference to it instead of adopting/owning/cloning.
fAttributes = attDefs;
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(XMLSchemaDescriptionImpl)
void XMLSchemaDescriptionImpl::serialize(XSerializeEngine& serEng)
{
XMLSchemaDescription::serialize(serEng);
if (serEng.isStoring())
{
serEng<<(int)fContextType;
serEng.writeString(fNamespace);
/***
*
* Serialize RefArrayVectorOf<XMLCh>* fLocationHints;
*
***/
XTemplateSerializer::storeObject(fLocationHints, serEng);
QName* tempQName = (QName*)fTriggeringComponent;
serEng<<tempQName;
tempQName = (QName*)fEnclosingElementName;
serEng<<tempQName;
XMLAttDef* tempAttDef = (XMLAttDef*)fAttributes;
serEng<<tempAttDef;
}
else
{
int i;
serEng>>i;
fContextType = (ContextType)i;
//the original fNamespace which came from the ctor needs deallocated
if (fNamespace)
{
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
}
serEng.readString((XMLCh*&)fNamespace);
/***
*
* Deserialize RefArrayVectorOf<XMLCh> fLocationHints
*
***/
XTemplateSerializer::loadObject(&fLocationHints, 4, true, serEng);
QName* tempQName;
serEng>>tempQName;
fTriggeringComponent = tempQName;
serEng>>tempQName;
fEnclosingElementName = tempQName;
XMLAttDef* tempAttDef;
serEng>>tempAttDef;
fAttributes=tempAttDef;
}
}
XMLSchemaDescriptionImpl::XMLSchemaDescriptionImpl(MemoryManager* const memMgr)
:XMLSchemaDescription(memMgr)
,fContextType(CONTEXT_UNKNOWN)
,fNamespace(0)
,fLocationHints(0)
,fTriggeringComponent(0)
,fEnclosingElementName(0)
,fAttributes(0)
{
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,185 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XMLSchemaDescriptionImpl.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XMLSCHEMADESCRIPTIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_XMLSCHEMADESCRIPTIONIMPL_HPP
#include <xercesc/framework/XMLSchemaDescription.hpp>
#include <xercesc/util/RefVectorOf.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLAttDefs;
class XMLPARSER_EXPORT XMLSchemaDescriptionImpl : public XMLSchemaDescription
{
public :
// -----------------------------------------------------------------------
/** @name constructor and destructor */
// -----------------------------------------------------------------------
//@{
XMLSchemaDescriptionImpl(
const XMLCh* const targetNamespace
, MemoryManager* const memMgr
);
~XMLSchemaDescriptionImpl();
//@}
// -----------------------------------------------------------------------
/** @name Implementation of GrammarDescription Interface */
// -----------------------------------------------------------------------
//@{
/**
* getGrammarKey
*
*/
virtual const XMLCh* getGrammarKey() const;
//@}
// -----------------------------------------------------------------------
/** @name Implementation of SchemaDescription Interface */
// -----------------------------------------------------------------------
//@{
/**
* getContextType
*
*/
virtual ContextType getContextType() const;
/**
* getTargetNamespace
*
*/
virtual const XMLCh* getTargetNamespace() const;
/**
* getLocationHints
*
*/
virtual const RefArrayVectorOf<XMLCh>* getLocationHints() const;
/**
* getTriggeringComponent
*
*/
virtual const QName* getTriggeringComponent() const;
/**
* getenclosingElementName
*
*/
virtual const QName* getEnclosingElementName() const;
/**
* getAttributes
*
*/
virtual const XMLAttDef* getAttributes() const;
/**
* setContextType
*
*/
virtual void setContextType(ContextType);
/**
* setTargetNamespace
*
*/
virtual void setTargetNamespace(const XMLCh* const);
/**
* setLocationHints
*
*/
virtual void setLocationHints(const XMLCh* const);
/**
* setTriggeringComponent
*
*/
virtual void setTriggeringComponent(QName* const);
/**
* getenclosingElementName
*
*/
virtual void setEnclosingElementName(QName* const);
/**
* setAttributes
*
*/
virtual void setAttributes(XMLAttDef* const);
//@}
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XMLSchemaDescriptionImpl)
XMLSchemaDescriptionImpl(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager);
private :
// -----------------------------------------------------------------------
/** name Unimplemented copy constructor and operator= */
// -----------------------------------------------------------------------
//@{
XMLSchemaDescriptionImpl(const XMLSchemaDescriptionImpl& );
XMLSchemaDescriptionImpl& operator=(const XMLSchemaDescriptionImpl& );
//@}
// -----------------------------------------------------------------------
// Private data members
//
// All data member in this implementation are owned to out survive
// parser. Except for fNamespace which is replicated upon set, the
// rest shall be created by the embedded memoryManager.
//
// fContextType
//
// fNamespace owned
//
// fLocationHints owned
//
// fTriggeringComponent owned
//
// fEnclosingElementName owned
//
// fAttributes referenced
//
// -----------------------------------------------------------------------
XMLSchemaDescription::ContextType fContextType;
const XMLCh* fNamespace;
RefArrayVectorOf<XMLCh>* fLocationHints;
const QName* fTriggeringComponent;
const QName* fEnclosingElementName;
const XMLAttDef* fAttributes;
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,524 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* $Id: XSDDOMParser.cpp 729944 2008-12-29 17:03:32Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/XSDDOMParser.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp>
#include <xercesc/internal/XMLScanner.hpp>
#include <xercesc/internal/ElemStack.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/impl/DOMElementImpl.hpp>
#include <xercesc/dom/impl/DOMAttrImpl.hpp>
#include <xercesc/dom/impl/DOMTextImpl.hpp>
#include <xercesc/framework/XMLValidityCodes.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// XSDDOMParser: Constructors and Destructor
// ---------------------------------------------------------------------------
XSDDOMParser::XSDDOMParser( XMLValidator* const valToAdopt
, MemoryManager* const manager
, XMLGrammarPool* const gramPool):
XercesDOMParser(valToAdopt, manager, gramPool)
, fSawFatal(false)
, fAnnotationDepth(-1)
, fInnerAnnotationDepth(-1)
, fDepth(-1)
, fUserErrorReporter(0)
, fUserEntityHandler(0)
, fURIs(0)
, fAnnotationBuf(1023, manager)
{
fURIs = new (manager) ValueVectorOf<unsigned int>(16, manager);
fXSDErrorReporter.setErrorReporter(this);
setValidationScheme(XercesDOMParser::Val_Never);
setDoNamespaces(true);
}
XSDDOMParser::~XSDDOMParser()
{
delete fURIs;
}
// ---------------------------------------------------------------------------
// XSDDOMParser: Helper methods
// ---------------------------------------------------------------------------
DOMElement* XSDDOMParser::createElementNSNode(const XMLCh *namespaceURI,
const XMLCh *qualifiedName)
{
ReaderMgr::LastExtEntityInfo lastInfo;
((ReaderMgr*) fScanner->getLocator())->getLastExtEntityInfo(lastInfo);
return getDocument()->createElementNS(namespaceURI, qualifiedName,
lastInfo.lineNumber, lastInfo.colNumber);
}
void XSDDOMParser::startAnnotation( const XMLElementDecl& elemDecl
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount)
{
fAnnotationBuf.append(chOpenAngle);
fAnnotationBuf.append(elemDecl.getFullName());
fAnnotationBuf.append(chSpace);
// attributes are a bit of a pain. To get this right, we have to keep track
// of the namespaces we've seen declared, then examine the namespace context
// for other namespaces so that we can also include them.
// optimized for simplicity and the case that not many
// namespaces are declared on this annotation...
fURIs->removeAllElements();
for (XMLSize_t i=0; i < attrCount; i++) {
const XMLAttr* oneAttrib = attrList.elementAt(i);
const XMLCh* attrValue = oneAttrib->getValue();
if (XMLString::equals(oneAttrib->getName(), XMLUni::fgXMLNSString))
fURIs->addElement(fScanner->getPrefixId(XMLUni::fgZeroLenString));
else if (!XMLString::compareNString(oneAttrib->getQName(), XMLUni::fgXMLNSColonString, 6))
fURIs->addElement(fScanner->getPrefixId(oneAttrib->getName()));
fAnnotationBuf.append(oneAttrib->getQName());
fAnnotationBuf.append(chEqual);
fAnnotationBuf.append(chDoubleQuote);
fAnnotationBuf.append(attrValue);
fAnnotationBuf.append(chDoubleQuote);
fAnnotationBuf.append(chSpace);
}
// now we have to look through currently in-scope namespaces to see what
// wasn't declared here
ValueVectorOf<PrefMapElem*>* namespaceContext = fScanner->getNamespaceContext();
for (XMLSize_t j=0; j < namespaceContext->size(); j++)
{
unsigned int prefId = namespaceContext->elementAt(j)->fPrefId;
if (!fURIs->containsElement(prefId)) {
const XMLCh* prefix = fScanner->getPrefixForId(prefId);
if (XMLString::equals(prefix, XMLUni::fgZeroLenString)) {
fAnnotationBuf.append(XMLUni::fgXMLNSString);
}
else {
fAnnotationBuf.append(XMLUni::fgXMLNSColonString);
fAnnotationBuf.append(prefix);
}
fAnnotationBuf.append(chEqual);
fAnnotationBuf.append(chDoubleQuote);
fAnnotationBuf.append(fScanner->getURIText(namespaceContext->elementAt(j)->fURIId));
fAnnotationBuf.append(chDoubleQuote);
fAnnotationBuf.append(chSpace);
fURIs->addElement(prefId);
}
}
fAnnotationBuf.append(chCloseAngle);
fAnnotationBuf.append(chLF);
}
void XSDDOMParser::startAnnotationElement( const XMLElementDecl& elemDecl
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount)
{
fAnnotationBuf.append(chOpenAngle);
fAnnotationBuf.append(elemDecl.getFullName());
//fAnnotationBuf.append(chSpace);
for(XMLSize_t i=0; i < attrCount; i++) {
const XMLAttr* oneAttr = attrList.elementAt(i);
fAnnotationBuf.append(chSpace);
fAnnotationBuf.append(oneAttr ->getQName());
fAnnotationBuf.append(chEqual);
fAnnotationBuf.append(chDoubleQuote);
fAnnotationBuf.append(oneAttr->getValue());
fAnnotationBuf.append(chDoubleQuote);
}
fAnnotationBuf.append(chCloseAngle);
}
void XSDDOMParser::endAnnotationElement( const XMLElementDecl& elemDecl
, bool complete)
{
if (complete)
{
fAnnotationBuf.append(chLF);
fAnnotationBuf.append(chOpenAngle);
fAnnotationBuf.append(chForwardSlash);
fAnnotationBuf.append(elemDecl.getFullName());
fAnnotationBuf.append(chCloseAngle);
// note that this is always called after endElement on <annotation>'s
// child and before endElement on annotation.
// hence, we must make this the child of the current
// parent's only child.
DOMTextImpl *node = (DOMTextImpl *)fDocument->createTextNode(fAnnotationBuf.getRawBuffer());
fCurrentNode->appendChild(node);
fAnnotationBuf.reset();
}
else //capturing character calls
{
fAnnotationBuf.append(chOpenAngle);
fAnnotationBuf.append(chForwardSlash);
fAnnotationBuf.append(elemDecl.getFullName());
fAnnotationBuf.append(chCloseAngle);
}
}
// ---------------------------------------------------------------------------
// XSDDOMParser: Setter methods
// ---------------------------------------------------------------------------
void XSDDOMParser::setUserErrorReporter(XMLErrorReporter* const errorReporter)
{
fUserErrorReporter = errorReporter;
fScanner->setErrorReporter(this);
}
void XSDDOMParser::setUserEntityHandler(XMLEntityHandler* const entityHandler)
{
fUserEntityHandler = entityHandler;
fScanner->setEntityHandler(this);
}
// ---------------------------------------------------------------------------
// XSDDOMParser: Implementation of the XMLDocumentHandler interface
// ---------------------------------------------------------------------------
void XSDDOMParser::startElement( const XMLElementDecl& elemDecl
, const unsigned int urlId
, const XMLCh* const elemPrefix
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount
, const bool isEmpty
, const bool isRoot)
{
fDepth++;
// while it is true that non-whitespace character data
// may only occur in appInfo or documentation
// elements, it's certainly legal for comments and PI's to
// occur as children of annotation; we need
// to account for these here.
if (fAnnotationDepth == -1)
{
if (XMLString::equals(elemDecl.getBaseName(), SchemaSymbols::fgELT_ANNOTATION) &&
XMLString::equals(getURIText(urlId), SchemaSymbols::fgURI_SCHEMAFORSCHEMA))
{
fAnnotationDepth = fDepth;
startAnnotation(elemDecl, attrList, attrCount);
}
}
else if (fDepth == fAnnotationDepth+1)
{
fInnerAnnotationDepth = fDepth;
startAnnotationElement(elemDecl, attrList, attrCount);
}
else
{
startAnnotationElement(elemDecl, attrList, attrCount);
if(isEmpty)
endElement(elemDecl, urlId, isRoot, elemPrefix);
// avoid falling through; don't call startElement in this case
return;
}
DOMElement *elem;
if (urlId != fScanner->getEmptyNamespaceId()) //TagName has a prefix
{
if (elemPrefix && *elemPrefix)
{
XMLBufBid elemQName(&fBufMgr);
elemQName.set(elemPrefix);
elemQName.append(chColon);
elemQName.append(elemDecl.getBaseName());
elem = createElementNSNode(
fScanner->getURIText(urlId), elemQName.getRawBuffer());
}
else {
elem = createElementNSNode(
fScanner->getURIText(urlId), elemDecl.getBaseName());
}
}
else {
elem = createElementNSNode(0, elemDecl.getBaseName());
}
DOMElementImpl *elemImpl = (DOMElementImpl *) elem;
for (XMLSize_t index = 0; index < attrCount; ++index)
{
const XMLAttr* oneAttrib = attrList.elementAt(index);
unsigned int attrURIId = oneAttrib->getURIId();
const XMLCh* namespaceURI = 0;
//for xmlns=...
if (XMLString::equals(oneAttrib->getName(), XMLUni::fgXMLNSString))
attrURIId = fScanner->getXMLNSNamespaceId();
//TagName has a prefix
if (attrURIId != fScanner->getEmptyNamespaceId())
namespaceURI = fScanner->getURIText(attrURIId); //get namespaceURI
// revisit. Optimize to init the named node map to the
// right size up front.
DOMAttrImpl *attr = (DOMAttrImpl *)
fDocument->createAttributeNS(namespaceURI, oneAttrib->getQName());
attr->setValue(oneAttrib -> getValue());
DOMNode* remAttr = elemImpl->setAttributeNodeNS(attr);
if (remAttr)
remAttr->release();
// Attributes of type ID. If this is one, add it to the hashtable of IDs
// that is constructed for use by GetElementByID().
if (oneAttrib->getType()==XMLAttDef::ID)
{
if (fDocument->fNodeIDMap == 0)
fDocument->fNodeIDMap = new (fDocument) DOMNodeIDMap(500, fDocument);
fDocument->fNodeIDMap->add(attr);
attr->fNode.isIdAttr(true);
}
attr->setSpecified(oneAttrib->getSpecified());
}
// set up the default attributes
if (elemDecl.hasAttDefs())
{
XMLAttDefList* defAttrs = &elemDecl.getAttDefList();
XMLAttDef* attr = 0;
DOMAttrImpl * insertAttr = 0;
for (XMLSize_t i=0; i<defAttrs->getAttDefCount(); i++)
{
attr = &defAttrs->getAttDef(i);
const XMLAttDef::DefAttTypes defType = attr->getDefaultType();
if ((defType == XMLAttDef::Default)
|| (defType == XMLAttDef::Fixed))
{
// DOM Level 2 wants all namespace declaration attributes
// to be bound to "http://www.w3.org/2000/xmlns/"
// So as long as the XML parser doesn't do it, it needs to
// done here.
const XMLCh* qualifiedName = attr->getFullName();
XMLBufBid bbPrefixQName(&fBufMgr);
XMLBuffer& prefixBuf = bbPrefixQName.getBuffer();
int colonPos = -1;
unsigned int uriId = fScanner->resolveQName(qualifiedName, prefixBuf, ElemStack::Mode_Attribute, colonPos);
const XMLCh* namespaceURI = 0;
if (XMLString::equals(qualifiedName, XMLUni::fgXMLNSString))
uriId = fScanner->getXMLNSNamespaceId();
//TagName has a prefix
if (uriId != fScanner->getEmptyNamespaceId())
namespaceURI = fScanner->getURIText(uriId);
insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS(
namespaceURI, qualifiedName);
DOMAttr* remAttr = elemImpl->setDefaultAttributeNodeNS(insertAttr);
if (remAttr)
remAttr->release();
if (attr->getValue() != 0)
{
insertAttr->setValue(attr->getValue());
insertAttr->setSpecified(false);
}
}
insertAttr = 0;
attr->reset();
}
}
fCurrentParent->appendChild(elem);
fCurrentParent = elem;
fCurrentNode = elem;
fWithinElement = true;
// If an empty element, do end right now (no endElement() will be called)
if (isEmpty)
endElement(elemDecl, urlId, isRoot, elemPrefix);
}
void XSDDOMParser::endElement( const XMLElementDecl& elemDecl
, const unsigned int
, const bool
, const XMLCh* const)
{
if(fAnnotationDepth > -1)
{
if (fInnerAnnotationDepth == fDepth)
{
fInnerAnnotationDepth = -1;
endAnnotationElement(elemDecl, false);
}
else if (fAnnotationDepth == fDepth)
{
fAnnotationDepth = -1;
endAnnotationElement(elemDecl, true);
}
else
{ // inside a child of annotation
endAnnotationElement(elemDecl, false);
fDepth--;
return;
}
}
fDepth--;
fCurrentNode = fCurrentParent;
fCurrentParent = fCurrentNode->getParentNode ();
// If we've hit the end of content, clear the flag.
//
if (fCurrentParent == fDocument)
fWithinElement = false;
}
void XSDDOMParser::docCharacters( const XMLCh* const chars
, const XMLSize_t length
, const bool cdataSection)
{
// Ignore chars outside of content
if (!fWithinElement)
return;
if (fInnerAnnotationDepth == -1)
{
if (!((ReaderMgr*) fScanner->getReaderMgr())->getCurrentReader()->isAllSpaces(chars, length))
{
ReaderMgr::LastExtEntityInfo lastInfo;
fScanner->getReaderMgr()->getLastExtEntityInfo(lastInfo);
fXSLocator.setValues(lastInfo.systemId, lastInfo.publicId, lastInfo.lineNumber, lastInfo.colNumber);
fXSDErrorReporter.emitError(XMLValid::NonWSContent, XMLUni::fgValidityDomain, &fXSLocator);
}
}
// when it's within either of the 2 annotation subelements, characters are
// allowed and we need to store them.
else if (cdataSection == true)
{
fAnnotationBuf.append(XMLUni::fgCDataStart);
fAnnotationBuf.append(chars, length);
fAnnotationBuf.append(XMLUni::fgCDataEnd);
}
else
{
for(unsigned int i = 0; i < length; i++ )
{
if(chars[i] == chAmpersand)
{
fAnnotationBuf.append(chAmpersand);
fAnnotationBuf.append(XMLUni::fgAmp);
fAnnotationBuf.append(chSemiColon);
}
else if (chars[i] == chOpenAngle)
{
fAnnotationBuf.append(chAmpersand);
fAnnotationBuf.append(XMLUni::fgLT);
fAnnotationBuf.append(chSemiColon);
}
else {
fAnnotationBuf.append(chars[i]);
}
}
}
}
void XSDDOMParser::docComment(const XMLCh* const comment)
{
if (fAnnotationDepth > -1)
{
fAnnotationBuf.append(XMLUni::fgCommentString);
fAnnotationBuf.append(comment);
fAnnotationBuf.append(chDash);
fAnnotationBuf.append(chDash);
fAnnotationBuf.append(chCloseAngle);
}
}
void XSDDOMParser::startEntityReference(const XMLEntityDecl&)
{
}
void XSDDOMParser::endEntityReference(const XMLEntityDecl&)
{
}
void XSDDOMParser::ignorableWhitespace( const XMLCh* const chars
, const XMLSize_t length
, const bool)
{
// Ignore chars before the root element
if (!fWithinElement || !fIncludeIgnorableWhitespace)
return;
if (fAnnotationDepth > -1)
fAnnotationBuf.append(chars, length);
}
// ---------------------------------------------------------------------------
// XSDDOMParser: Implementation of the XMLErrorReporter interface
// ---------------------------------------------------------------------------
void XSDDOMParser::error(const unsigned int code
, const XMLCh* const msgDomain
, const XMLErrorReporter::ErrTypes errType
, const XMLCh* const errorText
, const XMLCh* const systemId
, const XMLCh* const publicId
, const XMLFileLoc lineNum
, const XMLFileLoc colNum)
{
if (errType >= XMLErrorReporter::ErrType_Fatal)
fSawFatal = true;
if (fUserErrorReporter)
fUserErrorReporter->error(code, msgDomain, errType, errorText,
systemId, publicId, lineNum, colNum);
}
InputSource*
XSDDOMParser::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
{
if (fUserEntityHandler)
return fUserEntityHandler->resolveEntity(resourceIdentifier);
return 0;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,322 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XSDDOMParser.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XSDDOMPARSER_HPP)
#define XERCESC_INCLUDE_GUARD_XSDDOMPARSER_HPP
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/validators/schema/XSDErrorReporter.hpp>
#include <xercesc/validators/schema/XSDLocator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMElement;
class XMLValidator;
/**
* This class is used to parse schema documents into DOM trees
*/
class PARSERS_EXPORT XSDDOMParser : public XercesDOMParser
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
/** @name Constructors and Destructor */
//@{
/** Construct a XSDDOMParser, with an optional validator
*
* Constructor with an instance of validator class to use for
* validation. If you don't provide a validator, a default one will
* be created for you in the scanner.
*
* @param gramPool Pointer to the grammar pool instance from
* external application.
* The parser does NOT own it.
*
* @param valToAdopt Pointer to the validator instance to use. The
* parser is responsible for freeing the memory.
*/
XSDDOMParser
(
XMLValidator* const valToAdopt = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
, XMLGrammarPool* const gramPool = 0
);
/**
* Destructor
*/
~XSDDOMParser();
//@}
// -----------------------------------------------------------------------
// Implementation of the XMLDocumentHandler interface.
// -----------------------------------------------------------------------
/** @name Implementation of the XMLDocumentHandler interface. */
//@{
/** Handle a start element event
*
* This method is used to report the start of an element. It is
* called at the end of the element, by which time all attributes
* specified are also parsed. A new DOM Element node is created
* along with as many attribute nodes as required. This new element
* is added appended as a child of the current node in the tree, and
* then replaces it as the current node (if the isEmpty flag is false.)
*
* @param elemDecl A const reference to the object containing element
* declaration information.
* @param urlId An id referring to the namespace prefix, if
* namespaces setting is switched on.
* @param elemPrefix A const pointer to a Unicode string containing
* the namespace prefix for this element. Applicable
* only when namespace processing is enabled.
* @param attrList A const reference to the object containing the
* list of attributes just scanned for this element.
* @param attrCount A count of number of attributes in the list
* specified by the parameter 'attrList'.
* @param isEmpty A flag indicating whether this is an empty element
* or not. If empty, then no endElement() call will
* be made.
* @param isRoot A flag indicating whether this element was the
* root element.
* @see DocumentHandler#startElement
*/
virtual void startElement
(
const XMLElementDecl& elemDecl
, const unsigned int urlId
, const XMLCh* const elemPrefix
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount
, const bool isEmpty
, const bool isRoot
);
/** Handle and end of element event
*
* This method is used to indicate the end tag of an element. The
* DOM parser pops the current element off the top of the element
* stack, and make it the new current element.
*
* @param elemDecl A const reference to the object containing element
* declaration information.
* @param urlId An id referring to the namespace prefix, if
* namespaces setting is switched on.
* @param isRoot A flag indicating whether this element was the
* root element.
* @param elemPrefix A const pointer to a Unicode string containing
* the namespace prefix for this element. Applicable
* only when namespace processing is enabled.
*/
virtual void endElement
(
const XMLElementDecl& elemDecl
, const unsigned int urlId
, const bool isRoot
, const XMLCh* const elemPrefix
);
/** Handle document character events
*
* This method is used to report all the characters scanned by the
* parser. This DOM implementation stores this data in the appropriate
* DOM node, creating one if necessary.
*
* @param chars A const pointer to a Unicode string representing the
* character data.
* @param length The length of the Unicode string returned in 'chars'.
* @param cdataSection A flag indicating if the characters represent
* content from the CDATA section.
*/
virtual void docCharacters
(
const XMLCh* const chars
, const XMLSize_t length
, const bool cdataSection
);
/** Handle a document comment event
*
* This method is used to report any comments scanned by the parser.
* A new comment node is created which stores this data.
*
* @param comment A const pointer to a null terminated Unicode
* string representing the comment text.
*/
virtual void docComment
(
const XMLCh* const comment
);
/** Handle a start entity reference event
*
* This method is used to indicate the start of an entity reference.
* If the expand entity reference flag is true, then a new
* DOM Entity reference node is created.
*
* @param entDecl A const reference to the object containing the
* entity declaration information.
*/
virtual void startEntityReference
(
const XMLEntityDecl& entDecl
);
/** Handle and end of entity reference event
*
* This method is used to indicate that an end of an entity reference
* was just scanned.
*
* @param entDecl A const reference to the object containing the
* entity declaration information.
*/
virtual void endEntityReference
(
const XMLEntityDecl& entDecl
);
/** Handle an ignorable whitespace vent
*
* This method is used to report all the whitespace characters, which
* are determined to be 'ignorable'. This distinction between characters
* is only made, if validation is enabled.
*
* Any whitespace before content is ignored. If the current node is
* already of type DOMNode::TEXT_NODE, then these whitespaces are
* appended, otherwise a new Text node is created which stores this
* data. Essentially all contiguous ignorable characters are collected
* in one node.
*
* @param chars A const pointer to a Unicode string representing the
* ignorable whitespace character data.
* @param length The length of the Unicode string 'chars'.
* @param cdataSection A flag indicating if the characters represent
* content from the CDATA section.
*/
virtual void ignorableWhitespace
(
const XMLCh* const chars
, const XMLSize_t length
, const bool cdataSection
);
//@}
// -----------------------------------------------------------------------
// Get methods
// -----------------------------------------------------------------------
bool getSawFatal() const;
// -----------------------------------------------------------------------
// Set methods
// -----------------------------------------------------------------------
void setUserErrorReporter(XMLErrorReporter* const errorReporter);
void setUserEntityHandler(XMLEntityHandler* const entityHandler);
// -----------------------------------------------------------------------
// XMLErrorReporter interface
// -----------------------------------------------------------------------
virtual void error
(
const unsigned int errCode
, const XMLCh* const errDomain
, const ErrTypes type
, const XMLCh* const errorText
, const XMLCh* const systemId
, const XMLCh* const publicId
, const XMLFileLoc lineNum
, const XMLFileLoc colNum
);
// -----------------------------------------------------------------------
// XMLEntityHandler interface
// -----------------------------------------------------------------------
virtual InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier);
protected :
// -----------------------------------------------------------------------
// Protected Helper methods
// -----------------------------------------------------------------------
virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
const XMLCh *qualifiedName);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XSDDOMParser(const XSDDOMParser&);
XSDDOMParser& operator=(const XSDDOMParser&);
// -----------------------------------------------------------------------
// Private Helper methods
// -----------------------------------------------------------------------
void startAnnotation
(
const XMLElementDecl& elemDecl
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount
);
void startAnnotationElement
(
const XMLElementDecl& elemDecl
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount
);
void endAnnotationElement
(
const XMLElementDecl& elemDecl
, bool complete
);
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
bool fSawFatal;
int fAnnotationDepth;
int fInnerAnnotationDepth;
int fDepth;
XMLErrorReporter* fUserErrorReporter;
XMLEntityHandler* fUserEntityHandler;
ValueVectorOf<unsigned int>* fURIs;
XMLBuffer fAnnotationBuf;
XSDErrorReporter fXSDErrorReporter;
XSDLocator fXSLocator;
};
inline bool XSDDOMParser::getSawFatal() const
{
return fSawFatal;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,179 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/XMLErrorCodes.hpp>
#include <xercesc/framework/XMLValidityCodes.hpp>
#include <xercesc/framework/XMLErrorReporter.hpp>
#include <xercesc/util/XMLMsgLoader.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include <xercesc/validators/schema/XSDErrorReporter.hpp>
#include <xercesc/validators/schema/XSDLocator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Local static data
// ---------------------------------------------------------------------------
static XMLMsgLoader* gErrMsgLoader = 0;
static XMLMsgLoader* gValidMsgLoader = 0;
void XMLInitializer::initializeXSDErrorReporter()
{
gErrMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLErrDomain);
if (!gErrMsgLoader)
XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
gValidMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgValidityDomain);
if (!gValidMsgLoader)
XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
}
void XMLInitializer::terminateXSDErrorReporter()
{
delete gErrMsgLoader;
gErrMsgLoader = 0;
delete gValidMsgLoader;
gValidMsgLoader = 0;
}
// ---------------------------------------------------------------------------
// XSDErrorReporter: Constructors and Destructor
// ---------------------------------------------------------------------------
XSDErrorReporter::XSDErrorReporter(XMLErrorReporter* const errorReporter) :
fExitOnFirstFatal(false)
, fErrorReporter(errorReporter)
{
}
// ---------------------------------------------------------------------------
// XSDErrorReporter: Error reporting
// ---------------------------------------------------------------------------
void XSDErrorReporter::emitError(const unsigned int toEmit,
const XMLCh* const msgDomain,
const Locator* const aLocator)
{
// Bump the error count if it is not a warning
// if (XMLErrs::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
// incrementErrorCount();
//
// Load the message into alocal and replace any tokens found in
// the text.
//
const XMLSize_t msgSize = 1023;
XMLCh errText[msgSize + 1];
XMLMsgLoader* msgLoader = gErrMsgLoader;
XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit);
if (XMLString::equals(msgDomain, XMLUni::fgValidityDomain)) {
errType = XMLValid::errorType((XMLValid::Codes) toEmit);
msgLoader = gValidMsgLoader;
}
if (!msgLoader->loadMsg(toEmit, errText, msgSize))
{
// <TBD> Should probably load a default message here
}
if (fErrorReporter)
fErrorReporter->error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(),
aLocator->getPublicId(), aLocator->getLineNumber(),
aLocator->getColumnNumber());
// Bail out if its fatal an we are to give up on the first fatal error
if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal)
throw (XMLErrs::Codes) toEmit;
}
void XSDErrorReporter::emitError(const unsigned int toEmit,
const XMLCh* const msgDomain,
const Locator* const aLocator,
const XMLCh* const text1,
const XMLCh* const text2,
const XMLCh* const text3,
const XMLCh* const text4,
MemoryManager* const manager)
{
// Bump the error count if it is not a warning
// if (XMLErrs::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
// incrementErrorCount();
//
// Load the message into alocal and replace any tokens found in
// the text.
//
const XMLSize_t maxChars = 2047;
XMLCh errText[maxChars + 1];
XMLMsgLoader* msgLoader = gErrMsgLoader;
XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit);
if (XMLString::equals(msgDomain, XMLUni::fgValidityDomain)) {
errType = XMLValid::errorType((XMLValid::Codes) toEmit);
msgLoader = gValidMsgLoader;
}
if (!msgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, manager))
{
// <TBD> Should probably load a default message here
}
if (fErrorReporter)
fErrorReporter->error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(),
aLocator->getPublicId(), aLocator->getLineNumber(),
aLocator->getColumnNumber());
// Bail out if its fatal an we are to give up on the first fatal error
if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal)
throw (XMLErrs::Codes) toEmit;
}
void XSDErrorReporter::emitError(const XMLException& except,
const Locator* const aLocator)
{
const XMLCh* const errText = except.getMessage();
const unsigned int toEmit = except.getCode();
//Before the code was modified to call this routine it used to use
//the XMLErrs::DisplayErrorMessage error message, which is just {'0'}
//and that error message has errType of Error. So to be consistent
//with previous behaviour set the errType to be Error instead of
//getting the error type off of the exception.
//XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit);
XMLErrorReporter::ErrTypes errType = XMLErrorReporter::ErrType_Error;
if (fErrorReporter)
fErrorReporter->error(toEmit, XMLUni::fgExceptDomain, errType, errText, aLocator->getSystemId(),
aLocator->getPublicId(), aLocator->getLineNumber(),
aLocator->getColumnNumber());
// Bail out if its fatal an we are to give up on the first fatal error
//if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal)
// throw (XMLErrs::Codes) toEmit;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,115 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XSDErrorReporter.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XSDERRORREPORTER_HPP)
#define XERCESC_INCLUDE_GUARD_XSDERRORREPORTER_HPP
#include <xercesc/util/XMemory.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class Locator;
class XMLErrorReporter;
/**
* This class reports schema errors
*/
class VALIDATORS_EXPORT XSDErrorReporter : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors are hidden, only the virtual destructor is exposed
// -----------------------------------------------------------------------
XSDErrorReporter(XMLErrorReporter* const errorReporter = 0);
virtual ~XSDErrorReporter()
{
}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
bool getExitOnFirstFatal() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setErrorReporter(XMLErrorReporter* const errorReporter);
void setExitOnFirstFatal(const bool newValue);
// -----------------------------------------------------------------------
// Report error methods
// -----------------------------------------------------------------------
void emitError(const unsigned int toEmit,
const XMLCh* const msgDomain,
const Locator* const aLocator);
void emitError(const unsigned int toEmit,
const XMLCh* const msgDomain,
const Locator* const aLocator,
const XMLCh* const text1,
const XMLCh* const text2 = 0,
const XMLCh* const text3 = 0,
const XMLCh* const text4 = 0,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
void emitError(const XMLException& except,
const Locator* const aLocator);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and destructor
// -----------------------------------------------------------------------
XSDErrorReporter(const XSDErrorReporter&);
XSDErrorReporter& operator=(const XSDErrorReporter&);
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
bool fExitOnFirstFatal;
XMLErrorReporter* fErrorReporter;
};
// ---------------------------------------------------------------------------
// XSDErrorReporter: Getter methods
// ---------------------------------------------------------------------------
inline bool XSDErrorReporter::getExitOnFirstFatal() const
{
return fExitOnFirstFatal;
}
// ---------------------------------------------------------------------------
// XSDErrorReporter: Setter methods
// ---------------------------------------------------------------------------
inline void XSDErrorReporter::setExitOnFirstFatal(const bool newValue)
{
fExitOnFirstFatal = newValue;
}
inline void XSDErrorReporter::setErrorReporter(XMLErrorReporter* const errorReporter)
{
fErrorReporter = errorReporter;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,57 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XSDLocator.cpp 672273 2008-06-27 13:57:00Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/XSDLocator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// XSDLocator: Constructors and Destructor
// ---------------------------------------------------------------------------
XSDLocator::XSDLocator() :
fLineNo(0)
, fColumnNo(0)
, fSystemId(0)
, fPublicId(0)
{
}
// ---------------------------------------------------------------------------
// XSDLocator: Setter methods
// ---------------------------------------------------------------------------
void XSDLocator::setValues(const XMLCh* const systemId,
const XMLCh* const publicId,
const XMLFileLoc lineNo,
const XMLFileLoc columnNo)
{
fLineNo = lineNo;
fColumnNo = columnNo;
fSystemId = systemId;
fPublicId = publicId;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,141 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XSDLocator.hpp 672273 2008-06-27 13:57:00Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XSDLOCATOR_HPP)
#define XERCESC_INCLUDE_GUARD_XSDLOCATOR_HPP
/**
* A Locator implementation
*/
#include <xercesc/util/XMemory.hpp>
#include <xercesc/sax/Locator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class VALIDATORS_EXPORT XSDLocator: public XMemory, public Locator
{
public:
/** @name Constructors and Destructor */
//@{
/** Default constructor */
XSDLocator();
/** Destructor */
virtual ~XSDLocator()
{
}
//@}
/** @name The locator interface */
//@{
/**
* Return the public identifier for the current document event.
* <p>This will be the public identifier
* @return A string containing the public identifier, or
* null if none is available.
* @see #getSystemId
*/
virtual const XMLCh* getPublicId() const;
/**
* Return the system identifier for the current document event.
*
* <p>If the system identifier is a URL, the parser must resolve it
* fully before passing it to the application.</p>
*
* @return A string containing the system identifier, or null
* if none is available.
* @see #getPublicId
*/
virtual const XMLCh* getSystemId() const;
/**
* Return the line number where the current document event ends.
* Note that this is the line position of the first character
* after the text associated with the document event.
* @return The line number, or 0 if none is available.
* @see #getColumnNumber
*/
virtual XMLFileLoc getLineNumber() const;
/**
* Return the column number where the current document event ends.
* Note that this is the column number of the first
* character after the text associated with the document
* event. The first column in a line is position 1.
* @return The column number, or 0 if none is available.
* @see #getLineNumber
*/
virtual XMLFileLoc getColumnNumber() const;
//@}
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setValues(const XMLCh* const systemId,
const XMLCh* const publicId,
const XMLFileLoc lineNo, const XMLFileLoc columnNo);
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and destructor
// -----------------------------------------------------------------------
XSDLocator(const XSDLocator&);
XSDLocator& operator=(const XSDLocator&);
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
XMLFileLoc fLineNo;
XMLFileLoc fColumnNo;
const XMLCh* fSystemId;
const XMLCh* fPublicId;
};
// ---------------------------------------------------------------------------
// XSDLocator: Getter methods
// ---------------------------------------------------------------------------
inline XMLFileLoc XSDLocator::getLineNumber() const
{
return fLineNo;
}
inline XMLFileLoc XSDLocator::getColumnNumber() const
{
return fColumnNo;
}
inline const XMLCh* XSDLocator::getPublicId() const
{
return fPublicId;
}
inline const XMLCh* XSDLocator::getSystemId() const
{
return fSystemId;
}
XERCES_CPP_NAMESPACE_END
#endif
+125
View File
@@ -0,0 +1,125 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XUtil.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/XUtil.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/util/IllegalArgumentException.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMNode.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// Finds and returns the first child element node.
DOMElement* XUtil::getFirstChildElement(const DOMNode* const parent)
{
// search for node
DOMNode* child = parent->getFirstChild();
while (child != 0)
{
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
return (DOMElement*)child;
child = child->getNextSibling();
}
// not found
return 0;
}
// Finds and returns the first child node with the given name.
DOMElement* XUtil::getFirstChildElementNS(const DOMNode* const parent
, const XMLCh** const elemNames
, const XMLCh* const uriStr
, unsigned int length)
{
// search for node
DOMNode* child = parent->getFirstChild();
while (child != 0)
{
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
{
for (unsigned int i = 0; i < length; i++)
{
if (XMLString::equals(child->getNamespaceURI(), uriStr) &&
XMLString::equals(child->getLocalName(), elemNames[i]))
return (DOMElement*)child;
}
}
child = child->getNextSibling();
}
// not found
return 0;
}
// Finds and returns the last child element node.
DOMElement* XUtil::getNextSiblingElement(const DOMNode* const node)
{
// search for node
DOMNode* sibling = node->getNextSibling();
while (sibling != 0)
{
if (sibling->getNodeType() == DOMNode::ELEMENT_NODE)
return (DOMElement*)sibling;
sibling = sibling->getNextSibling();
}
// not found
return 0;
}
// Finds and returns the next sibling element node with the give name.
DOMElement* XUtil::getNextSiblingElementNS(const DOMNode* const node
, const XMLCh** const elemNames
, const XMLCh* const uriStr
, unsigned int length)
{
// search for node
DOMNode* sibling = node->getNextSibling();
while (sibling != 0)
{
if (sibling->getNodeType() == DOMNode::ELEMENT_NODE)
{
for (unsigned int i = 0; i < length; i++)
{
if (XMLString::equals(sibling->getNamespaceURI(), uriStr) &&
XMLString::equals(sibling->getLocalName(), elemNames[i]))
return (DOMElement*)sibling;
}
}
sibling = sibling->getNextSibling();
}
// not found
return 0;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,71 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XUtil.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XUTIL_HPP)
#define XERCESC_INCLUDE_GUARD_XUTIL_HPP
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMNode.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DOMNode;
class DOMElement;
/**
* Some useful utility methods.
*/
class VALIDATORS_EXPORT XUtil
{
public:
// Finds and returns the first child element node.
static DOMElement* getFirstChildElement(const DOMNode* const parent);
// Finds and returns the first child node with the given qualifiedname.
static DOMElement* getFirstChildElementNS(const DOMNode* const parent
, const XMLCh** const elemNames
, const XMLCh* const uriStr
, unsigned int length);
// Finds and returns the next sibling element node.
static DOMElement* getNextSiblingElement(const DOMNode* const node);
static DOMElement* getNextSiblingElementNS(const DOMNode* const node
, const XMLCh** const elemNames
, const XMLCh* const uriStr
, unsigned int length);
private:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
// This class cannot be instantiated.
XUtil() {};
~XUtil() {};
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,182 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XercesAttGroupInfo.cpp 676911 2008-07-15 13:27:32Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
#include <xercesc/util/QName.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// XercesAttGroupInfo: Constructors and Destructor
// ---------------------------------------------------------------------------
XercesAttGroupInfo::XercesAttGroupInfo(MemoryManager* const manager)
: fTypeWithId(false)
, fNameId(0)
, fNamespaceId(0)
, fAttributes(0)
, fAnyAttributes(0)
, fCompleteWildCard(0)
, fMemoryManager(manager)
{
}
XercesAttGroupInfo::XercesAttGroupInfo(unsigned int attGroupNameId,
unsigned int attGroupNamespaceId,
MemoryManager* const manager)
: fTypeWithId(false)
, fNameId(attGroupNameId)
, fNamespaceId(attGroupNamespaceId)
, fAttributes(0)
, fAnyAttributes(0)
, fCompleteWildCard(0)
, fMemoryManager(manager)
{
}
XercesAttGroupInfo::~XercesAttGroupInfo()
{
delete fAttributes;
delete fAnyAttributes;
delete fCompleteWildCard;
}
bool XercesAttGroupInfo::containsAttribute(const XMLCh* const name,
const unsigned int uri) {
if (fAttributes) {
XMLSize_t attCount = fAttributes->size();
if (attCount) {
for (XMLSize_t i=0; i < attCount; i++) {
QName* attName = fAttributes->elementAt(i)->getAttName();
if (attName->getURI() == uri &&
XMLString::equals(attName->getLocalPart(),name)) {
return true;
}
}
}
}
return false;
}
// ---------------------------------------------------------------------------
// XercesAttGroupInfo: Getter methods
// ---------------------------------------------------------------------------
const SchemaAttDef* XercesAttGroupInfo::getAttDef(const XMLCh* const baseName,
const int uriId) const {
// If no list, then return a null
if (!fAttributes)
return 0;
XMLSize_t attSize = fAttributes->size();
for (XMLSize_t i=0; i<attSize; i++) {
const SchemaAttDef* attDef = fAttributes->elementAt(i);
QName* attName = attDef->getAttName();
if (uriId == (int) attName->getURI() &&
XMLString::equals(baseName, attName->getLocalPart())) {
return attDef;
}
}
return 0;
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(XercesAttGroupInfo)
void XercesAttGroupInfo::serialize(XSerializeEngine& serEng)
{
if (serEng.isStoring())
{
serEng<<fTypeWithId;
serEng<<fNameId;
serEng<<fNamespaceId;
/***
*
* Serialize RefVectorOf<SchemaAttDef>* fAttributes;
*
***/
XTemplateSerializer::storeObject(fAttributes, serEng);
/***
*
* Serialize RefVectorOf<SchemaAttDef>* fAnyAttributes;
*
***/
XTemplateSerializer::storeObject(fAnyAttributes, serEng);
serEng<<fCompleteWildCard;
}
else
{
serEng>>fTypeWithId;
serEng>>fNameId;
serEng>>fNamespaceId;
/***
*
* Deserialize RefVectorOf<SchemaAttDef>* fAttributes;
*
***/
XTemplateSerializer::loadObject(&fAttributes, 4, true, serEng);
/***
*
* Deserialize RefVectorOf<SchemaAttDef>* fAnyAttributes;
*
***/
XTemplateSerializer::loadObject(&fAnyAttributes, 2, true, serEng);
serEng>>fCompleteWildCard;
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file XercesAttGroupInfo.cpp
*/
@@ -0,0 +1,257 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XercesAttGroupInfo.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XERCESATTGROUPINFO_HPP)
#define XERCESC_INCLUDE_GUARD_XERCESATTGROUPINFO_HPP
/**
* The class act as a place holder to store attributeGroup information.
*
* The class is intended for internal use.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/validators/schema/SchemaAttDef.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class VALIDATORS_EXPORT XercesAttGroupInfo : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Public Constructors/Destructor
// -----------------------------------------------------------------------
XercesAttGroupInfo
(
unsigned int attGroupNameId
, unsigned int attGroupNamespaceId
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
~XercesAttGroupInfo();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
bool containsTypeWithId() const;
XMLSize_t attributeCount() const;
XMLSize_t anyAttributeCount() const;
unsigned int getNameId() const;
unsigned int getNamespaceId() const;
SchemaAttDef* attributeAt(const XMLSize_t index);
const SchemaAttDef* attributeAt(const XMLSize_t index) const;
SchemaAttDef* anyAttributeAt(const XMLSize_t index);
const SchemaAttDef* anyAttributeAt(const XMLSize_t index) const;
SchemaAttDef* getCompleteWildCard() const;
const SchemaAttDef* getAttDef(const XMLCh* const baseName,
const int uriId) const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setTypeWithId(const bool other);
void addAttDef(SchemaAttDef* const toAdd, const bool toClone = false);
void addAnyAttDef(SchemaAttDef* const toAdd, const bool toClone = false);
void setCompleteWildCard(SchemaAttDef* const toSet);
// -----------------------------------------------------------------------
// Query methods
// -----------------------------------------------------------------------
bool containsAttribute(const XMLCh* const name, const unsigned int uri);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XercesAttGroupInfo)
XercesAttGroupInfo(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XercesAttGroupInfo(const XercesAttGroupInfo& elemInfo);
XercesAttGroupInfo& operator= (const XercesAttGroupInfo& other);
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
bool fTypeWithId;
unsigned int fNameId;
unsigned int fNamespaceId;
RefVectorOf<SchemaAttDef>* fAttributes;
RefVectorOf<SchemaAttDef>* fAnyAttributes;
SchemaAttDef* fCompleteWildCard;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// XercesAttGroupInfo: Getter methods
// ---------------------------------------------------------------------------
inline bool XercesAttGroupInfo::containsTypeWithId() const {
return fTypeWithId;
}
inline XMLSize_t XercesAttGroupInfo::attributeCount() const {
if (fAttributes) {
return fAttributes->size();
}
return 0;
}
inline XMLSize_t XercesAttGroupInfo::anyAttributeCount() const {
if (fAnyAttributes) {
return fAnyAttributes->size();
}
return 0;
}
inline unsigned int XercesAttGroupInfo::getNameId() const
{
return fNameId;
}
inline unsigned int XercesAttGroupInfo::getNamespaceId() const
{
return fNamespaceId;
}
inline SchemaAttDef*
XercesAttGroupInfo::attributeAt(const XMLSize_t index) {
if (fAttributes) {
return fAttributes->elementAt(index);
}
return 0;
}
inline const SchemaAttDef*
XercesAttGroupInfo::attributeAt(const XMLSize_t index) const {
if (fAttributes) {
return fAttributes->elementAt(index);
}
return 0;
}
inline SchemaAttDef*
XercesAttGroupInfo::anyAttributeAt(const XMLSize_t index) {
if (fAnyAttributes) {
return fAnyAttributes->elementAt(index);
}
return 0;
}
inline const SchemaAttDef*
XercesAttGroupInfo::anyAttributeAt(const XMLSize_t index) const {
if (fAnyAttributes) {
return fAnyAttributes->elementAt(index);
}
return 0;
}
inline SchemaAttDef*
XercesAttGroupInfo::getCompleteWildCard() const {
return fCompleteWildCard;
}
// ---------------------------------------------------------------------------
// XercesAttGroupInfo: Setter methods
// ---------------------------------------------------------------------------
inline void XercesAttGroupInfo::setTypeWithId(const bool other) {
fTypeWithId = other;
}
inline void XercesAttGroupInfo::addAttDef(SchemaAttDef* const toAdd,
const bool toClone) {
if (!fAttributes) {
fAttributes = new (fMemoryManager) RefVectorOf<SchemaAttDef>(4, true, fMemoryManager);
}
if (toClone) {
SchemaAttDef* clonedAttDef = new (fMemoryManager) SchemaAttDef(toAdd);
if (!clonedAttDef->getBaseAttDecl())
clonedAttDef->setBaseAttDecl(toAdd);
fAttributes->addElement(clonedAttDef);
}
else {
fAttributes->addElement(toAdd);
}
}
inline void XercesAttGroupInfo::addAnyAttDef(SchemaAttDef* const toAdd,
const bool toClone) {
if (!fAnyAttributes) {
fAnyAttributes = new (fMemoryManager) RefVectorOf<SchemaAttDef>(2, true, fMemoryManager);
}
if (toClone) {
SchemaAttDef* clonedAttDef = new (fMemoryManager) SchemaAttDef(toAdd);
if (!clonedAttDef->getBaseAttDecl())
clonedAttDef->setBaseAttDecl(toAdd);
fAnyAttributes->addElement(clonedAttDef);
}
else {
fAnyAttributes->addElement(toAdd);
}
}
inline void
XercesAttGroupInfo::setCompleteWildCard(SchemaAttDef* const toSet) {
if (fCompleteWildCard) {
delete fCompleteWildCard;
}
fCompleteWildCard = toSet;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file XercesAttGroupInfo.hpp
*/
@@ -0,0 +1,120 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XercesElementWildcard.cpp 671133 2008-06-24 11:22:29Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/XercesElementWildcard.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Local methods
// ---------------------------------------------------------------------------
/**
* XercesElementWildcard is used to check whether two element declarations conflict
*/
/**
* Check whether two element declarations conflict
*/
bool XercesElementWildcard::conflict(SchemaGrammar* const pGrammar,
ContentSpecNode::NodeTypes type1,
QName* q1,
ContentSpecNode::NodeTypes type2,
QName* q2,
SubstitutionGroupComparator* comparator)
{
if (type1 == ContentSpecNode::Leaf &&
type2 == ContentSpecNode::Leaf) {
if (comparator->isEquivalentTo(q1, q2) || comparator->isEquivalentTo(q2, q1))
return true;
}
else if (type1 == ContentSpecNode::Leaf) {
return uriInWildcard(pGrammar, q1, q2->getURI(), type2, comparator);
}
else if (type2 == ContentSpecNode::Leaf) {
return uriInWildcard(pGrammar, q2, q1->getURI(), type1, comparator);
}
else {
return wildcardIntersect(type1, q1->getURI(), type2, q2->getURI());
}
return false;
}
bool XercesElementWildcard::uriInWildcard(SchemaGrammar* const pGrammar,
QName* qname,
unsigned int wildcard,
ContentSpecNode::NodeTypes wtype,
SubstitutionGroupComparator* comparator)
{
if ((wtype & 0x0f)== ContentSpecNode::Any) {
return true;
}
else if ((wtype & 0x0f)== ContentSpecNode::Any_NS) {
// substitution of "uri" satisfies "wtype:wildcard"
return comparator->isAllowedByWildcard(pGrammar, qname, wildcard, false);
}
else if ((wtype & 0x0f)== ContentSpecNode::Any_Other) {
// substitution of "uri" satisfies "wtype:wildcard"
return comparator->isAllowedByWildcard(pGrammar, qname, wildcard, true);
}
return false;
}
bool XercesElementWildcard::wildcardIntersect(ContentSpecNode::NodeTypes t1,
unsigned int w1,
ContentSpecNode::NodeTypes t2,
unsigned int w2)
{
if (((t1 & 0x0f) == ContentSpecNode::Any) ||
((t2 & 0x0f) == ContentSpecNode::Any)) {
// if either one is "##any", then intersects
return true;
}
else if (((t1 & 0x0f) == ContentSpecNode::Any_NS) &&
((t2 & 0x0f) == ContentSpecNode::Any_NS)) {
// if both are "some_namespace" and equal, then intersects
return w1 == w2;
}
else if (((t1 & 0x0f) == ContentSpecNode::Any_Other) &&
((t2 & 0x0f) == ContentSpecNode::Any_Other)) {
// if both are "##other", then intersects
return true;
}
// Below we assume that empty string has id 1.
//
else if (((t1 & 0x0f) == ContentSpecNode::Any_NS) &&
((t2 & 0x0f) == ContentSpecNode::Any_Other))
{
return w1 != w2 && w1 != 1;
}
else if (((t1 & 0x0f) == ContentSpecNode::Any_Other) &&
((t2 & 0x0f) == ContentSpecNode::Any_NS))
{
return w1 != w2 && w2 != 1;
}
return false;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,81 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XercesElementWildcard.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XERCESELEMENTWILDCARD_HPP)
#define XERCESC_INCLUDE_GUARD_XERCESELEMENTWILDCARD_HPP
#include <xercesc/util/QName.hpp>
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/schema/SubstitutionGroupComparator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward declarations
// ---------------------------------------------------------------------------
class SchemaGrammar;
class VALIDATORS_EXPORT XercesElementWildcard
{
public :
// -----------------------------------------------------------------------
// Class static methods
// -----------------------------------------------------------------------
/*
* check whether two elements are in conflict
*/
static bool conflict(SchemaGrammar* const pGrammar,
ContentSpecNode::NodeTypes type1,
QName* q1,
ContentSpecNode::NodeTypes type2,
QName* q2,
SubstitutionGroupComparator* comparator);
private:
// -----------------------------------------------------------------------
// private helper methods
// -----------------------------------------------------------------------
static bool uriInWildcard(SchemaGrammar* const pGrammar,
QName* qname,
unsigned int wildcard,
ContentSpecNode::NodeTypes wtype,
SubstitutionGroupComparator* comparator);
static bool wildcardIntersect(ContentSpecNode::NodeTypes t1,
unsigned int w1,
ContentSpecNode::NodeTypes t2,
unsigned int w2);
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XercesElementWildcard();
~XercesElementWildcard();
};
XERCES_CPP_NAMESPACE_END
#endif // XERCESELEMENTWILDCARD_HPP
@@ -0,0 +1,141 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XercesGroupInfo.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/XercesGroupInfo.hpp>
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/schema/XSDLocator.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// XercesGroupInfo: Constructors and Destructor
// ---------------------------------------------------------------------------
XercesGroupInfo::XercesGroupInfo(MemoryManager* const manager)
: fCheckElementConsistency(true)
, fScope(Grammar::TOP_LEVEL_SCOPE)
, fNameId(0)
, fNamespaceId(0)
, fContentSpec(0)
, fElements(0)
, fBaseGroup(0)
, fLocator(0)
{
fElements = new (manager) RefVectorOf<SchemaElementDecl>(4, false, manager);
}
XercesGroupInfo::XercesGroupInfo(unsigned int groupNameId,
unsigned int groupNamespaceId,
MemoryManager* const manager)
: fCheckElementConsistency(true)
, fScope(Grammar::TOP_LEVEL_SCOPE)
, fNameId(groupNameId)
, fNamespaceId(groupNamespaceId)
, fContentSpec(0)
, fElements(0)
, fBaseGroup(0)
, fLocator(0)
{
fElements = new (manager) RefVectorOf<SchemaElementDecl>(4, false, manager);
}
XercesGroupInfo::~XercesGroupInfo()
{
delete fElements;
delete fContentSpec;
delete fLocator;
}
// ---------------------------------------------------------------------------
// XercesGroupInfo: Constructors and Destructor
// ---------------------------------------------------------------------------
void XercesGroupInfo::setLocator(XSDLocator* const aLocator) {
if (fLocator)
delete fLocator;
fLocator = aLocator;
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(XercesGroupInfo)
void XercesGroupInfo::serialize(XSerializeEngine& serEng)
{
if (serEng.isStoring())
{
serEng<<fCheckElementConsistency;
serEng<<fScope;
serEng<<fNameId;
serEng<<fNamespaceId;
serEng<<fContentSpec;
/***
*
* Serialize RefVectorOf<SchemaElementDecl>* fElements;
*
***/
XTemplateSerializer::storeObject(fElements, serEng);
serEng<<fBaseGroup;
//don't serialize XSDLocator* fLocator;
}
else
{
serEng>>fCheckElementConsistency;
serEng>>fScope;
serEng>>fNameId;
serEng>>fNamespaceId;
serEng>>fContentSpec;
/***
*
* Deserialize RefVectorOf<SchemaElementDecl>* fElements;
*
***/
XTemplateSerializer::loadObject(&fElements, 4, false, serEng);
serEng>>fBaseGroup;
//don't serialize XSDLocator* fLocator;
fLocator = 0;
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file XercesGroupInfo.cpp
*/
@@ -0,0 +1,204 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XercesGroupInfo.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XERCESGROUPINFO_HPP)
#define XERCESC_INCLUDE_GUARD_XERCESGROUPINFO_HPP
/**
* The class act as a place holder to store group information.
*
* The class is intended for internal use.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class ContentSpecNode;
class XSDLocator;
class VALIDATORS_EXPORT XercesGroupInfo : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Public Constructors/Destructor
// -----------------------------------------------------------------------
XercesGroupInfo
(
unsigned int groupNameId
, unsigned int groupNamespaceId
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
~XercesGroupInfo();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
bool getCheckElementConsistency() const;
unsigned int getScope() const;
XMLSize_t elementCount() const;
ContentSpecNode* getContentSpec() const;
SchemaElementDecl* elementAt(const XMLSize_t index);
const SchemaElementDecl* elementAt(const XMLSize_t index) const;
XSDLocator* getLocator() const;
XercesGroupInfo* getBaseGroup() const;
unsigned int getNameId() const;
unsigned int getNamespaceId() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setScope(const unsigned int other);
void setContentSpec(ContentSpecNode* const other);
void addElement(SchemaElementDecl* const toAdd);
void setLocator(XSDLocator* const aLocator);
void setBaseGroup(XercesGroupInfo* const baseGroup);
void setCheckElementConsistency(const bool aValue);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XercesGroupInfo)
XercesGroupInfo(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XercesGroupInfo(const XercesGroupInfo& elemInfo);
XercesGroupInfo& operator= (const XercesGroupInfo& other);
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
bool fCheckElementConsistency;
unsigned int fScope;
unsigned int fNameId;
unsigned int fNamespaceId;
ContentSpecNode* fContentSpec;
RefVectorOf<SchemaElementDecl>* fElements;
XercesGroupInfo* fBaseGroup; // redefine by restriction
XSDLocator* fLocator;
};
// ---------------------------------------------------------------------------
// XercesGroupInfo: Getter methods
// ---------------------------------------------------------------------------
inline unsigned int XercesGroupInfo::getScope() const {
return fScope;
}
inline XMLSize_t XercesGroupInfo::elementCount() const {
return fElements->size();
}
inline ContentSpecNode* XercesGroupInfo::getContentSpec() const {
return fContentSpec;
}
inline SchemaElementDecl*
XercesGroupInfo::elementAt(const XMLSize_t index) {
return fElements->elementAt(index);
}
inline const SchemaElementDecl*
XercesGroupInfo::elementAt(const XMLSize_t index) const {
return fElements->elementAt(index);
}
inline XSDLocator* XercesGroupInfo::getLocator() const {
return fLocator;
}
inline XercesGroupInfo* XercesGroupInfo::getBaseGroup() const {
return fBaseGroup;
}
inline bool XercesGroupInfo::getCheckElementConsistency() const {
return fCheckElementConsistency;
}
inline unsigned int XercesGroupInfo::getNameId() const
{
return fNameId;
}
inline unsigned int XercesGroupInfo::getNamespaceId() const
{
return fNamespaceId;
}
// ---------------------------------------------------------------------------
// XercesGroupInfo: Setter methods
// ---------------------------------------------------------------------------}
inline void XercesGroupInfo::setScope(const unsigned int other) {
fScope = other;
}
inline void XercesGroupInfo::setContentSpec(ContentSpecNode* const other) {
fContentSpec = other;
}
inline void XercesGroupInfo::addElement(SchemaElementDecl* const elem) {
if (!fElements->containsElement(elem))
fElements->addElement(elem);
}
inline void XercesGroupInfo::setBaseGroup(XercesGroupInfo* const baseGroup) {
fBaseGroup = baseGroup;
}
inline void XercesGroupInfo::setCheckElementConsistency(const bool aValue) {
fCheckElementConsistency = aValue;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file XercesGroupInfo.hpp
*/
@@ -0,0 +1,124 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: FieldActivator.cpp 679340 2008-07-24 10:28:29Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/FieldActivator.hpp>
#include <xercesc/validators/schema/identity/ValueStore.hpp>
#include <xercesc/validators/schema/identity/ValueStoreCache.hpp>
#include <xercesc/validators/schema/identity/XPathMatcherStack.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// FieldActivator: Constructors and Destructor
// ---------------------------------------------------------------------------
FieldActivator::FieldActivator(ValueStoreCache* const valueStoreCache,
XPathMatcherStack* const matcherStack,
MemoryManager* const manager)
: fValueStoreCache(valueStoreCache)
, fMatcherStack(matcherStack)
, fMayMatch(0)
, fMemoryManager(manager)
{
fMayMatch = new (manager) ValueHashTableOf<bool, PtrHasher>(29, manager);
}
FieldActivator::FieldActivator(const FieldActivator& other)
: XMemory(other)
, fValueStoreCache(other.fValueStoreCache)
, fMatcherStack(other.fMatcherStack)
, fMayMatch(0)
, fMemoryManager(other.fMemoryManager)
{
fMayMatch = new (fMemoryManager) ValueHashTableOf<bool, PtrHasher>(29, fMemoryManager);
ValueHashTableOfEnumerator<bool, PtrHasher> mayMatchEnum(other.fMayMatch, false, fMemoryManager);
// Build key set
while (mayMatchEnum.hasMoreElements())
{
IC_Field* field = (IC_Field*) mayMatchEnum.nextElementKey();
fMayMatch->put(field, other.fMayMatch->get(field));
}
}
FieldActivator::~FieldActivator()
{
delete fMayMatch;
}
// ---------------------------------------------------------------------------
// FieldActivator: Operator methods
// ---------------------------------------------------------------------------
FieldActivator& FieldActivator::operator =(const FieldActivator& other) {
if (this == &other) {
return *this;
}
fValueStoreCache = other.fValueStoreCache;
fMatcherStack = other.fMatcherStack;
return *this;
}
// ---------------------------------------------------------------------------
// FieldActivator: Operator methods
// ---------------------------------------------------------------------------
XPathMatcher* FieldActivator::activateField(IC_Field* const field, const int initialDepth) {
ValueStore* valueStore = fValueStoreCache->getValueStoreFor(field, initialDepth);
XPathMatcher* matcher = field->createMatcher(this, valueStore, fMemoryManager);
setMayMatch(field, true);
fMatcherStack->addMatcher(matcher);
matcher->startDocumentFragment();
return matcher;
}
void FieldActivator::startValueScopeFor(const IdentityConstraint* const ic,
const int initialDepth) {
XMLSize_t fieldCount = ic->getFieldCount();
for(XMLSize_t i=0; i<fieldCount; i++) {
const IC_Field* field = ic->getFieldAt(i);
ValueStore* valueStore = fValueStoreCache->getValueStoreFor(field, initialDepth);
valueStore->startValueScope();
}
}
void FieldActivator::endValueScopeFor(const IdentityConstraint* const ic, const int initialDepth) {
ValueStore* valueStore = fValueStoreCache->getValueStoreFor(ic, initialDepth);
valueStore->endValueScope();
}
XERCES_CPP_NAMESPACE_END
/**
* End of file FieldActivator.cpp
*/
@@ -0,0 +1,141 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: FieldActivator.hpp 679340 2008-07-24 10:28:29Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_FIELDACTIVATOR_HPP)
#define XERCESC_INCLUDE_GUARD_FIELDACTIVATOR_HPP
/**
* This class is responsible for activating fields within a specific scope;
* the caller merely requests the fields to be activated.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/ValueHashTableOf.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declaration
// ---------------------------------------------------------------------------
class IdentityConstraint;
class XPathMatcher;
class ValueStoreCache;
class IC_Field;
class XPathMatcherStack;
class VALIDATORS_EXPORT FieldActivator : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
FieldActivator(ValueStoreCache* const valueStoreCache,
XPathMatcherStack* const matcherStack,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
FieldActivator(const FieldActivator& other);
~FieldActivator();
// -----------------------------------------------------------------------
// Operator methods
// -----------------------------------------------------------------------
FieldActivator& operator =(const FieldActivator& other);
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
bool getMayMatch(IC_Field* const field);
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setValueStoreCache(ValueStoreCache* const other);
void setMatcherStack(XPathMatcherStack* const matcherStack);
void setMayMatch(IC_Field* const field, bool value);
// -----------------------------------------------------------------------
// Activation methods
// -----------------------------------------------------------------------
/**
* Start the value scope for the specified identity constraint. This
* method is called when the selector matches in order to initialize
* the value store.
*/
void startValueScopeFor(const IdentityConstraint* const ic, const int initialDepth);
/**
* Request to activate the specified field. This method returns the
* matcher for the field.
*/
XPathMatcher* activateField(IC_Field* const field, const int initialDepth);
/**
* Ends the value scope for the specified identity constraint.
*/
void endValueScopeFor(const IdentityConstraint* const ic, const int initialDepth);
private:
// -----------------------------------------------------------------------
// Data
// -----------------------------------------------------------------------
ValueStoreCache* fValueStoreCache;
XPathMatcherStack* fMatcherStack;
ValueHashTableOf<bool, PtrHasher>* fMayMatch;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// FieldActivator: Getter methods
// ---------------------------------------------------------------------------
inline bool FieldActivator::getMayMatch(IC_Field* const field) {
return fMayMatch->get(field);
}
// ---------------------------------------------------------------------------
// FieldActivator: Setter methods
// ---------------------------------------------------------------------------
inline void FieldActivator::setValueStoreCache(ValueStoreCache* const other) {
fValueStoreCache = other;
}
inline void
FieldActivator::setMatcherStack(XPathMatcherStack* const matcherStack) {
fMatcherStack = matcherStack;
}
inline void FieldActivator::setMayMatch(IC_Field* const field, bool value) {
fMayMatch->put(field, value);
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file FieldActivator.hpp
*/
@@ -0,0 +1,127 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: FieldValueMap.cpp 708224 2008-10-27 16:02:26Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/FieldValueMap.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
typedef JanitorMemFunCall<FieldValueMap> CleanupType;
// ---------------------------------------------------------------------------
// FieldValueMap: Constructors and Destructor
// ---------------------------------------------------------------------------
FieldValueMap::FieldValueMap(MemoryManager* const manager)
: fFields(0)
, fValidators(0)
, fValues(0)
, fMemoryManager(manager)
{
}
FieldValueMap::FieldValueMap(const FieldValueMap& other)
: XMemory(other)
, fFields(0)
, fValidators(0)
, fValues(0)
, fMemoryManager(other.fMemoryManager)
{
if (other.fFields) {
CleanupType cleanup(this, &FieldValueMap::cleanUp);
try {
XMLSize_t valuesSize = other.fValues->size();
fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(*(other.fFields));
fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(*(other.fValidators));
fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(other.fFields->curCapacity(), true, fMemoryManager);
for (XMLSize_t i=0; i<valuesSize; i++) {
fValues->addElement(XMLString::replicate(other.fValues->elementAt(i), fMemoryManager));
}
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
}
FieldValueMap::~FieldValueMap()
{
cleanUp();
}
// ---------------------------------------------------------------------------
// FieldValueMap: Private helper methods.
// ---------------------------------------------------------------------------
void FieldValueMap::cleanUp()
{
delete fFields;
delete fValidators;
delete fValues;
}
// ---------------------------------------------------------------------------
// FieldValueMap: Helper methods
// ---------------------------------------------------------------------------
bool FieldValueMap::indexOf(const IC_Field* const key, XMLSize_t& location) const {
if (fFields) {
XMLSize_t fieldSize = fFields->size();
for (XMLSize_t i=0; i < fieldSize; i++) {
if (fFields->elementAt(i) == key) {
location=i;
return true;
}
}
}
return false;
}
void FieldValueMap::clear()
{
if(fFields)
fFields->removeAllElements();
if(fValidators)
fValidators->removeAllElements();
if(fValues)
fValues->removeAllElements();
}
XERCES_CPP_NAMESPACE_END
/**
* End of file FieldValueMap.cpp
*/
@@ -0,0 +1,198 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: FieldValueMap.hpp 708224 2008-10-27 16:02:26Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_FIELDVALUEMAP_HPP)
#define XERCESC_INCLUDE_GUARD_FIELDVALUEMAP_HPP
/**
* This class maps values associated with fields of an identity constraint
* that have successfully matched some string in an instance document.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/ValueVectorOf.hpp>
#include <xercesc/util/RefArrayVectorOf.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declaration
// ---------------------------------------------------------------------------
class IC_Field;
class DatatypeValidator;
class VALIDATORS_EXPORT FieldValueMap : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
FieldValueMap(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
FieldValueMap(const FieldValueMap& other);
~FieldValueMap();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
DatatypeValidator* getDatatypeValidatorAt(const XMLSize_t index) const;
DatatypeValidator* getDatatypeValidatorFor(const IC_Field* const key) const;
XMLCh* getValueAt(const XMLSize_t index) const;
XMLCh* getValueFor(const IC_Field* const key) const;
IC_Field* keyAt(const XMLSize_t index) const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void put(IC_Field* const key, DatatypeValidator* const dv,
const XMLCh* const value);
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
XMLSize_t size() const;
bool indexOf(const IC_Field* const key, XMLSize_t& location) const;
void clear();
private:
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void cleanUp();
// -----------------------------------------------------------------------
// Unimplemented operators
// -----------------------------------------------------------------------
FieldValueMap& operator= (const FieldValueMap& other);
// -----------------------------------------------------------------------
// Data
// -----------------------------------------------------------------------
ValueVectorOf<IC_Field*>* fFields;
ValueVectorOf<DatatypeValidator*>* fValidators;
RefArrayVectorOf<XMLCh>* fValues;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// FieldValueMap: Getter methods
// ---------------------------------------------------------------------------
inline DatatypeValidator*
FieldValueMap::getDatatypeValidatorAt(const XMLSize_t index) const {
if (fValidators) {
return fValidators->elementAt(index);
}
return 0;
}
inline DatatypeValidator*
FieldValueMap::getDatatypeValidatorFor(const IC_Field* const key) const {
XMLSize_t location;
if (fValidators && indexOf(key, location)) {
return fValidators->elementAt(location);
}
return 0;
}
inline XMLCh* FieldValueMap::getValueAt(const XMLSize_t index) const {
if (fValues) {
return fValues->elementAt(index);
}
return 0;
}
inline XMLCh* FieldValueMap::getValueFor(const IC_Field* const key) const {
XMLSize_t location;
if (fValues && indexOf(key, location)) {
return fValues->elementAt(location);
}
return 0;
}
inline IC_Field* FieldValueMap::keyAt(const XMLSize_t index) const {
if (fFields) {
return fFields->elementAt(index);
}
return 0;
}
// ---------------------------------------------------------------------------
// FieldValueMap: Helper methods
// ---------------------------------------------------------------------------
inline XMLSize_t FieldValueMap::size() const {
if (fFields) {
return fFields->size();
}
return 0;
}
// ---------------------------------------------------------------------------
// FieldValueMap: Setter methods
// ---------------------------------------------------------------------------
inline void FieldValueMap::put(IC_Field* const key,
DatatypeValidator* const dv,
const XMLCh* const value) {
if (!fFields) {
fFields = new (fMemoryManager) ValueVectorOf<IC_Field*>(4, fMemoryManager);
fValidators = new (fMemoryManager) ValueVectorOf<DatatypeValidator*>(4, fMemoryManager);
fValues = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager);
}
XMLSize_t keyIndex;
bool bFound=indexOf(key, keyIndex);
if (!bFound) {
fFields->addElement(key);
fValidators->addElement(dv);
fValues->addElement(XMLString::replicate(value, fMemoryManager));
}
else {
fValidators->setElementAt(dv, keyIndex);
fValues->setElementAt(XMLString::replicate(value, fMemoryManager), keyIndex);
}
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file FieldValueMap.hpp
*/
@@ -0,0 +1,141 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Field.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/FieldActivator.hpp>
#include <xercesc/validators/schema/identity/IC_Field.hpp>
#include <xercesc/validators/schema/identity/ValueStore.hpp>
#include <xercesc/validators/schema/identity/XercesXPath.hpp>
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// FieldMatcher: Constructors and Destructor
// ---------------------------------------------------------------------------
FieldMatcher::FieldMatcher(XercesXPath* const xpath,
IC_Field* const aField,
ValueStore* const valueStore,
FieldActivator* const fieldActivator,
MemoryManager* const manager)
: XPathMatcher(xpath, (IdentityConstraint*) 0, manager)
, fValueStore(valueStore)
, fField(aField)
, fFieldActivator(fieldActivator)
{
}
// ---------------------------------------------------------------------------
// FieldMatcher: Match methods
// ---------------------------------------------------------------------------
void FieldMatcher::matched(const XMLCh* const content,
DatatypeValidator* const dv,
const bool isNil) {
if(isNil) {
fValueStore->reportNilError(fField->getIdentityConstraint());
}
fValueStore->addValue(fFieldActivator, fField, dv, content);
// once we've stored the value for this field, we set the mayMatch
// member to false so that, in the same scope, we don't match any more
// values (and throw an error instead).
fFieldActivator->setMayMatch(fField, false);
}
// ---------------------------------------------------------------------------
// IC_Field: Constructors and Destructor
// ---------------------------------------------------------------------------
IC_Field::IC_Field(XercesXPath* const xpath,
IdentityConstraint* const identityConstraint)
: fXPath(xpath)
, fIdentityConstraint(identityConstraint)
{
}
IC_Field::~IC_Field()
{
delete fXPath;
}
// ---------------------------------------------------------------------------
// IC_Field: operators
// ---------------------------------------------------------------------------
bool IC_Field::operator== (const IC_Field& other) const {
return (*fXPath == *(other.fXPath));
}
bool IC_Field::operator!= (const IC_Field& other) const {
return !operator==(other);
}
// ---------------------------------------------------------------------------
// IC_Field: Factory methods
// ---------------------------------------------------------------------------
XPathMatcher* IC_Field::createMatcher(FieldActivator* const fieldActivator,
ValueStore* const valueStore,
MemoryManager* const manager)
{
return new (manager) FieldMatcher(fXPath, this, valueStore, fieldActivator, manager);
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(IC_Field)
void IC_Field::serialize(XSerializeEngine& serEng)
{
if (serEng.isStoring())
{
serEng<<fXPath;
IdentityConstraint::storeIC(serEng, fIdentityConstraint);
}
else
{
serEng>>fXPath;
fIdentityConstraint = IdentityConstraint::loadIC(serEng);
}
}
IC_Field::IC_Field(MemoryManager* const )
:fXPath(0)
,fIdentityConstraint(0)
{
}
XERCES_CPP_NAMESPACE_END
/**
* End of file IC_Field.cpp
*/
@@ -0,0 +1,152 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Field.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_IC_FIELD_HPP)
#define XERCESC_INCLUDE_GUARD_IC_FIELD_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/XPathMatcher.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declaration
// ---------------------------------------------------------------------------
class ValueStore;
class FieldActivator;
class VALIDATORS_EXPORT IC_Field : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
IC_Field(XercesXPath* const xpath,
IdentityConstraint* const identityConstraint);
~IC_Field();
// -----------------------------------------------------------------------
// operators
// -----------------------------------------------------------------------
bool operator== (const IC_Field& other) const;
bool operator!= (const IC_Field& other) const;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
XercesXPath* getXPath() const { return fXPath; }
IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; }
// -----------------------------------------------------------------------
// Factory methods
// -----------------------------------------------------------------------
XPathMatcher* createMatcher
(
FieldActivator* const fieldActivator
, ValueStore* const valueStore
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(IC_Field)
IC_Field(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
IC_Field(const IC_Field& other);
IC_Field& operator= (const IC_Field& other);
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
XercesXPath* fXPath;
IdentityConstraint* fIdentityConstraint;
};
class VALIDATORS_EXPORT FieldMatcher : public XPathMatcher
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
~FieldMatcher() {}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
ValueStore* getValueStore() const { return fValueStore; }
IC_Field* getField() const { return fField; }
// -----------------------------------------------------------------------
// Virtual methods
// -----------------------------------------------------------------------
void matched(const XMLCh* const content, DatatypeValidator* const dv,
const bool isNil);
private:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
FieldMatcher(XercesXPath* const anXPath,
IC_Field* const aField,
ValueStore* const valueStore,
FieldActivator* const fieldActivator,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
FieldMatcher(const FieldMatcher& other);
FieldMatcher& operator= (const FieldMatcher& other);
// -----------------------------------------------------------------------
// Friends
// -----------------------------------------------------------------------
friend class IC_Field;
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
ValueStore* fValueStore;
IC_Field* fField;
FieldActivator* fFieldActivator;
};
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file IC_Field.hpp
*/
@@ -0,0 +1,67 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Key.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/IC_Key.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// IC_Key: Constructors and Destructor
// ---------------------------------------------------------------------------
IC_Key::IC_Key(const XMLCh* const identityConstraintName,
const XMLCh* const elemName,
MemoryManager* const manager)
:IdentityConstraint(identityConstraintName, elemName, manager)
{
}
IC_Key::~IC_Key()
{
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(IC_Key)
void IC_Key::serialize(XSerializeEngine& serEng)
{
IdentityConstraint::serialize(serEng);
//no data
}
IC_Key::IC_Key(MemoryManager* const manager)
:IdentityConstraint(0, 0, manager)
{
}
XERCES_CPP_NAMESPACE_END
/**
* End of file IC_Key.cpp
*/
@@ -0,0 +1,80 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Key.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_IC_KEY_HPP)
#define XERCESC_INCLUDE_GUARD_IC_KEY_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class VALIDATORS_EXPORT IC_Key: public IdentityConstraint
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
IC_Key(const XMLCh* const identityConstraintName,
const XMLCh* const elemName,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~IC_Key();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
short getType() const;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(IC_Key)
IC_Key(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
IC_Key(const IC_Key& other);
IC_Key& operator= (const IC_Key& other);
};
// ---------------------------------------------------------------------------
// IC_Key: Getter methods
// ---------------------------------------------------------------------------
inline short IC_Key::getType() const {
return IdentityConstraint::ICType_KEY;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file IC_Key.hpp
*/
@@ -0,0 +1,79 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_KeyRef.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/IC_KeyRef.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// IC_KeyRef: Constructors and Destructor
// ---------------------------------------------------------------------------
IC_KeyRef::IC_KeyRef(const XMLCh* const identityConstraintName,
const XMLCh* const elemName,
IdentityConstraint* const icKey,
MemoryManager* const manager)
: IdentityConstraint(identityConstraintName, elemName, manager)
, fKey(icKey)
{
}
IC_KeyRef::~IC_KeyRef()
{
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(IC_KeyRef)
void IC_KeyRef::serialize(XSerializeEngine& serEng)
{
IdentityConstraint::serialize(serEng);
if (serEng.isStoring())
{
IdentityConstraint::storeIC(serEng, fKey);
}
else
{
fKey = IdentityConstraint::loadIC(serEng);
}
}
IC_KeyRef::IC_KeyRef(MemoryManager* const manager)
:IdentityConstraint(0, 0, manager)
,fKey(0)
{
}
XERCES_CPP_NAMESPACE_END
/**
* End of file IC_KeyRef.cpp
*/
@@ -0,0 +1,92 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_KeyRef.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_IC_KEYREF_HPP)
#define XERCESC_INCLUDE_GUARD_IC_KEYREF_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class VALIDATORS_EXPORT IC_KeyRef: public IdentityConstraint
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
IC_KeyRef(const XMLCh* const identityConstraintName,
const XMLCh* const elemName,
IdentityConstraint* const icKey,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~IC_KeyRef();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
short getType() const;
IdentityConstraint* getKey() const;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(IC_KeyRef)
IC_KeyRef(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
IC_KeyRef(const IC_KeyRef& other);
IC_KeyRef& operator= (const IC_KeyRef& other);
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
IdentityConstraint* fKey;
};
// ---------------------------------------------------------------------------
// IC_KeyRef: Getter methods
// ---------------------------------------------------------------------------
inline short IC_KeyRef::getType() const {
return IdentityConstraint::ICType_KEYREF;
}
inline IdentityConstraint* IC_KeyRef::getKey() const {
return fKey;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file IC_KeyRef.hpp
*/
@@ -0,0 +1,178 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Selector.cpp 803869 2009-08-13 12:56:21Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/framework/XMLAttr.hpp>
#include <xercesc/validators/schema/identity/IC_Selector.hpp>
#include <xercesc/validators/schema/identity/XercesXPath.hpp>
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
#include <xercesc/validators/schema/identity/FieldActivator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// SelectorMatcher: Constructors and Destructor
// ---------------------------------------------------------------------------
SelectorMatcher::SelectorMatcher(XercesXPath* const xpath,
IC_Selector* const selector,
FieldActivator* const fieldActivator,
const int initialDepth,
MemoryManager* const manager)
: XPathMatcher(xpath, selector->getIdentityConstraint(), manager)
, fInitialDepth(initialDepth)
, fElementDepth(0)
, fMatchedDepth(-1)
, fSelector(selector)
, fFieldActivator(fieldActivator)
{
}
// ---------------------------------------------------------------------------
// FieldMatcher: XMLDocumentHandler methods
// ---------------------------------------------------------------------------
void SelectorMatcher::startDocumentFragment() {
XPathMatcher::startDocumentFragment();
fElementDepth = 0;
fMatchedDepth = -1;
}
void SelectorMatcher::startElement(const XMLElementDecl& elemDecl,
const unsigned int urlId,
const XMLCh* const elemPrefix,
const RefVectorOf<XMLAttr>& attrList,
const XMLSize_t attrCount,
ValidationContext* validationContext /*=0*/)
{
XPathMatcher::startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, validationContext);
fElementDepth++;
// activate the fields, if selector is matched
unsigned char matched = isMatched();
if ((fMatchedDepth == -1 && ((matched & XP_MATCHED) == XP_MATCHED))
|| ((matched & XP_MATCHED_D) == XP_MATCHED_D)) {
IdentityConstraint* ic = fSelector->getIdentityConstraint();
XMLSize_t count = ic->getFieldCount();
fMatchedDepth = fElementDepth;
fFieldActivator->startValueScopeFor(ic, fInitialDepth);
for (XMLSize_t i = 0; i < count; i++) {
XPathMatcher* matcher = fFieldActivator->activateField(ic->getFieldAt(i), fInitialDepth);
matcher->startElement(elemDecl, urlId, elemPrefix, attrList, attrCount, validationContext);
}
}
}
void SelectorMatcher::endElement(const XMLElementDecl& elemDecl,
const XMLCh* const elemContent,
ValidationContext* validationContext /*=0*/,
DatatypeValidator* actualValidator /*=0*/)
{
XPathMatcher::endElement(elemDecl, elemContent, validationContext, actualValidator);
if (fElementDepth-- == fMatchedDepth) {
fMatchedDepth = -1;
fFieldActivator->endValueScopeFor(fSelector->getIdentityConstraint(), fInitialDepth);
}
}
// ---------------------------------------------------------------------------
// IC_Selector: Constructors and Destructor
// ---------------------------------------------------------------------------
IC_Selector::IC_Selector(XercesXPath* const xpath,
IdentityConstraint* const identityConstraint)
: fXPath(xpath)
, fIdentityConstraint(identityConstraint)
{
}
IC_Selector::~IC_Selector()
{
delete fXPath;
}
// ---------------------------------------------------------------------------
// IC_Selector: operators
// ---------------------------------------------------------------------------
bool IC_Selector::operator ==(const IC_Selector& other) const {
return (*fXPath == *(other.fXPath));
}
bool IC_Selector::operator !=(const IC_Selector& other) const {
return !operator==(other);
}
// ---------------------------------------------------------------------------
// IC_Selector: Factory methods
// ---------------------------------------------------------------------------
XPathMatcher* IC_Selector::createMatcher(FieldActivator* const fieldActivator,
const int initialDepth,
MemoryManager* const manager) {
return new (manager) SelectorMatcher(fXPath, this, fieldActivator, initialDepth, manager);
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(IC_Selector)
void IC_Selector::serialize(XSerializeEngine& serEng)
{
if (serEng.isStoring())
{
serEng<<fXPath;
IdentityConstraint::storeIC(serEng, fIdentityConstraint);
}
else
{
serEng>>fXPath;
fIdentityConstraint = IdentityConstraint::loadIC(serEng);
}
}
IC_Selector::IC_Selector(MemoryManager* const )
:fXPath(0)
,fIdentityConstraint(0)
{
}
XERCES_CPP_NAMESPACE_END
/**
* End of file IC_Selector.cpp
*/
@@ -0,0 +1,155 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Selector.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_IC_SELECTOR_HPP)
#define XERCESC_INCLUDE_GUARD_IC_SELECTOR_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/XPathMatcher.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declaration
// ---------------------------------------------------------------------------
class FieldActivator;
class VALIDATORS_EXPORT IC_Selector : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
IC_Selector(XercesXPath* const xpath,
IdentityConstraint* const identityConstraint);
~IC_Selector();
// -----------------------------------------------------------------------
// operators
// -----------------------------------------------------------------------
bool operator== (const IC_Selector& other) const;
bool operator!= (const IC_Selector& other) const;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
XercesXPath* getXPath() const { return fXPath; }
IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; }
// -----------------------------------------------------------------------
// Factory methods
// -----------------------------------------------------------------------
XPathMatcher* createMatcher(FieldActivator* const fieldActivator,
const int initialDepth,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(IC_Selector)
IC_Selector(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
IC_Selector(const IC_Selector& other);
IC_Selector& operator= (const IC_Selector& other);
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
XercesXPath* fXPath;
IdentityConstraint* fIdentityConstraint;
};
class VALIDATORS_EXPORT SelectorMatcher : public XPathMatcher
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
~SelectorMatcher() {}
int getInitialDepth() const { return fInitialDepth; }
// -----------------------------------------------------------------------
// XMLDocumentHandler methods
// -----------------------------------------------------------------------
virtual void startDocumentFragment();
virtual void startElement(const XMLElementDecl& elemDecl,
const unsigned int urlId,
const XMLCh* const elemPrefix,
const RefVectorOf<XMLAttr>& attrList,
const XMLSize_t attrCount,
ValidationContext* validationContext = 0);
virtual void endElement(const XMLElementDecl& elemDecl,
const XMLCh* const elemContent,
ValidationContext* validationContext = 0,
DatatypeValidator* actualValidator = 0);
private:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
SelectorMatcher(XercesXPath* const anXPath,
IC_Selector* const selector,
FieldActivator* const fieldActivator,
const int initialDepth,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SelectorMatcher(const SelectorMatcher& other);
SelectorMatcher& operator= (const SelectorMatcher& other);
// -----------------------------------------------------------------------
// Friends
// -----------------------------------------------------------------------
friend class IC_Selector;
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
int fInitialDepth;
int fElementDepth;
int fMatchedDepth;
IC_Selector* fSelector;
FieldActivator* fFieldActivator;
};
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file IC_Selector.hpp
*/
@@ -0,0 +1,68 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Unique.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/IC_Unique.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// IC_Unique: Constructors and Destructor
// ---------------------------------------------------------------------------
IC_Unique::IC_Unique(const XMLCh* const identityConstraintName,
const XMLCh* const elemName,
MemoryManager* const manager)
: IdentityConstraint(identityConstraintName, elemName, manager)
{
}
IC_Unique::~IC_Unique()
{
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(IC_Unique)
void IC_Unique::serialize(XSerializeEngine& serEng)
{
IdentityConstraint::serialize(serEng);
//no data
}
IC_Unique::IC_Unique(MemoryManager* const manager)
:IdentityConstraint(0, 0, manager)
{
}
XERCES_CPP_NAMESPACE_END
/**
* End of file IC_Unique.cpp
*/
@@ -0,0 +1,84 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IC_Unique.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_IC_UNIQUE_HPP)
#define XERCESC_INCLUDE_GUARD_IC_UNIQUE_HPP
/**
* Schema unique identity constraint
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class VALIDATORS_EXPORT IC_Unique: public IdentityConstraint
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
IC_Unique(const XMLCh* const identityConstraintName,
const XMLCh* const elemName,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~IC_Unique();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
short getType() const;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(IC_Unique)
IC_Unique(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
IC_Unique(const IC_Unique& other);
IC_Unique& operator= (const IC_Unique& other);
};
// ---------------------------------------------------------------------------
// IC_Unique: Getter methods
// ---------------------------------------------------------------------------
inline short IC_Unique::getType() const {
return IdentityConstraint::ICType_UNIQUE;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file IC_Unique.hpp
*/
@@ -0,0 +1,226 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IdentityConstraint.cpp 676911 2008-07-15 13:27:32Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
#include <xercesc/validators/schema/identity/IC_Selector.hpp>
#include <xercesc/validators/schema/identity/IC_Field.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
//since we need to dynamically created each and every derivatives
//during deserialization by XSerializeEngine>>Derivative, we got
//to include all hpp
#include <xercesc/validators/schema/identity/IC_Unique.hpp>
#include <xercesc/validators/schema/identity/IC_Key.hpp>
#include <xercesc/validators/schema/identity/IC_KeyRef.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
typedef JanitorMemFunCall<IdentityConstraint> CleanupType;
// ---------------------------------------------------------------------------
// IdentityConstraint: Constructors and Destructor
// ---------------------------------------------------------------------------
IdentityConstraint::IdentityConstraint(const XMLCh* const identityConstraintName,
const XMLCh* const elemName,
MemoryManager* const manager)
: fIdentityConstraintName(0)
, fElemName(0)
, fSelector(0)
, fFields(0)
, fMemoryManager(manager)
, fNamespaceURI(-1)
{
CleanupType cleanup(this, &IdentityConstraint::cleanUp);
try {
fIdentityConstraintName = XMLString::replicate(identityConstraintName, fMemoryManager);
fElemName = XMLString::replicate(elemName, fMemoryManager);
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
IdentityConstraint::~IdentityConstraint()
{
cleanUp();
}
// ---------------------------------------------------------------------------
// IdentityConstraint: operators
// ---------------------------------------------------------------------------
bool IdentityConstraint::operator ==(const IdentityConstraint& other) const {
if (getType() != other.getType())
return false;
if (!XMLString::equals(fIdentityConstraintName, other.fIdentityConstraintName))
return false;
if (*fSelector != *(other.fSelector))
return false;
XMLSize_t fieldCount = fFields->size();
if (fieldCount != other.fFields->size())
return false;
for (XMLSize_t i = 0; i < fieldCount; i++) {
if (*(fFields->elementAt(i)) != *(other.fFields->elementAt(i)))
return false;
}
return true;
}
bool IdentityConstraint::operator !=(const IdentityConstraint& other) const {
return !operator==(other);
}
// ---------------------------------------------------------------------------
// IdentityConstraint: Setter methods
// ---------------------------------------------------------------------------
void IdentityConstraint::setSelector(IC_Selector* const selector) {
if (fSelector) {
delete fSelector;
}
fSelector = selector;
}
// ---------------------------------------------------------------------------
// IdentityConstraint: cleanUp methods
// ---------------------------------------------------------------------------
void IdentityConstraint::cleanUp() {
fMemoryManager->deallocate(fIdentityConstraintName);//delete [] fIdentityConstraintName;
fMemoryManager->deallocate(fElemName);//delete [] fElemName;
delete fFields;
delete fSelector;
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_NOCREATE(IdentityConstraint)
void IdentityConstraint::serialize(XSerializeEngine& serEng)
{
if (serEng.isStoring())
{
serEng.writeString(fIdentityConstraintName);
serEng.writeString(fElemName);
serEng<<fSelector;
serEng<<fNamespaceURI;
/***
*
* Serialize RefVectorOf<IC_Field>* fFields;
*
***/
XTemplateSerializer::storeObject(fFields, serEng);
}
else
{
serEng.readString(fIdentityConstraintName);
serEng.readString(fElemName);
serEng>>fSelector;
serEng>>fNamespaceURI;
/***
*
* Deserialize RefVectorOf<IC_Field>* fFields;
*
***/
XTemplateSerializer::loadObject(&fFields, 4, true, serEng);
}
}
void IdentityConstraint::storeIC(XSerializeEngine& serEng
, IdentityConstraint* const ic)
{
if (ic)
{
serEng<<(int) ic->getType();
serEng<<ic;
}
else
{
serEng<<(int) ICType_UNKNOWN;
}
}
IdentityConstraint* IdentityConstraint::loadIC(XSerializeEngine& serEng)
{
int type;
serEng>>type;
switch((ICType)type)
{
case ICType_UNIQUE:
IC_Unique* ic_unique;
serEng>>ic_unique;
return ic_unique;
case ICType_KEY:
IC_Key* ic_key;
serEng>>ic_key;
return ic_key;
case ICType_KEYREF:
IC_KeyRef* ic_keyref;
serEng>>ic_keyref;
return ic_keyref;
case ICType_UNKNOWN:
return 0;
default: //we treat this same as UnKnown
return 0;
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file IdentityConstraint.cpp
*/
@@ -0,0 +1,223 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IdentityConstraint.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_IDENTITYCONSTRAINT_HPP)
#define XERCESC_INCLUDE_GUARD_IDENTITYCONSTRAINT_HPP
/**
* The class act as a base class for schema identity constraints.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/validators/schema/identity/IC_Field.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class IC_Selector;
class VALIDATORS_EXPORT IdentityConstraint : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------
enum ICType {
ICType_UNIQUE = 0,
ICType_KEY = 1,
ICType_KEYREF = 2,
ICType_UNKNOWN
};
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
virtual ~IdentityConstraint();
// -----------------------------------------------------------------------
// operators
// -----------------------------------------------------------------------
bool operator== (const IdentityConstraint& other) const;
bool operator!= (const IdentityConstraint& other) const;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
virtual short getType() const = 0;
XMLSize_t getFieldCount() const;
XMLCh* getIdentityConstraintName() const;
XMLCh* getElementName() const;
IC_Selector* getSelector() const;
int getNamespaceURI() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setSelector(IC_Selector* const selector);
void setNamespaceURI(int uri);
// -----------------------------------------------------------------------
// Access methods
// -----------------------------------------------------------------------
void addField(IC_Field* const field);
const IC_Field* getFieldAt(const XMLSize_t index) const;
IC_Field* getFieldAt(const XMLSize_t index);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(IdentityConstraint)
static void storeIC(XSerializeEngine& serEng
, IdentityConstraint* const ic);
static IdentityConstraint* loadIC(XSerializeEngine& serEng);
protected:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
IdentityConstraint(const XMLCh* const identityConstraintName,
const XMLCh* const elementName,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
IdentityConstraint(const IdentityConstraint& other);
IdentityConstraint& operator= (const IdentityConstraint& other);
// -----------------------------------------------------------------------
// CleanUp methods
// -----------------------------------------------------------------------
void cleanUp();
// -----------------------------------------------------------------------
// Data members
//
// fIdentityConstraintName
// The identity constraint name
//
// fElemName
// The element name
//
// fSelector
// The selector information
//
// fFields
// The field(s) information
// -----------------------------------------------------------------------
XMLCh* fIdentityConstraintName;
XMLCh* fElemName;
IC_Selector* fSelector;
RefVectorOf<IC_Field>* fFields;
MemoryManager* fMemoryManager;
int fNamespaceURI;
};
// ---------------------------------------------------------------------------
// IdentityConstraint: Getter methods
// ---------------------------------------------------------------------------
inline XMLSize_t IdentityConstraint::getFieldCount() const {
if (fFields) {
return fFields->size();
}
return 0;
}
inline XMLCh* IdentityConstraint::getIdentityConstraintName() const {
return fIdentityConstraintName;
}
inline XMLCh* IdentityConstraint::getElementName() const {
return fElemName;
}
inline IC_Selector* IdentityConstraint::getSelector() const {
return fSelector;
}
inline int IdentityConstraint::getNamespaceURI() const
{
return fNamespaceURI;
}
// ---------------------------------------------------------------------------
// IdentityConstraint: Setter methods
// ---------------------------------------------------------------------------
inline void IdentityConstraint::setNamespaceURI(int uri)
{
fNamespaceURI = uri;
}
// ---------------------------------------------------------------------------
// IdentityConstraint: Access methods
// ---------------------------------------------------------------------------
inline void IdentityConstraint::addField(IC_Field* const field) {
if (!fFields) {
fFields = new (fMemoryManager) RefVectorOf<IC_Field>(4, true, fMemoryManager);
}
fFields->addElement(field);
}
inline const IC_Field* IdentityConstraint::getFieldAt(const XMLSize_t index) const {
if (fFields) {
return (fFields->elementAt(index));
}
return 0;
}
inline IC_Field* IdentityConstraint::getFieldAt(const XMLSize_t index) {
if (fFields) {
return (fFields->elementAt(index));
}
return 0;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file IdentityConstraint.hpp
*/
@@ -0,0 +1,215 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IdentityConstraintHandler.cpp 803869 2009-08-13 12:56:21Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include "IdentityConstraintHandler.hpp"
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
#include <xercesc/validators/schema/identity/FieldActivator.hpp>
#include <xercesc/validators/schema/identity/ValueStore.hpp>
#include <xercesc/validators/schema/identity/IC_Selector.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
typedef JanitorMemFunCall<IdentityConstraintHandler> CleanupType;
// ---------------------------------------------------------------------------
// IdentityConstraintHandler: Constructors and Destructor
// ---------------------------------------------------------------------------
IdentityConstraintHandler::IdentityConstraintHandler(XMLScanner* const scanner
, MemoryManager* const manager)
: fScanner(scanner)
, fMemoryManager(manager)
, fMatcherStack(0)
, fValueStoreCache(0)
, fFieldActivator(0)
{
CleanupType cleanup(this, &IdentityConstraintHandler::cleanUp);
try {
fMatcherStack = new (fMemoryManager) XPathMatcherStack(fMemoryManager);
fValueStoreCache = new (fMemoryManager) ValueStoreCache(fMemoryManager);
fFieldActivator = new (fMemoryManager) FieldActivator(fValueStoreCache, fMatcherStack, fMemoryManager);
fValueStoreCache->setScanner(scanner);
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
IdentityConstraintHandler::~IdentityConstraintHandler()
{
cleanUp();
}
// ---------------------------------------------------------------------------
// IdentityConstraintHandler: methods
// ---------------------------------------------------------------------------
void IdentityConstraintHandler::deactivateContext( SchemaElementDecl* const elem
, const XMLCh* const content
, ValidationContext* validationContext /*=0*/
, DatatypeValidator* actualValidator /*=0*/)
{
XMLSize_t oldCount = fMatcherStack->getMatcherCount();
if (oldCount || elem->getIdentityConstraintCount())
{
for (XMLSize_t i = oldCount; i > 0; i--)
{
XPathMatcher* matcher = fMatcherStack->getMatcherAt(i-1);
matcher->endElement(*(elem), content, validationContext, actualValidator);
}
if (fMatcherStack->size() > 0)
{
fMatcherStack->popContext();
}
// handle everything *but* keyref's.
XMLSize_t newCount = fMatcherStack->getMatcherCount();
for (XMLSize_t j = oldCount; j > newCount; j--)
{
XPathMatcher* matcher = fMatcherStack->getMatcherAt(j-1);
IdentityConstraint* ic = matcher->getIdentityConstraint();
if (ic && (ic->getType() != IdentityConstraint::ICType_KEYREF))
fValueStoreCache->transplant(ic, matcher->getInitialDepth());
}
// now handle keyref's...
for (XMLSize_t k = oldCount; k > newCount; k--)
{
XPathMatcher* matcher = fMatcherStack->getMatcherAt(k-1);
IdentityConstraint* ic = matcher->getIdentityConstraint();
if (ic && (ic->getType() == IdentityConstraint::ICType_KEYREF))
{
ValueStore* values = fValueStoreCache->getValueStoreFor(ic, matcher->getInitialDepth());
if (values) { // nothing to do if nothing matched!
values->endDocumentFragment(fValueStoreCache);
}
}
}
fValueStoreCache->endElement();
}
}
void IdentityConstraintHandler::activateIdentityConstraint
(
SchemaElementDecl* const elem
, int elemDepth
, const unsigned int uriId
, const XMLCh* const elemPrefix
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount
, ValidationContext* validationContext /*=0*/)
{
XMLSize_t count = elem->getIdentityConstraintCount();
if (count || fMatcherStack->getMatcherCount())
{
fValueStoreCache->startElement();
fMatcherStack->pushContext();
fValueStoreCache->initValueStoresFor( elem, elemDepth);
for (XMLSize_t i = 0; i < count; i++)
{
activateSelectorFor(elem->getIdentityConstraintAt(i), elemDepth);
}
// call all active identity constraints
count = fMatcherStack->getMatcherCount();
for (XMLSize_t j = 0; j < count; j++)
{
XPathMatcher* matcher = fMatcherStack->getMatcherAt(j);
matcher->startElement(*elem, uriId, elemPrefix, attrList, attrCount, validationContext);
}
}
}
void IdentityConstraintHandler::activateSelectorFor( IdentityConstraint* const ic
, const int initialDepth)
{
IC_Selector* selector = ic->getSelector();
if (!selector)
return;
XPathMatcher* matcher = selector->createMatcher(fFieldActivator, initialDepth, fMemoryManager);
fMatcherStack->addMatcher(matcher);
matcher->startDocumentFragment();
}
// ---------------------------------------------------------------------------
// IdentityConstraintHandler: Getter methods
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// IdentityConstraintHandler: cleanUp methods
// ---------------------------------------------------------------------------
void IdentityConstraintHandler::cleanUp()
{
if (fMatcherStack)
delete fMatcherStack;
if (fValueStoreCache)
delete fValueStoreCache;
if (fFieldActivator)
delete fFieldActivator;
}
void IdentityConstraintHandler::reset()
{
fValueStoreCache->startDocument();
fMatcherStack->clear();
}
XERCES_CPP_NAMESPACE_END
/**
* End of file IdentityConstraintHandler.cpp
*/
@@ -0,0 +1,159 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: IdentityConstraintHandler.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_IDENTITYCONSTRAINT_HANDLER_HPP)
#define XERCESC_INCLUDE_GUARD_IDENTITYCONSTRAINT_HANDLER_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/ValueStoreCache.hpp>
#include <xercesc/validators/schema/identity/XPathMatcherStack.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class XMLScanner;
class FieldActivator;
class MemoryManager;
class XMLElementDecl;
class VALIDATORS_EXPORT IdentityConstraintHandler: public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
virtual ~IdentityConstraintHandler();
IdentityConstraintHandler
(
XMLScanner* const scanner
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
inline XMLSize_t getMatcherCount() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Access methods
// -----------------------------------------------------------------------
inline void endDocument();
void deactivateContext
(
SchemaElementDecl* const elem
, const XMLCh* const content
, ValidationContext* validationContext = 0
, DatatypeValidator* actualValidator = 0);
void activateIdentityConstraint
(
SchemaElementDecl* const elem
, int elemDepth
, const unsigned int uriId
, const XMLCh* const elemPrefix
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount
, ValidationContext* validationContext = 0 );
void reset();
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
IdentityConstraintHandler(const IdentityConstraintHandler& other);
IdentityConstraintHandler& operator= (const IdentityConstraintHandler& other);
// -----------------------------------------------------------------------
// CleanUp methods
// -----------------------------------------------------------------------
void cleanUp();
// -----------------------------------------------------------------------
// Helper
// -----------------------------------------------------------------------
void activateSelectorFor(
IdentityConstraint* const ic
, const int initialDepth
) ;
// -----------------------------------------------------------------------
// Data members
//
// fMatcherStack
// Stack of active XPath matchers for identity constraints. All
// active XPath matchers are notified of startElement, characters
// and endElement callbacks in order to perform their matches.
//
// fValueStoreCache
// Cache of value stores for identity constraint fields.
//
// fFieldActivator
// Activates fields within a certain scope when a selector matches
// its xpath.
//
// -----------------------------------------------------------------------
XMLScanner* fScanner;
MemoryManager* fMemoryManager;
XPathMatcherStack* fMatcherStack;
ValueStoreCache* fValueStoreCache;
FieldActivator* fFieldActivator;
};
// ---------------------------------------------------------------------------
// IdentityConstraintHandler:
// ---------------------------------------------------------------------------
inline
void IdentityConstraintHandler::endDocument()
{
fValueStoreCache->endDocument();
}
inline
XMLSize_t IdentityConstraintHandler::getMatcherCount() const
{
return fMatcherStack->getMatcherCount();
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file IdentityConstraintHandler.hpp
*/
@@ -0,0 +1,352 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ValueStore.cpp 804209 2009-08-14 13:15:05Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/internal/XMLScanner.hpp>
#include <xercesc/framework/XMLValidator.hpp>
#include <xercesc/validators/datatype/DatatypeValidator.hpp>
#include <xercesc/validators/schema/identity/FieldActivator.hpp>
#include <xercesc/validators/schema/identity/ValueStore.hpp>
#include <xercesc/validators/schema/identity/IC_Field.hpp>
#include <xercesc/validators/schema/identity/IC_KeyRef.hpp>
#include <xercesc/validators/schema/identity/ValueStoreCache.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// ---------------------------------------------------------------------------
// ICValueHasher: the hasher for identity constraints values
// ---------------------------------------------------------------------------
XMLSize_t ICValueHasher::getHashVal(const void* key, XMLSize_t mod) const
{
const FieldValueMap* valueMap=(const FieldValueMap*)key;
XMLSize_t hashVal = 0;
XMLSize_t size = valueMap->size();
for (XMLSize_t j=0; j<size; j++) {
// reach the most generic datatype validator
DatatypeValidator* dv = valueMap->getDatatypeValidatorAt(j);
while(dv && dv->getBaseValidator())
dv = dv->getBaseValidator();
const XMLCh* const val = valueMap->getValueAt(j);
const XMLCh* canonVal = (dv && val)?dv->getCanonicalRepresentation(val, fMemoryManager):0;
if(canonVal)
{
hashVal += XMLString::hash(canonVal, mod);
fMemoryManager->deallocate((void*)canonVal);
}
else if(val)
hashVal += XMLString::hash(val, mod);
}
return hashVal % mod;
}
bool ICValueHasher::equals(const void *const key1, const void *const key2) const
{
const FieldValueMap* left=(const FieldValueMap*)key1;
const FieldValueMap* right=(const FieldValueMap*)key2;
XMLSize_t lSize = left->size();
XMLSize_t rSize = right->size();
if (lSize == rSize)
{
bool matchFound = true;
for (XMLSize_t j=0; j<rSize; j++) {
if (!isDuplicateOf(left->getDatatypeValidatorAt(j), left->getValueAt(j),
right->getDatatypeValidatorAt(j), right->getValueAt(j))) {
matchFound = false;
break;
}
}
if (matchFound) { // found it
return true;
}
}
return false;
}
bool ICValueHasher::isDuplicateOf(DatatypeValidator* const dv1, const XMLCh* const val1,
DatatypeValidator* const dv2, const XMLCh* const val2) const
{
// if either validator's null, fall back on string comparison
if(!dv1 || !dv2) {
return (XMLString::equals(val1, val2));
}
bool val1IsEmpty = (val1==0 || *val1==0);
bool val2IsEmpty = (val2==0 || *val2==0);
if (val1IsEmpty && val2IsEmpty) {
if (dv1 == dv2) {
return true;
}
return false;
}
if (val1IsEmpty || val2IsEmpty) {
return false;
}
// find the common ancestor, if there is one
DatatypeValidator* tempVal1 = dv1;
while(tempVal1)
{
DatatypeValidator* tempVal2 = dv2;
for(; tempVal2 != NULL && tempVal2 != tempVal1; tempVal2 = tempVal2->getBaseValidator()) ;
if (tempVal2)
return ((tempVal2->compare(val1, val2, fMemoryManager)) == 0);
tempVal1=tempVal1->getBaseValidator();
}
// if we're here it means the types weren't related. They are different:
return false;
}
// ---------------------------------------------------------------------------
// ValueStore: Constructors and Destructor
// ---------------------------------------------------------------------------
ValueStore::ValueStore(IdentityConstraint* const ic,
XMLScanner* const scanner,
MemoryManager* const manager)
: fDoReportError(false)
, fValuesCount(0)
, fIdentityConstraint(ic)
, fValues(manager)
, fValueTuples(0)
, fScanner(scanner)
, fMemoryManager(manager)
{
fDoReportError = (scanner && (scanner->getValidationScheme() == XMLScanner::Val_Always));
}
ValueStore::~ValueStore()
{
delete fValueTuples;
}
// ---------------------------------------------------------------------------
// ValueStore: Helper methods
// ---------------------------------------------------------------------------
void ValueStore::addValue(FieldActivator* const fieldActivator,
IC_Field* const field,
DatatypeValidator* const dv,
const XMLCh* const value) {
if (!fieldActivator->getMayMatch(field) && fDoReportError) {
fScanner->getValidator()->emitError(XMLValid::IC_FieldMultipleMatch);
}
// do we even know this field?
XMLSize_t index;
bool bFound = fValues.indexOf(field, index);
if (!bFound) {
if (fDoReportError) {
fScanner->getValidator()->emitError(XMLValid::IC_UnknownField);
}
return;
}
// store value
if (!fValues.getDatatypeValidatorAt(index) &&
!fValues.getValueAt(index)) {
fValuesCount++;
}
fValues.put(field, dv, value);
if (fValuesCount == fValues.size()) {
// is this value as a group duplicated?
if (contains(&fValues)) {
duplicateValue();
}
// store values
if (!fValueTuples) {
fValueTuples = new (fMemoryManager) RefHashTableOf<FieldValueMap, ICValueHasher>(107, true, ICValueHasher(fMemoryManager), fMemoryManager);
}
FieldValueMap* pICItem = new (fMemoryManager) FieldValueMap(fValues);
fValueTuples->put(pICItem, pICItem);
}
}
void ValueStore::append(const ValueStore* const other) {
if (!other->fValueTuples) {
return;
}
RefHashTableOfEnumerator<FieldValueMap, ICValueHasher> iter(other->fValueTuples, false, fMemoryManager);
while(iter.hasMoreElements())
{
FieldValueMap& valueMap = iter.nextElement();
if (!contains(&valueMap)) {
if (!fValueTuples) {
fValueTuples = new (fMemoryManager) RefHashTableOf<FieldValueMap, ICValueHasher>(107, true, ICValueHasher(fMemoryManager), fMemoryManager);
}
FieldValueMap* pICItem = new (fMemoryManager) FieldValueMap(valueMap);
fValueTuples->put(pICItem, pICItem);
}
}
}
void ValueStore::startValueScope() {
fValuesCount = 0;
XMLSize_t count = fIdentityConstraint->getFieldCount();
for (XMLSize_t i = 0; i < count; i++) {
fValues.put(fIdentityConstraint->getFieldAt(i), 0, 0);
}
}
void ValueStore::endValueScope() {
if (fValuesCount == 0) {
if (fIdentityConstraint->getType() == IdentityConstraint::ICType_KEY && fDoReportError) {
fScanner->getValidator()->emitError(XMLValid::IC_AbsentKeyValue,
fIdentityConstraint->getElementName());
}
return;
}
// do we have enough values?
if ((fValuesCount != fIdentityConstraint->getFieldCount()) && fDoReportError) {
if(fIdentityConstraint->getType()==IdentityConstraint::ICType_KEY)
{
fScanner->getValidator()->emitError(XMLValid::IC_KeyNotEnoughValues,
fIdentityConstraint->getElementName(), fIdentityConstraint->getIdentityConstraintName());
}
}
}
bool ValueStore::contains(const FieldValueMap* const other) {
if (fValueTuples)
return fValueTuples->get(other)!=0;
return false;
}
void ValueStore::clear()
{
fValuesCount=0;
fValues.clear();
if(fValueTuples)
fValueTuples->removeAll();
}
// ---------------------------------------------------------------------------
// ValueStore: Document handling methods
// ---------------------------------------------------------------------------
void ValueStore::endDocumentFragment(ValueStoreCache* const valueStoreCache) {
if (fIdentityConstraint->getType() == IdentityConstraint::ICType_KEYREF) {
// verify references
// get the key store corresponding (if it exists):
ValueStore* keyValueStore = valueStoreCache->getGlobalValueStoreFor(((IC_KeyRef*) fIdentityConstraint)->getKey());
if (!keyValueStore) {
if (fDoReportError) {
fScanner->getValidator()->emitError(XMLValid::IC_KeyRefOutOfScope,
fIdentityConstraint->getIdentityConstraintName());
}
return;
}
if(fValueTuples)
{
RefHashTableOfEnumerator<FieldValueMap, ICValueHasher> iter(fValueTuples, false, fMemoryManager);
while(iter.hasMoreElements())
{
FieldValueMap& valueMap = iter.nextElement();
if (!keyValueStore->contains(&valueMap) && fDoReportError) {
fScanner->getValidator()->emitError(XMLValid::IC_KeyNotFound,
fIdentityConstraint->getElementName());
}
}
}
}
}
// ---------------------------------------------------------------------------
// ValueStore: Error reporting methods
// ---------------------------------------------------------------------------
void ValueStore::reportNilError(IdentityConstraint* const ic) {
if (fDoReportError && ic->getType() == IdentityConstraint::ICType_KEY) {
fScanner->getValidator()->emitError(XMLValid::IC_KeyMatchesNillable,
ic->getElementName());
}
}
void ValueStore::duplicateValue() {
if (fDoReportError) {
switch (fIdentityConstraint->getType()) {
case IdentityConstraint::ICType_UNIQUE:
{
fScanner->getValidator()->emitError(XMLValid::IC_DuplicateUnique,
fIdentityConstraint->getElementName());
break;
}
case IdentityConstraint::ICType_KEY:
{
fScanner->getValidator()->emitError(XMLValid::IC_DuplicateKey,
fIdentityConstraint->getElementName());
break;
}
}
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file ValueStore.cpp
*/
@@ -0,0 +1,146 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ValueStore.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_VALUESTORE_HPP)
#define XERCESC_INCLUDE_GUARD_VALUESTORE_HPP
/**
* This class stores values associated to an identity constraint.
* Each value stored corresponds to a field declared for the identity
* constraint.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/FieldValueMap.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declaration
// ---------------------------------------------------------------------------
class FieldActivator;
class IdentityConstraint;
class XMLScanner;
class ValueStoreCache;
struct ICValueHasher
{
ICValueHasher(MemoryManager* const manager) : fMemoryManager(manager) {}
XMLSize_t getHashVal(const void* key, XMLSize_t mod) const;
bool equals(const void *const key1, const void *const key2) const;
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
/**
* Returns whether a field associated <DatatypeValidator, String> value
* is a duplicate of another associated value.
* It is a duplicate only if either of these conditions are true:
* - The Datatypes are the same or related by derivation and the values
* are in the same valuespace.
* - The datatypes are unrelated and the values are Stringwise identical.
*/
bool isDuplicateOf(DatatypeValidator* const dv1, const XMLCh* const val1,
DatatypeValidator* const dv2, const XMLCh* const val2) const;
MemoryManager* fMemoryManager;
};
class VALIDATORS_EXPORT ValueStore : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
ValueStore(IdentityConstraint* const ic,
XMLScanner* const scanner,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~ValueStore();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
IdentityConstraint* getIdentityConstraint() const;
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void append(const ValueStore* const other);
void startValueScope();
void endValueScope();
void addValue(FieldActivator* const fieldActivator,
IC_Field* const field,
DatatypeValidator* const dv,
const XMLCh* const value);
bool contains(const FieldValueMap* const other);
void clear();
// -----------------------------------------------------------------------
// Document handling methods
// -----------------------------------------------------------------------
void endDocumentFragment(ValueStoreCache* const valueStoreCache);
// -----------------------------------------------------------------------
// Error reporting methods
// -----------------------------------------------------------------------
void duplicateValue();
void reportNilError(IdentityConstraint* const ic);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
ValueStore(const ValueStore& other);
ValueStore& operator= (const ValueStore& other);
// -----------------------------------------------------------------------
// Data
// -----------------------------------------------------------------------
bool fDoReportError;
XMLSize_t fValuesCount;
IdentityConstraint* fIdentityConstraint;
FieldValueMap fValues;
RefHashTableOf<FieldValueMap, ICValueHasher>* fValueTuples;
XMLScanner* fScanner; // for error reporting - REVISIT
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// ValueStore: Getter methods
// ---------------------------------------------------------------------------
inline IdentityConstraint*
ValueStore::getIdentityConstraint() const {
return fIdentityConstraint;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file ValueStore.hpp
*/
@@ -0,0 +1,184 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ValueStoreCache.cpp 708224 2008-10-27 16:02:26Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/ValueStoreCache.hpp>
#include <xercesc/validators/schema/identity/ValueStore.hpp>
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
typedef JanitorMemFunCall<ValueStoreCache> CleanupType;
// ---------------------------------------------------------------------------
// ValueStoreCache: Constructors and Destructor
// ---------------------------------------------------------------------------
ValueStoreCache::ValueStoreCache(MemoryManager* const manager)
: fValueStores(0)
, fGlobalICMap(0)
, fIC2ValueStoreMap(0)
, fGlobalMapStack(0)
, fScanner(0)
, fMemoryManager(manager)
{
CleanupType cleanup(this, &ValueStoreCache::cleanUp);
try {
init();
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
ValueStoreCache::~ValueStoreCache()
{
cleanUp();
}
// ---------------------------------------------------------------------------
// ValueStoreCache: Document handling methods
// ---------------------------------------------------------------------------
void ValueStoreCache::startDocument() {
fIC2ValueStoreMap->removeAll();
fGlobalICMap->removeAll();
fValueStores->removeAllElements();
fGlobalMapStack->removeAllElements();
}
void ValueStoreCache::startElement() {
fGlobalMapStack->push(fGlobalICMap);
fGlobalICMap = new (fMemoryManager) RefHashTableOf<ValueStore, PtrHasher>
(
13
, false
, fMemoryManager
);
}
void ValueStoreCache::endElement() {
if (fGlobalMapStack->empty()) {
return; // must be an invalid doc!
}
RefHashTableOf<ValueStore, PtrHasher>* oldMap = fGlobalMapStack->pop();
RefHashTableOfEnumerator<ValueStore, PtrHasher> mapEnum(oldMap, false, fMemoryManager);
// Janitor<RefHashTableOf<ValueStore> > janMap(oldMap);
while (mapEnum.hasMoreElements()) {
ValueStore& oldVal = mapEnum.nextElement();
IdentityConstraint* ic = oldVal.getIdentityConstraint();
ValueStore* currVal = fGlobalICMap->get(ic);
if (!currVal) {
fGlobalICMap->put(ic, &oldVal);
}
else {
currVal->append(&oldVal);
}
}
delete oldMap;
}
// ---------------------------------------------------------------------------
// ValueStoreCache: Helper methods
// ---------------------------------------------------------------------------
void ValueStoreCache::cleanUp() {
delete fIC2ValueStoreMap;
delete fGlobalICMap;
delete fGlobalMapStack;
delete fValueStores;
}
void ValueStoreCache::init() {
fValueStores = new (fMemoryManager) RefVectorOf<ValueStore>(8, false, fMemoryManager);
fGlobalICMap = new (fMemoryManager) RefHashTableOf<ValueStore, PtrHasher>
(
13
, false
, fMemoryManager
);
fIC2ValueStoreMap = new (fMemoryManager) RefHash2KeysTableOf<ValueStore, PtrHasher>
(
13
, true
, fMemoryManager
);
fGlobalMapStack = new (fMemoryManager) RefStackOf<RefHashTableOf<ValueStore, PtrHasher> >(8, true, fMemoryManager);
}
void ValueStoreCache::initValueStoresFor(SchemaElementDecl* const elemDecl,
const int initialDepth) {
// initialize value stores for unique fields
XMLSize_t icCount = elemDecl->getIdentityConstraintCount();
for (XMLSize_t i=0; i<icCount; i++) {
IdentityConstraint* ic = elemDecl->getIdentityConstraintAt(i);
ValueStore* valueStore=fIC2ValueStoreMap->get(ic, initialDepth);
if(valueStore==0)
{
valueStore = new (fMemoryManager) ValueStore(ic, fScanner, fMemoryManager);
fIC2ValueStoreMap->put(ic, initialDepth, valueStore);
}
else
valueStore->clear();
fValueStores->addElement(valueStore);
}
}
void ValueStoreCache::transplant(IdentityConstraint* const ic, const int initialDepth) {
if (ic->getType() == IdentityConstraint::ICType_KEYREF) {
return;
}
ValueStore* newVals = fIC2ValueStoreMap->get(ic, initialDepth);
ValueStore* currVals = fGlobalICMap->get(ic);
if (currVals) {
currVals->append(newVals);
} else {
fGlobalICMap->put(ic, newVals);
}
}
XERCES_CPP_NAMESPACE_END
/**
* End of file ValueStoreCache.cpp
*/
@@ -0,0 +1,172 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ValueStoreCache.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_VALUESTORECACHE_HPP)
#define XERCESC_INCLUDE_GUARD_VALUESTORECACHE_HPP
/**
* This class is used to store the values for identity constraints.
*
* Sketch of algorithm:
* - When a constraint is first encountered, its values are stored in the
* (local) fIC2ValueStoreMap;
* - Once it is validated (i.e., when it goes out of scope), its values are
* merged into the fGlobalICMap;
* - As we encounter keyref's, we look at the global table to validate them.
* - 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 below in the stack. When a
* start tag is encountered, we create a new fGlobalICMap.
* i.e., the top of the fGlobalIDMapStack always contains the preceding
* siblings' eligible id constraints; the fGlobalICMap contains
* descendants+self. Keyrefs can only match descendants+self.
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/RefHash2KeysTableOf.hpp>
#include <xercesc/util/RefStackOf.hpp>
#include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
#include <xercesc/validators/schema/identity/IC_Field.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declaration
// ---------------------------------------------------------------------------
class ValueStore;
class SchemaElementDecl;
class XMLScanner;
class VALIDATORS_EXPORT ValueStoreCache : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
ValueStoreCache(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~ValueStoreCache();
// -----------------------------------------------------------------------
// Setter Methods
// -----------------------------------------------------------------------
void setScanner(XMLScanner* const scanner);
// -----------------------------------------------------------------------
// Document Handling methods
// -----------------------------------------------------------------------
void startDocument();
void startElement();
void endElement();
void endDocument();
// -----------------------------------------------------------------------
// Initialization methods
// -----------------------------------------------------------------------
void initValueStoresFor(SchemaElementDecl* const elemDecl, const int initialDepth);
// -----------------------------------------------------------------------
// Access methods
// -----------------------------------------------------------------------
ValueStore* getValueStoreFor(const IC_Field* const field, const int initialDepth);
ValueStore* getValueStoreFor(const IdentityConstraint* const ic, const int initialDepth);
ValueStore* getGlobalValueStoreFor(const IdentityConstraint* const ic);
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
/** This method takes the contents of the (local) ValueStore associated
* with ic and moves them into the global hashtable, if ic is a <unique>
* or a <key>. If it's a <keyRef>, then we leave it for later.
*/
void transplant(IdentityConstraint* const ic, const int initialDepth);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
ValueStoreCache(const ValueStoreCache& other);
ValueStoreCache& operator= (const ValueStoreCache& other);
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void init();
void cleanUp();
// -----------------------------------------------------------------------
// Data
// -----------------------------------------------------------------------
RefVectorOf<ValueStore>* fValueStores;
RefHashTableOf<ValueStore, PtrHasher>* fGlobalICMap;
RefHash2KeysTableOf<ValueStore, PtrHasher>* fIC2ValueStoreMap;
RefStackOf<RefHashTableOf<ValueStore, PtrHasher> >* fGlobalMapStack;
XMLScanner* fScanner;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// ValueStoreCache: Access methods
// ---------------------------------------------------------------------------
inline void ValueStoreCache::setScanner(XMLScanner* const scanner) {
fScanner = scanner;
}
// ---------------------------------------------------------------------------
// ValueStoreCache: Access methods
// ---------------------------------------------------------------------------
inline ValueStore*
ValueStoreCache::getValueStoreFor(const IC_Field* const field, const int initialDepth) {
return fIC2ValueStoreMap->get(field->getIdentityConstraint(), initialDepth);
}
inline ValueStore*
ValueStoreCache::getValueStoreFor(const IdentityConstraint* const ic, const int initialDepth) {
return fIC2ValueStoreMap->get(ic, initialDepth);
}
inline ValueStore*
ValueStoreCache::getGlobalValueStoreFor(const IdentityConstraint* const ic) {
return fGlobalICMap->get(ic);
}
// ---------------------------------------------------------------------------
// ValueStoreCache: Document handling methods
// ---------------------------------------------------------------------------
inline void ValueStoreCache::endDocument() {
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file ValueStoreCache.hpp
*/
@@ -0,0 +1,34 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPathException.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XPATHEXCEPTION_HPP)
#define XERCESC_INCLUDE_GUARD_XPATHEXCEPTION_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
MakeXMLException(XPathException, VALIDATORS_EXPORT)
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,413 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPathMatcher.cpp 804234 2009-08-14 14:20:16Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/XPathMatcher.hpp>
#include <xercesc/validators/schema/identity/XercesXPath.hpp>
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
#include <xercesc/validators/schema/SchemaAttDef.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp>
#include <xercesc/util/RuntimeException.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/framework/ValidationContext.hpp>
XERCES_CPP_NAMESPACE_BEGIN
typedef JanitorMemFunCall<XPathMatcher> CleanupType;
// ---------------------------------------------------------------------------
// XPathMatcher: Constructors and Destructor
// ---------------------------------------------------------------------------
XPathMatcher::XPathMatcher( XercesXPath* const xpath
, MemoryManager* const manager)
: fLocationPathSize(0)
, fMatched(0)
, fNoMatchDepth(0)
, fCurrentStep(0)
, fStepIndexes(0)
, fLocationPaths(0)
, fIdentityConstraint(0)
, fMemoryManager(manager)
{
CleanupType cleanup(this, &XPathMatcher::cleanUp);
try {
init(xpath);
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
XPathMatcher::XPathMatcher(XercesXPath* const xpath,
IdentityConstraint* const ic,
MemoryManager* const manager)
: fLocationPathSize(0)
, fMatched(0)
, fNoMatchDepth(0)
, fCurrentStep(0)
, fStepIndexes(0)
, fLocationPaths(0)
, fIdentityConstraint(ic)
, fMemoryManager(manager)
{
CleanupType cleanup(this, &XPathMatcher::cleanUp);
try {
init(xpath);
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
XPathMatcher::~XPathMatcher()
{
cleanUp();
}
// ---------------------------------------------------------------------------
// XPathMatcher: Helper methods
// ---------------------------------------------------------------------------
void XPathMatcher::init(XercesXPath* const xpath) {
if (xpath) {
fLocationPaths = xpath->getLocationPaths();
fLocationPathSize = (fLocationPaths ? fLocationPaths->size() : 0);
if (fLocationPathSize) {
fStepIndexes = new (fMemoryManager) RefVectorOf<ValueStackOf<XMLSize_t> >(fLocationPathSize, true, fMemoryManager);
fCurrentStep = (XMLSize_t*) fMemoryManager->allocate
(
fLocationPathSize * sizeof(XMLSize_t)
);//new int[fLocationPathSize];
fNoMatchDepth = (XMLSize_t*) fMemoryManager->allocate
(
fLocationPathSize * sizeof(XMLSize_t)
);//new int[fLocationPathSize];
fMatched = (unsigned char*) fMemoryManager->allocate
(
fLocationPathSize * sizeof(unsigned char)
);//new int[fLocationPathSize];
for(XMLSize_t i=0; i < fLocationPathSize; i++) {
fStepIndexes->addElement(new (fMemoryManager) ValueStackOf<XMLSize_t>(8, fMemoryManager));
}
}
}
}
// ---------------------------------------------------------------------------
// XPathMatcher: XMLDocumentHandler methods
// ---------------------------------------------------------------------------
void XPathMatcher::startDocumentFragment() {
for(XMLSize_t i = 0; i < fLocationPathSize; i++) {
fStepIndexes->elementAt(i)->removeAllElements();
fCurrentStep[i] = 0;
fNoMatchDepth[i] = 0;
fMatched[i] = 0;
}
}
void XPathMatcher::startElement(const XMLElementDecl& elemDecl,
const unsigned int urlId,
const XMLCh* const elemPrefix,
const RefVectorOf<XMLAttr>& attrList,
const XMLSize_t attrCount,
ValidationContext* validationContext /*=0*/) {
for (XMLSize_t i = 0; i < fLocationPathSize; i++) {
// push context
XMLSize_t startStep = fCurrentStep[i];
fStepIndexes->elementAt(i)->push(startStep);
// try next xpath, if not matching
if ((fMatched[i] & XP_MATCHED_D) == XP_MATCHED || fNoMatchDepth[i] > 0) {
fNoMatchDepth[i]++;
continue;
}
if((fMatched[i] & XP_MATCHED_D) == XP_MATCHED_D) {
fMatched[i] = XP_MATCHED_DP;
}
// consume self::node() steps
XercesLocationPath* locPath = fLocationPaths->elementAt(i);
XMLSize_t stepSize = locPath->getStepSize();
while (fCurrentStep[i] < stepSize &&
locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::AxisType_SELF) {
fCurrentStep[i]++;
}
if (fCurrentStep[i] == stepSize) {
fMatched[i] = XP_MATCHED;
continue;
}
// now if the current step is a descendant step, we let the next
// step do its thing; if it fails, we reset ourselves
// to look at this step for next time we're called.
// so first consume all descendants:
XMLSize_t descendantStep = fCurrentStep[i];
while (fCurrentStep[i] < stepSize &&
locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::AxisType_DESCENDANT) {
fCurrentStep[i]++;
}
bool sawDescendant = fCurrentStep[i] > descendantStep;
if (fCurrentStep[i] == stepSize) {
fNoMatchDepth[i]++;
continue;
}
// match child::... step, if haven't consumed any self::node()
if ((fCurrentStep[i] == startStep || fCurrentStep[i] > descendantStep) &&
locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::AxisType_CHILD) {
XercesStep* step = locPath->getStep(fCurrentStep[i]);
XercesNodeTest* nodeTest = step->getNodeTest();
QName elemQName(elemPrefix, elemDecl.getElementName()->getLocalPart(), urlId, fMemoryManager);
if (!matches(nodeTest, &elemQName)) {
if(fCurrentStep[i] > descendantStep) {
fCurrentStep[i] = descendantStep;
continue;
}
fNoMatchDepth[i]++;
continue;
}
fCurrentStep[i]++;
}
if (fCurrentStep[i] == stepSize) {
if (sawDescendant) {
fCurrentStep[i] = descendantStep;
fMatched[i] = XP_MATCHED_D;
}
else {
fMatched[i] = XP_MATCHED;
}
continue;
}
// match attribute::... step
if (fCurrentStep[i] < stepSize &&
locPath->getStep(fCurrentStep[i])->getAxisType() == XercesStep::AxisType_ATTRIBUTE) {
if (attrCount) {
XercesNodeTest* nodeTest = locPath->getStep(fCurrentStep[i])->getNodeTest();
for (XMLSize_t attrIndex = 0; attrIndex < attrCount; attrIndex++) {
const XMLAttr* curDef = attrList.elementAt(attrIndex);
if (matches(nodeTest, curDef->getAttName())) {
fCurrentStep[i]++;
if (fCurrentStep[i] == stepSize) {
fMatched[i] = XP_MATCHED_A;
SchemaAttDef* attDef = ((SchemaElementDecl&) elemDecl).getAttDef(curDef->getName(), curDef->getURIId());
DatatypeValidator* dv = (attDef) ? attDef->getDatatypeValidator() : 0;
const XMLCh* value = curDef->getValue();
// store QName using their Clark name
if(dv && dv->getType()==DatatypeValidator::QName)
{
int index=XMLString::indexOf(value, chColon);
if(index==-1)
matched(value, dv, false);
else
{
XMLBuffer buff(1023, fMemoryManager);
buff.append(chOpenCurly);
if(validationContext)
{
XMLCh* prefix=(XMLCh*)fMemoryManager->allocate((index+1)*sizeof(XMLCh));
ArrayJanitor<XMLCh> janPrefix(prefix, fMemoryManager);
XMLString::subString(prefix, value, 0, (XMLSize_t)index, fMemoryManager);
buff.append(validationContext->getURIForPrefix(prefix));
}
buff.append(chCloseCurly);
buff.append(value+index+1);
matched(buff.getRawBuffer(), dv, false);
}
}
else
matched(value, dv, false);
}
break;
}
}
}
if ((fMatched[i] & XP_MATCHED) != XP_MATCHED) {
if(fCurrentStep[i] > descendantStep) {
fCurrentStep[i] = descendantStep;
continue;
}
fNoMatchDepth[i]++;
}
}
}
}
void XPathMatcher::endElement(const XMLElementDecl& elemDecl,
const XMLCh* const elemContent,
ValidationContext* validationContext /*=0*/,
DatatypeValidator* actualValidator /*=0*/) {
for(XMLSize_t i = 0; i < fLocationPathSize; i++) {
// go back a step
fCurrentStep[i] = fStepIndexes->elementAt(i)->pop();
// don't do anything, if not matching
if (fNoMatchDepth[i] > 0) {
fNoMatchDepth[i]--;
}
// signal match, if appropriate
else {
if (fMatched[i] == 0)
continue;
if ((fMatched[i] & XP_MATCHED_A) == XP_MATCHED_A) {
fMatched[i] = 0;
continue;
}
DatatypeValidator* dv = actualValidator?actualValidator:((SchemaElementDecl*) &elemDecl)->getDatatypeValidator();
bool isNillable = (((SchemaElementDecl *) &elemDecl)->getMiscFlags() & SchemaSymbols::XSD_NILLABLE) != 0;
// store QName using their Clark name
if(dv && dv->getType()==DatatypeValidator::QName)
{
int index=XMLString::indexOf(elemContent, chColon);
if(index==-1)
matched(elemContent, dv, isNillable);
else
{
XMLBuffer buff(1023, fMemoryManager);
buff.append(chOpenCurly);
if(validationContext)
{
XMLCh* prefix=(XMLCh*)fMemoryManager->allocate((index+1)*sizeof(XMLCh));
ArrayJanitor<XMLCh> janPrefix(prefix, fMemoryManager);
XMLString::subString(prefix, elemContent, 0, (XMLSize_t)index, fMemoryManager);
buff.append(validationContext->getURIForPrefix(prefix));
}
buff.append(chCloseCurly);
buff.append(elemContent+index+1);
matched(buff.getRawBuffer(), dv, isNillable);
}
}
else
matched(elemContent, dv, isNillable);
fMatched[i] = 0;
}
}
}
// ---------------------------------------------------------------------------
// XPathMatcher: Match methods
// ---------------------------------------------------------------------------
unsigned char XPathMatcher::isMatched() {
// xpath has been matched if any one of the members of the union have matched.
for (XMLSize_t i=0; i < fLocationPathSize; i++) {
if (((fMatched[i] & XP_MATCHED) == XP_MATCHED)
&& ((fMatched[i] & XP_MATCHED_DP) != XP_MATCHED_DP))
return fMatched[i];
}
return 0;
}
void XPathMatcher::matched(const XMLCh* const,
DatatypeValidator* const,
const bool) {
return;
}
bool XPathMatcher::matches(const XercesNodeTest* nodeTest, const QName* qName)
{
if (nodeTest->getType() == XercesNodeTest::NodeType_QNAME) {
return (*nodeTest->getName())==(*qName);
}
if (nodeTest->getType() == XercesNodeTest::NodeType_NAMESPACE) {
return nodeTest->getName()->getURI() == qName->getURI();
}
// NodeType_WILDCARD
return true;
}
// ---------------------------------------------------------------------------
// XPathMatcher: Match methods
// ---------------------------------------------------------------------------
int XPathMatcher::getInitialDepth() const
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
return 0; // to make some compilers happy
}
XERCES_CPP_NAMESPACE_END
/**
* End of file XPathMatcher.cpp
*/
@@ -0,0 +1,182 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPathMatcher.hpp 803869 2009-08-13 12:56:21Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XPATHMATCHER_HPP)
#define XERCESC_INCLUDE_GUARD_XPATHMATCHER_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/ValueStackOf.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declaration
// ---------------------------------------------------------------------------
class XMLElementDecl;
class XercesXPath;
class IdentityConstraint;
class DatatypeValidator;
class XMLStringPool;
class XercesLocationPath;
class XMLAttr;
class XercesNodeTest;
class QName;
class ValidationContext;
class VALIDATORS_EXPORT XPathMatcher : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XPathMatcher(XercesXPath* const xpath,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XPathMatcher(XercesXPath* const xpath,
IdentityConstraint* const ic,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
virtual ~XPathMatcher();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; }
MemoryManager* getMemoryManager() const { return fMemoryManager; }
// -----------------------------------------------------------------------
// Match methods
// -----------------------------------------------------------------------
/**
* Returns true if XPath has been matched.
*/
unsigned char isMatched();
virtual int getInitialDepth() const;
// -----------------------------------------------------------------------
// XMLDocumentHandler methods
// -----------------------------------------------------------------------
virtual void startDocumentFragment();
virtual void startElement(const XMLElementDecl& elemDecl,
const unsigned int urlId,
const XMLCh* const elemPrefix,
const RefVectorOf<XMLAttr>& attrList,
const XMLSize_t attrCount,
ValidationContext* validationContext = 0);
virtual void endElement(const XMLElementDecl& elemDecl,
const XMLCh* const elemContent,
ValidationContext* validationContext = 0,
DatatypeValidator* actualValidator = 0);
enum
{
XP_MATCHED = 1 // matched any way
, XP_MATCHED_A = 3 // matched on the attribute axis
, XP_MATCHED_D = 5 // matched on the descendant-or-self axixs
, XP_MATCHED_DP = 13 // matched some previous (ancestor) node on the
// descendant-or-self-axis, but not this node
};
protected:
// -----------------------------------------------------------------------
// Match methods
// -----------------------------------------------------------------------
/**
* This method is called when the XPath handler matches the XPath
* expression. Subclasses can override this method to provide default
* handling upon a match.
*/
virtual void matched(const XMLCh* const content,
DatatypeValidator* const dv, const bool isNil);
bool matches(const XercesNodeTest* nodeTest, const QName* qName);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XPathMatcher(const XPathMatcher&);
XPathMatcher& operator=(const XPathMatcher&);
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void init(XercesXPath* const xpath);
void cleanUp();
// -----------------------------------------------------------------------
// Data members
//
// fMatched
// Indicates whether XPath has been matched or not
//
// fNoMatchDepth
// Indicates whether matching is successful for the given xpath
// expression.
//
// fCurrentStep
// Stores current step.
//
// fStepIndexes
// Integer stack of step indexes.
//
// fLocationPaths
// fLocationPathSize
// XPath location path, and its size.
//
// fIdentityConstraint
// The identity constraint we're the matcher for. Only used for
// selectors.
//
// -----------------------------------------------------------------------
XMLSize_t fLocationPathSize;
unsigned char* fMatched;
XMLSize_t* fNoMatchDepth;
XMLSize_t* fCurrentStep;
RefVectorOf<ValueStackOf<XMLSize_t> >* fStepIndexes;
RefVectorOf<XercesLocationPath>* fLocationPaths;
IdentityConstraint* fIdentityConstraint;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// XPathMatcher: Helper methods
// ---------------------------------------------------------------------------
inline void XPathMatcher::cleanUp() {
fMemoryManager->deallocate(fMatched);//delete [] fMatched;
fMemoryManager->deallocate(fNoMatchDepth);//delete [] fNoMatchDepth;
fMemoryManager->deallocate(fCurrentStep);//delete [] fCurrentStep;
delete fStepIndexes;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file XPathMatcher.hpp
*/
@@ -0,0 +1,86 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPathMatcherStack.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/XPathMatcherStack.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
typedef JanitorMemFunCall<XPathMatcherStack> CleanupType;
// ---------------------------------------------------------------------------
// XPathMatherStack: Constructors and Destructor
// ---------------------------------------------------------------------------
XPathMatcherStack::XPathMatcherStack(MemoryManager* const manager)
: fMatchersCount(0)
, fContextStack(0)
, fMatchers(0)
{
CleanupType cleanup(this, &XPathMatcherStack::cleanUp);
try {
fContextStack = new (manager) ValueStackOf<int>(8, manager);
fMatchers = new (manager) RefVectorOf<XPathMatcher>(8, true, manager);
}
catch(const OutOfMemoryException&)
{
cleanup.release();
throw;
}
cleanup.release();
}
XPathMatcherStack::~XPathMatcherStack() {
cleanUp();
}
// ---------------------------------------------------------------------------
// XPathMatcherStack: Private helper methods.
// ---------------------------------------------------------------------------
void XPathMatcherStack::cleanUp()
{
delete fContextStack;
delete fMatchers;
}
// ---------------------------------------------------------------------------
// XPathMatherStack: Clear methods
// ---------------------------------------------------------------------------
void XPathMatcherStack::clear() {
fContextStack->removeAllElements();
fMatchers->removeAllElements();
fMatchersCount = 0;
}
XERCES_CPP_NAMESPACE_END
/**
* End of file XPathMatcherStack.cpp
*/
@@ -0,0 +1,139 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPathMatcherStack.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XPATHMATCHERSTACK_HPP)
#define XERCESC_INCLUDE_GUARD_XPATHMATCHERSTACK_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/schema/identity/XPathMatcher.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class VALIDATORS_EXPORT XPathMatcherStack : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XPathMatcherStack(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~XPathMatcherStack();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
XPathMatcher* getMatcherAt(const XMLSize_t index) const;
XMLSize_t getMatcherCount() const;
XMLSize_t size() const;
// -----------------------------------------------------------------------
// Access methods
// -----------------------------------------------------------------------
void addMatcher(XPathMatcher* const matcher);
// -----------------------------------------------------------------------
// Stack methods
// -----------------------------------------------------------------------
void pushContext();
void popContext();
// -----------------------------------------------------------------------
// Reset methods
// -----------------------------------------------------------------------
void clear();
private:
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void cleanUp();
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XPathMatcherStack(const XPathMatcherStack& other);
XPathMatcherStack& operator= (const XPathMatcherStack& other);
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
unsigned int fMatchersCount;
ValueStackOf<int>* fContextStack;
RefVectorOf<XPathMatcher>* fMatchers;
};
// ---------------------------------------------------------------------------
// XPathMatcherStack: Getter methods
// ---------------------------------------------------------------------------
inline XMLSize_t XPathMatcherStack::size() const {
return fContextStack->size();
}
inline XMLSize_t XPathMatcherStack::getMatcherCount() const {
return fMatchersCount;
}
inline XPathMatcher*
XPathMatcherStack::getMatcherAt(const XMLSize_t index) const {
return fMatchers->elementAt(index);
}
// ---------------------------------------------------------------------------
// XPathMatcherStack: Stack methods
// ---------------------------------------------------------------------------
inline void XPathMatcherStack::pushContext() {
fContextStack->push(fMatchersCount);
}
inline void XPathMatcherStack::popContext() {
fMatchersCount = fContextStack->pop();
}
// ---------------------------------------------------------------------------
// XPathMatcherStack: Access methods
// ---------------------------------------------------------------------------
inline void XPathMatcherStack::addMatcher(XPathMatcher* const matcher) {
if (fMatchersCount == fMatchers->size()) {
fMatchers->addElement(matcher);
fMatchersCount++;
}
else {
fMatchers->setElementAt(matcher, fMatchersCount++);
}
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file XPathMatcherStack.hpp
*/
@@ -0,0 +1,161 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPathSymbols.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/validators/schema/identity/XPathSymbols.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// SchemaSymbols: Static data
// ---------------------------------------------------------------------------
const XMLCh XPathSymbols::fgSYMBOL_AND[] =
{
chLatin_a, chLatin_n, chLatin_d, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_OR[] =
{
chLatin_o, chLatin_r, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_MOD[] =
{
chLatin_m, chLatin_o, chLatin_d, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_DIV[] =
{
chLatin_d, chLatin_i, chLatin_v, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_COMMENT[] =
{
chLatin_c, chLatin_o, chLatin_m, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_TEXT[] =
{
chLatin_t, chLatin_e, chLatin_x, chLatin_t, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_PI[] =
{
chLatin_p, chLatin_r, chLatin_o, chLatin_c, chLatin_e, chLatin_s, chLatin_s,
chLatin_i, chLatin_n, chLatin_g, chDash, chLatin_i, chLatin_n, chLatin_s, chLatin_t,
chLatin_r, chLatin_u, chLatin_c, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_NODE[] =
{
chLatin_n, chLatin_o, chLatin_d, chLatin_e, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_ANCESTOR[] =
{
chLatin_a, chLatin_n, chLatin_c, chLatin_e, chLatin_s, chLatin_t, chLatin_o,
chLatin_r, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_ANCESTOR_OR_SELF[] =
{
chLatin_a, chLatin_n, chLatin_c, chLatin_e, chLatin_s, chLatin_t, chLatin_o,
chLatin_r, chDash, chLatin_o, chLatin_r, chDash, chLatin_s, chLatin_e,
chLatin_l, chLatin_f, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_ATTRIBUTE[] =
{
chLatin_a, chLatin_t, chLatin_t, chLatin_r, chLatin_i, chLatin_b, chLatin_u,
chLatin_t, chLatin_e, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_CHILD[] =
{
chLatin_c, chLatin_h, chLatin_i, chLatin_l, chLatin_d, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_DESCENDANT[] =
{
chLatin_d, chLatin_e, chLatin_s, chLatin_c, chLatin_e, chLatin_n, chLatin_d,
chLatin_a, chLatin_n, chLatin_t, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_DESCENDANT_OR_SELF[] =
{
chLatin_d, chLatin_e, chLatin_s, chLatin_c, chLatin_e, chLatin_n, chLatin_d,
chLatin_a, chLatin_n, chLatin_t, chDash, chLatin_o, chLatin_r, chDash, chLatin_s,
chLatin_e, chLatin_l, chLatin_f, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_FOLLOWING[] =
{
chLatin_f, chLatin_o, chLatin_l, chLatin_l, chLatin_o, chLatin_w, chLatin_i,
chLatin_n, chLatin_g, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_FOLLOWING_SIBLING[] =
{
chLatin_f, chLatin_o, chLatin_l, chLatin_l, chLatin_o, chLatin_w, chLatin_i,
chLatin_n, chLatin_g, chDash, chLatin_s, chLatin_i, chLatin_b, chLatin_l, chLatin_i,
chLatin_n, chLatin_g, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_NAMESPACE[] =
{
chLatin_n, chLatin_a, chLatin_m, chLatin_e, chLatin_s, chLatin_p, chLatin_a,
chLatin_c, chLatin_e, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_PARENT[] =
{
chLatin_p, chLatin_a, chLatin_r, chLatin_e, chLatin_n, chLatin_t, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_PRECEDING[] =
{
chLatin_p, chLatin_r, chLatin_e, chLatin_c, chLatin_e, chLatin_d, chLatin_i,
chLatin_n, chLatin_g, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_PRECEDING_SIBLING[] =
{
chLatin_p, chLatin_r, chLatin_e, chLatin_c, chLatin_e, chLatin_d, chLatin_i,
chLatin_n, chLatin_g, chDash, chLatin_s, chLatin_i, chLatin_b, chLatin_l, chLatin_i,
chLatin_n, chLatin_g, chNull
};
const XMLCh XPathSymbols::fgSYMBOL_SELF[] =
{
chLatin_s, chLatin_e, chLatin_l, chLatin_f, chNull
};
XERCES_CPP_NAMESPACE_END
/**
* End of file XPathSymbols.cpp
*/
@@ -0,0 +1,75 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XPathSymbols.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XPATHSYMBOLS_HPP)
#define XERCESC_INCLUDE_GUARD_XPATHSYMBOLS_HPP
#include <xercesc/util/XercesDefs.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/*
* Collection of symbols used to parse a Schema Grammar
*/
class VALIDATORS_EXPORT XPathSymbols
{
public :
// -----------------------------------------------------------------------
// Constant data
// -----------------------------------------------------------------------
static const XMLCh fgSYMBOL_AND[];
static const XMLCh fgSYMBOL_OR[];
static const XMLCh fgSYMBOL_MOD[];
static const XMLCh fgSYMBOL_DIV[];
static const XMLCh fgSYMBOL_COMMENT[];
static const XMLCh fgSYMBOL_TEXT[];
static const XMLCh fgSYMBOL_PI[];
static const XMLCh fgSYMBOL_NODE[];
static const XMLCh fgSYMBOL_ANCESTOR[];
static const XMLCh fgSYMBOL_ANCESTOR_OR_SELF[];
static const XMLCh fgSYMBOL_ATTRIBUTE[];
static const XMLCh fgSYMBOL_CHILD[];
static const XMLCh fgSYMBOL_DESCENDANT[];
static const XMLCh fgSYMBOL_DESCENDANT_OR_SELF[];
static const XMLCh fgSYMBOL_FOLLOWING[];
static const XMLCh fgSYMBOL_FOLLOWING_SIBLING[];
static const XMLCh fgSYMBOL_NAMESPACE[];
static const XMLCh fgSYMBOL_PARENT[];
static const XMLCh fgSYMBOL_PRECEDING[];
static const XMLCh fgSYMBOL_PRECEDING_SIBLING[];
static const XMLCh fgSYMBOL_SELF[];
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XPathSymbols();
};
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file XPathSymbols.hpp
*/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,499 @@
/*
* 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
*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XercesXPath.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XERCESXPATH_HPP)
#define XERCESC_INCLUDE_GUARD_XERCESXPATH_HPP
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/QName.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/util/ValueVectorOf.hpp>
#include <xercesc/validators/schema/NamespaceScope.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// Forward Declarations
// ---------------------------------------------------------------------------
class XMLStringPool;
class VALIDATORS_EXPORT XercesNodeTest : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------
enum NodeType {
NodeType_QNAME = 1,
NodeType_WILDCARD = 2,
NodeType_NODE = 3,
NodeType_NAMESPACE= 4,
NodeType_UNKNOWN
};
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XercesNodeTest(const short type,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XercesNodeTest(const QName* const qName);
XercesNodeTest(const XMLCh* const prefix, const unsigned int uriId,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XercesNodeTest(const XercesNodeTest& other);
~XercesNodeTest() { delete fName; }
// -----------------------------------------------------------------------
// Operators
// -----------------------------------------------------------------------
XercesNodeTest& operator= (const XercesNodeTest& other);
bool operator== (const XercesNodeTest& other) const;
bool operator!= (const XercesNodeTest& other) const;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
short getType() const { return fType; }
QName* getName() const { return fName; }
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XercesNodeTest)
XercesNodeTest(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
short fType;
QName* fName;
};
/**
* A location path step comprised of an axis and node test.
*/
class VALIDATORS_EXPORT XercesStep : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------
enum AxisType { // Axis type
AxisType_CHILD = 1,
AxisType_ATTRIBUTE = 2,
AxisType_SELF = 3,
AxisType_DESCENDANT = 4,
AxisType_UNKNOWN
};
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XercesStep(const unsigned short axisType, XercesNodeTest* const nodeTest);
XercesStep(const XercesStep& other);
~XercesStep() { delete fNodeTest; }
// -----------------------------------------------------------------------
// Operators
// -----------------------------------------------------------------------
XercesStep& operator= (const XercesStep& other);
bool operator== (const XercesStep& other) const;
bool operator!= (const XercesStep& other) const;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
unsigned short getAxisType() const { return fAxisType; }
XercesNodeTest* getNodeTest() const { return fNodeTest; }
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XercesStep)
XercesStep(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
unsigned short fAxisType;
XercesNodeTest* fNodeTest;
};
/**
* A location path representation for an XPath expression.
*/
class VALIDATORS_EXPORT XercesLocationPath : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XercesLocationPath(RefVectorOf<XercesStep>* const steps);
~XercesLocationPath() { delete fSteps; }
// -----------------------------------------------------------------------
// Operators
// -----------------------------------------------------------------------
bool operator== (const XercesLocationPath& other) const;
bool operator!= (const XercesLocationPath& other) const;
// -----------------------------------------------------------------------
// Access methods
// -----------------------------------------------------------------------
XMLSize_t getStepSize() const;
void addStep(XercesStep* const aStep);
XercesStep* getStep(const XMLSize_t index) const;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XercesLocationPath)
XercesLocationPath(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XercesLocationPath(const XercesLocationPath& other);
XercesLocationPath& operator= (const XercesLocationPath& other);
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
RefVectorOf<XercesStep>* fSteps;
};
class VALIDATORS_EXPORT XercesXPath : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------
/**
* [28] ExprToken ::= '(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::'
* | NameTest | NodeType | Operator | FunctionName
* | AxisName | Literal | Number | VariableReference
*/
enum {
EXPRTOKEN_OPEN_PAREN = 0,
EXPRTOKEN_CLOSE_PAREN = 1,
EXPRTOKEN_OPEN_BRACKET = 2,
EXPRTOKEN_CLOSE_BRACKET = 3,
EXPRTOKEN_PERIOD = 4,
EXPRTOKEN_DOUBLE_PERIOD = 5,
EXPRTOKEN_ATSIGN = 6,
EXPRTOKEN_COMMA = 7,
EXPRTOKEN_DOUBLE_COLON = 8,
EXPRTOKEN_NAMETEST_ANY = 9,
EXPRTOKEN_NAMETEST_NAMESPACE = 10,
EXPRTOKEN_NAMETEST_QNAME = 11,
EXPRTOKEN_NODETYPE_COMMENT = 12,
EXPRTOKEN_NODETYPE_TEXT = 13,
EXPRTOKEN_NODETYPE_PI = 14,
EXPRTOKEN_NODETYPE_NODE = 15,
EXPRTOKEN_OPERATOR_AND = 16,
EXPRTOKEN_OPERATOR_OR = 17,
EXPRTOKEN_OPERATOR_MOD = 18,
EXPRTOKEN_OPERATOR_DIV = 19,
EXPRTOKEN_OPERATOR_MULT = 20,
EXPRTOKEN_OPERATOR_SLASH = 21,
EXPRTOKEN_OPERATOR_DOUBLE_SLASH = 22,
EXPRTOKEN_OPERATOR_UNION = 23,
EXPRTOKEN_OPERATOR_PLUS = 24,
EXPRTOKEN_OPERATOR_MINUS = 25,
EXPRTOKEN_OPERATOR_EQUAL = 26,
EXPRTOKEN_OPERATOR_NOT_EQUAL = 27,
EXPRTOKEN_OPERATOR_LESS = 28,
EXPRTOKEN_OPERATOR_LESS_EQUAL = 29,
EXPRTOKEN_OPERATOR_GREATER = 30,
EXPRTOKEN_OPERATOR_GREATER_EQUAL = 31,
EXPRTOKEN_FUNCTION_NAME = 32,
EXPRTOKEN_AXISNAME_ANCESTOR = 33,
EXPRTOKEN_AXISNAME_ANCESTOR_OR_SELF = 34,
EXPRTOKEN_AXISNAME_ATTRIBUTE = 35,
EXPRTOKEN_AXISNAME_CHILD = 36,
EXPRTOKEN_AXISNAME_DESCENDANT = 37,
EXPRTOKEN_AXISNAME_DESCENDANT_OR_SELF = 38,
EXPRTOKEN_AXISNAME_FOLLOWING = 39,
EXPRTOKEN_AXISNAME_FOLLOWING_SIBLING = 40,
EXPRTOKEN_AXISNAME_NAMESPACE = 41,
EXPRTOKEN_AXISNAME_PARENT = 42,
EXPRTOKEN_AXISNAME_PRECEDING = 43,
EXPRTOKEN_AXISNAME_PRECEDING_SIBLING = 44,
EXPRTOKEN_AXISNAME_SELF = 45,
EXPRTOKEN_LITERAL = 46,
EXPRTOKEN_NUMBER = 47,
EXPRTOKEN_VARIABLE_REFERENCE = 48
};
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XercesXPath(const XMLCh* const xpathExpr,
XMLStringPool* const stringPool,
XercesNamespaceResolver* const scopeContext,
const unsigned int emptyNamespaceId,
const bool isSelector = false,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
~XercesXPath();
// -----------------------------------------------------------------------
// Operators
// -----------------------------------------------------------------------
bool operator== (const XercesXPath& other) const;
bool operator!= (const XercesXPath& other) const;
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
RefVectorOf<XercesLocationPath>* getLocationPaths() const;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XercesXPath)
XercesXPath(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XMLCh* getExpression();
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XercesXPath(const XercesXPath& other);
XercesXPath& operator= (const XercesXPath& other);
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void cleanUp();
void checkForSelectedAttributes();
void parseExpression(XMLStringPool* const stringPool,
XercesNamespaceResolver* const scopeContext);
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
unsigned int fEmptyNamespaceId;
XMLCh* fExpression;
RefVectorOf<XercesLocationPath>* fLocationPaths;
MemoryManager* fMemoryManager;
};
class VALIDATORS_EXPORT XPathScanner : public XMemory
{
public:
// -----------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------
enum {
CHARTYPE_INVALID = 0, // invalid XML character
CHARTYPE_OTHER = 1, // not special - one of "#%&;?\^`{}~" or DEL
CHARTYPE_WHITESPACE = 2, // one of "\t\n\r " (0x09, 0x0A, 0x0D, 0x20)
CHARTYPE_EXCLAMATION = 3, // '!' (0x21)
CHARTYPE_QUOTE = 4, // '\"' or '\'' (0x22 and 0x27)
CHARTYPE_DOLLAR = 5, // '$' (0x24)
CHARTYPE_OPEN_PAREN = 6, // '(' (0x28)
CHARTYPE_CLOSE_PAREN = 7, // ')' (0x29)
CHARTYPE_STAR = 8, // '*' (0x2A)
CHARTYPE_PLUS = 9, // '+' (0x2B)
CHARTYPE_COMMA = 10, // ',' (0x2C)
CHARTYPE_MINUS = 11, // '-' (0x2D)
CHARTYPE_PERIOD = 12, // '.' (0x2E)
CHARTYPE_SLASH = 13, // '/' (0x2F)
CHARTYPE_DIGIT = 14, // '0'-'9' (0x30 to 0x39)
CHARTYPE_COLON = 15, // ':' (0x3A)
CHARTYPE_LESS = 16, // '<' (0x3C)
CHARTYPE_EQUAL = 17, // '=' (0x3D)
CHARTYPE_GREATER = 18, // '>' (0x3E)
CHARTYPE_ATSIGN = 19, // '@' (0x40)
CHARTYPE_LETTER = 20, // 'A'-'Z' or 'a'-'z' (0x41 to 0x5A and 0x61 to 0x7A)
CHARTYPE_OPEN_BRACKET = 21, // '[' (0x5B)
CHARTYPE_CLOSE_BRACKET = 22, // ']' (0x5D)
CHARTYPE_UNDERSCORE = 23, // '_' (0x5F)
CHARTYPE_UNION = 24, // '|' (0x7C)
CHARTYPE_NONASCII = 25 // Non-ASCII Unicode codepoint (>= 0x80)
};
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XPathScanner(XMLStringPool* const stringPool);
virtual ~XPathScanner() {}
// -----------------------------------------------------------------------
// Scan methods
// -----------------------------------------------------------------------
bool scanExpression(const XMLCh* const data, XMLSize_t currentOffset,
const XMLSize_t endOffset, ValueVectorOf<int>* const tokens);
protected:
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
/**
* This method adds the specified token to the token list. By default,
* this method allows all tokens. However, subclasses can can override
* this method in order to disallow certain tokens from being used in the
* scanned XPath expression. This is a convenient way of allowing only
* a subset of XPath.
*/
virtual void addToken(ValueVectorOf<int>* const tokens, const int aToken);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XPathScanner(const XPathScanner& other);
XPathScanner& operator= (const XPathScanner& other);
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void init();
// -----------------------------------------------------------------------
// Scan methods
// -----------------------------------------------------------------------
XMLSize_t scanNCName(const XMLCh* const data, const XMLSize_t endOffset,
XMLSize_t currentOffset);
XMLSize_t scanNumber(const XMLCh* const data, const XMLSize_t endOffset,
XMLSize_t currentOffset, ValueVectorOf<int>* const tokens);
// -----------------------------------------------------------------------
// Data members
// -----------------------------------------------------------------------
int fAndSymbol;
int fOrSymbol;
int fModSymbol;
int fDivSymbol;
int fCommentSymbol;
int fTextSymbol;
int fPISymbol;
int fNodeSymbol;
int fAncestorSymbol;
int fAncestorOrSelfSymbol;
int fAttributeSymbol;
int fChildSymbol;
int fDescendantSymbol;
int fDescendantOrSelfSymbol;
int fFollowingSymbol;
int fFollowingSiblingSymbol;
int fNamespaceSymbol;
int fParentSymbol;
int fPrecedingSymbol;
int fPrecedingSiblingSymbol;
int fSelfSymbol;
XMLStringPool* fStringPool;
static const XMLByte fASCIICharMap[128];
};
class VALIDATORS_EXPORT XPathScannerForSchema: public XPathScanner
{
public:
// -----------------------------------------------------------------------
// Constructors/Destructor
// -----------------------------------------------------------------------
XPathScannerForSchema(XMLStringPool* const stringPool);
~XPathScannerForSchema() {}
protected:
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void addToken(ValueVectorOf<int>* const tokens, const int aToken);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XPathScannerForSchema(const XPathScannerForSchema& other);
XPathScannerForSchema& operator= (const XPathScannerForSchema& other);
};
// ---------------------------------------------------------------------------
// XercesLocationPath: Access methods
// ---------------------------------------------------------------------------
inline XMLSize_t XercesLocationPath::getStepSize() const {
if (fSteps)
return fSteps->size();
return 0;
}
inline void XercesLocationPath::addStep(XercesStep* const aStep) {
fSteps->addElement(aStep);
}
inline XercesStep* XercesLocationPath::getStep(const XMLSize_t index) const {
if (fSteps)
return fSteps->elementAt(index);
return 0;
}
// ---------------------------------------------------------------------------
// XercesScanner: Helper methods
// ---------------------------------------------------------------------------
inline void XPathScanner::addToken(ValueVectorOf<int>* const tokens,
const int aToken) {
tokens->addElement(aToken);
}
// ---------------------------------------------------------------------------
// XercesXPath: Getter methods
// ---------------------------------------------------------------------------
inline RefVectorOf<XercesLocationPath>* XercesXPath::getLocationPaths() const {
return fLocationPaths;
}
inline XMLCh* XercesXPath::getExpression() {
return fExpression;
}
XERCES_CPP_NAMESPACE_END
#endif
/**
* End of file XercesPath.hpp
*/