All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Choice.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2011 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/serialization/se/Choice.cpp
22 
23  \brief Support for Choice serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/Choice.h"
30 #include "../../xsd/Group.h"
31 #include "../../xsd/Sequence.h"
32 #include "Any.h"
33 #include "Choice.h"
34 #include "Element.h"
35 #include "Group.h"
36 #include "Sequence.h"
37 #include "Utils.h"
38 
39 // STL
40 #include <cassert>
41 #include <memory>
42 #include <set>
43 #include <string>
44 
46 {
47  assert(reader.getNodeType() == te::xml::START_ELEMENT);
48  assert(reader.getElementLocalName() == "choice");
49 
50  std::auto_ptr<te::xsd::Choice> choice(new te::xsd::Choice);
51 
52  // Id
53  ReadIdentifiable(choice.get(), reader);
54 
55  // MinOccurs and MaxOccurs
56  ReadOccurs(choice.get(), reader);
57 
58  reader.next();
59 
60  // Grammar: (annotation?,(element|group|choice|sequence|any)*)
61 
62  // Annotation
63  ReadAnnotated(choice.get(), reader);
64 
65  std::set<std::string> children;
66  children.insert("element");
67  children.insert("group");
68  children.insert("choice");
69  children.insert("sequence");
70  children.insert("any");
71 
72  std::set<std::string>::iterator it;
73  while(reader.getNodeType() == te::xml::START_ELEMENT &&
74  (it = children.find(reader.getElementLocalName())) != children.end())
75  {
76  std::string tag = *it;
77  if(tag == "element")
78  {
79  choice->addElement(ReadElement(reader));
80  continue;
81  }
82 
83  if(tag == "group")
84  {
85  choice->addContent(ReadGroup(reader));
86  continue;
87  }
88 
89  if(tag == "choice")
90  {
91  choice->addContent(ReadChoice(reader));
92  continue;
93  }
94 
95  if(tag == "sequence")
96  {
97  choice->addContent(ReadSequence(reader));
98  continue;
99  }
100 
101  if(tag == "any")
102  choice->addAny(ReadAny(reader));
103  }
104 
105  assert(reader.getNodeType() == te::xml::END_ELEMENT);
106  reader.next();
107 
108  return choice.release();
109 }
110 
112 {
113 }
TESERIALIZATIONEXPORT te::xsd::Sequence * ReadSequence(te::xml::Reader &reader)
Definition: Sequence.cpp:45
This class models a XML reader object.
Definition: Reader.h:55
virtual bool next()=0
It gets the next event to be read.
void ReadAnnotated(te::xsd::Annotated *annotated, te::xml::Reader &reader)
Definition: Utils.cpp:50
TESERIALIZATIONEXPORT te::xsd::Element * ReadElement(te::xml::Reader &reader)
Definition: Element.cpp:50
Support for Any serialization.
TESERIALIZATIONEXPORT te::xsd::Choice * ReadChoice(te::xml::Reader &reader)
Definition: Choice.cpp:45
TESERIALIZATIONEXPORT te::xsd::Group * ReadGroup(te::xml::Reader &reader)
Definition: Group.cpp:43
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
void ReadIdentifiable(te::xsd::Identifiable *identifiable, te::xml::Reader &reader)
Definition: Utils.cpp:41
void ReadOccurs(te::xsd::Occurs *occurs, te::xml::Reader &reader)
Definition: Utils.cpp:62
Support for Choice serialization.
Utility methods for Schema serialization.
Support for Sequence serialization.
This class models the XML Schema choice element.
Definition: Choice.h:57
virtual NodeType getNodeType() const =0
It return the type of node read.
Support for Element serialization.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
TESERIALIZATIONEXPORT te::xsd::Any * ReadAny(te::xml::Reader &reader)
Definition: Any.cpp:38
Support for Group serialization.
This class models a XML writer object.
Definition: Writer.h:52