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: XSSimpleTypeDefinition.cpp 674012 2008-07-04 11:18:21Z borisk $ 00020 */ 00021 00022 #include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp> 00023 #include <xercesc/framework/psvi/XSFacet.hpp> 00024 #include <xercesc/framework/psvi/XSMultiValueFacet.hpp> 00025 #include <xercesc/framework/psvi/XSAnnotation.hpp> 00026 #include <xercesc/framework/psvi/XSModel.hpp> 00027 #include <xercesc/validators/datatype/DatatypeValidator.hpp> 00028 #include <xercesc/validators/datatype/UnionDatatypeValidator.hpp> 00029 #include <xercesc/util/XMLStringTokenizer.hpp> 00030 #include <xercesc/util/XMLUniDefs.hpp> 00031 00032 XERCES_CPP_NAMESPACE_BEGIN 00033 00034 // --------------------------------------------------------------------------- 00035 // Local, static functions 00036 // --------------------------------------------------------------------------- 00037 static bool XSSimpleTypeDefinitionTestFlag(int flag) 00038 { 00039 if (flag) 00040 return true; 00041 return false; 00042 } 00043 00044 00045 // --------------------------------------------------------------------------- 00046 // XSSimpleTypeDefinition: Constructors and Destructors 00047 // --------------------------------------------------------------------------- 00048 XSSimpleTypeDefinition::XSSimpleTypeDefinition 00049 ( 00050 DatatypeValidator* const datatypeValidator 00051 , VARIETY stVariety 00052 , XSTypeDefinition* const xsBaseType 00053 , XSSimpleTypeDefinition* const primitiveOrItemType 00054 , XSSimpleTypeDefinitionList* const memberTypes 00055 , XSAnnotation* headAnnot 00056 , XSModel* const xsModel 00057 , MemoryManager* const manager 00058 ) 00059 : XSTypeDefinition(SIMPLE_TYPE, xsBaseType, xsModel, manager) 00060 , fDefinedFacets(0) 00061 , fFixedFacets(0) 00062 , fVariety(stVariety) 00063 , fDatatypeValidator(datatypeValidator) 00064 , fXSFacetList(0) 00065 , fXSMultiValueFacetList(0) 00066 , fPatternList(0) 00067 , fPrimitiveOrItemType(primitiveOrItemType) 00068 , fMemberTypes(memberTypes) 00069 , fXSAnnotationList(0) 00070 { 00071 int finalset = fDatatypeValidator->getFinalSet(); 00072 if (finalset) 00073 { 00074 if (finalset & SchemaSymbols::XSD_EXTENSION) 00075 fFinal |= XSConstants::DERIVATION_EXTENSION; 00076 00077 if (finalset & SchemaSymbols::XSD_RESTRICTION) 00078 fFinal |= XSConstants::DERIVATION_RESTRICTION; 00079 00080 if (finalset & SchemaSymbols::XSD_LIST) 00081 fFinal |= XSConstants::DERIVATION_LIST; 00082 00083 if (finalset & SchemaSymbols::XSD_UNION) 00084 fFinal |= XSConstants::DERIVATION_UNION; 00085 } 00086 00087 if (headAnnot) 00088 { 00089 XSAnnotation* annot = headAnnot; 00090 00091 fXSAnnotationList = new (manager) RefVectorOf<XSAnnotation>(3, false, manager); 00092 do 00093 { 00094 fXSAnnotationList->addElement(annot); 00095 annot = annot->getNext(); 00096 } while (annot); 00097 } 00098 } 00099 00100 XSSimpleTypeDefinition::~XSSimpleTypeDefinition() 00101 { 00102 if (fXSFacetList) 00103 delete fXSFacetList; 00104 00105 if (fXSMultiValueFacetList) 00106 delete fXSMultiValueFacetList; 00107 00108 if (fPatternList) 00109 delete fPatternList; 00110 00111 // don't delete fPrimitiveOrItemType -> deleted by XSModel 00112 if (fMemberTypes) 00113 delete fMemberTypes; 00114 00115 if (fXSAnnotationList) 00116 delete fXSAnnotationList; 00117 } 00118 00119 00120 // --------------------------------------------------------------------------- 00121 // XSSimpleTypeDefinition: access methods 00122 // --------------------------------------------------------------------------- 00123 bool XSSimpleTypeDefinition::isDefinedFacet(FACET facetName) 00124 { 00125 return XSSimpleTypeDefinitionTestFlag(fDefinedFacets & facetName); 00126 } 00127 00128 bool XSSimpleTypeDefinition::isFixedFacet(FACET facetName) 00129 { 00130 return XSSimpleTypeDefinitionTestFlag(fFixedFacets & facetName); 00131 } 00132 00133 const XMLCh *XSSimpleTypeDefinition::getLexicalFacetValue(FACET facetName) 00134 { 00135 XMLSize_t size = fXSFacetList->size(); 00136 for (XMLSize_t i=0; i<size; i++) 00137 { 00138 if (((fXSFacetList->elementAt(i))->getFacetKind()) == facetName) 00139 return (fXSFacetList->elementAt(i))->getLexicalFacetValue(); 00140 } 00141 return 0; 00142 } 00143 00144 StringList *XSSimpleTypeDefinition::getLexicalEnumeration() 00145 { 00146 return (RefArrayVectorOf<XMLCh>*) fDatatypeValidator->getEnumString(); 00147 } 00148 00149 XSSimpleTypeDefinition::ORDERING XSSimpleTypeDefinition::getOrdered() const 00150 { 00151 return fDatatypeValidator->getOrdered(); 00152 } 00153 00154 bool XSSimpleTypeDefinition::getFinite() const 00155 { 00156 return fDatatypeValidator->getFinite(); 00157 } 00158 00159 bool XSSimpleTypeDefinition::getBounded() const 00160 { 00161 return fDatatypeValidator->getBounded(); 00162 } 00163 00164 bool XSSimpleTypeDefinition::getNumeric() const 00165 { 00166 return fDatatypeValidator->getNumeric(); 00167 } 00168 00169 00170 // --------------------------------------------------------------------------- 00171 // XSSimpleTypeDefinition: virtual methods 00172 // --------------------------------------------------------------------------- 00173 const XMLCh *XSSimpleTypeDefinition::getName() const 00174 { 00175 return fDatatypeValidator->getTypeLocalName(); 00176 } 00177 00178 const XMLCh *XSSimpleTypeDefinition::getNamespace() 00179 { 00180 return fDatatypeValidator->getTypeUri(); 00181 } 00182 00183 XSNamespaceItem *XSSimpleTypeDefinition::getNamespaceItem() 00184 { 00185 return fXSModel->getNamespaceItem(getNamespace()); 00186 } 00187 00188 bool XSSimpleTypeDefinition::getAnonymous() const 00189 { 00190 return fDatatypeValidator->getAnonymous(); 00191 } 00192 00193 XSTypeDefinition *XSSimpleTypeDefinition::getBaseType() 00194 { 00195 return fBaseType; 00196 } 00197 00198 bool XSSimpleTypeDefinition::derivedFromType(const XSTypeDefinition * const ancestorType) 00199 { 00200 if (!ancestorType) 00201 return false; 00202 00203 XSTypeDefinition* type; 00204 00205 if (ancestorType->getTypeCategory() == XSTypeDefinition::COMPLEX_TYPE) 00206 { 00207 type = (XSTypeDefinition*) ancestorType; 00208 if (ancestorType == type->getBaseType()) 00209 { 00210 // ancestor is anytype 00211 return true; 00212 } 00213 return false; 00214 } 00215 00216 type = this; 00217 XSTypeDefinition* lastType = 0; // anysimple type has a base type of anytype 00218 // anytype has a basetype of anytype so will have infinite loop... 00219 00220 while (type && (type != ancestorType) && (type != lastType)) 00221 { 00222 lastType = type; 00223 type = type->getBaseType(); 00224 } 00225 00226 return (type == ancestorType); 00227 } 00228 00229 // --------------------------------------------------------------------------- 00230 // XSSimpleTypeDefinition: helper methods 00231 // --------------------------------------------------------------------------- 00232 void XSSimpleTypeDefinition::setFacetInfo 00233 ( 00234 int definedFacets 00235 , int fixedFacets 00236 , XSFacetList* const xsFacetList 00237 , XSMultiValueFacetList* const xsMultiValueFacetList 00238 , StringList* const patternList 00239 ) 00240 { 00241 fDefinedFacets = definedFacets; 00242 fFixedFacets = fixedFacets; 00243 fXSFacetList = xsFacetList; 00244 fXSMultiValueFacetList = xsMultiValueFacetList; 00245 fPatternList = patternList; 00246 } 00247 00248 00249 XERCES_CPP_NAMESPACE_END