GME  13
NOTATIONDatatypeValidator.cpp
Go to the documentation of this file.
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: NOTATIONDatatypeValidator.cpp 676911 2008-07-15 13:27:32Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/validators/datatype/NOTATIONDatatypeValidator.hpp>
00026 #include <xercesc/util/XMLUri.hpp>
00027 #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>
00028 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
00029 #include <xercesc/util/OutOfMemoryException.hpp>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 // ---------------------------------------------------------------------------
00034 //  Constructors and Destructor
00035 // ---------------------------------------------------------------------------
00036 NOTATIONDatatypeValidator::NOTATIONDatatypeValidator(MemoryManager* const manager)
00037 :AbstractStringValidator(0, 0, 0, DatatypeValidator::NOTATION, manager)
00038 {}
00039 
00040 NOTATIONDatatypeValidator::~NOTATIONDatatypeValidator()
00041 {}
00042 
00043 NOTATIONDatatypeValidator::NOTATIONDatatypeValidator(
00044                           DatatypeValidator*            const baseValidator
00045                         , RefHashTableOf<KVStringPair>* const facets
00046                         , RefArrayVectorOf<XMLCh>*           const enums
00047                         , const int                           finalSet
00048                         , MemoryManager* const manager)
00049 :AbstractStringValidator(baseValidator, facets, finalSet, DatatypeValidator::NOTATION, manager)
00050 {
00051     init(enums, manager);
00052 }
00053 
00054 DatatypeValidator* NOTATIONDatatypeValidator::newInstance
00055 (
00056       RefHashTableOf<KVStringPair>* const facets
00057     , RefArrayVectorOf<XMLCh>* const      enums
00058     , const int                           finalSet
00059     , MemoryManager* const                manager
00060 )
00061 {
00062     return (DatatypeValidator*) new (manager) NOTATIONDatatypeValidator(this, facets, enums, finalSet, manager);
00063 }
00064 
00065 // ---------------------------------------------------------------------------
00066 //  Utilities
00067 // ---------------------------------------------------------------------------
00068 
00069 void NOTATIONDatatypeValidator::checkValueSpace(const XMLCh* const content
00070                                                 , MemoryManager* const manager)
00071 {
00072 
00073     if (!XMLString::isValidNOTATION(content, manager))
00074     {
00075         ThrowXMLwithMemMgr1(InvalidDatatypeValueException
00076                 , XMLExcepts::VALUE_NOTATION_Invalid
00077                 , content
00078                 , manager);
00079     }
00080 
00081 }
00082 
00083 void NOTATIONDatatypeValidator::checkContent( const XMLCh*             const content
00084                                           ,       ValidationContext* const context
00085                                           ,       bool                     asBase
00086                                           ,       MemoryManager*     const manager
00087                                           )
00088 {
00089 
00090     //validate against base validator if any
00091     NOTATIONDatatypeValidator *pBaseValidator = (NOTATIONDatatypeValidator*) this->getBaseValidator();
00092     if (pBaseValidator)
00093         pBaseValidator->checkContent(content, context, true, manager);
00094 
00095     int thisFacetsDefined = getFacetsDefined();
00096 
00097     // we check pattern first
00098     if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 )
00099     {
00100         if (getRegex()->matches(content, manager) ==false)
00101         {
00102             ThrowXMLwithMemMgr2(InvalidDatatypeValueException
00103                     , XMLExcepts::VALUE_NotMatch_Pattern
00104                     , content
00105                     , getPattern()
00106                     , manager);
00107         }
00108     }
00109 
00110     // if this is a base validator, we only need to check pattern facet
00111     // all other facet were inherited by the derived type
00112     if (asBase)
00113         return;
00114 
00115     checkValueSpace(content, manager);
00116 
00117     if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 &&
00118         (getEnumeration() != 0))
00119     {
00120         XMLCh* normContent = XMLString::replicate(content, manager);
00121         ArrayJanitor<XMLCh>  jan(normContent, manager);
00122         normalizeContent(normContent, manager);
00123 
00124         XMLSize_t i=0;
00125         XMLSize_t enumLength = getEnumeration()->size();
00126         for ( ; i < enumLength; i++)
00127         {
00128             if (XMLString::equals(normContent, getEnumeration()->elementAt(i)))
00129                 break;
00130         }
00131 
00132         if (i == enumLength)
00133             ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager);
00134     }
00135 
00136     checkAdditionalFacet(content, manager);
00137 }
00138 
00139 /***
00140  * Support for Serialization/De-serialization
00141  ***/
00142 
00143 IMPL_XSERIALIZABLE_TOCREATE(NOTATIONDatatypeValidator)
00144 
00145 void NOTATIONDatatypeValidator::serialize(XSerializeEngine& serEng)
00146 {
00147     AbstractStringValidator::serialize(serEng);
00148 }
00149 
00150 XERCES_CPP_NAMESPACE_END
00151