GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: XSWildcard.cpp 674012 2008-07-04 11:18:21Z borisk $ 00020 */ 00021 00022 #include <xercesc/framework/psvi/XSWildcard.hpp> 00023 #include <xercesc/framework/psvi/XSModel.hpp> 00024 #include <xercesc/util/ValueVectorOf.hpp> 00025 #include <xercesc/util/StringPool.hpp> 00026 #include <xercesc/validators/common/ContentSpecNode.hpp> 00027 #include <xercesc/validators/schema/SchemaAttDef.hpp> 00028 00029 XERCES_CPP_NAMESPACE_BEGIN 00030 00031 // --------------------------------------------------------------------------- 00032 // XSWildcard: Constructors and Destructor 00033 // --------------------------------------------------------------------------- 00034 XSWildcard::XSWildcard(SchemaAttDef* const attWildCard, 00035 XSAnnotation* const annot, 00036 XSModel* const xsModel, 00037 MemoryManager* const manager) 00038 : XSObject(XSConstants::WILDCARD, xsModel, manager) 00039 , fConstraintType(NSCONSTRAINT_ANY) 00040 , fProcessContents(PC_STRICT) 00041 , fNsConstraintList(0) 00042 , fAnnotation(annot) 00043 { 00044 XMLAttDef::AttTypes attType = attWildCard->getType(); 00045 if (attType == XMLAttDef::Any_Other) 00046 { 00047 fConstraintType = NSCONSTRAINT_NOT; 00048 fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(1, true, manager); 00049 fNsConstraintList->addElement 00050 ( 00051 XMLString::replicate(fXSModel->getURIStringPool()->getValueForId( 00052 attWildCard->getAttName()->getURI()), manager) 00053 ); 00054 } 00055 else if (attType == XMLAttDef::Any_List) 00056 { 00057 fConstraintType = NSCONSTRAINT_DERIVATION_LIST; 00058 ValueVectorOf<unsigned int>* nsList = attWildCard->getNamespaceList(); 00059 if (nsList) 00060 { 00061 XMLSize_t nsListSize = nsList->size(); 00062 if (nsListSize) 00063 { 00064 fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(nsListSize, true, manager); 00065 for (XMLSize_t i=0; i < nsListSize; i++) 00066 { 00067 fNsConstraintList->addElement 00068 ( 00069 XMLString::replicate 00070 ( 00071 fXSModel->getURIStringPool()->getValueForId 00072 ( 00073 nsList->elementAt(i) 00074 ) 00075 , manager 00076 ) 00077 ); 00078 } 00079 } 00080 } 00081 } 00082 00083 XMLAttDef::DefAttTypes attDefType = attWildCard->getDefaultType(); 00084 if (attDefType == XMLAttDef::ProcessContents_Skip) 00085 fProcessContents = PC_SKIP; 00086 else if (attDefType == XMLAttDef::ProcessContents_Lax) 00087 fProcessContents = PC_LAX; 00088 } 00089 00090 XSWildcard::XSWildcard(const ContentSpecNode* const elmWildCard, 00091 XSAnnotation* const annot, 00092 XSModel* const xsModel, 00093 MemoryManager* const manager) 00094 : XSObject(XSConstants::WILDCARD, xsModel, manager) 00095 , fConstraintType(NSCONSTRAINT_ANY) 00096 , fProcessContents(PC_STRICT) 00097 , fNsConstraintList(0) 00098 , fAnnotation(annot) 00099 { 00100 ContentSpecNode::NodeTypes nodeType = elmWildCard->getType(); 00101 if ((nodeType & 0x0f) == ContentSpecNode::Any_Other) 00102 { 00103 fConstraintType = NSCONSTRAINT_NOT; 00104 if (nodeType == ContentSpecNode::Any_Other_Lax) 00105 fProcessContents = PC_LAX; 00106 else if (nodeType == ContentSpecNode::Any_Other_Skip) 00107 fProcessContents = PC_SKIP; 00108 } 00109 else if ((nodeType & 0x0f) == ContentSpecNode::Any_NS) 00110 { 00111 fConstraintType = NSCONSTRAINT_DERIVATION_LIST; 00112 if (nodeType == ContentSpecNode::Any_NS_Lax) 00113 fProcessContents = PC_LAX; 00114 else if (nodeType == ContentSpecNode::Any_NS_Skip) 00115 fProcessContents = PC_SKIP; 00116 } 00117 else if (nodeType == ContentSpecNode::Any_NS_Choice) 00118 { 00119 fConstraintType = NSCONSTRAINT_DERIVATION_LIST; 00120 // inspect the second child, not the first one, as the first could hold another Any_NS_Choice wrapper 00121 // if the choices are more than 2, while the second child is always a leaf node 00122 ContentSpecNode::NodeTypes anyType = elmWildCard->getSecond()->getType(); 00123 00124 if (anyType == ContentSpecNode::Any_NS_Lax) 00125 fProcessContents = PC_LAX; 00126 else if (anyType == ContentSpecNode::Any_NS_Skip) 00127 fProcessContents = PC_SKIP; 00128 00129 fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(4, true, manager); 00130 buildNamespaceList(elmWildCard); 00131 } 00132 // must be any 00133 else 00134 { 00135 if (nodeType == ContentSpecNode::Any_Lax) 00136 fProcessContents = PC_LAX; 00137 else if (nodeType == ContentSpecNode::Any_Skip) 00138 fProcessContents = PC_SKIP; 00139 } 00140 00141 if (fConstraintType == NSCONSTRAINT_NOT 00142 || (fConstraintType == NSCONSTRAINT_DERIVATION_LIST 00143 && !fNsConstraintList)) 00144 { 00145 fNsConstraintList = new (manager) RefArrayVectorOf<XMLCh>(1, true, manager); 00146 fNsConstraintList->addElement 00147 ( 00148 XMLString::replicate(fXSModel->getURIStringPool()->getValueForId( 00149 elmWildCard->getElement()->getURI()), manager) 00150 ); 00151 } 00152 } 00153 00154 XSWildcard::~XSWildcard() 00155 { 00156 if (fNsConstraintList) 00157 delete fNsConstraintList; 00158 } 00159 00160 // --------------------------------------------------------------------------- 00161 // XSWildcard: helper methods 00162 // --------------------------------------------------------------------------- 00163 void XSWildcard::buildNamespaceList(const ContentSpecNode* const rootNode) 00164 { 00165 ContentSpecNode::NodeTypes nodeType = rootNode->getType(); 00166 if (nodeType == ContentSpecNode::Any_NS_Choice) 00167 { 00168 buildNamespaceList(rootNode->getFirst()); 00169 buildNamespaceList(rootNode->getSecond()); 00170 } 00171 else 00172 { 00173 fNsConstraintList->addElement 00174 ( 00175 XMLString::replicate(fXSModel->getURIStringPool()->getValueForId( 00176 rootNode->getElement()->getURI()), fMemoryManager) 00177 ); 00178 } 00179 } 00180 00181 XERCES_CPP_NAMESPACE_END