All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ComplexType.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/ComplexType.cpp
22 
23  \brief Support for ComplexType serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/All.h"
30 #include "../../xsd/Attribute.h"
31 #include "../../xsd/AttributeGroup.h"
32 #include "../../xsd/Choice.h"
33 #include "../../xsd/ComplexType.h"
34 #include "../../xsd/Group.h"
35 #include "../../xsd/Sequence.h"
36 #include "All.h"
37 #include "AnyAttribute.h"
38 #include "Attribute.h"
39 #include "AttributeGroup.h"
40 #include "Choice.h"
41 #include "ComplexContent.h"
42 #include "ComplexType.h"
43 #include "Group.h"
44 #include "Sequence.h"
45 #include "SimpleContent.h"
46 #include "Utils.h"
47 
48 // STL
49 #include <cassert>
50 #include <memory>
51 #include <set>
52 #include <string>
53 
55 {
56  assert(reader.getNodeType() == te::xml::START_ELEMENT);
57  assert(reader.getElementLocalName() == "complexType");
58 
59  std::auto_ptr<te::xsd::ComplexType> ct(new te::xsd::ComplexType);
60 
61  // Id
62  ReadIdentifiable(ct.get(), reader);
63 
64  // Name
65  std::size_t pos = reader.getAttrPosition("name");
66  if(pos != std::string::npos)
67  ct->setName(new std::string(reader.getAttr(pos)));
68 
69  // Abstract
70  pos = reader.getAttrPosition("abstract");
71  if(pos != std::string::npos)
72  ct->setAsAbstract(reader.getAttr(pos) == "true" ? true : false);
73 
74  // Mixed
75  pos = reader.getAttrPosition("mixed");
76  if(pos != std::string::npos)
77  ct->setAsMixed(reader.getAttr(pos) == "true" ? true : false);
78 
79  // TODO: Block and Final ?
80 
81  reader.next();
82 
83  /* Grammar: (annotation?,(simpleContent|complexContent|((group|all|
84  choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?)))) */
85 
86  // Annotation
87  ReadAnnotated(ct.get(), reader);
88 
89  std::set<std::string> children;
90  children.insert("simpleContent");
91  children.insert("complexContent");
92  children.insert("group");
93  children.insert("all");
94  children.insert("choice");
95  children.insert("sequence");
96  children.insert("attribute");
97  children.insert("attributeGroup");
98  children.insert("anyAttribute");
99 
100  std::set<std::string>::iterator it;
101  while(reader.getNodeType() == te::xml::START_ELEMENT &&
102  (it = children.find(reader.getElementLocalName())) != children.end())
103  {
104  std::string tag = *it;
105  if(tag == "simpleContent")
106  {
107  ct->setSimpleContent(ReadSimpleContent(reader));
108  continue;
109  }
110 
111  if(tag == "complexContent")
112  {
113  ct->setComplexContent(ReadComplexContent(reader));
114  continue;
115  }
116 
117  if(tag == "group")
118  {
119  ct->setContent(ReadGroup(reader));
120  continue;
121  }
122 
123  if(tag == "all")
124  {
125  ct->setContent(ReadAll(reader));
126  continue;
127  }
128 
129  if(tag == "choice")
130  {
131  ct->setContent(ReadChoice(reader));
132  continue;
133  }
134 
135  if(tag == "sequence")
136  {
137  ct->setContent(ReadSequence(reader));
138  continue;
139  }
140 
141  if(tag == "attribute")
142  {
143  ct->addAttribute(ReadAttribute(reader));
144  continue;
145  }
146 
147  if(tag == "attributeGroup")
148  {
149  ct->addAttribute(ReadAttributeGroup(reader));
150  continue;
151  }
152 
153  if(tag == "anyAttribute")
154  ct->setAnyAttribute(ReadAnyAttribute(reader));
155  }
156 
157  assert(reader.getNodeType() == te::xml::END_ELEMENT);
158  reader.next();
159 
160  return ct.release();
161 }
162 
164 {
165 }
TESERIALIZATIONEXPORT te::xsd::SimpleContent * ReadSimpleContent(te::xml::Reader &reader)
TESERIALIZATIONEXPORT te::xsd::Sequence * ReadSequence(te::xml::Reader &reader)
Definition: Sequence.cpp:45
This class models a XML reader object.
Definition: Reader.h:55
Support for SimpleContent serialization.
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
It models a XML Schema Complex Type definition.
Definition: ComplexType.h:56
TESERIALIZATIONEXPORT te::xsd::ComplexContent * ReadComplexContent(te::xml::Reader &reader)
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 te::xsd::AnyAttribute * ReadAnyAttribute(te::xml::Reader &reader)
Support for ComplexContent serialization.
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
Support for Attribute serialization.
TESERIALIZATIONEXPORT te::xsd::Attribute * ReadAttribute(te::xml::Reader &reader)
Definition: Attribute.cpp:39
TESERIALIZATIONEXPORT te::xsd::ComplexType * ReadComplexType(te::xml::Reader &reader)
Definition: ComplexType.cpp:54
Support for Choice serialization.
Support for AnyAttribute serialization.
Support for All serialization.
Utility methods for Schema serialization.
TESERIALIZATIONEXPORT te::xsd::All * ReadAll(te::xml::Reader &reader)
Definition: All.cpp:38
Support for Sequence serialization.
Support for ComplexType serialization.
virtual NodeType getNodeType() const =0
It return the type of node read.
TESERIALIZATIONEXPORT te::xsd::AttributeGroup * ReadAttributeGroup(te::xml::Reader &reader)
Support for AttributeGroup serialization.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
virtual std::size_t getAttrPosition(const std::string &name) const =0
It returns the attribute position.
Support for Group serialization.
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.
This class models a XML writer object.
Definition: Writer.h:52