All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Restriction4SimpleType.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/Restriction4SimpleType.cpp
22 
23  \brief Support for Restriction on a simpleType serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/SimpleTypeConstructor.h"
30 #include "../../xsd/Restriction4SimpleType.h"
31 #include "Restriction4SimpleType.h"
32 #include "SimpleType.h"
33 #include "Utils.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 #include <set>
39 #include <string>
40 
42 {
43  assert(reader.getNodeType() == te::xml::START_ELEMENT);
44  assert(reader.getElementLocalName() == "restriction");
45 
46  std::auto_ptr<te::xsd::Restriction4SimpleType> restriction(new te::xsd::Restriction4SimpleType);
47 
48  // Id
49  ReadIdentifiable(restriction.get(), reader);
50 
51  // Base
52  std::size_t pos = reader.getAttrPosition("base");
53  if(pos != std::string::npos)
54  restriction->setBase(CreateQName(reader.getAttr(pos)));
55 
56  reader.next();
57 
58  /* Grammar: (annotation?,(simpleType?,(minExclusive|minInclusive|maxExclusive|maxInclusive|
59  totalDigits|fractionDigits|length|minLength|maxLength|enumeration|whiteSpace|pattern)*)) */
60 
61  std::set<std::string> children;
62  children.insert("minExclusive");
63  children.insert("minInclusive");
64  children.insert("maxExclusive");
65  children.insert("maxInclusive");
66  children.insert("totalDigits");
67  children.insert("fractionDigits");
68  children.insert("length");
69  children.insert("minLength");
70  children.insert("maxLength");
71  children.insert("enumeration");
72  children.insert("whiteSpace");
73  children.insert("pattern");
74 
75  // Annotation
76  ReadAnnotated(restriction.get(), reader);
77 
78  // Simple Type
79  if(reader.getElementLocalName() == "simpleType")
80  restriction->setSimpleType(ReadSimpleType(reader));
81 
82  std::set<std::string>::iterator it;
83  while(reader.getNodeType() == te::xml::START_ELEMENT &&
84  (it = children.find(reader.getElementLocalName())) != children.end())
85  {
86  // Facet
87  pos = reader.getAttrPosition("value");
88  assert(pos != std::string::npos);
89  restriction->addFacet(GetFacetType(*it), reader.getAttr(pos));
90 
91  reader.next();
92  assert(reader.getNodeType() == te::xml::END_ELEMENT); // End of Facet
93 
94  reader.next();
95  }
96 
97  assert(reader.getNodeType() == te::xml::END_ELEMENT);
98  reader.next();
99 
100  return restriction.release();
101 }
102 
104 {
105 }
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 SimpleType serialization.
te::xsd::QName * CreateQName(const std::string &name)
Definition: Utils.cpp:77
TESERIALIZATIONEXPORT te::xsd::Restriction4SimpleType * ReadRestriction4SimpleType(te::xml::Reader &reader)
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.
The restriction element defines restrictions on a simpleType definition.
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
Support for Restriction on a simpleType serialization.
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