GME  13
ENTITYDatatypeValidator.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: ENTITYDatatypeValidator.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/validators/datatype/ENTITYDatatypeValidator.hpp>
00026 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
00027 #include <xercesc/framework/XMLEntityDecl.hpp>
00028 #include <xercesc/util/XMLChar.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00032 // ---------------------------------------------------------------------------
00033 //  Constructors and Destructor
00034 // ---------------------------------------------------------------------------
00035 ENTITYDatatypeValidator::ENTITYDatatypeValidator(MemoryManager* const manager)
00036 :StringDatatypeValidator(0, 0, 0, DatatypeValidator::ENTITY, manager)
00037 {}
00038 
00039 ENTITYDatatypeValidator::ENTITYDatatypeValidator(
00040                           DatatypeValidator*            const baseValidator
00041                         , RefHashTableOf<KVStringPair>* const facets
00042                         , RefArrayVectorOf<XMLCh>*      const enums
00043                         , const int                           finalSet
00044                         , MemoryManager* const                manager)
00045 :StringDatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::ENTITY, manager)
00046 {
00047     init(enums, manager);
00048 }
00049 
00050 ENTITYDatatypeValidator::~ENTITYDatatypeValidator()
00051 {}
00052 
00053 DatatypeValidator* ENTITYDatatypeValidator::newInstance
00054 (
00055       RefHashTableOf<KVStringPair>* const facets
00056     , RefArrayVectorOf<XMLCh>* const      enums
00057     , const int                           finalSet
00058     , MemoryManager* const                manager
00059 )
00060 {
00061     return (DatatypeValidator*) new (manager) ENTITYDatatypeValidator(this, facets, enums, finalSet, manager);
00062 }
00063 
00064 // -----------------------------------------------------------------------
00065 // Compare methods
00066 // -----------------------------------------------------------------------
00067 int ENTITYDatatypeValidator::compare(const XMLCh* const lValue
00068                                    , const XMLCh* const rValue
00069                                    ,       MemoryManager*     const)
00070 {
00071     return ( XMLString::equals(lValue, rValue)? 0 : -1);
00072 }
00073 
00074 void ENTITYDatatypeValidator::validate(const XMLCh*             const content
00075                                      ,       ValidationContext* const context
00076                                      ,       MemoryManager*     const manager)
00077 {
00078     // use StringDatatypeValidator (which in turn, invoke
00079     // the baseValidator) to validate content against
00080     // facets if any.
00081     //
00082     StringDatatypeValidator::validate(content, context, manager);
00083 
00084     //
00085     // parse the entity iff an EntityDeclPool is provided
00086     //
00087     if (context)
00088     {
00089         context->checkEntity(content);
00090     }
00091 
00092 }
00093 
00094 void ENTITYDatatypeValidator::checkValueSpace(const XMLCh* const content
00095                                               , MemoryManager* const manager)
00096 {
00097     //
00098     // 3.3.11 check must: "NCName"
00099     //
00100     if ( !XMLChar1_0::isValidNCName(content, XMLString::stringLen(content)) )
00101     {
00102         ThrowXMLwithMemMgr1(InvalidDatatypeValueException
00103                 , XMLExcepts::VALUE_Invalid_NCName
00104                 , content
00105                 , manager);
00106     }
00107 
00108 }
00109 
00110 /***
00111  * Support for Serialization/De-serialization
00112  ***/
00113 
00114 IMPL_XSERIALIZABLE_TOCREATE(ENTITYDatatypeValidator)
00115 
00116 void ENTITYDatatypeValidator::serialize(XSerializeEngine& serEng)
00117 {
00118     StringDatatypeValidator::serialize(serEng);
00119 }
00120 
00121 XERCES_CPP_NAMESPACE_END
00122