GME  13
Base64BinaryDatatypeValidator.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: Base64BinaryDatatypeValidator.cpp 695949 2008-09-16 15:57:44Z borisk $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/validators/datatype/Base64BinaryDatatypeValidator.hpp>
00026 #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>
00027 #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
00028 #include <xercesc/util/Base64.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00032 // ---------------------------------------------------------------------------
00033 //  Constructors and Destructor
00034 // ---------------------------------------------------------------------------
00035 Base64BinaryDatatypeValidator::Base64BinaryDatatypeValidator(MemoryManager* const manager)
00036 :AbstractStringValidator(0, 0, 0, DatatypeValidator::Base64Binary, manager)
00037 {}
00038 
00039 Base64BinaryDatatypeValidator::~Base64BinaryDatatypeValidator()
00040 {}
00041 
00042 Base64BinaryDatatypeValidator::Base64BinaryDatatypeValidator(
00043                           DatatypeValidator*            const baseValidator
00044                         , RefHashTableOf<KVStringPair>* const facets
00045                         , RefArrayVectorOf<XMLCh>*      const enums
00046                         , const int                           finalSet
00047                         , MemoryManager* const                manager)
00048 :AbstractStringValidator(baseValidator, facets, finalSet, DatatypeValidator::Base64Binary, manager)
00049 {
00050     init(enums, manager);
00051 }
00052 
00053 DatatypeValidator* Base64BinaryDatatypeValidator::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) Base64BinaryDatatypeValidator(this, facets, enums, finalSet, manager);
00062 }
00063 
00064 // ---------------------------------------------------------------------------
00065 //  Utilities
00066 // ---------------------------------------------------------------------------
00067 
00068 void Base64BinaryDatatypeValidator::checkValueSpace(const XMLCh* const content
00069                                                     , MemoryManager* const manager)
00070 {
00071     if (!content || !*content)
00072         return;
00073 
00074     if (Base64::getDataLength(content, manager, Base64::Conf_Schema) < 0)
00075     {
00076         ThrowXMLwithMemMgr1(InvalidDatatypeValueException
00077                 , XMLExcepts::VALUE_Not_Base64
00078                 , content
00079                 , manager);
00080     }
00081 }
00082 
00083 XMLSize_t Base64BinaryDatatypeValidator::getLength(const XMLCh* const content
00084                                          , MemoryManager* const manager) const
00085 {
00086     if (!content || !*content)
00087         return 0;
00088 
00089     return (XMLSize_t)Base64::getDataLength(content, manager, Base64::Conf_Schema);
00090 }
00091 
00092 void Base64BinaryDatatypeValidator::normalizeEnumeration(MemoryManager* const manager)
00093 {
00094 
00095     XMLSize_t enumLength = getEnumeration()->size();
00096     for ( XMLSize_t i=0; i < enumLength; i++)
00097     {
00098         XMLString::removeWS(getEnumeration()->elementAt(i), manager);
00099     }
00100 
00101 }
00102 
00103 void Base64BinaryDatatypeValidator::normalizeContent(XMLCh* const content
00104                                                      , MemoryManager* const manager) const
00105 {
00106     XMLString::removeWS(content, manager);
00107 }
00108 
00109 /***
00110  * Support for Serialization/De-serialization
00111  ***/
00112 
00113 IMPL_XSERIALIZABLE_TOCREATE(Base64BinaryDatatypeValidator)
00114 
00115 void Base64BinaryDatatypeValidator::serialize(XSerializeEngine& serEng)
00116 {
00117     AbstractStringValidator::serialize(serEng);
00118 }
00119 
00120 XERCES_CPP_NAMESPACE_END
00121