All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Extension.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/Extension.cpp
22 
23  \brief Support for Extension 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/Extension.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 "Extension.h"
42 #include "Group.h"
43 #include "Sequence.h"
44 #include "Utils.h"
45 
46 // STL
47 #include <cassert>
48 #include <memory>
49 #include <set>
50 #include <string>
51 
53 {
54  assert(reader.getNodeType() == te::xml::START_ELEMENT);
55  assert(reader.getElementLocalName() == "extension");
56 
57  std::auto_ptr<te::xsd::Extension> extension(new te::xsd::Extension);
58 
59  // Id
60  ReadIdentifiable(extension.get(), reader);
61 
62  // Base
63  std::size_t pos = reader.getAttrPosition("base");
64  if(pos != std::string::npos)
65  extension->setBase(CreateQName(reader.getAttr(pos)));
66 
67  reader.next();
68 
69  /* Grammar: (annotation?,((group|all|choice|sequence)?,
70  ((attribute|attributeGroup)*,anyAttribute?))) */
71 
72  // Annotation
73  ReadAnnotated(extension.get(), reader);
74 
75  std::set<std::string> children;
76  children.insert("group");
77  children.insert("all");
78  children.insert("choice");
79  children.insert("sequence");
80  children.insert("attribute");
81  children.insert("attributeGroup");
82  children.insert("anyAttribute");
83 
84  std::set<std::string>::iterator it;
85  while(reader.getNodeType() == te::xml::START_ELEMENT &&
86  (it = children.find(reader.getElementLocalName())) != children.end())
87  {
88  std::string tag = *it;
89  if(tag == "group")
90  {
91  extension->setContent(ReadGroup(reader));
92  continue;
93  }
94 
95  if(tag == "all")
96  {
97  extension->setContent(ReadAll(reader));
98  continue;
99  }
100 
101  if(tag == "choice")
102  {
103  extension->setContent(ReadChoice(reader));
104  continue;
105  }
106 
107  if(tag == "sequence")
108  {
109  extension->setContent(ReadSequence(reader));
110  continue;
111  }
112 
113  if(tag == "attribute")
114  {
115  extension->addAttribute(ReadAttribute(reader));
116  continue;
117  }
118 
119  if(tag == "attributeGroup")
120  {
121  extension->addAttribute(ReadAttributeGroup(reader));
122  continue;
123  }
124 
125  if(tag == "anyAttribute")
126  extension->setAnyAttribute(ReadAnyAttribute(reader));
127  }
128 
129  assert(reader.getNodeType() == te::xml::END_ELEMENT);
130  reader.next();
131 
132  return extension.release();
133 }
134 
136 {
137 }
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 te::xsd::AnyAttribute * ReadAnyAttribute(te::xml::Reader &reader)
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.
This class models an extension element that can be used to extend an existing simpleType or complexTy...
Definition: Extension.h:52
te::xsd::QName * CreateQName(const std::string &name)
Definition: Utils.cpp:77
TESERIALIZATIONEXPORT te::xsd::Attribute * ReadAttribute(te::xml::Reader &reader)
Definition: Attribute.cpp:39
Support for Extension serialization.
Support for Choice serialization.
Support for AnyAttribute serialization.
TESERIALIZATIONEXPORT te::xsd::Extension * ReadExtension(te::xml::Reader &reader)
Definition: Extension.cpp:52
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.
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