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