All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
XSDSerializer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib 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
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/xsd/XSDSerializer.cpp
22 
23  \brief Data serialization for the XSD module.
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../xml/AbstractWriter.h"
29 #include "../../../xml/Reader.h"
30 #include "../../../xml/ReaderFactory.h"
31 #include "../../All.h"
32 #include "../../Annotated.h"
33 #include "../../Annotation.h"
34 #include "../../Any.h"
35 #include "../../AnyAttribute.h"
36 #include "../../AppInfo.h"
37 #include "../../Attribute.h"
38 #include "../../AttributeGroup.h"
39 #include "../../Choice.h"
40 #include "../../ComplexContent.h"
41 #include "../../ComplexType.h"
42 #include "../../Documentation.h"
43 #include "../../Element.h"
44 #include "../../Exception.h"
45 #include "../../Extension.h"
46 #include "../../Field.h"
47 #include "../../Group.h"
48 #include "../../Import.h"
49 #include "../../Include.h"
50 #include "../../Key.h"
51 #include "../../KeyRef.h"
52 #include "../../List.h"
53 #include "../../QName.h"
54 #include "../../Redefine.h"
55 #include "../../Restriction4ComplexContent.h"
56 #include "../../Restriction4SimpleContent.h"
57 #include "../../Restriction4SimpleType.h"
58 #include "../../Selector.h"
59 #include "../../SimpleContent.h"
60 #include "../../SimpleType.h"
61 #include "../../Schema.h"
62 #include "../../Sequence.h"
63 #include "../../Union.h"
64 #include "../../Unique.h"
65 #include "XSDSerializer.h"
66 
67 // STL
68 #include <cassert>
69 #include <memory>
70 #include <set>
71 
72 // Boost
73 #include <boost/format.hpp>
74 
75 //#ifdef TE_ENABLED_XML
76 
78 {
79  assert(reader.getNodeType() == te::xml::START_ELEMENT);
80  assert(reader.getElementLocalName() == "all");
81 
82  std::auto_ptr<All> all(new All);
83 
84 // Id
85  ReadIdentifiable(all.get(), reader);
86 
87 // MinOccurs and MaxOccurs
88  ReadOccurs(all.get(), reader);
89 
90  reader.next();
91 
92 // Grammar: (annotation?,element*)
93 
94 // Annotation
95  ReadAnnotated(all.get(), reader);
96 
97 // Elements
98  while(reader.getNodeType() == te::xml::START_ELEMENT && (reader.getElementLocalName() == "element"))
99  all->addElement(ReadElement(reader));
100 
101  assert(reader.getNodeType() == te::xml::END_ELEMENT);
102  reader.next();
103 
104  return all.release();
105 }
106 
108 {
109 }
110 
112 {
113  assert(reader.getNodeType() == te::xml::START_ELEMENT);
114  assert(reader.getElementLocalName() == "annotation");
115 
116  std::auto_ptr<Annotation> annotation(new Annotation());
117 
118  // Id
119  ReadIdentifiable(annotation.get(), reader);
120 
121  reader.next();
122 
123  while(reader.getNodeType() == te::xml::START_ELEMENT &&
124  ((reader.getElementLocalName() == "appinfo") ||
125  (reader.getElementLocalName() == "documentation")))
126  {
127  std::string tag = reader.getElementLocalName();
128  if(tag == "appinfo")
129  {
130 // Reads the AppInfo
131  AppInfo* appinfo = new AppInfo(0, 0);
132 
133 // Source
134  std::size_t pos = reader.getAttrPosition("version");
135  if(pos != std::string::npos)
136  appinfo->setSource(new std::string(reader.getAttr(pos)));
137 
138 // Value
139  reader.next();
140  assert(reader.getNodeType() == te::xml::VALUE);
141  appinfo->setValue(new std::string(reader.getElementValue()));
142 
143 // Adds the appinfo on annotation
144  annotation->add(appinfo);
145 
146  reader.next();
147  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of AppInfo element
148 
149  reader.next();
150 
151  continue;
152  }
153 
154  if(tag == "documentation")
155  {
156 // Reads the Documentation
158 
159 // Source
160  std::size_t pos = reader.getAttrPosition("version");
161  if(pos != std::string::npos)
162  doc->setSource(new std::string(reader.getAttr(pos)));
163 
164 // xml:lang
165  pos = reader.getAttrPosition("xml:lang");
166  if(pos != std::string::npos)
167  doc->setLang(new std::string(reader.getAttr(pos)));
168 
169 // Value
170  reader.next();
171  assert(reader.getNodeType() == te::xml::VALUE);
172  doc->setValue(new std::string(reader.getElementValue()));
173 
174 // Adds the appinfo on annotation
175  annotation->add(doc);
176 
177  reader.next();
178  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of Documentation element
179 
180  reader.next();
181  }
182  }
183 
184  assert(reader.getNodeType() == te::xml::END_ELEMENT);
185  reader.next();
186 
187  return annotation.release();
188 }
189 
191 {
192 }
193 
195 {
196  assert(reader.getNodeType() == te::xml::START_ELEMENT);
197  assert(reader.getElementLocalName() == "any");
198 
199  std::auto_ptr<Any> any(new Any);
200 
201 // Id
202  ReadIdentifiable(any.get(), reader);
203 
204 // MinOccurs and MaxOccurs
205  ReadOccurs(any.get(), reader);
206 
207 // Namespace
208  std::size_t pos = reader.getAttrPosition("namespace");
209 
210  if(pos != std::string::npos)
211  any->setNamespace(new std::string(reader.getAttr(pos)));
212 
213 // ProcessContents
214  pos = reader.getAttrPosition("processContents");
215 
216  if(pos != std::string::npos)
217  {
218  std::string value = reader.getAttr(pos);
220  value == "skip" ? pc = te::xsd::SKIP : pc = te::xsd::STRICT;
221  any->setProcessContents(pc);
222  }
223 
224  reader.next();
225 
226 // Grammar: (annotation?)
227 
228 // Annotation
229  ReadAnnotated(any.get(), reader);
230 
231  assert(reader.getNodeType() == te::xml::END_ELEMENT);
232  reader.next();
233 
234  return any.release();
235 }
236 
238 {
239 }
240 
242 {
243  assert(reader.getNodeType() == te::xml::START_ELEMENT);
244  assert(reader.getElementLocalName() == "anyAttribute");
245 
246  std::auto_ptr<te::xsd::AnyAttribute> anyAttribute(new te::xsd::AnyAttribute);
247 
248  // Id
249  ReadIdentifiable(anyAttribute.get(), reader);
250 
251  // Namespace
252  std::size_t pos = reader.getAttrPosition("namespace");
253  if(pos != std::string::npos)
254  anyAttribute->setNamespace(new std::string(reader.getAttr(pos)));
255 
256  // ProcessContents
257  pos = reader.getAttrPosition("processContents");
258  if(pos != std::string::npos)
259  {
260  std::string value = reader.getAttr(pos);
262  value == "skip" ? pc = te::xsd::SKIP : pc = te::xsd::STRICT;
263  anyAttribute->setProcessContents(pc);
264  }
265 
266  reader.next();
267 
268  // Grammar: (annotation?)
269 
270  // Annotation
271  ReadAnnotated(anyAttribute.get(), reader);
272 
273  assert(reader.getNodeType() == te::xml::END_ELEMENT);
274  reader.next();
275 
276  return anyAttribute.release();
277 }
278 
280 {
281 }
282 
284 {
285  assert(reader.getNodeType() == te::xml::START_ELEMENT);
286  assert(reader.getElementLocalName() == "attribute");
287 
288  std::auto_ptr<te::xsd::Attribute> attribute(new te::xsd::Attribute);
289 
290  // Id
291  ReadIdentifiable(attribute.get(), reader);
292 
293  // Default
294  std::size_t pos = reader.getAttrPosition("default");
295  if(pos != std::string::npos)
296  attribute->setDefault(new std::string(reader.getAttr(pos)));
297 
298  // Fixed
299  pos = reader.getAttrPosition("fixed");
300  if(pos != std::string::npos)
301  attribute->setFixed(new std::string(reader.getAttr(pos)));
302 
303  // Form
304  pos = reader.getAttrPosition("Form");
305  if(pos != std::string::npos)
306  attribute->setForm(reader.getAttr(pos) == "qualified" ? te::xsd::Qualified : te::xsd::Unqualified);
307 
308  // Name
309  pos = reader.getAttrPosition("name");
310  if(pos != std::string::npos)
311  attribute->setName(new std::string(reader.getAttr(pos)));
312 
313  // Ref
314  pos = reader.getAttrPosition("ref");
315  if(pos != std::string::npos)
316  attribute->setRef(CreateQName(reader.getAttr(pos)));
317 
318  // Type
319  pos = reader.getAttrPosition("type");
320  if(pos != std::string::npos)
321  attribute->setType(CreateQName(reader.getAttr(pos)));
322 
323  // Use
324  pos = reader.getAttrPosition("use");
325  if(pos != std::string::npos)
326  {
327  std::string value = reader.getAttr(pos);
329  value == "prohibited" ? use = te::xsd::PROHIBITED : use = te::xsd::REQUIRED;
330  attribute->setUse(use);
331  }
332 
333  reader.next();
334 
335  // Grammar: (annotation?,(simpleType?))
336 
337  // Annotation
338  ReadAnnotated(attribute.get(), reader);
339 
340  // Simple Type
341  if(reader.getElementLocalName() == "simpleType")
342  attribute->setInnerType(ReadSimpleType(reader));
343 
344  assert(reader.getNodeType() == te::xml::END_ELEMENT);
345  reader.next();
346 
347  return attribute.release();
348 }
349 
351 {
352 }
353 
355 {
356  assert(reader.getNodeType() == te::xml::START_ELEMENT);
357  assert(reader.getElementLocalName() == "attributeGroup");
358 
359  std::auto_ptr<te::xsd::AttributeGroup> attributeGroup(new te::xsd::AttributeGroup);
360 
361  // Id
362  ReadIdentifiable(attributeGroup.get(), reader);
363 
364  // Name
365  std::size_t pos = reader.getAttrPosition("name");
366  if(pos != std::string::npos)
367  attributeGroup->setName(new std::string(reader.getAttr(pos)));
368 
369  // Ref
370  pos = reader.getAttrPosition("ref");
371  if(pos != std::string::npos)
372  attributeGroup->setRef(CreateQName(reader.getAttr(pos)));
373 
374  reader.next();
375 
376  // Grammar: (annotation?),((attribute|attributeGroup)*,anyAttribute?))
377 
378  // Annotation
379  ReadAnnotated(attributeGroup.get(), reader);
380 
381  std::set<std::string> children;
382  children.insert("attribute");
383  children.insert("attributeGroup");
384 
385  std::set<std::string>::iterator it;
386  while(reader.getNodeType() == te::xml::START_ELEMENT &&
387  (it = children.find(reader.getElementLocalName())) != children.end())
388  {
389  std::string tag = *it;
390  if(tag == "attribute")
391  {
392  attributeGroup->addAttribute(ReadAttribute(reader));
393  continue;
394  }
395 
396  attributeGroup->addAttribute(ReadAttributeGroup(reader));
397  }
398 
399  // AnyAttribute
400  if(reader.getElementLocalName() == "anyAttribute")
401  attributeGroup->setAnyAttribute(ReadAnyAttribute(reader));
402 
403  assert(reader.getNodeType() == te::xml::END_ELEMENT);
404  reader.next();
405 
406  return attributeGroup.release();
407 }
408 
410 {
411 }
412 
414 {
415  assert(reader.getNodeType() == te::xml::START_ELEMENT);
416  assert(reader.getElementLocalName() == "choice");
417 
418  std::auto_ptr<te::xsd::Choice> choice(new te::xsd::Choice);
419 
420  // Id
421  ReadIdentifiable(choice.get(), reader);
422 
423  // MinOccurs and MaxOccurs
424  ReadOccurs(choice.get(), reader);
425 
426  reader.next();
427 
428  // Grammar: (annotation?,(element|group|choice|sequence|any)*)
429 
430  // Annotation
431  ReadAnnotated(choice.get(), reader);
432 
433  std::set<std::string> children;
434  children.insert("element");
435  children.insert("group");
436  children.insert("choice");
437  children.insert("sequence");
438  children.insert("any");
439 
440  std::set<std::string>::iterator it;
441  while(reader.getNodeType() == te::xml::START_ELEMENT &&
442  (it = children.find(reader.getElementLocalName())) != children.end())
443  {
444  std::string tag = *it;
445  if(tag == "element")
446  {
447  choice->addElement(ReadElement(reader));
448  continue;
449  }
450 
451  if(tag == "group")
452  {
453  choice->addContent(ReadGroup(reader));
454  continue;
455  }
456 
457  if(tag == "choice")
458  {
459  choice->addContent(ReadChoice(reader));
460  continue;
461  }
462 
463  if(tag == "sequence")
464  {
465  choice->addContent(ReadSequence(reader));
466  continue;
467  }
468 
469  if(tag == "any")
470  choice->addAny(ReadAny(reader));
471  }
472 
473  assert(reader.getNodeType() == te::xml::END_ELEMENT);
474  reader.next();
475 
476  return choice.release();
477 }
478 
480 {
481 }
482 
484 {
485  assert(reader.getNodeType() == te::xml::START_ELEMENT);
486  assert(reader.getElementLocalName() == "complexContent");
487 
488  std::auto_ptr<te::xsd::ComplexContent> cc(new te::xsd::ComplexContent);
489 
490  // Id
491  ReadIdentifiable(cc.get(), reader);
492 
493  // Mixed
494  std::size_t pos = reader.getAttrPosition("mixed");
495  if(pos != std::string::npos)
496  cc->setAsMixed(reader.getAttr(pos) == "true" ? true : false);
497 
498  reader.next();
499 
500  /* Grammar: (annotation?,(restriction|extension)) */
501 
502  // Annotation
503  ReadAnnotated(cc.get(), reader);
504 
505  // Restriction
506  if(reader.getElementLocalName() == "restriction")
507  {
508  cc->setTypeDerivation(ReadRestriction4ComplexContent(reader));
509  return cc.release();
510  }
511 
512  assert(reader.getElementLocalName() == "extension");
513  cc->setTypeDerivation(ReadExtension(reader));
514 
515  assert(reader.getNodeType() == te::xml::END_ELEMENT);
516  reader.next();
517 
518  return cc.release();
519 }
520 
522 {
523 }
524 
526 {
527  assert(reader.getNodeType() == te::xml::START_ELEMENT);
528  assert(reader.getElementLocalName() == "complexType");
529 
530  std::auto_ptr<te::xsd::ComplexType> ct(new te::xsd::ComplexType);
531 
532  // Id
533  ReadIdentifiable(ct.get(), reader);
534 
535  // Name
536  std::size_t pos = reader.getAttrPosition("name");
537  if(pos != std::string::npos)
538  ct->setName(new std::string(reader.getAttr(pos)));
539 
540  // Abstract
541  pos = reader.getAttrPosition("abstract");
542  if(pos != std::string::npos)
543  ct->setAsAbstract(reader.getAttr(pos) == "true" ? true : false);
544 
545  // Mixed
546  pos = reader.getAttrPosition("mixed");
547  if(pos != std::string::npos)
548  ct->setAsMixed(reader.getAttr(pos) == "true" ? true : false);
549 
550  // TODO: Block and Final ?
551 
552  reader.next();
553 
554  /* Grammar: (annotation?,(simpleContent|complexContent|((group|all|
555  choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?)))) */
556 
557  // Annotation
558  ReadAnnotated(ct.get(), reader);
559 
560  std::set<std::string> children;
561  children.insert("simpleContent");
562  children.insert("complexContent");
563  children.insert("group");
564  children.insert("all");
565  children.insert("choice");
566  children.insert("sequence");
567  children.insert("attribute");
568  children.insert("attributeGroup");
569  children.insert("anyAttribute");
570 
571  std::set<std::string>::iterator it;
572  while(reader.getNodeType() == te::xml::START_ELEMENT &&
573  (it = children.find(reader.getElementLocalName())) != children.end())
574  {
575  std::string tag = *it;
576  if(tag == "simpleContent")
577  {
578  ct->setSimpleContent(ReadSimpleContent(reader));
579  continue;
580  }
581 
582  if(tag == "complexContent")
583  {
584  ct->setComplexContent(ReadComplexContent(reader));
585  continue;
586  }
587 
588  if(tag == "group")
589  {
590  ct->setContent(ReadGroup(reader));
591  continue;
592  }
593 
594  if(tag == "all")
595  {
596  ct->setContent(ReadAll(reader));
597  continue;
598  }
599 
600  if(tag == "choice")
601  {
602  ct->setContent(ReadChoice(reader));
603  continue;
604  }
605 
606  if(tag == "sequence")
607  {
608  ct->setContent(ReadSequence(reader));
609  continue;
610  }
611 
612  if(tag == "attribute")
613  {
614  ct->addAttribute(ReadAttribute(reader));
615  continue;
616  }
617 
618  if(tag == "attributeGroup")
619  {
620  ct->addAttribute(ReadAttributeGroup(reader));
621  continue;
622  }
623 
624  if(tag == "anyAttribute")
625  ct->setAnyAttribute(ReadAnyAttribute(reader));
626  }
627 
628  assert(reader.getNodeType() == te::xml::END_ELEMENT);
629  reader.next();
630 
631  return ct.release();
632 }
633 
635 {
636 }
637 
639 {
640  assert(reader.getNodeType() == te::xml::START_ELEMENT);
641  assert(reader.getElementLocalName() == "element");
642 
643  std::auto_ptr<te::xsd::Element> element(new te::xsd::Element);
644 
645  // Id
646  ReadIdentifiable(element.get(), reader);
647 
648  // Name
649  std::size_t pos = reader.getAttrPosition("name");
650  if(pos != std::string::npos)
651  element->setName(new std::string(reader.getAttr(pos)));
652 
653  // Ref
654  pos = reader.getAttrPosition("ref");
655  if(pos != std::string::npos)
656  element->setRef(CreateQName(reader.getAttr(pos)));
657 
658  // Type
659  pos = reader.getAttrPosition("type");
660  if(pos != std::string::npos)
661  element->setType(CreateQName(reader.getAttr(pos)));
662 
663  // SubstitutionGroup
664  pos = reader.getAttrPosition("substitutionGroup");
665  if(pos != std::string::npos)
666  element->setSubstitutionGroup(CreateQName(reader.getAttr(pos)));
667 
668  // Default
669  pos = reader.getAttrPosition("default");
670  if(pos != std::string::npos)
671  element->setDefaultValue(new std::string(reader.getAttr(pos)));
672 
673  // Fixed
674  pos = reader.getAttrPosition("fixed");
675  if(pos != std::string::npos)
676  element->setFixedValue(new std::string(reader.getAttr(pos)));
677 
678  // MinOccurs and MaxOccurs
679  ReadOccurs(element.get(), reader);
680 
681  // Nillable
682  pos = reader.getAttrPosition("nillable");
683  if(pos != std::string::npos)
684  element->setAsNillable(reader.getAttr(pos) == "true" ? true : false);
685 
686  // Abstract
687  pos = reader.getAttrPosition("abstract");
688  if(pos != std::string::npos)
689  element->setAsAbstract(reader.getAttr(pos) == "true" ? true : false);
690 
691  // TODO: Block and Final ?
692 
693  reader.next();
694 
695  // Grammar: annotation?,((simpleType|complexType)?,(unique|key|keyref)*))
696 
697  ReadAnnotated(element.get(), reader);
698 
699  if(reader.getElementLocalName() == "simpleType")
700  element->setContentType(ReadSimpleType(reader));
701  else if(reader.getElementLocalName() == "complexType")
702  element->setContentType(ReadComplexType(reader));
703 
704  std::set<std::string> children;
705  children.insert("unique");
706  children.insert("key");
707  children.insert("keyref");
708 
709  std::set<std::string>::iterator it;
710  while(reader.getNodeType() == te::xml::START_ELEMENT &&
711  (it = children.find(reader.getElementLocalName())) != children.end())
712  {
713  std::string tag = *it;
714  if(tag == "unique")
715  {
716  element->addIdentityConstraint(ReadUnique(reader));
717  continue;
718  }
719 
720  if(tag == "key")
721  {
722  element->addIdentityConstraint(ReadKey(reader));
723  continue;
724  }
725 
726  if(tag == "keyref")
727  element->addIdentityConstraint(ReadKeyRef(reader));
728  }
729 
730  assert(reader.getNodeType() == te::xml::END_ELEMENT);
731  reader.next();
732 
733  return element.release();
734 }
735 
737 {
738 }
739 
741 {
742  assert(reader.getNodeType() == te::xml::START_ELEMENT);
743  assert(reader.getElementLocalName() == "extension");
744 
745  std::auto_ptr<te::xsd::Extension> extension(new te::xsd::Extension);
746 
747  // Id
748  ReadIdentifiable(extension.get(), reader);
749 
750  // Base
751  std::size_t pos = reader.getAttrPosition("base");
752  if(pos != std::string::npos)
753  extension->setBase(CreateQName(reader.getAttr(pos)));
754 
755  reader.next();
756 
757  /* Grammar: (annotation?,((group|all|choice|sequence)?,
758  ((attribute|attributeGroup)*,anyAttribute?))) */
759 
760  // Annotation
761  ReadAnnotated(extension.get(), reader);
762 
763  std::set<std::string> children;
764  children.insert("group");
765  children.insert("all");
766  children.insert("choice");
767  children.insert("sequence");
768  children.insert("attribute");
769  children.insert("attributeGroup");
770  children.insert("anyAttribute");
771 
772  std::set<std::string>::iterator it;
773  while(reader.getNodeType() == te::xml::START_ELEMENT &&
774  (it = children.find(reader.getElementLocalName())) != children.end())
775  {
776  std::string tag = *it;
777  if(tag == "group")
778  {
779  extension->setContent(ReadGroup(reader));
780  continue;
781  }
782 
783  if(tag == "all")
784  {
785  extension->setContent(ReadAll(reader));
786  continue;
787  }
788 
789  if(tag == "choice")
790  {
791  extension->setContent(ReadChoice(reader));
792  continue;
793  }
794 
795  if(tag == "sequence")
796  {
797  extension->setContent(ReadSequence(reader));
798  continue;
799  }
800 
801  if(tag == "attribute")
802  {
803  extension->addAttribute(ReadAttribute(reader));
804  continue;
805  }
806 
807  if(tag == "attributeGroup")
808  {
809  extension->addAttribute(ReadAttributeGroup(reader));
810  continue;
811  }
812 
813  if(tag == "anyAttribute")
814  extension->setAnyAttribute(ReadAnyAttribute(reader));
815  }
816 
817  assert(reader.getNodeType() == te::xml::END_ELEMENT);
818  reader.next();
819 
820  return extension.release();
821 }
822 
824 {
825 }
826 
828 {
829  assert(reader.getNodeType() == te::xml::START_ELEMENT);
830  assert(reader.getElementLocalName() == "field");
831 
832  std::auto_ptr<te::xsd::Field> field(new te::xsd::Field(0));
833 
834  // Id
835  ReadIdentifiable(field.get(), reader);
836 
837  // XPath
838  std::size_t pos = reader.getAttrPosition("xpath");
839  assert(pos != std::string::npos);
840  field->setXPath(new std::string(reader.getAttr(pos)));
841 
842  reader.next();
843 
844  // Grammar: (annotation?)
845 
846  // Annotation
847  ReadAnnotated(field.get(), reader);
848 
849  assert(reader.getNodeType() == te::xml::END_ELEMENT);
850  reader.next();
851 
852  return field.release();
853 }
854 
856 {
857 }
858 
860 {
861  assert(reader.getNodeType() == te::xml::START_ELEMENT);
862  assert(reader.getElementLocalName() == "group");
863 
864  std::auto_ptr<te::xsd::Group> group(new te::xsd::Group);
865 
866  // Id
867  ReadIdentifiable(group.get(), reader);
868 
869  // Name
870  std::size_t pos = reader.getAttrPosition("name");
871  if(pos != std::string::npos)
872  group->setName(new std::string(reader.getAttr(pos)));
873 
874  // Ref
875  pos = reader.getAttrPosition("ref");
876  if(pos != std::string::npos)
877  group->setRef(CreateQName(reader.getAttr(pos)));
878 
879  // MinOccurs and MaxOccurs
880  ReadOccurs(group.get(), reader);
881 
882  reader.next();
883 
884  // Grammar: (annotation?,(all|choice|sequence)?)
885 
886  // Annotation
887  ReadAnnotated(group.get(), reader);
888 
889  if(reader.getElementLocalName() == "all")
890  group->setContent(ReadAll(reader));
891  else if(reader.getElementLocalName() == "choice")
892  group->setContent(ReadChoice(reader));
893  else if(reader.getElementLocalName() == "sequence")
894  group->setContent(ReadSequence(reader));
895  else throw; // TODO: Add an exception here...
896 
897  assert(reader.getNodeType() == te::xml::END_ELEMENT);
898  reader.next();
899 
900  return group.release();
901 }
902 
904 {
905 }
906 
908 {
909  assert(reader.getNodeType() == te::xml::START_ELEMENT);
910  assert(reader.getElementLocalName() == "import");
911 
912  std::auto_ptr<te::xsd::Import> import(new te::xsd::Import(0, 0));
913 
914  // Id
915  ReadIdentifiable(import.get(), reader);
916 
917  // Namespace
918  std::size_t pos = reader.getAttrPosition("namespace");
919  if(pos != std::string::npos)
920  import->setNamespace(new std::string(reader.getAttr(pos)));
921 
922  // SchemaLocation
923  pos = reader.getAttrPosition("schemaLocation");
924  if(pos != std::string::npos)
925  import->setSchemaLocation(new std::string(reader.getAttr(pos)));
926 
927  reader.next();
928 
929  // Annotation
930  ReadAnnotated(import.get(), reader);
931 
932  assert(reader.getNodeType() == te::xml::END_ELEMENT);
933  reader.next();
934 
935  return import.release();
936 }
937 
939 {
940 }
941 
943 {
944  assert(reader.getNodeType() == te::xml::START_ELEMENT);
945  assert(reader.getElementLocalName() == "include");
946 
947  std::auto_ptr<te::xsd::Include> include(new te::xsd::Include(""));
948 
949  // Id
950  ReadIdentifiable(include.get(), reader);
951 
952  // SchemaLocation
953  std::size_t pos = reader.getAttrPosition("schemaLocation");
954  if(pos != std::string::npos)
955  include->setSchemaLocation(reader.getAttr(pos));
956 
957  reader.next();
958 
959  // Annotation
960  ReadAnnotated(include.get(), reader);
961 
962  assert(reader.getNodeType() == te::xml::END_ELEMENT);
963  reader.next();
964 
965  return include.release();
966 }
967 
969 {
970 }
971 
973 {
974  assert(reader.getNodeType() == te::xml::START_ELEMENT);
975  assert(reader.getElementLocalName() == "key");
976 
977  std::auto_ptr<te::xsd::Key> key(new te::xsd::Key(0));
978 
979  // Id
980  ReadIdentifiable(key.get(), reader);
981 
982  // Name
983  std::size_t pos = reader.getAttrPosition("name");
984  assert(pos != std::string::npos);
985  key->setName(new std::string(reader.getAttr(pos)));
986 
987  reader.next();
988 
989  // Grammar: (annotation?,(selector,field+))
990 
991  // Annotation
992  ReadAnnotated(key.get(), reader);
993 
994  // Selector
995  if(reader.getElementLocalName() == "selector")
996  {
997  key->setSelector(ReadSelector(reader));
998  return key.release();
999  }
1000 
1001  // Fields
1002  while(reader.getNodeType() == te::xml::START_ELEMENT && reader.getElementLocalName() == "field")
1003  key->addField(ReadField(reader));
1004 
1005  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1006  reader.next();
1007 
1008  return key.release();
1009 }
1010 
1012 {
1013 }
1014 
1016 {
1017  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1018  assert(reader.getElementLocalName() == "keyref");
1019 
1020  std::auto_ptr<te::xsd::KeyRef> keyRef(new te::xsd::KeyRef(0, 0));
1021 
1022  // Id
1023  ReadIdentifiable(keyRef.get(), reader);
1024 
1025  // Name
1026  std::size_t pos = reader.getAttrPosition("name");
1027  assert(pos != std::string::npos);
1028  keyRef->setName(new std::string(reader.getAttr(pos)));
1029 
1030  // Refer
1031  pos = reader.getAttrPosition("refer");
1032  assert(pos != std::string::npos);
1033  keyRef->setRef(CreateQName(reader.getAttr(pos)));
1034 
1035  reader.next();
1036 
1037  // Grammar: (annotation?,(selector,field+))
1038 
1039  // Annotation
1040  ReadAnnotated(keyRef.get(), reader);
1041 
1042  // Selector
1043  if(reader.getElementLocalName() == "selector")
1044  {
1045  keyRef->setSelector(ReadSelector(reader));
1046  return keyRef.release();
1047  }
1048 
1049  // Fields
1050  while(reader.getNodeType() == te::xml::START_ELEMENT && reader.getElementLocalName() == "field")
1051  keyRef->addField(ReadField(reader));
1052 
1053  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1054  reader.next();
1055 
1056  return keyRef.release();
1057 }
1058 
1060 {
1061 }
1062 
1064 {
1065  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1066  assert(reader.getElementLocalName() == "list");
1067 
1068  std::auto_ptr<te::xsd::List> list(new te::xsd::List);
1069 
1070  // Id
1071  ReadIdentifiable(list.get(), reader);
1072 
1073  // ItemType
1074  std::size_t pos = reader.getAttrPosition("itemType");
1075  if(pos != std::string::npos)
1076  list->setItemType(CreateQName(reader.getAttr(pos)));
1077 
1078  reader.next();
1079 
1080  // Grammar: (annotation?,(simpleType?))
1081 
1082  // Annotation
1083  ReadAnnotated(list.get(), reader);
1084 
1085  // Simple Type
1086  if(reader.getElementLocalName() == "simpleType")
1087  list->setSimpleType(ReadSimpleType(reader));
1088 
1089  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1090  reader.next();
1091 
1092  return list.release();
1093 }
1094 
1096 {
1097 }
1098 
1100 {
1101  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1102  assert(reader.getElementLocalName() == "redefine");
1103 
1104  std::auto_ptr<te::xsd::Redefine> redefine(new te::xsd::Redefine(""));
1105 
1106  // Id
1107  ReadIdentifiable(redefine.get(), reader);
1108 
1109  // SchemaLocation
1110  std::size_t pos = reader.getAttrPosition("schemaLocation");
1111  if(pos != std::string::npos)
1112  redefine->setSchemaLocation(reader.getAttr(pos));
1113 
1114  reader.next();
1115 
1116  // Grammar: (annotation|(simpleType|complexType|group|attributeGroup))*
1117 
1118  std::set<std::string> children;
1119  children.insert("annotation");
1120  children.insert("simpleType");
1121  children.insert("complexType");
1122  children.insert("group");
1123  children.insert("attributeGroup");
1124 
1125  std::set<std::string>::iterator it;
1126  while(reader.getNodeType() == te::xml::START_ELEMENT &&
1127  (it = children.find(reader.getElementLocalName())) != children.end())
1128  {
1129  std::string tag = *it;
1130  if(tag == "annotation")
1131  {
1132  redefine->addAnnotation(ReadAnnotation(reader));
1133  continue;
1134  }
1135 
1136  if(tag == "simpleType")
1137  {
1138  redefine->addType(ReadSimpleType(reader));
1139  continue;
1140  }
1141 
1142  if(tag == "complexType")
1143  {
1144  redefine->addType(ReadComplexType(reader));
1145  continue;
1146  }
1147 
1148  if(tag == "group")
1149  {
1150  redefine->addGroup(ReadGroup(reader));
1151  continue;
1152  }
1153 
1154  if(tag == "attributeGroup")
1155  redefine->addAttributeGroup(ReadAttributeGroup(reader));
1156  }
1157 
1158  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1159  reader.next();
1160 
1161  return redefine.release();
1162 }
1163 
1165 {
1166 }
1167 
1169 {
1170  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1171  assert(reader.getElementLocalName() == "restriction");
1172 
1173  std::auto_ptr<te::xsd::Restriction4ComplexContent> restriction(new te::xsd::Restriction4ComplexContent(0, 0));
1174 
1175  // Id
1176  ReadIdentifiable(restriction.get(), reader);
1177 
1178  // Base
1179  std::size_t pos = reader.getAttrPosition("base");
1180  if(pos != std::string::npos)
1181  restriction->setBase(CreateQName(reader.getAttr(pos)));
1182 
1183  reader.next();
1184 
1185  /* Grammar: (annotation?,(group|all|choice|sequence)?,
1186  ((attribute|attributeGroup)*,anyAttribute?)) */
1187 
1188  std::set<std::string> children;
1189  children.insert("group");
1190  children.insert("all");
1191  children.insert("choice");
1192  children.insert("sequence");
1193  children.insert("attribute");
1194  children.insert("attributeGroup");
1195  children.insert("anyAttribute");
1196 
1197  // Annotation
1198  ReadAnnotated(restriction.get(), reader);
1199 
1200  std::set<std::string>::iterator it;
1201  while(reader.getNodeType() == te::xml::START_ELEMENT &&
1202  (it = children.find(reader.getElementLocalName())) != children.end())
1203  {
1204  std::string tag = *it;
1205 
1206  if(tag == "group")
1207  {
1208  restriction->setContent(ReadGroup(reader));
1209  continue;
1210  }
1211 
1212  if(tag == "all")
1213  {
1214  restriction->setContent(ReadAll(reader));
1215  continue;
1216  }
1217 
1218  if(tag == "choice")
1219  {
1220  restriction->setContent(ReadChoice(reader));
1221  continue;
1222  }
1223 
1224  if(tag == "sequence")
1225  {
1226  restriction->setContent(ReadSequence(reader));
1227  continue;
1228  }
1229 
1230  if(tag == "attribute")
1231  {
1232  restriction->addAttribute(ReadAttribute(reader));
1233  continue;
1234  }
1235 
1236  if(tag == "attributeGroup")
1237  {
1238  restriction->addAttribute(ReadAttributeGroup(reader));
1239  continue;
1240  }
1241 
1242  if(tag == "anyAttribute")
1243  restriction->setAnyAttribute(ReadAnyAttribute(reader));
1244  }
1245 
1246  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1247  reader.next();
1248 
1249  return restriction.release();
1250 }
1251 
1253 {
1254 }
1255 
1257 {
1258  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1259  assert(reader.getElementLocalName() == "restriction");
1260 
1261  std::auto_ptr<te::xsd::Restriction4SimpleContent> restriction(new te::xsd::Restriction4SimpleContent(0, 0));
1262 
1263  // Id
1264  ReadIdentifiable(restriction.get(), reader);
1265 
1266  // Base
1267  std::size_t pos = reader.getAttrPosition("base");
1268  if(pos != std::string::npos)
1269  restriction->setBase(CreateQName(reader.getAttr(pos)));
1270 
1271  reader.next();
1272 
1273  /* Grammar: (annotation?,(simpleType?,(minExclusive |minInclusive|
1274  maxExclusive|maxInclusive|totalDigits|fractionDigits|
1275  length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
1276  ((attribute|attributeGroup)*,anyAttribute?)) */
1277 
1278  std::set<std::string> children;
1279  children.insert("minExclusive");
1280  children.insert("minInclusive");
1281  children.insert("maxExclusive");
1282  children.insert("maxInclusive");
1283  children.insert("totalDigits");
1284  children.insert("fractionDigits");
1285  children.insert("length");
1286  children.insert("minLength");
1287  children.insert("maxLength");
1288  children.insert("enumeration");
1289  children.insert("whiteSpace");
1290  children.insert("pattern");
1291  children.insert("attribute");
1292  children.insert("attributeGroup");
1293  children.insert("anyAttribute");
1294 
1295  // Annotation
1296  ReadAnnotated(restriction.get(), reader);
1297 
1298  // Simple Type
1299  if(reader.getElementLocalName() == "simpleType")
1300  restriction->setSimpleType(ReadSimpleType(reader));
1301 
1302  std::set<std::string>::iterator it;
1303  while(reader.getNodeType() == te::xml::START_ELEMENT &&
1304  (it = children.find(reader.getElementLocalName())) != children.end())
1305  {
1306  std::string tag = *it;
1307 
1308  if(tag == "attribute")
1309  {
1310  restriction->addAttribute(ReadAttribute(reader));
1311  continue;
1312  }
1313 
1314  if(tag == "attributeGroup")
1315  {
1316  restriction->addAttribute(ReadAttributeGroup(reader));
1317  continue;
1318  }
1319 
1320  if(tag == "anyAttribute")
1321  {
1322  restriction->setAnyAttribute(ReadAnyAttribute(reader));
1323  continue;
1324  }
1325 
1326  // Facet
1327  pos = reader.getAttrPosition("value");
1328  assert(pos != std::string::npos);
1329  restriction->addFacet(GetFacetType(tag), reader.getAttr(pos));
1330 
1331  reader.next();
1332  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of Facet
1333 
1334  reader.next();
1335  }
1336 
1337  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1338  reader.next();
1339 
1340  return restriction.release();
1341 }
1342 
1344 {
1345 }
1346 
1348 {
1349  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1350  assert(reader.getElementLocalName() == "restriction");
1351 
1352  std::auto_ptr<te::xsd::Restriction4SimpleType> restriction(new te::xsd::Restriction4SimpleType);
1353 
1354  // Id
1355  ReadIdentifiable(restriction.get(), reader);
1356 
1357  // Base
1358  std::size_t pos = reader.getAttrPosition("base");
1359  if(pos != std::string::npos)
1360  restriction->setBase(CreateQName(reader.getAttr(pos)));
1361 
1362  reader.next();
1363 
1364  /* Grammar: (annotation?,(simpleType?,(minExclusive|minInclusive|maxExclusive|maxInclusive|
1365  totalDigits|fractionDigits|length|minLength|maxLength|enumeration|whiteSpace|pattern)*)) */
1366 
1367  std::set<std::string> children;
1368  children.insert("minExclusive");
1369  children.insert("minInclusive");
1370  children.insert("maxExclusive");
1371  children.insert("maxInclusive");
1372  children.insert("totalDigits");
1373  children.insert("fractionDigits");
1374  children.insert("length");
1375  children.insert("minLength");
1376  children.insert("maxLength");
1377  children.insert("enumeration");
1378  children.insert("whiteSpace");
1379  children.insert("pattern");
1380 
1381  // Annotation
1382  ReadAnnotated(restriction.get(), reader);
1383 
1384  // Simple Type
1385  if(reader.getElementLocalName() == "simpleType")
1386  restriction->setSimpleType(ReadSimpleType(reader));
1387 
1388  std::set<std::string>::iterator it;
1389  while(reader.getNodeType() == te::xml::START_ELEMENT &&
1390  (it = children.find(reader.getElementLocalName())) != children.end())
1391  {
1392  // Facet
1393  pos = reader.getAttrPosition("value");
1394  assert(pos != std::string::npos);
1395  restriction->addFacet(GetFacetType(*it), reader.getAttr(pos));
1396 
1397  reader.next();
1398  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of Facet
1399 
1400  reader.next();
1401  }
1402 
1403  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1404  reader.next();
1405 
1406  return restriction.release();
1407 }
1408 
1410 {
1411 }
1412 
1414 {
1415  std::auto_ptr<te::xml::Reader> reader(te::xml::ReaderFactory::make("XERCES"));
1416  reader->setValidationScheme(false);
1417  reader->setIgnoreWhiteSpaces(true);
1418  reader->read(path);
1419 
1420  if(!reader->next())
1421  throw Exception((boost::format(TE_TR("Could not read the XSD Schema in file: %1%.")) % path).str());
1422 
1423  if(reader->getNodeType() != te::xml::START_ELEMENT)
1424  throw Exception((boost::format(TE_TR("Error reading the document %1%, the start element wasn't found.")) % path).str());
1425 
1426  return ReadSchema(*reader);
1427 }
1428 
1430 {
1431  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1432  assert(reader.getElementLocalName() == "schema");
1433 
1434  std::auto_ptr<te::xsd::Schema> schema(new te::xsd::Schema(0));
1435 
1436  // Namespaces
1437  std::size_t numberOfNamespaces = reader.getNumberOfNamespaces();
1438  for(std::size_t i = 0; i < numberOfNamespaces; ++i)
1439  {
1440  std::pair<std::string, std::string> ns;
1441  reader.getNamespace(i, ns);
1442  schema->getNamespaces().insert(boost::bimap<std::string, std::string>::value_type(ns.first, ns.second));
1443  }
1444 
1445  // Id
1446  ReadIdentifiable(schema.get(), reader);
1447 
1448  // AttributeFormDefault
1449  std::size_t pos = reader.getAttrPosition("attributeFormDefault");
1450  if(pos != std::string::npos)
1451  schema->setAttributeFormDefault(reader.getAttr(pos) == "qualified" ? te::xsd::Qualified : te::xsd::Unqualified);
1452 
1453  // ElementFormDefault
1454  pos = reader.getAttrPosition("elementFormDefault");
1455  if(pos != std::string::npos)
1456  schema->setElementFormDefault(reader.getAttr(pos) == "qualified" ? te::xsd::Qualified : te::xsd::Unqualified);
1457 
1458  // TODO: BlockDefault and FinalDefault ?
1459 
1460  // TargetNamespace
1461  pos = reader.getAttrPosition("targetNamespace");
1462  if(pos != std::string::npos)
1463  schema->setTargetNamespace(reader.getAttr(pos));
1464 
1465  // Version
1466  pos = reader.getAttrPosition("version");
1467  if(pos != std::string::npos)
1468  schema->setVersion(reader.getAttr(pos));
1469 
1470  reader.next();
1471 
1472  /* Grammar: ((include|import|redefine|annotation)*,(((simpleType|complexType|
1473  group|attributeGroup)|element|attribute|notation),annotation*)*) */
1474 
1475  /* TODO: Using a set to find the element's children. Temporary solution!
1476  Suggestion: we can put this information on a static member of te::xsd classes. - Uba, 2013 */
1477  std::set<std::string> children;
1478  children.insert("include");
1479  children.insert("import");
1480  children.insert("redefine");
1481  children.insert("annotation");
1482  children.insert("simpleType");
1483  children.insert("complexType");
1484  children.insert("group");
1485  children.insert("attributeGroup");
1486  children.insert("element");
1487  children.insert("attribute");
1488  children.insert("notation");
1489 
1490  std::set<std::string>::iterator it;
1491  while(reader.getNodeType() == te::xml::START_ELEMENT &&
1492  (it = children.find(reader.getElementLocalName())) != children.end())
1493  {
1494  std::string tag = *it;
1495  if(tag == "include")
1496  {
1497  schema->addInclude(ReadInclude(reader));
1498  continue;
1499  }
1500 
1501  if(tag == "import")
1502  {
1503  schema->addImport(ReadImport(reader));
1504  continue;
1505  }
1506 
1507  if(tag == "redefine")
1508  {
1509  schema->addRedefine(ReadRedefine(reader));
1510  continue;
1511  }
1512 
1513  if(tag == "annotation")
1514  {
1515  schema->addAnnotation(ReadAnnotation(reader));
1516  continue;
1517  }
1518 
1519  if(tag == "simpleType")
1520  {
1521  schema->addSimpleType(ReadSimpleType(reader));
1522  continue;
1523  }
1524 
1525  if(tag == "complexType")
1526  {
1527  schema->addComplexType(ReadComplexType(reader));
1528  continue;
1529  }
1530 
1531  if(tag == "group")
1532  {
1533  schema->addGroup(ReadGroup(reader));
1534  continue;
1535  }
1536 
1537  if(tag == "attributeGroup")
1538  {
1539  schema->addAttributeGroup(ReadAttributeGroup(reader));
1540  continue;
1541  }
1542 
1543  if(tag == "element")
1544  {
1545  schema->addElement(ReadElement(reader));
1546  continue;
1547  }
1548 
1549  if(tag == "attribute")
1550  schema->addAttribute(ReadAttribute(reader));
1551  }
1552 
1553  assert(reader.getNodeType() == te::xml::END_DOCUMENT);
1554 
1555  return schema.release();
1556 }
1557 
1559 {
1560 }
1561 
1563 {
1564  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1565  assert(reader.getElementLocalName() == "selector");
1566 
1567  std::auto_ptr<te::xsd::Selector> selector(new te::xsd::Selector(0));
1568 
1569  // Id
1570  ReadIdentifiable(selector.get(), reader);
1571 
1572  // XPath
1573  std::size_t pos = reader.getAttrPosition("xpath");
1574  assert(pos != std::string::npos);
1575  selector->setXPath(new std::string(reader.getAttr(pos)));
1576 
1577  reader.next();
1578 
1579  // Grammar: (annotation?)
1580 
1581  // Annotation
1582  ReadAnnotated(selector.get(), reader);
1583 
1584  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1585  reader.next();
1586 
1587  return selector.release();
1588 }
1589 
1591 {
1592 }
1593 
1595 {
1596  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1597  assert(reader.getElementLocalName() == "sequence");
1598 
1599  std::auto_ptr<te::xsd::Sequence> sequence(new te::xsd::Sequence);
1600 
1601  // Id
1602  ReadIdentifiable(sequence.get(), reader);
1603 
1604  // MinOccurs and MaxOccurs
1605  ReadOccurs(sequence.get(), reader);
1606 
1607  reader.next();
1608 
1609  // Grammar: (annotation?,(element|group|choice|sequence|any)*)
1610 
1611  // Annotation
1612  ReadAnnotated(sequence.get(), reader);
1613 
1614  std::set<std::string> children;
1615  children.insert("element");
1616  children.insert("group");
1617  children.insert("choice");
1618  children.insert("sequence");
1619  children.insert("any");
1620 
1621  std::set<std::string>::iterator it;
1622  while(reader.getNodeType() == te::xml::START_ELEMENT &&
1623  (it = children.find(reader.getElementLocalName())) != children.end())
1624  {
1625  std::string tag = *it;
1626  if(tag == "element")
1627  {
1628  sequence->addElement(ReadElement(reader));
1629  continue;
1630  }
1631 
1632  if(tag == "group")
1633  {
1634  sequence->addContent(ReadGroup(reader));
1635  continue;
1636  }
1637 
1638  if(tag == "choice")
1639  {
1640  sequence->addContent(ReadChoice(reader));
1641  continue;
1642  }
1643 
1644  if(tag == "sequence")
1645  {
1646  sequence->addContent(ReadSequence(reader));
1647  continue;
1648  }
1649 
1650  if(tag == "any")
1651  sequence->addAny(ReadAny(reader));
1652  }
1653 
1654  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1655  reader.next();
1656 
1657  return sequence.release();
1658 }
1659 
1661 {
1662 }
1663 
1665 {
1666  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1667  assert(reader.getElementLocalName() == "simpleContent");
1668 
1669  std::auto_ptr<te::xsd::SimpleContent> sc(new te::xsd::SimpleContent);
1670 
1671  // Id
1672  ReadIdentifiable(sc.get(), reader);
1673 
1674  reader.next();
1675 
1676  // Grammar: (annotation?,(restriction|extension))
1677 
1678  // Annotation
1679  ReadAnnotated(sc.get(), reader);
1680 
1681  if(reader.getElementLocalName() == "restriction")
1682  sc->setTypeDerivation(ReadRestriction4SimpleContent(reader));
1683  else if(reader.getElementLocalName() == "extension")
1684  sc->setTypeDerivation(ReadExtension(reader));
1685  else throw; // TODO: Add an exception here...
1686 
1687  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1688  reader.next();
1689 
1690  return sc.release();
1691 }
1692 
1694 {
1695 }
1696 
1698 {
1699  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1700  assert(reader.getElementLocalName() == "simpleType");
1701 
1702  std::auto_ptr<te::xsd::SimpleType> st(new te::xsd::SimpleType);
1703 
1704  // Id
1705  ReadIdentifiable(st.get(), reader);
1706 
1707  // Name
1708  std::size_t pos = reader.getAttrPosition("name");
1709  if(pos != std::string::npos)
1710  st->setName(new std::string(reader.getAttr(pos)));
1711 
1712  reader.next();
1713 
1714  // Grammar: (annotation?,(restriction|list|union))
1715 
1716  // Annotation
1717  ReadAnnotated(st.get(), reader);
1718 
1719  if(reader.getElementLocalName() == "restriction")
1720  st->setConstructor(ReadRestriction4SimpleType(reader));
1721  else if(reader.getElementLocalName() == "list")
1722  st->setConstructor(ReadList(reader));
1723  else if(reader.getElementLocalName() == "union")
1724  st->setConstructor(ReadUnion(reader));
1725  else throw; // TODO: Add an exception here...
1726 
1727  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1728  reader.next();
1729 
1730  return st.release();
1731 }
1732 
1734 {
1735 }
1736 
1738 {
1739  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1740  assert(reader.getElementLocalName() == "union");
1741 
1742  std::auto_ptr<te::xsd::Union> u(new te::xsd::Union);
1743 
1744  // Id
1745  ReadIdentifiable(u.get(), reader);
1746 
1747  // Member Types (List of QNames)
1748  std::size_t pos = reader.getAttrPosition("memberTypes");
1749  if(pos != std::string::npos)
1750  {
1751  std::string value = reader.getAttr(pos);
1752  std::vector<std::string> tokens;
1753  te::common::Tokenize(value, tokens, " ");
1754  for(std::size_t i = 0; i < tokens.size(); ++i)
1755  u->addMemberType(CreateQName(tokens[i]));
1756  }
1757 
1758  reader.next();
1759 
1760  // Grammar: (annotation?, (simpleType*))
1761 
1762  // Annotation
1763  ReadAnnotated(u.get(), reader);
1764 
1765  // SimpleTypes
1766  while(reader.getNodeType() == te::xml::START_ELEMENT && (reader.getElementLocalName() == "simpleType"))
1767  u->addSimpleType(ReadSimpleType(reader));
1768 
1769  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1770  reader.next();
1771 
1772  return u.release();
1773 }
1774 
1776 {
1777 }
1778 
1780 {
1781  assert(reader.getNodeType() == te::xml::START_ELEMENT);
1782  assert(reader.getElementLocalName() == "unique");
1783 
1784  std::auto_ptr<te::xsd::Unique> unique(new te::xsd::Unique(0));
1785 
1786  // Id
1787  ReadIdentifiable(unique.get(), reader);
1788 
1789  // Name
1790  std::size_t pos = reader.getAttrPosition("name");
1791  assert(pos != std::string::npos);
1792  unique->setName(new std::string(reader.getAttr(pos)));
1793 
1794  reader.next();
1795 
1796  // Grammar: (annotation?,(selector,field+))
1797 
1798  // Annotation
1799  ReadAnnotated(unique.get(), reader);
1800 
1801  // Selector
1802  if(reader.getElementLocalName() == "selector")
1803  {
1804  unique->setSelector(ReadSelector(reader));
1805  return unique.release();
1806  }
1807 
1808  // Fields
1809  while(reader.getNodeType() == te::xml::START_ELEMENT && reader.getElementLocalName() == "field")
1810  unique->addField(ReadField(reader));
1811 
1812  assert(reader.getNodeType() == te::xml::END_ELEMENT);
1813  reader.next();
1814 
1815  return unique.release();
1816 }
1817 
1819 {
1820 }
1821 
1823 {
1824  assert(identifiable);
1825 
1826  std::size_t pos = reader.getAttrPosition("id");
1827  if(pos != std::string::npos)
1828  identifiable->setId(new std::string(reader.getAttr(pos)));
1829 }
1830 
1832 {
1833  assert(annotated);
1834 
1835  if((reader.getNodeType() != te::xml::START_ELEMENT) ||
1836  (reader.getElementLocalName() != "annotation"))
1837  return;
1838 
1839  te::xsd::Annotation* annotation = ReadAnnotation(reader);
1840  annotated->setAnnotation(annotation);
1841 }
1842 
1844 {
1845  assert(occurs);
1846 
1847  // MinOccurs
1848  std::size_t pos = reader.getAttrPosition("minOccurs");
1849  if(pos != std::string::npos)
1850  occurs->setMinOccurs(static_cast<unsigned int>(reader.getAttrAsInt32(pos)));
1851 
1852  // MaxOccurs
1853  pos = reader.getAttrPosition("maxOccurs");
1854  if(pos != std::string::npos)
1855  reader.getAttr(pos) == "unbounded" ? occurs->setMaxOccurs(te::xsd::Occurs::unbounded) : occurs->setMaxOccurs(reader.getAttrAsInt32(pos));
1856 }
1857 
1859 {
1860  std::vector<std::string> tokens;
1861  te::common::Tokenize(name, tokens, ":");
1862  assert(tokens.size() >= 2);
1863 
1864  return new te::xsd::QName(tokens[0], tokens[1]);
1865 }
1866 
1868 {
1869  if(name == "minExclusive")
1870  return te::xsd::MinExclusive;
1871  if(name == "minInclusive")
1872  return te::xsd::MinInclusive;
1873  if(name == "maxExclusive")
1874  return te::xsd::MaxExclusive;
1875  if(name == "maxInclusive")
1876  return te::xsd::MaxInclusive;
1877  if(name == "totalDigits")
1878  return te::xsd::TotalDigits;
1879  if(name == "fractionDigits")
1880  return te::xsd::FractionDigits;
1881  if(name == "length")
1882  return te::xsd::Length;
1883  if(name == "minLength")
1884  return te::xsd::MinLength;
1885  if(name == "maxLength")
1886  return te::xsd::MaxLength;
1887  if(name == "enumeration")
1888  return te::xsd::Enumeration;
1889  if(name == "whiteSpace")
1890  return te::xsd::WhiteSpace;
1891 
1892  return te::xsd::Pattern;
1893 }
1894 
1895 //#endif
void setId(std::string *id)
it sets the id.
Specifies the lower bounds for numeric values. (>=)
Definition: Enums.h:100
TEXSDEXPORT void Save(All *all, te::xml::AbstractWriter &writer)
TEXSDEXPORT Element * ReadElement(te::xml::Reader &reader)
virtual std::size_t getAttrPosition(const std::string &name) const =0
It returns the attribute position.
TEXSDEXPORT AttributeGroup * ReadAttributeGroup(te::xml::Reader &reader)
AttributeUse
It specifies how the attribute is used.
Definition: Enums.h:69
TEXSDEXPORT Include * ReadInclude(te::xml::Reader &reader)
It models an XML Schema complexContent element.
Specifies the maximum number of characters or list items allowed.
Definition: Enums.h:98
static const unsigned int unbounded
Identifer for "unbounded" max values.
Definition: Occurs.h:108
This class models a XML reader object.
Definition: Reader.h:55
TEXSDEXPORT Extension * ReadExtension(te::xml::Reader &reader)
This class models an object that specifies information to be used by applications.
Definition: AppInfo.h:48
void ReadOccurs(Occurs *occurs, te::xml::Reader &reader)
This class models an XML Schema all element.
Definition: All.h:54
A base class for XSD classes that may allow annotation.
Definition: Annotated.h:49
TEXSDEXPORT AnyAttribute * ReadAnyAttribute(te::xml::Reader &reader)
A base class for XSD classes that have occurs attributes.
Definition: Occurs.h:43
TEXSDEXPORT Unique * ReadUnique(te::xml::Reader &reader)
The restriction class can be used to define restrictions on a complexContent.
TEXSDEXPORT ComplexContent * ReadComplexContent(te::xml::Reader &reader)
A class that models a XML schema (XSD).
Definition: Schema.h:63
TEXSDEXPORT Group * ReadGroup(te::xml::Reader &reader)
virtual void getNamespace(std::size_t i, std::pair< std::string, std::string > &ns) const =0
TEXSDEXPORT Sequence * ReadSequence(te::xml::Reader &reader)
It models a XML Schema import.
Definition: Import.h:47
Defines the exact sequence of characters that are acceptable.
Definition: Enums.h:102
TEXSDEXPORT List * ReadList(te::xml::Reader &reader)
This class models the element of a XML Schema.
Definition: Element.h:56
TEXSDEXPORT Any * ReadAny(te::xml::Reader &reader)
Specifies the exact number of characters or list items allowed.
Definition: Enums.h:95
It models a XML Schema include.
Definition: Include.h:46
This class models a sequence element in a XML Schema.
Definition: Sequence.h:58
TEXSDEXPORT Field * ReadField(te::xml::Reader &reader)
void setMinOccurs(unsigned int minOccurs)
It sets the minOccurs value.
Definition: Occurs.cpp:45
static te::xml::Reader * make()
It creates a new XML reader using the dafault implementation.
TEXSDEXPORT SimpleType * ReadSimpleType(te::xml::Reader &reader)
This class models a XML writer object.
TEXSDEXPORT Restriction4SimpleContent * ReadRestriction4SimpleContent(te::xml::Reader &reader)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
void setSource(std::string *source)
It sets the URI reference that specifies the source of the information.
It indicates that the attribute use is required.
Definition: Enums.h:71
It models the unique element in an XML Schema.
Definition: Unique.h:43
The XML processor does not attempt to validate any elements from the specified namespaces.
Definition: Enums.h:127
It models the XML Schema any element.
Definition: Any.h:49
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
virtual boost::int32_t getAttrAsInt32(const std::string &name) const
It returns the attribute value in the case of an element node with valid attributes.
Definition: Reader.cpp:49
void setMaxOccurs(unsigned int maxOccurs)
It sets the maxOccurs value.
Definition: Occurs.cpp:50
void setLang(std::string *lang)
It sets the language of the information.
It indicates that the attribute attribute must be qualified with the namespace prefix and the no-colo...
Definition: Enums.h:114
It models a XML Schema redefine.
Definition: Redefine.h:52
It is used to define a simple type element as a list of values.
Definition: List.h:45
TEXSDEXPORT Restriction4ComplexContent * ReadRestriction4ComplexContent(te::xml::Reader &reader)
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Definition: StringUtils.h:216
Specifies the upper bounds for numeric values. (<)
Definition: Enums.h:96
TEXSDEXPORT Schema * ReadSchema(const std::string &path)
This class models a key element from an XML Schema.
Definition: Key.h:43
It models an XML anyAttribute element.
Definition: AnyAttribute.h:49
This restriction class defines restrictions on a simpleContent.
TEXSDEXPORT Redefine * ReadRedefine(te::xml::Reader &reader)
A class that models a documentation element used to enter text comments in annotations.
Definition: Documentation.h:48
void setValue(std::string *doc)
It sets the information associated to the annotation.
It models a XML Schema Complex Type definition.
Definition: ComplexType.h:56
void ReadIdentifiable(Identifiable *identifiable, te::xml::Reader &reader)
A base class for XSD classes that must provide a unique ID property.
Definition: Identifiable.h:46
This class models the XML Schema choice element.
Definition: Choice.h:57
It models a XML Schema attribute.
Definition: Attribute.h:61
ProcessContents
It enumerates the possible ways that the XML processor should handle validation against the elements ...
Definition: Enums.h:123
QName * CreateQName(const std::string &name)
Specifies the minimum number of characters or list items allowed.
Definition: Enums.h:101
It models the field element of an XML Schema.
Definition: Field.h:47
It indicates that the attribute cannot be used.
Definition: Enums.h:73
It indicates that the attribute use is optional. This is the default.
Definition: Enums.h:72
TEXSDEXPORT Selector * ReadSelector(te::xml::Reader &reader)
void ReadAnnotated(Annotated *annotated, te::xml::Reader &reader)
TEXSDEXPORT Key * ReadKey(te::xml::Reader &reader)
It models the selector element of an XML Schema.
Definition: Selector.h:44
Specifies the lower bounds for numeric values. (>)
Definition: Enums.h:99
void setAnnotation(Annotation *ann)
It sets the associated annotation.
Definition: Annotated.cpp:35
virtual std::size_t getNumberOfNamespaces() const =0
virtual std::string getAttr(const std::string &name) const =0
It returns the attribute value in the case of an element node with valid attributes.
The XML processor must obtain the schema for the required namespaces and validate the elements (this ...
Definition: Enums.h:125
Specifies how white space (line feeds, tabs, spaces and carriage returns) is handled.
Definition: Enums.h:104
TEXSDEXPORT Import * ReadImport(te::xml::Reader &reader)
void setValue(std::string *value)
It sets the information to be used by the application.
Definition: AppInfo.cpp:65
Specifies the maximum number of digits allowed.
Definition: Enums.h:103
Same as strict but; if the schema cannot be obtained, no errors will occur.
Definition: Enums.h:126
TEXSDEXPORT Attribute * ReadAttribute(te::xml::Reader &reader)
TEXSDEXPORT All * ReadAll(te::xml::Reader &reader)
This class models an extension element that can be used to extend an existing simpleType or complexTy...
Definition: Extension.h:52
TEXSDEXPORT Choice * ReadChoice(te::xml::Reader &reader)
A class to be used to represent XML qualified names.
Definition: QName.h:49
virtual NodeType getNodeType() const =0
It return the type of node read.
This class models a keyref element from a XML Schema element.
Definition: KeyRef.h:46
virtual std::string getElementValue() const =0
It returns the element data value in the case of VALUE node.
Specifies the upper bounds for numeric values. (<=)
Definition: Enums.h:97
A class that models an XML Schema simpleContent element.
Definition: SimpleContent.h:50
It defines a simple type as a collection (union) of values from specified simple data types...
Definition: Union.h:50
It indicates that the attribute attribute is not required to be qualified with the namespace prefix a...
Definition: Enums.h:115
FacetType
It enumerates the available facet types.
Definition: Enums.h:91
The restriction element defines restrictions on a simpleType definition.
void setSource(std::string *source)
It sets the URI that specifies the source of the information.
Definition: AppInfo.cpp:71
TEXSDEXPORT SimpleContent * ReadSimpleContent(te::xml::Reader &reader)
TEXSDEXPORT ComplexType * ReadComplexType(te::xml::Reader &reader)
TEXSDEXPORT Union * ReadUnion(te::xml::Reader &reader)
A class that models a XSD annotation element.
Definition: Annotation.h:55
TEXSDEXPORT Restriction4SimpleType * ReadRestriction4SimpleType(te::xml::Reader &reader)
virtual bool next()=0
It gets the next event to be read.
It models a XML Schema SimpleType element.
Definition: SimpleType.h:54
TEXSDEXPORT KeyRef * ReadKeyRef(te::xml::Reader &reader)
FacetType GetFacetType(const std::string &name)
Defines a list of acceptable values.
Definition: Enums.h:93
This class models a group element in a XML Schema.
Definition: Group.h:52
TEXSDEXPORT Annotation * ReadAnnotation(te::xml::Reader &reader)
Specifies the maximum number of decimal places allowed.
Definition: Enums.h:94