1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: XSValue.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(XSVALUE_HPP) |
---|
23 | #define XSVALUE_HPP |
---|
24 | |
---|
25 | #include <xercesc/util/PlatformUtils.hpp> |
---|
26 | #include <xercesc/util/ValueHashTableOf.hpp> |
---|
27 | |
---|
28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
29 | |
---|
30 | class RegularExpression; |
---|
31 | |
---|
32 | class XMLPARSER_EXPORT XSValue : public XMemory |
---|
33 | { |
---|
34 | public: |
---|
35 | |
---|
36 | enum DataType { |
---|
37 | dt_string = 0, |
---|
38 | dt_boolean = 1, |
---|
39 | dt_decimal = 2, |
---|
40 | dt_float = 3, |
---|
41 | dt_double = 4, |
---|
42 | dt_duration = 5, |
---|
43 | dt_dateTime = 6, |
---|
44 | dt_time = 7, |
---|
45 | dt_date = 8, |
---|
46 | dt_gYearMonth = 9, |
---|
47 | dt_gYear = 10, |
---|
48 | dt_gMonthDay = 11, |
---|
49 | dt_gDay = 12, |
---|
50 | dt_gMonth = 13, |
---|
51 | dt_hexBinary = 14, |
---|
52 | dt_base64Binary = 15, |
---|
53 | dt_anyURI = 16, |
---|
54 | dt_QName = 17, |
---|
55 | dt_NOTATION = 18, |
---|
56 | dt_normalizedString = 19, |
---|
57 | dt_token = 20, |
---|
58 | dt_language = 21, |
---|
59 | dt_NMTOKEN = 22, |
---|
60 | dt_NMTOKENS = 23, |
---|
61 | dt_Name = 24, |
---|
62 | dt_NCName = 25, |
---|
63 | dt_ID = 26, |
---|
64 | dt_IDREF = 27, |
---|
65 | dt_IDREFS = 28, |
---|
66 | dt_ENTITY = 29, |
---|
67 | dt_ENTITIES = 30, |
---|
68 | dt_integer = 31, |
---|
69 | dt_nonPositiveInteger = 32, |
---|
70 | dt_negativeInteger = 33, |
---|
71 | dt_long = 34, |
---|
72 | dt_int = 35, |
---|
73 | dt_short = 36, |
---|
74 | dt_byte = 37, |
---|
75 | dt_nonNegativeInteger = 38, |
---|
76 | dt_unsignedLong = 39, |
---|
77 | dt_unsignedInt = 40, |
---|
78 | dt_unsignedShort = 41, |
---|
79 | dt_unsignedByte = 42, |
---|
80 | dt_positiveInteger = 43, |
---|
81 | dt_MAXCOUNT = 44 |
---|
82 | }; |
---|
83 | |
---|
84 | enum XMLVersion { |
---|
85 | ver_10, |
---|
86 | ver_11 |
---|
87 | }; |
---|
88 | |
---|
89 | enum Status { |
---|
90 | st_Init, |
---|
91 | st_NoContent, |
---|
92 | st_NoCanRep, |
---|
93 | st_NoActVal, |
---|
94 | st_NotSupported, |
---|
95 | st_CantCreateRegEx, |
---|
96 | st_FOCA0002, //invalid lexical value |
---|
97 | st_FOCA0001, //input value too large/too small for decimal |
---|
98 | st_FOCA0003, //input value too large for integer |
---|
99 | st_FODT0003, //invalid timezone value |
---|
100 | st_UnknownType |
---|
101 | }; |
---|
102 | |
---|
103 | enum DataGroup { |
---|
104 | dg_numerics, |
---|
105 | dg_datetimes, |
---|
106 | dg_strings |
---|
107 | }; |
---|
108 | |
---|
109 | enum DoubleFloatType |
---|
110 | { |
---|
111 | DoubleFloatType_NegINF, |
---|
112 | DoubleFloatType_PosINF, |
---|
113 | DoubleFloatType_NaN, |
---|
114 | DoubleFloatType_Zero, |
---|
115 | DoubleFloatType_Normal |
---|
116 | }; |
---|
117 | |
---|
118 | // Constructors and Destructor |
---|
119 | // ----------------------------------------------------------------------- |
---|
120 | /** @name Destructor */ |
---|
121 | //@{ |
---|
122 | ~XSValue(); |
---|
123 | //@} |
---|
124 | |
---|
125 | //--------------------------------- |
---|
126 | /** @name Externalization methods */ |
---|
127 | //@{ |
---|
128 | |
---|
129 | /** |
---|
130 | * Validate a given string of the data type specified |
---|
131 | * |
---|
132 | * @param content data to be validated |
---|
133 | * @param datatype schema datatype |
---|
134 | * @param status validation status which is set upon validation fails |
---|
135 | * @param version xml version |
---|
136 | * @param manager memory manager provided |
---|
137 | */ |
---|
138 | static |
---|
139 | bool validate |
---|
140 | ( |
---|
141 | const XMLCh* const content |
---|
142 | , DataType datatype |
---|
143 | , Status& status |
---|
144 | , XMLVersion version = ver_10 |
---|
145 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
146 | ); |
---|
147 | |
---|
148 | /** |
---|
149 | * Get the canonical representation for a given string of the |
---|
150 | * data type specified |
---|
151 | * |
---|
152 | * @param content raw data |
---|
153 | * @param datatype schema datatype |
---|
154 | * @param status validation status which is set upon validation fails |
---|
155 | * @param version xml version |
---|
156 | * @param toValidate to validate the content before generate canonical representation |
---|
157 | * @param manager memory manager provided |
---|
158 | */ |
---|
159 | static |
---|
160 | XMLCh* getCanonicalRepresentation |
---|
161 | ( |
---|
162 | const XMLCh* const content |
---|
163 | , DataType datatype |
---|
164 | , Status& status |
---|
165 | , XMLVersion version = ver_10 |
---|
166 | , bool toValidate = true |
---|
167 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
168 | ); |
---|
169 | |
---|
170 | /** |
---|
171 | * Get the actual value, in the form of XSValue, for a given string of the |
---|
172 | * data type specified |
---|
173 | * |
---|
174 | * Client application is responsible for the deleletion of the XSValue returned. |
---|
175 | * |
---|
176 | * @param content raw data |
---|
177 | * @param datatype schema datatype |
---|
178 | * @param status validation status which is set upon validation fails |
---|
179 | * @param version xml version |
---|
180 | * @param toValidate to validate the content before generate actual value |
---|
181 | * @param manager memory manager provided |
---|
182 | */ |
---|
183 | static |
---|
184 | XSValue* getActualValue |
---|
185 | ( |
---|
186 | const XMLCh* const content |
---|
187 | , DataType datatype |
---|
188 | , Status& status |
---|
189 | , XMLVersion version = ver_10 |
---|
190 | , bool toValidate = true |
---|
191 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
192 | ); |
---|
193 | |
---|
194 | static |
---|
195 | DataType getDataType (const XMLCh* const dtString); |
---|
196 | |
---|
197 | //@} |
---|
198 | |
---|
199 | //---------------------------------- |
---|
200 | /** public data */ |
---|
201 | |
---|
202 | struct XSValue_Data { |
---|
203 | |
---|
204 | DataType f_datatype; |
---|
205 | |
---|
206 | union { |
---|
207 | bool f_bool; |
---|
208 | char f_char; |
---|
209 | unsigned char f_uchar; |
---|
210 | short f_short; |
---|
211 | unsigned short f_ushort; |
---|
212 | int f_int; |
---|
213 | unsigned int f_uint; |
---|
214 | long f_long; |
---|
215 | unsigned long f_ulong; |
---|
216 | float f_float; |
---|
217 | double f_double; |
---|
218 | XMLCh* f_strVal; |
---|
219 | XMLByte* f_byteVal; |
---|
220 | |
---|
221 | struct decimal { |
---|
222 | double f_dvalue; |
---|
223 | } f_decimal; |
---|
224 | |
---|
225 | struct datetime { |
---|
226 | int f_year; |
---|
227 | int f_month; |
---|
228 | int f_day; |
---|
229 | int f_hour; |
---|
230 | int f_min; |
---|
231 | int f_second; |
---|
232 | double f_milisec; |
---|
233 | |
---|
234 | } f_datetime; |
---|
235 | |
---|
236 | struct doubletype { |
---|
237 | double f_double; |
---|
238 | DoubleFloatType f_doubleEnum; |
---|
239 | } f_doubleType; |
---|
240 | |
---|
241 | struct floattype { |
---|
242 | float f_float; |
---|
243 | DoubleFloatType f_floatEnum; |
---|
244 | } f_floatType; |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | } fValue; |
---|
249 | |
---|
250 | } fData; |
---|
251 | |
---|
252 | static |
---|
253 | void reinitMutex(); |
---|
254 | |
---|
255 | static |
---|
256 | void reinitRegEx(); |
---|
257 | |
---|
258 | static |
---|
259 | void reinitRegistry(); |
---|
260 | |
---|
261 | private: |
---|
262 | |
---|
263 | typedef union |
---|
264 | { |
---|
265 | long f_long; |
---|
266 | unsigned long f_ulong; |
---|
267 | } t_value; |
---|
268 | |
---|
269 | /** @name Constructors */ |
---|
270 | //@{ |
---|
271 | /** |
---|
272 | * The default constructor |
---|
273 | * |
---|
274 | */ |
---|
275 | XSValue( |
---|
276 | DataType const dt |
---|
277 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
278 | ); |
---|
279 | |
---|
280 | //@}; |
---|
281 | |
---|
282 | // ----------------------------------------------------------------------- |
---|
283 | // Unimplemented constructors and operators |
---|
284 | // ----------------------------------------------------------------------- |
---|
285 | XSValue(const XSValue&); |
---|
286 | XSValue & operator=(const XSValue &); |
---|
287 | |
---|
288 | //--------------------------------- |
---|
289 | /** @name Helpers */ |
---|
290 | |
---|
291 | //@{ |
---|
292 | |
---|
293 | static const XSValue::DataGroup inGroup[]; |
---|
294 | static const bool numericSign[]; |
---|
295 | |
---|
296 | //@} |
---|
297 | |
---|
298 | static |
---|
299 | bool validateNumerics |
---|
300 | ( |
---|
301 | const XMLCh* const content |
---|
302 | , DataType datatype |
---|
303 | , Status& status |
---|
304 | , MemoryManager* const manager |
---|
305 | ); |
---|
306 | |
---|
307 | static |
---|
308 | bool validateDateTimes |
---|
309 | ( |
---|
310 | const XMLCh* const content |
---|
311 | , DataType datatype |
---|
312 | , Status& status |
---|
313 | , MemoryManager* const manager |
---|
314 | ); |
---|
315 | |
---|
316 | static |
---|
317 | bool validateStrings |
---|
318 | ( |
---|
319 | const XMLCh* const content |
---|
320 | , DataType datatype |
---|
321 | , Status& status |
---|
322 | , XMLVersion version |
---|
323 | , MemoryManager* const manager |
---|
324 | ); |
---|
325 | |
---|
326 | static |
---|
327 | XMLCh* getCanRepNumerics |
---|
328 | ( |
---|
329 | const XMLCh* const content |
---|
330 | , DataType datatype |
---|
331 | , Status& status |
---|
332 | , bool toValidate |
---|
333 | , MemoryManager* const manager |
---|
334 | ); |
---|
335 | |
---|
336 | static |
---|
337 | XMLCh* getCanRepDateTimes |
---|
338 | ( |
---|
339 | const XMLCh* const content |
---|
340 | , DataType datatype |
---|
341 | , Status& status |
---|
342 | , bool toValidate |
---|
343 | , MemoryManager* const manager |
---|
344 | ); |
---|
345 | |
---|
346 | static |
---|
347 | XMLCh* getCanRepStrings |
---|
348 | ( |
---|
349 | const XMLCh* const content |
---|
350 | , DataType datatype |
---|
351 | , Status& status |
---|
352 | , XMLVersion version |
---|
353 | , bool toValidate |
---|
354 | , MemoryManager* const manager |
---|
355 | ); |
---|
356 | |
---|
357 | static |
---|
358 | XSValue* getActValNumerics |
---|
359 | ( |
---|
360 | const XMLCh* const content |
---|
361 | , DataType datatype |
---|
362 | , Status& status |
---|
363 | , bool toValidate |
---|
364 | , MemoryManager* const manager |
---|
365 | ); |
---|
366 | |
---|
367 | static |
---|
368 | XSValue* getActValDateTimes |
---|
369 | ( |
---|
370 | const XMLCh* const content |
---|
371 | , DataType datatype |
---|
372 | , Status& status |
---|
373 | , MemoryManager* const manager |
---|
374 | ); |
---|
375 | |
---|
376 | static |
---|
377 | XSValue* getActValStrings |
---|
378 | ( |
---|
379 | const XMLCh* const content |
---|
380 | , DataType datatype |
---|
381 | , Status& status |
---|
382 | , XMLVersion version |
---|
383 | , bool toValidate |
---|
384 | , MemoryManager* const manager |
---|
385 | ); |
---|
386 | |
---|
387 | static |
---|
388 | bool getActualNumericValue |
---|
389 | ( |
---|
390 | const XMLCh* const content |
---|
391 | , Status& status |
---|
392 | , t_value& retVal |
---|
393 | , MemoryManager* const manager |
---|
394 | , DataType datatype |
---|
395 | ); |
---|
396 | |
---|
397 | static ValueHashTableOf<DataType>* fDataTypeRegistry; |
---|
398 | |
---|
399 | // ----------------------------------------------------------------------- |
---|
400 | // static helper methods |
---|
401 | // ----------------------------------------------------------------------- |
---|
402 | static void initializeRegistry(); |
---|
403 | friend class XMLInitializer; |
---|
404 | |
---|
405 | // ----------------------------------------------------------------------- |
---|
406 | // data members |
---|
407 | // ----------------------------------------------------------------------- |
---|
408 | bool fMemAllocated; |
---|
409 | MemoryManager* fMemoryManager; |
---|
410 | |
---|
411 | }; |
---|
412 | |
---|
413 | XERCES_CPP_NAMESPACE_END |
---|
414 | |
---|
415 | #endif |
---|