All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleType.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/SimpleType.cpp
22 
23  \brief Support for SimpleType serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/List.h"
30 #include "../../xsd/Restriction4SimpleType.h"
31 #include "../../xsd/SimpleType.h"
32 #include "../../xsd/Union.h"
33 #include "List.h"
34 #include "SimpleType.h"
35 #include "Restriction4SimpleType.h"
36 #include "Union.h"
37 #include "Utils.h"
38 
39 // STL
40 #include <cassert>
41 #include <memory>
42 #include <string>
43 
45 {
46  assert(reader.getNodeType() == te::xml::START_ELEMENT);
47  assert(reader.getElementLocalName() == "simpleType");
48 
49  std::auto_ptr<te::xsd::SimpleType> st(new te::xsd::SimpleType);
50 
51  // Id
52  ReadIdentifiable(st.get(), reader);
53 
54  // Name
55  std::size_t pos = reader.getAttrPosition("name");
56  if(pos != std::string::npos)
57  st->setName(new std::string(reader.getAttr(pos)));
58 
59  reader.next();
60 
61  // Grammar: (annotation?,(restriction|list|union))
62 
63  // Annotation
64  ReadAnnotated(st.get(), reader);
65 
66  if(reader.getElementLocalName() == "restriction")
67  st->setConstructor(ReadRestriction4SimpleType(reader));
68  else if(reader.getElementLocalName() == "list")
69  st->setConstructor(ReadList(reader));
70  else if(reader.getElementLocalName() == "union")
71  st->setConstructor(ReadUnion(reader));
72  else throw; // TODO: Add an exception here...
73 
74  assert(reader.getNodeType() == te::xml::END_ELEMENT);
75  reader.next();
76 
77  return st.release();
78 }
79 
81 {
82 }
It models a XML Schema SimpleType element.
Definition: SimpleType.h:54
Support for List serialization.
TESERIALIZATIONEXPORT te::xsd::List * ReadList(te::xml::Reader &reader)
Definition: List.cpp:39
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 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 Union serialization.
Support for SimpleType serialization.
TESERIALIZATIONEXPORT te::xsd::Restriction4SimpleType * ReadRestriction4SimpleType(te::xml::Reader &reader)
Utility methods for Schema serialization.
TESERIALIZATIONEXPORT te::xsd::Union * ReadUnion(te::xml::Reader &reader)
Definition: Union.cpp:42
virtual NodeType getNodeType() const =0
It return the type of node read.
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::SimpleType * ReadSimpleType(te::xml::Reader &reader)
Definition: SimpleType.cpp:44
Support for Restriction on a simpleType serialization.
virtual std::size_t getAttrPosition(const std::string &name) const =0
It returns the attribute position.
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