All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Attribute.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/Attribute.cpp
22 
23  \brief Support for Attribute serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/Attribute.h"
30 #include "Attribute.h"
31 #include "SimpleType.h"
32 #include "Utils.h"
33 
34 // STL
35 #include <cassert>
36 #include <memory>
37 #include <string>
38 
40 {
41  assert(reader.getNodeType() == te::xml::START_ELEMENT);
42  assert(reader.getElementLocalName() == "attribute");
43 
44  std::auto_ptr<te::xsd::Attribute> attribute(new te::xsd::Attribute);
45 
46  // Id
47  ReadIdentifiable(attribute.get(), reader);
48 
49  // Default
50  std::size_t pos = reader.getAttrPosition("default");
51  if(pos != std::string::npos)
52  attribute->setDefault(new std::string(reader.getAttr(pos)));
53 
54  // Fixed
55  pos = reader.getAttrPosition("fixed");
56  if(pos != std::string::npos)
57  attribute->setFixed(new std::string(reader.getAttr(pos)));
58 
59  // Form
60  pos = reader.getAttrPosition("Form");
61  if(pos != std::string::npos)
62  attribute->setForm(reader.getAttr(pos) == "qualified" ? te::xsd::Qualified : te::xsd::Unqualified);
63 
64  // Name
65  pos = reader.getAttrPosition("name");
66  if(pos != std::string::npos)
67  attribute->setName(new std::string(reader.getAttr(pos)));
68 
69  // Ref
70  pos = reader.getAttrPosition("ref");
71  if(pos != std::string::npos)
72  attribute->setRef(CreateQName(reader.getAttr(pos)));
73 
74  // Type
75  pos = reader.getAttrPosition("type");
76  if(pos != std::string::npos)
77  attribute->setType(CreateQName(reader.getAttr(pos)));
78 
79  // Use
80  pos = reader.getAttrPosition("use");
81  if(pos != std::string::npos)
82  {
83  std::string value = reader.getAttr(pos);
85  value == "prohibited" ? use = te::xsd::PROHIBITED : use = te::xsd::REQUIRED;
86  attribute->setUse(use);
87  }
88 
89  reader.next();
90 
91  // Grammar: (annotation?,(simpleType?))
92 
93  // Annotation
94  ReadAnnotated(attribute.get(), reader);
95 
96  // Simple Type
97  if(reader.getElementLocalName() == "simpleType")
98  attribute->setInnerType(ReadSimpleType(reader));
99 
100  assert(reader.getNodeType() == te::xml::END_ELEMENT);
101  reader.next();
102 
103  return attribute.release();
104 }
105 
107 {
108 }
It indicates that the attribute attribute is not required to be qualified with the namespace prefix a...
Definition: Enums.h:115
It indicates that the attribute cannot be used.
Definition: Enums.h:73
It indicates that the attribute use is required.
Definition: Enums.h:71
It indicates that the attribute attribute must be qualified with the namespace prefix and the no-colo...
Definition: Enums.h:114
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
It models a XML Schema attribute.
Definition: Attribute.h:61
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
AttributeUse
It specifies how the attribute is used.
Definition: Enums.h:69
It indicates that the attribute use is optional. This is the default.
Definition: Enums.h:72
Utility methods for Schema serialization.
virtual NodeType getNodeType() const =0
It return the type of node read.
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