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