GME  13
DateDatatypeValidator.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: DateDatatypeValidator.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/validators/datatype/DateDatatypeValidator.hpp>
00026 #include <xercesc/util/OutOfMemoryException.hpp>
00027 
00028 XERCES_CPP_NAMESPACE_BEGIN
00029 
00030 // ---------------------------------------------------------------------------
00031 //  Constructors and Destructor
00032 // ---------------------------------------------------------------------------
00033 DateDatatypeValidator::DateDatatypeValidator(MemoryManager* const manager)
00034 :DateTimeValidator(0, 0, 0, DatatypeValidator::Date, manager)
00035 {
00036     setOrdered(XSSimpleTypeDefinition::ORDERED_PARTIAL);
00037 }
00038 
00039 DateDatatypeValidator::DateDatatypeValidator(
00040                           DatatypeValidator*            const baseValidator
00041                         , RefHashTableOf<KVStringPair>* const facets
00042                         , RefArrayVectorOf<XMLCh>*      const enums
00043                         , const int                           finalSet
00044                         , MemoryManager* const                manager)
00045 :DateTimeValidator(baseValidator, facets, finalSet, DatatypeValidator::Date, manager)
00046 {
00047     init(enums, manager);
00048 }
00049 
00050 DateDatatypeValidator::~DateDatatypeValidator()
00051 {}
00052 
00053 DatatypeValidator* DateDatatypeValidator::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) DateDatatypeValidator(this, facets, enums, finalSet, manager);
00062 }
00063 
00064 //
00065 // caller need to release the date created here
00066 //
00067 XMLDateTime* DateDatatypeValidator::parse(const XMLCh* const content, MemoryManager* const manager)
00068 {
00069     XMLDateTime *pRetDate = new (manager) XMLDateTime(content, manager);
00070     Janitor<XMLDateTime> jan(pRetDate);
00071 
00072     try
00073     {
00074         pRetDate->parseDate();
00075     }
00076     catch(const OutOfMemoryException&)
00077     {
00078         jan.release();
00079 
00080         throw;
00081     }
00082 
00083     return jan.release();
00084 }
00085 
00086 void DateDatatypeValidator::parse(XMLDateTime* const pDate)
00087 {
00088     pDate->parseDate();
00089 }
00090 
00091 const XMLCh* DateDatatypeValidator::getCanonicalRepresentation(const XMLCh*         const rawData
00092                                                               ,      MemoryManager* const memMgr
00093                                                               ,      bool                 toValidate) const
00094 {
00095     MemoryManager* toUse = memMgr? memMgr : fMemoryManager;
00096 
00097     if (toValidate)
00098     {
00099         DateDatatypeValidator* temp = (DateDatatypeValidator*) this;
00100 
00101         try
00102         {
00103             temp->checkContent(rawData, 0, false, toUse);   
00104         }
00105         catch (...)
00106         {
00107             return 0;
00108         }
00109     }
00110     
00111     try
00112     {
00113         XMLDateTime aDateTime(rawData, toUse);
00114         aDateTime.parseDate();
00115         return aDateTime.getDateCanonicalRepresentation(toUse);
00116     }
00117     catch (...)
00118     {
00119         return 0;
00120     }
00121 
00122 }
00123 
00124 /***
00125  * Support for Serialization/De-serialization
00126  ***/
00127 
00128 IMPL_XSERIALIZABLE_TOCREATE(DateDatatypeValidator)
00129 
00130 void DateDatatypeValidator::serialize(XSerializeEngine& serEng)
00131 {
00132     DateTimeValidator::serialize(serEng);
00133 }
00134 
00135 XERCES_CPP_NAMESPACE_END
00136