All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Redefine.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/Redefine.cpp
22 
23  \brief Support for Redefine serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/ComplexType.h"
30 #include "../../xsd/Redefine.h"
31 #include "../../xsd/SimpleType.h"
32 #include "Annotation.h"
33 #include "AttributeGroup.h"
34 #include "ComplexType.h"
35 #include "Group.h"
36 #include "Redefine.h"
37 #include "SimpleType.h"
38 #include "Utils.h"
39 
40 // STL
41 #include <cassert>
42 #include <memory>
43 #include <set>
44 #include <string>
45 
47 {
48  assert(reader.getNodeType() == te::xml::START_ELEMENT);
49  assert(reader.getElementLocalName() == "redefine");
50 
51  std::auto_ptr<te::xsd::Redefine> redefine(new te::xsd::Redefine(""));
52 
53  // Id
54  ReadIdentifiable(redefine.get(), reader);
55 
56  // SchemaLocation
57  std::size_t pos = reader.getAttrPosition("schemaLocation");
58  if(pos != std::string::npos)
59  redefine->setSchemaLocation(reader.getAttr(pos));
60 
61  reader.next();
62 
63  // Grammar: (annotation|(simpleType|complexType|group|attributeGroup))*
64 
65  std::set<std::string> children;
66  children.insert("annotation");
67  children.insert("simpleType");
68  children.insert("complexType");
69  children.insert("group");
70  children.insert("attributeGroup");
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 == "annotation")
78  {
79  redefine->addAnnotation(ReadAnnotation(reader));
80  continue;
81  }
82 
83  if(tag == "simpleType")
84  {
85  redefine->addType(ReadSimpleType(reader));
86  continue;
87  }
88 
89  if(tag == "complexType")
90  {
91  redefine->addType(ReadComplexType(reader));
92  continue;
93  }
94 
95  if(tag == "group")
96  {
97  redefine->addGroup(ReadGroup(reader));
98  continue;
99  }
100 
101  if(tag == "attributeGroup")
102  redefine->addAttributeGroup(ReadAttributeGroup(reader));
103  }
104 
105  assert(reader.getNodeType() == te::xml::END_ELEMENT);
106  reader.next();
107 
108  return redefine.release();
109 }
110 
112 {
113 }
This class models a XML reader object.
Definition: Reader.h:55
virtual bool next()=0
It gets the next event to be read.
TESERIALIZATIONEXPORT te::xsd::Annotation * ReadAnnotation(te::xml::Reader &reader)
Definition: Annotation.cpp:40
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
It models a XML Schema redefine.
Definition: Redefine.h:52
Support for Annotation serialization.
TESERIALIZATIONEXPORT te::xsd::Redefine * ReadRedefine(te::xml::Reader &reader)
Definition: Redefine.cpp:46
Support for SimpleType serialization.
TESERIALIZATIONEXPORT te::xsd::ComplexType * ReadComplexType(te::xml::Reader &reader)
Definition: ComplexType.cpp:54
Utility methods for Schema 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.
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.
Support for Redefine serialization.
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