00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 #ifndef XML_DATETIME_HPP
00124 #define XML_DATETIME_HPP
00125
00126 #include <xercesc/util/XMLNumber.hpp>
00127 #include <xercesc/util/PlatformUtils.hpp>
00128 #include <xercesc/util/XMLString.hpp>
00129 #include <xercesc/util/XMLUniDefs.hpp>
00130 #include <xercesc/util/SchemaDateTimeException.hpp>
00131
00132 XERCES_CPP_NAMESPACE_BEGIN
00133
00134 class XMLDateTime : public XMLNumber
00135 {
00136 public:
00137
00138 enum valueIndex
00139 {
00140 CentYear = 0,
00141 Month ,
00142 Day ,
00143 Hour ,
00144 Minute ,
00145 Second ,
00146 MiliSecond ,
00147 utc ,
00148 TOTAL_SIZE
00149 };
00150
00151 enum utcType
00152 {
00153 UTC_UNKNOWN = 0,
00154 UTC_STD ,
00155 UTC_POS ,
00156 UTC_NEG
00157 };
00158
00159
00160
00161
00162
00163 XMLDateTime(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00164 XMLDateTime(const XMLCh* const,
00165 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00166 ~XMLDateTime();
00167
00168 inline void setBuffer(const XMLCh* const);
00169
00170
00171
00172
00173
00174 XMLDateTime(const XMLDateTime&);
00175
00176 XMLDateTime& operator=(const XMLDateTime&);
00177
00178
00179
00180
00181
00187 virtual XMLCh* toString() const;
00188
00189 virtual XMLCh* getRawData() const;
00190
00191 virtual const XMLCh* getFormattedString() const;
00192
00193 virtual int getSign() const;
00194
00195
00196
00197
00198
00199 XMLCh* getDateTimeCanonicalRepresentation(MemoryManager* const memMgr) const;
00200
00201 XMLCh* getTimeCanonicalRepresentation(MemoryManager* const memMgr) const;
00202
00203
00204
00205
00206
00207 void parseDateTime();
00208
00209 void parseDate();
00210
00211 void parseTime();
00212
00213 void parseDay();
00214
00215 void parseMonth();
00216
00217 void parseYear();
00218
00219 void parseMonthDay();
00220
00221 void parseYearMonth();
00222
00223 void parseDuration();
00224
00225
00226
00227
00228 static int compare(const XMLDateTime* const
00229 , const XMLDateTime* const);
00230
00231 static int compare(const XMLDateTime* const
00232 , const XMLDateTime* const
00233 , bool );
00234
00235 static int compareOrder(const XMLDateTime* const
00236 , const XMLDateTime* const);
00237
00238
00239
00240
00241 DECL_XSERIALIZABLE(XMLDateTime)
00242
00243 private:
00244
00245
00246
00247
00248
00249 enum timezoneIndex
00250 {
00251 hh = 0,
00252 mm ,
00253 TIMEZONE_ARRAYSIZE
00254 };
00255
00256
00257
00258
00259 static int compareResult(int
00260 , int
00261 , bool);
00262
00263 static void addDuration(XMLDateTime* pDuration
00264 , const XMLDateTime* const pBaseDate
00265 , int index);
00266
00267
00268 static int compareResult(const XMLDateTime* const
00269 , const XMLDateTime* const
00270 , bool
00271 , int);
00272
00273 static inline int getRetVal(int, int);
00274
00275
00276
00277
00278
00279 inline void reset();
00280
00281 inline void assertBuffer() const;
00282
00283 inline void copy(const XMLDateTime&);
00284
00285
00286 inline void initParser();
00287
00288 inline bool isNormalized() const;
00289
00290
00291
00292
00293
00294 void getDate();
00295
00296 void getTime();
00297
00298 void getYearMonth();
00299
00300 void getTimeZone(const int);
00301
00302 void parseTimeZone();
00303
00304
00305
00306
00307
00308 int findUTCSign(const int start);
00309
00310 int indexOf(const int start
00311 , const int end
00312 , const XMLCh ch) const;
00313
00314 int parseInt(const int start
00315 , const int end) const;
00316
00317 int parseIntYear(const int end) const;
00318
00319
00320
00321
00322
00323 void validateDateTime() const;
00324
00325 void normalize();
00326
00327 void fillString(XMLCh*& ptr, valueIndex ind, int expLen) const;
00328
00329 int fillYearString(XMLCh*& ptr, valueIndex ind) const;
00330
00331 void searchMiliSeconds(XMLCh*& miliStartPtr, XMLCh*& miliEndPtr) const;
00332
00333
00334
00335
00336 bool operator==(const XMLDateTime& toCompare) const;
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 int fValue[TOTAL_SIZE];
00357 int fTimeZone[TIMEZONE_ARRAYSIZE];
00358 int fStart;
00359 int fEnd;
00360 int fBufferMaxLen;
00361 XMLCh* fBuffer;
00362 MemoryManager* fMemoryManager;
00363 };
00364
00365 inline void XMLDateTime::setBuffer(const XMLCh* const aString)
00366 {
00367 reset();
00368
00369 fEnd = XMLString::stringLen(aString);
00370 if (fEnd > 0) {
00371
00372 if (fEnd > fBufferMaxLen)
00373 {
00374 fMemoryManager->deallocate(fBuffer);
00375 fBufferMaxLen = fEnd + 8;
00376 fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
00377 }
00378
00379 memcpy(fBuffer, aString, (fEnd+1) * sizeof(XMLCh));
00380 }
00381 }
00382
00383 inline void XMLDateTime::reset()
00384 {
00385 for ( int i=0; i < TOTAL_SIZE; i++ )
00386 fValue[i] = 0;
00387
00388 fTimeZone[hh] = fTimeZone[mm] = 0;
00389 fStart = fEnd = 0;
00390
00391 if (fBuffer)
00392 *fBuffer = 0;
00393 }
00394
00395 inline void XMLDateTime::copy(const XMLDateTime& rhs)
00396 {
00397 for ( int i = 0; i < TOTAL_SIZE; i++ )
00398 fValue[i] = rhs.fValue[i];
00399
00400 fTimeZone[hh] = rhs.fTimeZone[hh];
00401 fTimeZone[mm] = rhs.fTimeZone[mm];
00402 fStart = rhs.fStart;
00403 fEnd = rhs.fEnd;
00404
00405 if (fEnd > 0)
00406 {
00407 if (fEnd > fBufferMaxLen)
00408 {
00409 fMemoryManager->deallocate(fBuffer);
00410 fBufferMaxLen = rhs.fBufferMaxLen;
00411 fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
00412 }
00413
00414 memcpy(fBuffer, rhs.fBuffer, (fEnd+1) * sizeof(XMLCh));
00415 }
00416 }
00417
00418 inline void XMLDateTime::assertBuffer() const
00419 {
00420 if ( ( !fBuffer ) ||
00421 ( fBuffer[0] == chNull ) )
00422 {
00423 ThrowXMLwithMemMgr(SchemaDateTimeException
00424 , XMLExcepts::DateTime_Assert_Buffer_Fail
00425 , fMemoryManager);
00426 }
00427
00428 }
00429
00430 inline void XMLDateTime::initParser()
00431 {
00432 assertBuffer();
00433 fStart = 0;
00434
00435 }
00436
00437 inline bool XMLDateTime::isNormalized() const
00438 {
00439 return ( fValue[utc] == UTC_STD ? true : false );
00440 }
00441
00442 inline int XMLDateTime::getRetVal(int c1, int c2)
00443 {
00444 if ((c1 == LESS_THAN && c2 == GREATER_THAN) ||
00445 (c1 == GREATER_THAN && c2 == LESS_THAN) )
00446 {
00447 return INDETERMINATE;
00448 }
00449
00450 return ( c1 != INDETERMINATE ) ? c1 : c2;
00451 }
00452
00453 XERCES_CPP_NAMESPACE_END
00454
00455 #endif