All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Group.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/Group.cpp
22 
23  \brief Support for Group serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/All.h"
30 #include "../../xsd/Choice.h"
31 #include "../../xsd/Group.h"
32 #include "../../xsd/Sequence.h"
33 #include "All.h"
34 #include "Choice.h"
35 #include "Group.h"
36 #include "Sequence.h"
37 #include "Utils.h"
38 
39 // STL
40 #include <cassert>
41 #include <memory>
42 
44 {
45  assert(reader.getNodeType() == te::xml::START_ELEMENT);
46  assert(reader.getElementLocalName() == "group");
47 
48  std::auto_ptr<te::xsd::Group> group(new te::xsd::Group);
49 
50  // Id
51  ReadIdentifiable(group.get(), reader);
52 
53  // Name
54  std::size_t pos = reader.getAttrPosition("name");
55  if(pos != std::string::npos)
56  group->setName(new std::string(reader.getAttr(pos)));
57 
58  // Ref
59  pos = reader.getAttrPosition("ref");
60  if(pos != std::string::npos)
61  group->setRef(CreateQName(reader.getAttr(pos)));
62 
63  // MinOccurs and MaxOccurs
64  ReadOccurs(group.get(), reader);
65 
66  reader.next();
67 
68  // Grammar: (annotation?,(all|choice|sequence)?)
69 
70  // Annotation
71  ReadAnnotated(group.get(), reader);
72 
73  if(reader.getElementLocalName() == "all")
74  group->setContent(ReadAll(reader));
75  else if(reader.getElementLocalName() == "choice")
76  group->setContent(ReadChoice(reader));
77  else if(reader.getElementLocalName() == "sequence")
78  group->setContent(ReadSequence(reader));
79  else throw; // TODO: Add an exception here...
80 
81  assert(reader.getNodeType() == te::xml::END_ELEMENT);
82  reader.next();
83 
84  return group.release();
85 }
86 
88 {
89 }
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::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
te::xsd::QName * CreateQName(const std::string &name)
Definition: Utils.cpp:77
void ReadOccurs(te::xsd::Occurs *occurs, te::xml::Reader &reader)
Definition: Utils.cpp:62
Support for Choice 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.
virtual NodeType getNodeType() const =0
It return the type of node read.
This class models a group element in a XML Schema.
Definition: Group.h:52
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