All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Restriction4SimpleContent.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/Restriction4SimpleContent.cpp
22 
23  \brief Support for Restriction on a simpleContent serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/Attribute.h"
30 #include "../../xsd/AttributeGroup.h"
31 #include "../../xsd/Restriction4SimpleContent.h"
32 #include "AnyAttribute.h"
33 #include "Attribute.h"
34 #include "AttributeGroup.h"
36 #include "SimpleType.h"
37 #include "Utils.h"
38 
39 // STL
40 #include <cassert>
41 #include <memory>
42 #include <set>
43 #include <string>
44 
46 {
47  assert(reader.getNodeType() == te::xml::START_ELEMENT);
48  assert(reader.getElementLocalName() == "restriction");
49 
50  std::auto_ptr<te::xsd::Restriction4SimpleContent> restriction(new te::xsd::Restriction4SimpleContent(0, 0));
51 
52  // Id
53  ReadIdentifiable(restriction.get(), reader);
54 
55  // Base
56  std::size_t pos = reader.getAttrPosition("base");
57  if(pos != std::string::npos)
58  restriction->setBase(CreateQName(reader.getAttr(pos)));
59 
60  reader.next();
61 
62  /* Grammar: (annotation?,(simpleType?,(minExclusive |minInclusive|
63  maxExclusive|maxInclusive|totalDigits|fractionDigits|
64  length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
65  ((attribute|attributeGroup)*,anyAttribute?)) */
66 
67  std::set<std::string> children;
68  children.insert("minExclusive");
69  children.insert("minInclusive");
70  children.insert("maxExclusive");
71  children.insert("maxInclusive");
72  children.insert("totalDigits");
73  children.insert("fractionDigits");
74  children.insert("length");
75  children.insert("minLength");
76  children.insert("maxLength");
77  children.insert("enumeration");
78  children.insert("whiteSpace");
79  children.insert("pattern");
80  children.insert("attribute");
81  children.insert("attributeGroup");
82  children.insert("anyAttribute");
83 
84  // Annotation
85  ReadAnnotated(restriction.get(), reader);
86 
87  // Simple Type
88  if(reader.getElementLocalName() == "simpleType")
89  restriction->setSimpleType(ReadSimpleType(reader));
90 
91  std::set<std::string>::iterator it;
92  while(reader.getNodeType() == te::xml::START_ELEMENT &&
93  (it = children.find(reader.getElementLocalName())) != children.end())
94  {
95  std::string tag = *it;
96 
97  if(tag == "attribute")
98  {
99  restriction->addAttribute(ReadAttribute(reader));
100  continue;
101  }
102 
103  if(tag == "attributeGroup")
104  {
105  restriction->addAttribute(ReadAttributeGroup(reader));
106  continue;
107  }
108 
109  if(tag == "anyAttribute")
110  {
111  restriction->setAnyAttribute(ReadAnyAttribute(reader));
112  continue;
113  }
114 
115  // Facet
116  pos = reader.getAttrPosition("value");
117  assert(pos != std::string::npos);
118  restriction->addFacet(GetFacetType(tag), reader.getAttr(pos));
119 
120  reader.next();
121  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of Facet
122 
123  reader.next();
124  }
125 
126  assert(reader.getNodeType() == te::xml::END_ELEMENT);
127  reader.next();
128 
129  return restriction.release();
130 }
131 
133 {
134 }
Support for Restriction on a simpleContent serialization.
TESERIALIZATIONEXPORT te::xsd::Restriction4SimpleContent * ReadRestriction4SimpleContent(te::xml::Reader &reader)
This restriction class defines restrictions on a simpleContent.
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::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 SimpleType 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 AnyAttribute serialization.
Utility methods for Schema serialization.
te::xsd::FacetType GetFacetType(const std::string &name)
Definition: Utils.cpp:86
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.
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