All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Restriction4ComplexContent.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/Restriction4ComplexContent.cpp
22 
23  \brief Support for Restriction on a complexContent 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/Group.h"
34 #include "../../xsd/Restriction4ComplexContent.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 "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() == "restriction");
56 
57  std::auto_ptr<te::xsd::Restriction4ComplexContent> restriction(new te::xsd::Restriction4ComplexContent(0, 0));
58 
59  // Id
60  ReadIdentifiable(restriction.get(), reader);
61 
62  // Base
63  std::size_t pos = reader.getAttrPosition("base");
64  if(pos != std::string::npos)
65  restriction->setBase(CreateQName(reader.getAttr(pos)));
66 
67  reader.next();
68 
69  /* Grammar: (annotation?,(group|all|choice|sequence)?,
70  ((attribute|attributeGroup)*,anyAttribute?)) */
71 
72  std::set<std::string> children;
73  children.insert("group");
74  children.insert("all");
75  children.insert("choice");
76  children.insert("sequence");
77  children.insert("attribute");
78  children.insert("attributeGroup");
79  children.insert("anyAttribute");
80 
81  // Annotation
82  ReadAnnotated(restriction.get(), reader);
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 
90  if(tag == "group")
91  {
92  restriction->setContent(ReadGroup(reader));
93  continue;
94  }
95 
96  if(tag == "all")
97  {
98  restriction->setContent(ReadAll(reader));
99  continue;
100  }
101 
102  if(tag == "choice")
103  {
104  restriction->setContent(ReadChoice(reader));
105  continue;
106  }
107 
108  if(tag == "sequence")
109  {
110  restriction->setContent(ReadSequence(reader));
111  continue;
112  }
113 
114  if(tag == "attribute")
115  {
116  restriction->addAttribute(ReadAttribute(reader));
117  continue;
118  }
119 
120  if(tag == "attributeGroup")
121  {
122  restriction->addAttribute(ReadAttributeGroup(reader));
123  continue;
124  }
125 
126  if(tag == "anyAttribute")
127  restriction->setAnyAttribute(ReadAnyAttribute(reader));
128  }
129 
130  assert(reader.getNodeType() == te::xml::END_ELEMENT);
131  reader.next();
132 
133  return restriction.release();
134 }
135 
137 {
138 }
TESERIALIZATIONEXPORT te::xsd::Restriction4ComplexContent * ReadRestriction4ComplexContent(te::xml::Reader &reader)
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.
Support for Restriction on a complexContent serialization.
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 Choice serialization.
Support for AnyAttribute 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.
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.
The restriction class can be used to define restrictions on a complexContent.
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