00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * Copyright (c) 2001 The Apache Software Foundation. All rights 00005 * reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * 2. Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in 00016 * the documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * 3. The end-user documentation included with the redistribution, 00020 * if any, must include the following acknowledgment: 00021 * "This product includes software developed by the 00022 * Apache Software Foundation (http://www.apache.org/)." 00023 * Alternately, this acknowledgment may appear in the software itself, 00024 * if and wherever such third-party acknowledgments normally appear. 00025 * 00026 * 4. The names "Xerces" and "Apache Software Foundation" must 00027 * not be used to endorse or promote products derived from this 00028 * software without prior written permission. For written 00029 * permission, please contact apache\@apache.org. 00030 * 00031 * 5. Products derived from this software may not be called "Apache", 00032 * nor may "Apache" appear in their name, without prior written 00033 * permission of the Apache Software Foundation. 00034 * 00035 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00036 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00037 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00038 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00039 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00040 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00041 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00042 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00043 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00044 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00045 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00046 * SUCH DAMAGE. 00047 * ==================================================================== 00048 * 00049 * This software consists of voluntary contributions made by many 00050 * individuals on behalf of the Apache Software Foundation, and was 00051 * originally based on software copyright (c) 2001, International 00052 * Business Machines, Inc., http://www.ibm.com . For more information 00053 * on the Apache Software Foundation, please see 00054 * <http://www.apache.org/>. 00055 */ 00056 00057 /* 00058 * $Id: XMLDateTime.hpp,v 1.1 2002/05/11 21:17:44 bhavani Exp $ 00059 * $Log: XMLDateTime.hpp,v $ 00060 * Revision 1.1 2002/05/11 21:17:44 bhavani 00061 * CR#CR062582# adding xercesc 1.7 file 00062 * 00063 * Revision 1.1.1.1 2002/02/01 22:22:14 peiyongz 00064 * sane_include 00065 * 00066 * Revision 1.4 2001/11/22 20:23:00 peiyongz 00067 * _declspec(dllimport) and inline warning C4273 00068 * 00069 * Revision 1.3 2001/11/12 20:36:54 peiyongz 00070 * SchemaDateTimeException defined 00071 * 00072 * Revision 1.2 2001/11/09 20:41:45 peiyongz 00073 * Fix: compilation error on Solaris and AIX. 00074 * 00075 * Revision 1.1 2001/11/07 19:16:03 peiyongz 00076 * DateTime Port 00077 * 00078 */ 00079 00080 #ifndef XML_DATETIME_HPP 00081 #define XML_DATETIME_HPP 00082 00083 #include <xercesc/util/XercesDefs.hpp> 00084 #include <xercesc/util/XMLNumber.hpp> 00085 #include <xercesc/util/XMLString.hpp> 00086 #include <xercesc/util/XMLUniDefs.hpp> 00087 #include <xercesc/util/SchemaDateTimeException.hpp> 00088 00089 class XMLUTIL_EXPORT XMLDateTime : public XMLNumber 00090 { 00091 public: 00092 00093 // to be moved to XMLNumber 00094 enum 00095 { 00096 LESS_THAN = -1, 00097 EQUAL = 0, 00098 GREATER_THAN = 1, 00099 INDETERMINATE = 2 00100 }; 00101 00102 enum valueIndex 00103 { 00104 CentYear = 0, 00105 Month , 00106 Day , 00107 Hour , 00108 Minute , 00109 Second , 00110 MiliSecond , 00111 utc , 00112 TOTAL_SIZE 00113 }; 00114 00115 enum utcType 00116 { 00117 UTC_UNKNOWN = 0, 00118 UTC_STD , // set in parse() or normalize() 00119 UTC_POS , // set in parse() 00120 UTC_NEG // set in parse() 00121 }; 00122 00123 // ----------------------------------------------------------------------- 00124 // ctors and dtor 00125 // ----------------------------------------------------------------------- 00126 00127 XMLDateTime(); 00128 00129 XMLDateTime(const XMLCh* const); 00130 00131 ~XMLDateTime(); 00132 00133 inline void setBuffer(const XMLCh* const); 00134 00135 // ----------------------------------------------------------------------- 00136 // Copy ctor and Assignment operators 00137 // ----------------------------------------------------------------------- 00138 00139 XMLDateTime(const XMLDateTime&); 00140 00141 XMLDateTime& operator=(const XMLDateTime&); 00142 00143 // ----------------------------------------------------------------------- 00144 // Implementation of Abstract Interface 00145 // ----------------------------------------------------------------------- 00146 00147 virtual XMLCh* toString() const; 00148 00149 virtual int getSign() const; 00150 00151 // ----------------------------------------------------------------------- 00152 // parsers 00153 // ----------------------------------------------------------------------- 00154 00155 void parseDateTime(); //DateTime 00156 00157 void parseDate(); //Date 00158 00159 void parseTime(); //Time 00160 00161 void parseDay(); //gDay 00162 00163 void parseMonth(); //gMonth 00164 00165 void parseYear(); //gYear 00166 00167 void parseMonthDay(); //gMonthDay 00168 00169 void parseYearMonth(); //gYearMonth 00170 00171 void parseDuration(); //duration 00172 00173 // ----------------------------------------------------------------------- 00174 // Comparison 00175 // ----------------------------------------------------------------------- 00176 static int compare(const XMLDateTime* const 00177 , const XMLDateTime* const); 00178 00179 static int compare(const XMLDateTime* const 00180 , const XMLDateTime* const 00181 , bool ); 00182 00183 static int compareOrder(const XMLDateTime* const 00184 , const XMLDateTime* const); 00185 00186 private: 00187 00188 // ----------------------------------------------------------------------- 00189 // Constant data 00190 // ----------------------------------------------------------------------- 00191 // 00192 enum timezoneIndex 00193 { 00194 hh = 0, 00195 mm , 00196 TIMEZONE_ARRAYSIZE 00197 }; 00198 00199 // ----------------------------------------------------------------------- 00200 // Comparison 00201 // ----------------------------------------------------------------------- 00202 static int compareResult(short 00203 , short 00204 , bool); 00205 00206 static void addDuration(XMLDateTime* pDuration 00207 , const XMLDateTime* const pBaseDate 00208 , int index); 00209 00210 00211 static int compareResult(const XMLDateTime* const 00212 , const XMLDateTime* const 00213 , bool 00214 , int); 00215 00216 static inline int getRetVal(int, int); 00217 00218 // ----------------------------------------------------------------------- 00219 // helper 00220 // ----------------------------------------------------------------------- 00221 00222 inline void reset(); 00223 00224 inline void assertBuffer() const; 00225 00226 inline void copy(const XMLDateTime&); 00227 00228 // allow multiple parsing 00229 inline void initParser(); 00230 00231 inline bool isNormalized() const; 00232 00233 // ----------------------------------------------------------------------- 00234 // scaners 00235 // ----------------------------------------------------------------------- 00236 00237 void getDate(); 00238 00239 void getTime(); 00240 00241 void getYearMonth(); 00242 00243 void getTimeZone(const int); 00244 00245 void parseTimeZone(); 00246 00247 // ----------------------------------------------------------------------- 00248 // locator and converter 00249 // ----------------------------------------------------------------------- 00250 00251 int findUTCSign(const int start); 00252 00253 int indexOf(const int start 00254 , const int end 00255 , const XMLCh ch) const; 00256 00257 int parseInt(const int start 00258 , const int end) const; 00259 00260 int parseIntYear(const int end) const; 00261 00262 // ----------------------------------------------------------------------- 00263 // validator and normalizer 00264 // ----------------------------------------------------------------------- 00265 00266 void validateDateTime() const; 00267 00268 void normalize(); 00269 00270 // ----------------------------------------------------------------------- 00271 // Unimplemented operator == 00272 // ----------------------------------------------------------------------- 00273 bool operator==(const XMLDateTime& toCompare) const; 00274 00275 00276 // ----------------------------------------------------------------------- 00277 // Private data members 00278 // 00279 // fValue[] 00280 // object representation of date time. 00281 // 00282 // fTimeZone[] 00283 // temporary storage for normalization 00284 // 00285 // fStart, fEnd 00286 // pointers to the portion of fBuffer being parsed 00287 // 00288 // fBuffer 00289 // raw data to be parsed, own it. 00290 // 00291 // ----------------------------------------------------------------------- 00292 00293 int fValue[TOTAL_SIZE]; 00294 int fTimeZone[TIMEZONE_ARRAYSIZE]; 00295 int fStart; 00296 int fEnd; 00297 00298 XMLCh* fBuffer; 00299 00300 }; 00301 00302 inline void XMLDateTime::setBuffer(const XMLCh* const aString) 00303 { 00304 reset(); 00305 fBuffer = XMLString::replicate(aString); 00306 fEnd = XMLString::stringLen(fBuffer); 00307 00308 } 00309 00310 inline void XMLDateTime::reset() 00311 { 00312 for ( int i=0; i < TOTAL_SIZE; i++ ) 00313 fValue[i] = 0; 00314 00315 fTimeZone[hh] = fTimeZone[mm] = 0; 00316 fStart = fEnd = 0; 00317 00318 if (fBuffer) 00319 { 00320 delete[] fBuffer; 00321 fBuffer = 0; 00322 } 00323 00324 } 00325 00326 inline void XMLDateTime::copy(const XMLDateTime& rhs) 00327 { 00328 for ( int i = 0; i < TOTAL_SIZE; i++ ) 00329 fValue[i] = rhs.fValue[i]; 00330 00331 fTimeZone[hh] = rhs.fTimeZone[hh]; 00332 fTimeZone[mm] = rhs.fTimeZone[mm]; 00333 fStart = rhs.fStart; 00334 fEnd = rhs.fEnd; 00335 00336 if (fBuffer) 00337 { 00338 delete[] fBuffer; 00339 fBuffer = 0; 00340 } 00341 00342 if (rhs.fBuffer) 00343 fBuffer = XMLString::replicate(rhs.fBuffer); 00344 00345 } 00346 00347 inline void XMLDateTime::assertBuffer() const 00348 { 00349 if ( ( !fBuffer ) || 00350 ( fBuffer[0] == chNull ) ) 00351 { 00352 ThrowXML(SchemaDateTimeException 00353 , XMLExcepts::DateTime_Assert_Buffer_Fail); 00354 } 00355 00356 } 00357 00358 inline void XMLDateTime::initParser() 00359 { 00360 assertBuffer(); 00361 fStart = 0; // to ensure scan from the very first beginning 00362 // in case the pointer is updated accidentally by someone else. 00363 } 00364 00365 inline bool XMLDateTime::isNormalized() const 00366 { 00367 return ( fValue[utc] == UTC_STD ? true : false ); 00368 } 00369 00370 inline int XMLDateTime::getRetVal(int c1, int c2) 00371 { 00372 if ((c1 == LESS_THAN && c2 == GREATER_THAN) || 00373 (c1 == GREATER_THAN && c2 == LESS_THAN) ) 00374 { 00375 return INDETERMINATE; 00376 } 00377 00378 return ( c1 != INDETERMINATE ) ? c1 : c2; 00379 } 00380 00381 #endif