All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Union.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/Union.cpp
22 
23  \brief Support for Union serialization.
24 */
25 
26 // TerraLib
27 #include "../../common/StringUtils.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "../../xsd/Union.h"
31 #include "Annotation.h"
32 #include "Union.h"
33 #include "SimpleType.h"
34 #include "Utils.h"
35 
36 // STL
37 #include <cassert>
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
43 {
44  assert(reader.getNodeType() == te::xml::START_ELEMENT);
45  assert(reader.getElementLocalName() == "union");
46 
47  std::auto_ptr<te::xsd::Union> u(new te::xsd::Union);
48 
49  // Id
50  ReadIdentifiable(u.get(), reader);
51 
52  // Member Types (List of QNames)
53  std::size_t pos = reader.getAttrPosition("memberTypes");
54  if(pos != std::string::npos)
55  {
56  std::string value = reader.getAttr(pos);
57  std::vector<std::string> tokens;
58  te::common::Tokenize(value, tokens, " ");
59  for(std::size_t i = 0; i < tokens.size(); ++i)
60  u->addMemberType(CreateQName(tokens[i]));
61  }
62 
63  reader.next();
64 
65  // Grammar: (annotation?, (simpleType*))
66 
67  // Annotation
68  ReadAnnotated(u.get(), reader);
69 
70  // SimpleTypes
71  while(reader.getNodeType() == te::xml::START_ELEMENT && (reader.getElementLocalName() == "simpleType"))
72  u->addSimpleType(ReadSimpleType(reader));
73 
74  assert(reader.getNodeType() == te::xml::END_ELEMENT);
75  reader.next();
76 
77  return u.release();
78 }
79 
81 {
82 }
It defines a simple type as a collection (union) of values from specified simple data types...
Definition: Union.h:50
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.
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
Support for Annotation serialization.
Support for SimpleType serialization.
te::xsd::QName * CreateQName(const std::string &name)
Definition: Utils.cpp:77
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
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