wsdlpull
1.23
Toggle main menu visibility
Loading...
Searching...
No Matches
src
schemaparser
SimpleType.cpp
Go to the documentation of this file.
1
/*
2
* wsdlpull - A C++ parser for WSDL (Web services description language)
3
* Copyright (C) 2005-2007 Vivek Krishna
4
*
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
14
*
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the Free
17
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*
19
*
20
*/
21
22
#include "
schemaparser/SimpleType.h
"
23
24
//TODO .Need to add checks for validating the occurence of consecutive facets_
25
namespace
Schema
{
26
27
SimpleType::SimpleType
(
const
std::string& ns)
28
:
XSDType
(ns),
29
isList_(false),
30
isUnion_(false),
31
uTypes_(0)
32
{
33
setContentModel
(
Schema::Simple
);
34
facetId_.clear();
35
36
validFacets_ =
new
int
[
XSD_ANYURI
+ 1];
37
38
//This table maintains a flag which indicates what facets_ are valid for a simple type
39
validFacets_[
XSD_STRING
] = validFacets_[
XSD_NMTOKEN
] = validFacets_[
XSD_NMTOKENS
] =
40
validFacets_[
XSD_TOKEN
] =
41
LENGTH
|
MINLEN
|
MAXLEN
|
ENUM
|
WSP
|
PATTERN
;
42
validFacets_[
XSD_INTEGER
] = validFacets_[
XSD_INT
] = validFacets_[
XSD_UINT
] =
43
validFacets_[
XSD_BYTE
] = validFacets_[
XSD_POSINT
] =
44
ENUM
|
WSP
|
MAXEX
|
MINEX
|
MAXINC
|
MININC
|
TOTALDIGITS
|
FRAC
|
45
PATTERN
;
46
validFacets_[
XSD_LONG
] = validFacets_[
XSD_ULONG
] = validFacets_[
XSD_DECIMAL
] =
47
validFacets_[
XSD_INT
];
48
validFacets_[
XSD_SHORT
] = validFacets_[
XSD_USHORT
] = validFacets_[
XSD_INT
];
49
validFacets_[
XSD_FLOAT
] = validFacets_[
XSD_DOUBLE
] =
50
ENUM
|
WSP
|
MAXEX
|
MINEX
|
MAXINC
|
MININC
|
PATTERN
;
51
validFacets_[
XSD_BOOLEAN
] =
WSP
|
PATTERN
;
52
validFacets_[
XSD_TIME
] = validFacets_[
XSD_DATETIME
] = validFacets_[
XSD_DATE
] =
53
ENUM
|
WSP
|
MAXEX
|
MINEX
|
MAXINC
|
MININC
|
PATTERN
;
54
validFacets_[
XSD_QNAME
] = validFacets_[
XSD_NCNAME
] = validFacets_[
XSD_ANYURI
] =
55
LENGTH
|
MINLEN
|
MAXLEN
|
ENUM
|
WSP
|
PATTERN
;
56
validFacets_[
XSD_ANY
] = validFacets_[
XSD_ANYTYPE
] =
NONE
|
PATTERN
;
57
validFacets_[
XSD_BASE64BIN
] = validFacets_[
XSD_STRING
];
58
59
//initialize the union??TODO
60
facetValue_.numEnums = 0;
61
62
facets_[
"length"
] =
LENGTH
;
63
facets_[
"minLength"
]=
MINLEN
;
64
facets_[
"maxLength"
]=
MAXLEN
;
65
facets_[
"enumeration"
]=
ENUM
;
66
facets_[
"whiteSpace"
]=
WSP
;
67
facets_[
"pattern"
]=
PATTERN
;
68
facets_[
"maxInclusive"
]=
MAXINC
;
69
facets_[
"maxExclusive"
]=
MAXEX
;
70
facets_[
"minInclusive"
]=
MININC
;
71
facets_[
"minExclusive"
]=
MINEX
;
72
facets_[
"totalDigits"
]=
TOTALDIGITS
;
73
facets_[
"fractionDigits"
]=
FRAC
;
74
}
75
76
SimpleType::~SimpleType
() {
77
delete
[] validFacets_;
78
}
79
80
//This function also sets the facet if valid
81
bool
82
SimpleType::isvalidFacet
(std::string facet)
83
{
84
if
(
getBaseTypeId
() == 0){
85
error(
"isValidFacet:Unknown base type"
);
86
return
false
;
87
}
88
int
facetType=facets_[facet];
89
if
(validFacets_[
getBaseTypeId
()] | facetType)
90
return
true
;
91
else
92
return
false
;
93
}
94
95
96
//TODO ..need to add checks to see which facets_ can appear together.
97
void
98
SimpleType::setFacetValue
(std::string facet,
99
std::string val)
100
{
101
int
num = -1;
102
int
facetType=facets_[facet];
103
switch
(facetType)
104
{
105
case
ENUM
:
106
facetValue_.numEnums++;
107
enumValues_.push_back(val);
108
break
;
109
case
PATTERN
:
110
facetValue_.pattern = (
const
char
*) val.c_str();
111
break
;
112
case
WSP
:
113
if
(val ==
"preserve"
)
114
facetValue_.wsp =
PRESERVE
;
115
116
else
if
(val ==
"collapse"
)
117
facetValue_.wsp =
COLLAPSE
;
118
119
else
if
(val ==
"replace"
)
120
facetValue_.wsp =
REPLACE
;
121
122
else
123
error(
"Invalid facet value for whitespace"
);
124
break
;
125
//all other facet values are numbers
126
default
:
127
num =
XmlUtils::parseInt
(val);
128
break
;
129
}
130
131
switch
(facetType)
132
{
133
case
MAXEX
:
134
facetValue_.valRange.maxex = num;
135
break
;
136
case
MAXINC
:
137
facetValue_.valRange.maxinc = num;
138
break
;
139
case
MININC
:
140
facetValue_.valRange.mininc = num;
141
break
;
142
case
MINEX
:
143
facetValue_.valRange.minex = num;
144
break
;
145
case
LENGTH
:
146
facetValue_.length = num;
147
break
;
148
case
MINLEN
:
149
facetValue_.lenRange.minlen = num;
150
break
;
151
case
MAXLEN
:
152
facetValue_.lenRange.maxlen = num;
153
break
;
154
case
TOTALDIGITS
:
155
facetValue_.tot = num;
156
break
;
157
case
FRAC
:
158
facetValue_.frac = num;
159
break
;
160
default
:
161
break
;
162
}
163
164
int
numFacets_=facetId_.size();
165
if
(!(numFacets_!=0 && (facetId_[numFacets_ - 1] ==
ENUM
)))
166
facetId_.push_back(facetType);
167
//In case of enum the new enum value does not define a new facet
168
}
169
170
171
bool
172
SimpleType::isValidInt
(
int
val)
const
173
{
174
if
(!(
getBaseTypeId
() ==
Schema::XSD_INT
||
175
getBaseTypeId
() ==
Schema::XSD_INTEGER
))
176
return
false
;
177
int
numdigits = 1, tmp = val;
178
bool
valid =
true
;
179
while
((tmp = tmp / 10))
180
numdigits++;
181
for
(
size_t
i = 0; i < facetId_.size() && valid; i++)
182
{
183
switch
(facetId_[i])
184
{
185
case
MAXEX
:
186
if
(val < facetValue_.valRange.maxex)
187
valid =
true
;
188
else
189
valid =
false
;
190
break
;
191
case
MAXINC
:
192
if
(val <= facetValue_.valRange.maxinc)
193
valid =
true
;
194
195
else
196
valid =
false
;
197
break
;
198
case
MININC
:
199
if
(val >= facetValue_.valRange.mininc)
200
valid =
true
;
201
202
else
203
valid =
false
;
204
break
;
205
case
MINEX
:
206
if
(val > facetValue_.valRange.minex)
207
valid =
true
;
208
209
else
210
valid =
false
;
211
break
;
212
case
LENGTH
:
213
if
(numdigits == facetValue_.length)
214
valid =
true
;
215
216
else
217
valid =
false
;
218
break
;
219
case
MINLEN
:
220
if
(numdigits >= facetValue_.lenRange.minlen)
221
valid =
true
;
222
223
else
224
valid =
false
;
225
break
;
226
case
MAXLEN
:
227
if
(numdigits <= facetValue_.lenRange.maxlen)
228
valid =
true
;
229
230
else
231
valid =
false
;
232
break
;
233
default
:
234
valid =
false
;
235
}
236
}
237
return
valid;
238
}
239
240
241
bool
242
SimpleType::isValidFloat
(
float
val)
const
243
{
244
245
//TODO
246
return
true
;
247
}
248
249
250
bool
251
SimpleType::isValidString
(std::string val)
const
252
{
253
int
strlen = val.length();
254
bool
valid =
true
;
255
std::list < std::string >::const_iterator pEnums;
256
for
(
size_t
i = 0; i < facetId_.size(); i++)
257
{
258
switch
(facetId_[i])
259
{
260
case
LENGTH
:
261
if
(strlen == facetValue_.length)
262
valid =
true
;
263
264
else
265
valid =
false
;
266
break
;
267
case
MINLEN
:
268
if
(strlen >= facetValue_.lenRange.minlen)
269
valid =
true
;
270
271
else
272
valid =
false
;
273
break
;
274
case
MAXLEN
:
275
if
(strlen <= facetValue_.lenRange.maxlen)
276
valid =
true
;
277
278
else
279
valid =
false
;
280
break
;
281
case
ENUM
:
282
{
283
valid=
false
;
284
for
(pEnums = enumValues_.begin();
285
pEnums != enumValues_.end();
286
pEnums++){
287
288
if
(*pEnums == val)
289
valid =
true
;
290
}
291
break
;
292
}
293
case
PATTERN
:
294
valid =
true
;
//TODO
295
break
;
296
default
:
297
valid =
true
;
298
}
299
}
300
return
valid;
301
}
302
303
304
/*This function returns the facet values of the requested facet type
305
if the type is restricted by it.
306
For enum it returns(via val*) a ptr to std::list<std::string>.
307
For all other facets_ related to length,its returns(via val*) an int pointer
308
For inclusive and exclusive facets it returns (via val*) ptr to the value
309
for example
310
int * minex=0;
311
simpleType.getFacetValue(SimpleType::MAXINC,minex);
312
*/
313
314
//TODO add cases to return pointers to other facet values
315
bool
316
SimpleType::getFacetValue
(
int
facet,
void
*& val)
317
{
318
val = 0;
319
bool
isFacetPresent =
false
;
320
for
(
size_t
i = 0;
321
i < facetId_.size() && !isFacetPresent;
322
i++)
323
isFacetPresent = (facetId_[i] == facet);
324
325
if
(!isFacetPresent)
326
return
false
;
327
switch
(facet)
328
{
329
case
ENUM
:
330
val = (
void
*) &(enumValues_);
331
return
true
;
332
break
;
333
case
MAXINC
:
334
val = &(facetValue_.valRange.maxinc);
335
return
true
;
336
break
;
337
case
MAXEX
:
338
val = (
void
*) &(facetValue_.valRange.maxex);
339
return
true
;
340
break
;
341
case
MININC
:
342
val = (
void
*) &(facetValue_.valRange.mininc);
343
return
true
;
344
break
;
345
case
MINEX
:
346
val = (
void
*) &(facetValue_.valRange.minex);
347
return
true
;
348
break
;
349
case
LENGTH
:
350
val = (
void
*) &(facetValue_.length);
351
return
true
;
352
break
;
353
case
MINLEN
:
354
val = (
void
*) &(facetValue_.lenRange.minlen);
355
return
true
;
356
break
;
357
case
MAXLEN
:
358
val = (
void
*) &(facetValue_.lenRange.minlen);
359
return
true
;
360
break
;
361
case
PATTERN
:
362
val = (
void
*) &(facetValue_.pattern);
363
return
true
;
364
break
;
365
case
TOTALDIGITS
:
366
val = (
void
*) &(facetValue_.tot);
367
return
true
;
368
break
;
369
case
FRAC
:
370
371
default
:
372
val = 0;
373
return
false
;
374
}
375
}
376
377
378
void
SimpleType::error(std::string msg)
379
{
380
msg +=
"SimpleType::error()"
;
381
SchemaParserException
spe(msg);
382
throw
spe;
383
return
;
384
}
385
}
SimpleType.h
Schema::SchemaParserException
Definition
SchemaParserException.h:29
Schema::SimpleType::~SimpleType
~SimpleType()
Definition
SimpleType.cpp:76
Schema::SimpleType::setFacetValue
void setFacetValue(std::string facet, std::string val)
Definition
SimpleType.cpp:98
Schema::SimpleType::SimpleType
SimpleType(const std::string &ns)
Definition
SimpleType.cpp:27
Schema::SimpleType::isValidFloat
bool isValidFloat(float val) const
Definition
SimpleType.cpp:242
Schema::SimpleType::isValidInt
bool isValidInt(int val) const
Definition
SimpleType.cpp:172
Schema::SimpleType::isValidString
bool isValidString(std::string val) const
Definition
SimpleType.cpp:251
Schema::SimpleType::MAXLEN
@ MAXLEN
Definition
SimpleType.h:105
Schema::SimpleType::MINLEN
@ MINLEN
Definition
SimpleType.h:104
Schema::SimpleType::NONE
@ NONE
Definition
SimpleType.h:102
Schema::SimpleType::WSP
@ WSP
Definition
SimpleType.h:107
Schema::SimpleType::MININC
@ MININC
Definition
SimpleType.h:109
Schema::SimpleType::LENGTH
@ LENGTH
Definition
SimpleType.h:103
Schema::SimpleType::MAXINC
@ MAXINC
Definition
SimpleType.h:108
Schema::SimpleType::FRAC
@ FRAC
Definition
SimpleType.h:113
Schema::SimpleType::MINEX
@ MINEX
Definition
SimpleType.h:111
Schema::SimpleType::PATTERN
@ PATTERN
Definition
SimpleType.h:114
Schema::SimpleType::ENUM
@ ENUM
Definition
SimpleType.h:106
Schema::SimpleType::TOTALDIGITS
@ TOTALDIGITS
Definition
SimpleType.h:112
Schema::SimpleType::MAXEX
@ MAXEX
Definition
SimpleType.h:110
Schema::SimpleType::isvalidFacet
bool isvalidFacet(std::string facet)
Definition
SimpleType.cpp:82
Schema::SimpleType::getFacetValue
bool getFacetValue(int facet, void *&val)
Definition
SimpleType.cpp:316
Schema::SimpleType::PRESERVE
@ PRESERVE
Definition
SimpleType.h:120
Schema::SimpleType::COLLAPSE
@ COLLAPSE
Definition
SimpleType.h:122
Schema::SimpleType::REPLACE
@ REPLACE
Definition
SimpleType.h:121
Schema::XSDType::XSDType
XSDType(const std::string &ns)
Definition
XSDType.h:125
Schema::XSDType::getBaseTypeId
int getBaseTypeId() const
Definition
XSDType.h:185
Schema::XSDType::setContentModel
virtual void setContentModel(Schema::ContentModelType)
Definition
XSDType.h:229
Schema
Definition
Annotation.h:27
Schema::Simple
@ Simple
Definition
Schema.h:46
Schema::XSD_POSINT
@ XSD_POSINT
Definition
Schema.h:67
Schema::XSD_NCNAME
@ XSD_NCNAME
Definition
Schema.h:82
Schema::XSD_UINT
@ XSD_UINT
Definition
Schema.h:68
Schema::XSD_NMTOKENS
@ XSD_NMTOKENS
Definition
Schema.h:84
Schema::XSD_ANYTYPE
@ XSD_ANYTYPE
Definition
Schema.h:88
Schema::XSD_USHORT
@ XSD_USHORT
Definition
Schema.h:72
Schema::XSD_DOUBLE
@ XSD_DOUBLE
Definition
Schema.h:75
Schema::XSD_LONG
@ XSD_LONG
Definition
Schema.h:69
Schema::XSD_BASE64BIN
@ XSD_BASE64BIN
Definition
Schema.h:85
Schema::XSD_NMTOKEN
@ XSD_NMTOKEN
Definition
Schema.h:83
Schema::XSD_QNAME
@ XSD_QNAME
Definition
Schema.h:81
Schema::XSD_TOKEN
@ XSD_TOKEN
Definition
Schema.h:80
Schema::XSD_SHORT
@ XSD_SHORT
Definition
Schema.h:71
Schema::XSD_DATETIME
@ XSD_DATETIME
Definition
Schema.h:78
Schema::XSD_TIME
@ XSD_TIME
Definition
Schema.h:77
Schema::XSD_FLOAT
@ XSD_FLOAT
Definition
Schema.h:74
Schema::XSD_DECIMAL
@ XSD_DECIMAL
Definition
Schema.h:73
Schema::XSD_BYTE
@ XSD_BYTE
Definition
Schema.h:66
Schema::XSD_ULONG
@ XSD_ULONG
Definition
Schema.h:70
Schema::XSD_INTEGER
@ XSD_INTEGER
Definition
Schema.h:64
Schema::XSD_INT
@ XSD_INT
Definition
Schema.h:65
Schema::XSD_STRING
@ XSD_STRING
Definition
Schema.h:63
Schema::XSD_DATE
@ XSD_DATE
Definition
Schema.h:79
Schema::XSD_BOOLEAN
@ XSD_BOOLEAN
Definition
Schema.h:76
Schema::XSD_ANY
@ XSD_ANY
Definition
Schema.h:87
Schema::XSD_ANYURI
@ XSD_ANYURI
Definition
Schema.h:89
XmlUtils::parseInt
int parseInt(std::string s, int radix=10)
Definition
XmlUtils.cpp:57
Generated by
1.17.0