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: SCMPrint.cpp,v $
|
---|
19 | * Revision 1.5 2004/09/28 04:42:21 cargilld
|
---|
20 | * Update sample to use an error handler and only generate xsmodel when a schema document has been loaded successfully.
|
---|
21 | *
|
---|
22 | * Revision 1.4 2004/09/08 13:55:34 peiyongz
|
---|
23 | * Apache License Version 2.0
|
---|
24 | *
|
---|
25 | * Revision 1.3 2004/09/02 14:59:29 cargilld
|
---|
26 | * Add OutOfMemoryException block to samples.
|
---|
27 | *
|
---|
28 | * Revision 1.2 2004/02/12 13:58:58 cargilld
|
---|
29 | * Fix build errors.
|
---|
30 | *
|
---|
31 | * Revision 1.1 2004/02/11 20:53:05 peiyongz
|
---|
32 | * SCMPrint
|
---|
33 | *
|
---|
34 | */
|
---|
35 |
|
---|
36 | // ---------------------------------------------------------------------------
|
---|
37 | // Includes
|
---|
38 | // ---------------------------------------------------------------------------
|
---|
39 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
40 | #include <xercesc/sax2/SAX2XMLReader.hpp>
|
---|
41 | #include <xercesc/sax2/XMLReaderFactory.hpp>
|
---|
42 | #include <xercesc/internal/XMLGrammarPoolImpl.hpp>
|
---|
43 | #include <xercesc/framework/psvi/XSModel.hpp>
|
---|
44 | #include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
---|
45 | #include <xercesc/framework/psvi/XSTypeDefinition.hpp>
|
---|
46 | #include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
---|
47 | #include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
---|
48 | #include <xercesc/framework/psvi/XSParticle.hpp>
|
---|
49 | #include <xercesc/framework/psvi/XSModelGroup.hpp>
|
---|
50 | #if defined(XERCES_NEW_IOSTREAMS)
|
---|
51 | #include <iostream>
|
---|
52 | #include <fstream>
|
---|
53 | #else
|
---|
54 | #include <iostream.h>
|
---|
55 | #include <fstream.h>
|
---|
56 | #endif
|
---|
57 | #include <stdlib.h>
|
---|
58 | #include <string.h>
|
---|
59 | #include <xercesc/util/OutOfMemoryException.hpp>
|
---|
60 | #include <xercesc/sax2/DefaultHandler.hpp>
|
---|
61 |
|
---|
62 | XERCES_CPP_NAMESPACE_USE
|
---|
63 |
|
---|
64 | // ---------------------------------------------------------------------------
|
---|
65 | // Forward references
|
---|
66 | // ---------------------------------------------------------------------------
|
---|
67 | static void usage();
|
---|
68 |
|
---|
69 | void processElements(XSNamedMap<XSObject> *xsElements);
|
---|
70 | void processTypeDefinitions(XSNamedMap<XSObject> *xsTypeDefs);
|
---|
71 | void printBasic(XSObject *xsObject, const char *type);
|
---|
72 | void printCompositorTypeConnector(XSModelGroup::COMPOSITOR_TYPE type);
|
---|
73 | void processSimpleTypeDefinition(XSSimpleTypeDefinition * xsSimpleTypeDef);
|
---|
74 | void processComplexTypeDefinition(XSComplexTypeDefinition *xsComplexTypeDef);
|
---|
75 | void processParticle(XSParticle *xsParticle);
|
---|
76 |
|
---|
77 | // ---------------------------------------------------------------------------
|
---|
78 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
79 | // trancoding of XMLCh data to local code page for display.
|
---|
80 | // ---------------------------------------------------------------------------
|
---|
81 | class StrX
|
---|
82 | {
|
---|
83 | public :
|
---|
84 | // -----------------------------------------------------------------------
|
---|
85 | // Constructors and Destructor
|
---|
86 | // -----------------------------------------------------------------------
|
---|
87 | StrX(const XMLCh* const toTranscode)
|
---|
88 | {
|
---|
89 | // Call the private transcoding method
|
---|
90 | fLocalForm = XMLString::transcode(toTranscode);
|
---|
91 | }
|
---|
92 |
|
---|
93 | ~StrX()
|
---|
94 | {
|
---|
95 | XMLString::release(&fLocalForm);
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | // -----------------------------------------------------------------------
|
---|
100 | // Getter methods
|
---|
101 | // -----------------------------------------------------------------------
|
---|
102 | const char* localForm() const
|
---|
103 | {
|
---|
104 | return fLocalForm;
|
---|
105 | }
|
---|
106 |
|
---|
107 | private :
|
---|
108 | // -----------------------------------------------------------------------
|
---|
109 | // Private data members
|
---|
110 | //
|
---|
111 | // fLocalForm
|
---|
112 | // This is the local code page form of the string.
|
---|
113 | // -----------------------------------------------------------------------
|
---|
114 | char* fLocalForm;
|
---|
115 | };
|
---|
116 |
|
---|
117 | inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
118 | {
|
---|
119 | target << toDump.localForm();
|
---|
120 | return target;
|
---|
121 | }
|
---|
122 |
|
---|
123 | class SCMPrintHandler : public DefaultHandler
|
---|
124 | {
|
---|
125 | public:
|
---|
126 | // -----------------------------------------------------------------------
|
---|
127 | // Constructors and Destructor
|
---|
128 | // -----------------------------------------------------------------------
|
---|
129 | SCMPrintHandler();
|
---|
130 | ~SCMPrintHandler();
|
---|
131 |
|
---|
132 | bool getSawErrors() const
|
---|
133 | {
|
---|
134 | return fSawErrors;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void warning(const SAXParseException& exc);
|
---|
138 | void error(const SAXParseException& exc);
|
---|
139 | void fatalError(const SAXParseException& exc);
|
---|
140 | void resetErrors();
|
---|
141 |
|
---|
142 |
|
---|
143 | private:
|
---|
144 | bool fSawErrors;
|
---|
145 | };
|
---|
146 |
|
---|
147 | SCMPrintHandler::SCMPrintHandler() :
|
---|
148 | fSawErrors(false)
|
---|
149 | {
|
---|
150 | }
|
---|
151 |
|
---|
152 | SCMPrintHandler::~SCMPrintHandler()
|
---|
153 | {
|
---|
154 | }
|
---|
155 |
|
---|
156 | // ---------------------------------------------------------------------------
|
---|
157 | // SCMPrintHandler: Overrides of the SAX ErrorHandler interface
|
---|
158 | // ---------------------------------------------------------------------------
|
---|
159 | void SCMPrintHandler::error(const SAXParseException& e)
|
---|
160 | {
|
---|
161 | fSawErrors = true;
|
---|
162 | XERCES_STD_QUALIFIER cerr << "\nError at file " << StrX(e.getSystemId())
|
---|
163 | << ", line " << e.getLineNumber()
|
---|
164 | << ", char " << e.getColumnNumber()
|
---|
165 | << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
166 | }
|
---|
167 |
|
---|
168 | void SCMPrintHandler::fatalError(const SAXParseException& e)
|
---|
169 | {
|
---|
170 | fSawErrors = true;
|
---|
171 | XERCES_STD_QUALIFIER cerr << "\nFatal Error at file " << StrX(e.getSystemId())
|
---|
172 | << ", line " << e.getLineNumber()
|
---|
173 | << ", char " << e.getColumnNumber()
|
---|
174 | << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
175 | }
|
---|
176 |
|
---|
177 | void SCMPrintHandler::warning(const SAXParseException& e)
|
---|
178 | {
|
---|
179 | XERCES_STD_QUALIFIER cerr << "\nWarning at file " << StrX(e.getSystemId())
|
---|
180 | << ", line " << e.getLineNumber()
|
---|
181 | << ", char " << e.getColumnNumber()
|
---|
182 | << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
183 | }
|
---|
184 |
|
---|
185 | void SCMPrintHandler::resetErrors()
|
---|
186 | {
|
---|
187 | fSawErrors = false;
|
---|
188 | }
|
---|
189 |
|
---|
190 | // ---------------------------------------------------------------------------
|
---|
191 | // Local helper methods
|
---|
192 | // ---------------------------------------------------------------------------
|
---|
193 | static void usage()
|
---|
194 | {
|
---|
195 | XERCES_STD_QUALIFIER cout << "\nUsage:\n"
|
---|
196 | " SCMPrint [options] <XSD file | List file>\n\n"
|
---|
197 | "This program parses XML Schema file(s), to show how one can\n"
|
---|
198 | "access the Schema Content Model information.\n\n"
|
---|
199 | "Options:\n"
|
---|
200 | " -f Enable full schema constraint checking processing. Defaults to off.\n"
|
---|
201 | " -l Indicate the input file is a List File that has a list of XSD files.\n"
|
---|
202 | " Default to off (Input file is a XSD file).\n"
|
---|
203 | " -? Show this help.\n\n"
|
---|
204 | << XERCES_STD_QUALIFIER endl;
|
---|
205 | }
|
---|
206 |
|
---|
207 | // ---------------------------------------------------------------------------
|
---|
208 | // Program entry point
|
---|
209 | // ---------------------------------------------------------------------------
|
---|
210 | int main(int argC, char* argV[])
|
---|
211 | {
|
---|
212 | // Check command line and extract arguments.
|
---|
213 | if (argC < 2)
|
---|
214 | {
|
---|
215 | usage();
|
---|
216 | return 1;
|
---|
217 | }
|
---|
218 |
|
---|
219 | // cannot return out of catch-blocks lest exception-destruction
|
---|
220 | // result in calls to destroyed memory handler!
|
---|
221 | int errorCode = 0;
|
---|
222 | try
|
---|
223 | {
|
---|
224 | XMLPlatformUtils::Initialize();
|
---|
225 | }
|
---|
226 |
|
---|
227 | catch (const XMLException& toCatch)
|
---|
228 | {
|
---|
229 | XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
---|
230 | << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
231 | errorCode = 2;
|
---|
232 | }
|
---|
233 | if(errorCode) {
|
---|
234 | XMLPlatformUtils::Terminate();
|
---|
235 | return errorCode;
|
---|
236 | }
|
---|
237 |
|
---|
238 | bool doList = false;
|
---|
239 | bool schemaFullChecking = false;
|
---|
240 | const char* xsdFile = 0;
|
---|
241 | int argInd;
|
---|
242 |
|
---|
243 | for (argInd = 1; argInd < argC; argInd++)
|
---|
244 | {
|
---|
245 | // Break out on first parm not starting with a dash
|
---|
246 | if (argV[argInd][0] != '-')
|
---|
247 | break;
|
---|
248 |
|
---|
249 | // Watch for special case help request
|
---|
250 | if (!strcmp(argV[argInd], "-?"))
|
---|
251 | {
|
---|
252 | usage();
|
---|
253 | return 1;
|
---|
254 | }
|
---|
255 | else if (!strcmp(argV[argInd], "-l")
|
---|
256 | || !strcmp(argV[argInd], "-L"))
|
---|
257 | {
|
---|
258 | doList = true;
|
---|
259 | }
|
---|
260 | else if (!strcmp(argV[argInd], "-f")
|
---|
261 | || !strcmp(argV[argInd], "-F"))
|
---|
262 | {
|
---|
263 | schemaFullChecking = true;
|
---|
264 | }
|
---|
265 | else
|
---|
266 | {
|
---|
267 | XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
|
---|
268 | << "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | //
|
---|
273 | // There should be only one and only one parameter left, and that
|
---|
274 | // should be the file name.
|
---|
275 | //
|
---|
276 | if (argInd != argC - 1)
|
---|
277 | {
|
---|
278 | usage();
|
---|
279 | return 1;
|
---|
280 | }
|
---|
281 |
|
---|
282 | try
|
---|
283 | {
|
---|
284 | XMLGrammarPool *grammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
|
---|
285 |
|
---|
286 | SAX2XMLReaderImpl* parser = new SAX2XMLReaderImpl(XMLPlatformUtils::fgMemoryManager, grammarPool);
|
---|
287 | parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
|
---|
288 | parser->setFeature(XMLUni::fgXercesSchema, true);
|
---|
289 | parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
|
---|
290 | parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
|
---|
291 | parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
|
---|
292 | parser->setFeature(XMLUni::fgXercesDynamic, true);
|
---|
293 | parser->setProperty(XMLUni::fgXercesScannerName, (void *)XMLUni::fgSGXMLScanner);
|
---|
294 |
|
---|
295 | SCMPrintHandler handler;
|
---|
296 | parser->setErrorHandler(&handler);
|
---|
297 |
|
---|
298 | bool more = true;
|
---|
299 | bool parsedOneSchemaOkay = false;
|
---|
300 | XERCES_STD_QUALIFIER ifstream fin;
|
---|
301 |
|
---|
302 | // the input is a list file
|
---|
303 | if (doList)
|
---|
304 | fin.open(argV[argInd]);
|
---|
305 |
|
---|
306 | if (fin.fail()) {
|
---|
307 | XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
|
---|
308 | return 3;
|
---|
309 | }
|
---|
310 |
|
---|
311 | while (more)
|
---|
312 | {
|
---|
313 | char fURI[1000];
|
---|
314 | //initialize the array to zeros
|
---|
315 | memset(fURI,0,sizeof(fURI));
|
---|
316 |
|
---|
317 | if (doList) {
|
---|
318 | if (! fin.eof() ) {
|
---|
319 | fin.getline (fURI, sizeof(fURI));
|
---|
320 | if (!*fURI)
|
---|
321 | continue;
|
---|
322 | else {
|
---|
323 | xsdFile = fURI;
|
---|
324 | XERCES_STD_QUALIFIER cerr << "==Parsing== " << xsdFile << XERCES_STD_QUALIFIER endl;
|
---|
325 | }
|
---|
326 | }
|
---|
327 | else
|
---|
328 | break;
|
---|
329 | }
|
---|
330 | else {
|
---|
331 | xsdFile = argV[argInd];
|
---|
332 | more = false;
|
---|
333 | }
|
---|
334 |
|
---|
335 | parser->loadGrammar(xsdFile, Grammar::SchemaGrammarType, true);
|
---|
336 | if (handler.getSawErrors())
|
---|
337 | {
|
---|
338 | handler.resetErrors();
|
---|
339 | }
|
---|
340 | else
|
---|
341 | {
|
---|
342 | parsedOneSchemaOkay = true;
|
---|
343 | }
|
---|
344 | }
|
---|
345 |
|
---|
346 | if (parsedOneSchemaOkay)
|
---|
347 | {
|
---|
348 | XERCES_STD_QUALIFIER cout << "********** Printing out information from Schema **********" << "\n\n";
|
---|
349 |
|
---|
350 | XSModel *xsModel = grammarPool->getXSModel();
|
---|
351 | if (xsModel)
|
---|
352 | {
|
---|
353 | StringList *namespaces = xsModel->getNamespaces();
|
---|
354 | for (unsigned i = 0; i < namespaces->size(); i++) {
|
---|
355 |
|
---|
356 | XERCES_STD_QUALIFIER cout << "Processing Namespace: ";
|
---|
357 | const XMLCh *nameSpace = namespaces->elementAt(i);
|
---|
358 | if (nameSpace && (XMLString::stringLen(nameSpace)>0))
|
---|
359 | XERCES_STD_QUALIFIER cout << StrX(nameSpace);
|
---|
360 | XERCES_STD_QUALIFIER cout << "\n============================================" << XERCES_STD_QUALIFIER endl << XERCES_STD_QUALIFIER endl;
|
---|
361 |
|
---|
362 | processElements(xsModel->getComponentsByNamespace(XSConstants::ELEMENT_DECLARATION,
|
---|
363 | nameSpace));
|
---|
364 | processTypeDefinitions(xsModel->getComponentsByNamespace(XSConstants::TYPE_DEFINITION,
|
---|
365 | nameSpace));
|
---|
366 | }
|
---|
367 | }
|
---|
368 | else
|
---|
369 | {
|
---|
370 | XERCES_STD_QUALIFIER cout << "No XSModel to print" << "\n\n";
|
---|
371 | }
|
---|
372 | }
|
---|
373 | else
|
---|
374 | {
|
---|
375 | XERCES_STD_QUALIFIER cout << "Did not parse a schema document cleanly so not printing Schema for Schema XSModel information";
|
---|
376 | }
|
---|
377 |
|
---|
378 | XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
---|
379 | }
|
---|
380 | catch (const OutOfMemoryException&)
|
---|
381 | {
|
---|
382 | XERCES_STD_QUALIFIER cerr << "OutOfMemoryException during parsing: '" << xsdFile << "'\n" << XERCES_STD_QUALIFIER endl;
|
---|
383 | errorCode = 6;
|
---|
384 | }
|
---|
385 | catch (const XMLException& e)
|
---|
386 | {
|
---|
387 | XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xsdFile << "'\n"
|
---|
388 | << "Exception message is: \n"
|
---|
389 | << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
390 | errorCode = 4;
|
---|
391 | }
|
---|
392 | catch (...)
|
---|
393 | {
|
---|
394 | XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << xsdFile << "'\n" << XERCES_STD_QUALIFIER endl;
|
---|
395 | errorCode = 5;
|
---|
396 | }
|
---|
397 |
|
---|
398 | XMLPlatformUtils::Terminate();
|
---|
399 |
|
---|
400 | return errorCode;
|
---|
401 | }
|
---|
402 |
|
---|
403 | void printBasic(XSObject *xsObject, const char *type)
|
---|
404 | {
|
---|
405 | XERCES_STD_QUALIFIER cout << "Name:\t\t\t";
|
---|
406 | const XMLCh *nameSpace = xsObject->getNamespace();
|
---|
407 | if (nameSpace && (XMLString::stringLen(nameSpace)>0)) {
|
---|
408 | XERCES_STD_QUALIFIER cout << StrX(nameSpace) << ", ";
|
---|
409 | }
|
---|
410 | XERCES_STD_QUALIFIER cout << StrX(xsObject->getName()) << "\n";
|
---|
411 | XERCES_STD_QUALIFIER cout << "Component Type:\t" << type << XERCES_STD_QUALIFIER endl;
|
---|
412 | }
|
---|
413 |
|
---|
414 | void processElements(XSNamedMap<XSObject> *xsElements)
|
---|
415 | {
|
---|
416 | if (!xsElements || xsElements->getLength() == 0) {
|
---|
417 | XERCES_STD_QUALIFIER cout << "no elements\n\n" << XERCES_STD_QUALIFIER endl;
|
---|
418 | return;
|
---|
419 | }
|
---|
420 | for (unsigned i=0; i < xsElements->getLength(); i++) {
|
---|
421 | XSElementDeclaration *xsElement = (XSElementDeclaration *)xsElements->item(i);
|
---|
422 | printBasic(xsElement, "Element");
|
---|
423 |
|
---|
424 | // Content Model
|
---|
425 | XSTypeDefinition *xsTypeDef = xsElement->getTypeDefinition();
|
---|
426 | XERCES_STD_QUALIFIER cout << "Content Model" << "\n";
|
---|
427 | XERCES_STD_QUALIFIER cout << "\tType:\t";
|
---|
428 | if (xsTypeDef->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE) {
|
---|
429 | XERCES_STD_QUALIFIER cout << "Simple\n";
|
---|
430 | } else {
|
---|
431 | XERCES_STD_QUALIFIER cout << "Complex\n";
|
---|
432 | }
|
---|
433 | XERCES_STD_QUALIFIER cout << "\tName:\t"
|
---|
434 | << StrX(xsTypeDef->getName()) << "\n";
|
---|
435 |
|
---|
436 | XERCES_STD_QUALIFIER cout << "\n--------------------------------------------" << XERCES_STD_QUALIFIER endl;
|
---|
437 | }
|
---|
438 | }
|
---|
439 |
|
---|
440 | void processSimpleTypeDefinition(XSSimpleTypeDefinition * xsSimpleTypeDef)
|
---|
441 | {
|
---|
442 | XSTypeDefinition *xsBaseTypeDef = xsSimpleTypeDef->getBaseType();
|
---|
443 | XERCES_STD_QUALIFIER cout << "Base:\t\t\t";
|
---|
444 | XERCES_STD_QUALIFIER cout << StrX(xsBaseTypeDef->getName()) << XERCES_STD_QUALIFIER endl;
|
---|
445 |
|
---|
446 | int facets = xsSimpleTypeDef->getDefinedFacets();
|
---|
447 | if (facets) {
|
---|
448 | XERCES_STD_QUALIFIER cout << "Facets:\n";
|
---|
449 |
|
---|
450 | if (facets & XSSimpleTypeDefinition::FACET_LENGTH)
|
---|
451 | XERCES_STD_QUALIFIER cout << "\tLength:\t\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_LENGTH)) << XERCES_STD_QUALIFIER endl;
|
---|
452 | if (facets & XSSimpleTypeDefinition::FACET_MINLENGTH)
|
---|
453 | XERCES_STD_QUALIFIER cout << "\tMinLength:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MINLENGTH)) << XERCES_STD_QUALIFIER endl;
|
---|
454 | if (facets & XSSimpleTypeDefinition::FACET_MAXLENGTH)
|
---|
455 | XERCES_STD_QUALIFIER cout << "\tMaxLength:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MAXLENGTH)) << XERCES_STD_QUALIFIER endl;
|
---|
456 | if (facets & XSSimpleTypeDefinition::FACET_PATTERN) {
|
---|
457 | StringList *lexicalPatterns = xsSimpleTypeDef->getLexicalPattern();
|
---|
458 | if (lexicalPatterns && lexicalPatterns->size()) {
|
---|
459 | XERCES_STD_QUALIFIER cout << "\tPattern:\t\t";
|
---|
460 | for (unsigned i = 0; i < lexicalPatterns->size(); i++) {
|
---|
461 | XERCES_STD_QUALIFIER cout << StrX(lexicalPatterns->elementAt(i));
|
---|
462 | }
|
---|
463 | XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
---|
464 | }
|
---|
465 | }
|
---|
466 | if (facets & XSSimpleTypeDefinition::FACET_WHITESPACE)
|
---|
467 | XERCES_STD_QUALIFIER cout << "\tWhitespace:\t\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_WHITESPACE)) << XERCES_STD_QUALIFIER endl;
|
---|
468 | if (facets & XSSimpleTypeDefinition::FACET_MAXINCLUSIVE)
|
---|
469 | XERCES_STD_QUALIFIER cout << "\tMaxInclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MAXINCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
---|
470 | if (facets & XSSimpleTypeDefinition::FACET_MAXEXCLUSIVE)
|
---|
471 | XERCES_STD_QUALIFIER cout << "\tMaxExclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MAXEXCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
---|
472 | if (facets & XSSimpleTypeDefinition::FACET_MINEXCLUSIVE)
|
---|
473 | XERCES_STD_QUALIFIER cout << "\tMinExclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MINEXCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
---|
474 | if (facets & XSSimpleTypeDefinition::FACET_MININCLUSIVE)
|
---|
475 | XERCES_STD_QUALIFIER cout << "\tMinInclusive:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_MININCLUSIVE)) << XERCES_STD_QUALIFIER endl;
|
---|
476 | if (facets & XSSimpleTypeDefinition::FACET_TOTALDIGITS)
|
---|
477 | XERCES_STD_QUALIFIER cout << "\tTotalDigits:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_TOTALDIGITS)) << XERCES_STD_QUALIFIER endl;
|
---|
478 | if (facets & XSSimpleTypeDefinition::FACET_FRACTIONDIGITS)
|
---|
479 | XERCES_STD_QUALIFIER cout << "\tFractionDigits:\t" << StrX(xsSimpleTypeDef->getLexicalFacetValue(XSSimpleTypeDefinition::FACET_FRACTIONDIGITS)) << XERCES_STD_QUALIFIER endl;
|
---|
480 | if (facets & XSSimpleTypeDefinition::FACET_ENUMERATION) {
|
---|
481 | StringList *lexicalEnums = xsSimpleTypeDef->getLexicalEnumeration();
|
---|
482 | if (lexicalEnums && lexicalEnums->size()) {
|
---|
483 | XERCES_STD_QUALIFIER cout << "\tEnumeration:\n";
|
---|
484 | for (unsigned i = 0; i < lexicalEnums->size(); i++) {
|
---|
485 | XERCES_STD_QUALIFIER cout << "\t\t\t" << StrX(lexicalEnums->elementAt(i)) << "\n";
|
---|
486 | }
|
---|
487 | XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
---|
488 | }
|
---|
489 | }
|
---|
490 | }
|
---|
491 | }
|
---|
492 |
|
---|
493 | void printCompositorTypeConnector(XSModelGroup::COMPOSITOR_TYPE type)
|
---|
494 | {
|
---|
495 | switch (type) {
|
---|
496 | case XSModelGroup::COMPOSITOR_SEQUENCE :
|
---|
497 | XERCES_STD_QUALIFIER cout << ",";
|
---|
498 | break;
|
---|
499 | case XSModelGroup::COMPOSITOR_CHOICE :
|
---|
500 | XERCES_STD_QUALIFIER cout << "|";
|
---|
501 | break;
|
---|
502 | case XSModelGroup::COMPOSITOR_ALL :
|
---|
503 | XERCES_STD_QUALIFIER cout << "*";
|
---|
504 | break;
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 | void processParticle(XSParticle *xsParticle)
|
---|
509 | {
|
---|
510 | XSParticle::TERM_TYPE termType = xsParticle->getTermType();
|
---|
511 | if (termType == XSParticle::TERM_ELEMENT) {
|
---|
512 | XSElementDeclaration *xsElement = xsParticle->getElementTerm();
|
---|
513 | XERCES_STD_QUALIFIER cout << StrX(xsElement->getName());
|
---|
514 | } else if (termType == XSParticle::TERM_MODELGROUP) {
|
---|
515 | XERCES_STD_QUALIFIER cout << "(";
|
---|
516 |
|
---|
517 | XSModelGroup *xsModelGroup = xsParticle->getModelGroupTerm();
|
---|
518 | XSModelGroup::COMPOSITOR_TYPE compositorType = xsModelGroup->getCompositor();
|
---|
519 | XSParticleList *xsParticleList = xsModelGroup->getParticles();
|
---|
520 | for (unsigned i = 0; i < xsParticleList->size()-1; i++) {
|
---|
521 | processParticle(xsParticleList->elementAt(i));
|
---|
522 | printCompositorTypeConnector(compositorType);
|
---|
523 | }
|
---|
524 | processParticle(xsParticleList->elementAt(xsParticleList->size()-1));
|
---|
525 |
|
---|
526 | XERCES_STD_QUALIFIER cout << ")";
|
---|
527 | } else if (termType == XSParticle::TERM_WILDCARD) {
|
---|
528 | XERCES_STD_QUALIFIER cout << "* (wildcard)";
|
---|
529 | }
|
---|
530 | }
|
---|
531 |
|
---|
532 | void processComplexTypeDefinition(XSComplexTypeDefinition *xsComplexTypeDef)
|
---|
533 | {
|
---|
534 | XSTypeDefinition *xsBaseTypeDef = xsComplexTypeDef->getBaseType();
|
---|
535 | if (xsBaseTypeDef) {
|
---|
536 | XERCES_STD_QUALIFIER cout << "Base:\t\t\t";
|
---|
537 | XERCES_STD_QUALIFIER cout << StrX(xsBaseTypeDef->getName()) << "\n";
|
---|
538 | }
|
---|
539 |
|
---|
540 | XERCES_STD_QUALIFIER cout << "Content Model:\t";
|
---|
541 | XSComplexTypeDefinition::CONTENT_TYPE contentType = xsComplexTypeDef->getContentType();
|
---|
542 | if (contentType == XSComplexTypeDefinition::CONTENTTYPE_ELEMENT ||
|
---|
543 | contentType == XSComplexTypeDefinition::CONTENTTYPE_MIXED) {
|
---|
544 | processParticle(xsComplexTypeDef->getParticle());
|
---|
545 | XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl;
|
---|
546 | }
|
---|
547 | }
|
---|
548 |
|
---|
549 | void processTypeDefinitions(XSNamedMap<XSObject> *xsTypeDefs)
|
---|
550 | {
|
---|
551 | if (!xsTypeDefs) return;
|
---|
552 |
|
---|
553 | for (unsigned i=0; i < xsTypeDefs->getLength(); i++) {
|
---|
554 | XSTypeDefinition *xsTypeDef = (XSTypeDefinition *)xsTypeDefs->item(i);
|
---|
555 |
|
---|
556 | printBasic(xsTypeDef, "Type Definition");
|
---|
557 |
|
---|
558 | // Content Model
|
---|
559 | XERCES_STD_QUALIFIER cout << "Category:\t";
|
---|
560 | if (xsTypeDef->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE) {
|
---|
561 | XERCES_STD_QUALIFIER cout << "\tSimple\n";
|
---|
562 | processSimpleTypeDefinition((XSSimpleTypeDefinition *)xsTypeDef);
|
---|
563 | } else {
|
---|
564 | XERCES_STD_QUALIFIER cout << "\tComplex\n";
|
---|
565 | processComplexTypeDefinition((XSComplexTypeDefinition *)xsTypeDef);
|
---|
566 | }
|
---|
567 |
|
---|
568 | XERCES_STD_QUALIFIER cout << "\n--------------------------------------------" << XERCES_STD_QUALIFIER endl;
|
---|
569 | }
|
---|
570 | }
|
---|