All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnyAttribute.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/AnyAttribute.cpp
22 
23  \brief Support for AnyAttribute serialization.
24 */
25 
26 // TerraLib
27 #include "../../xml/Reader.h"
28 #include "../../xml/Writer.h"
29 #include "../../xsd/AnyAttribute.h"
30 #include "AnyAttribute.h"
31 #include "Utils.h"
32 
33 // STL
34 #include <cassert>
35 #include <memory>
36 #include <string>
37 
39 {
40  assert(reader.getNodeType() == te::xml::START_ELEMENT);
41  assert(reader.getElementLocalName() == "anyAttribute");
42 
43  std::auto_ptr<te::xsd::AnyAttribute> anyAttribute(new te::xsd::AnyAttribute);
44 
45  // Id
46  ReadIdentifiable(anyAttribute.get(), reader);
47 
48  // Namespace
49  std::size_t pos = reader.getAttrPosition("namespace");
50  if(pos != std::string::npos)
51  anyAttribute->setNamespace(new std::string(reader.getAttr(pos)));
52 
53  // ProcessContents
54  pos = reader.getAttrPosition("processContents");
55  if(pos != std::string::npos)
56  {
57  std::string value = reader.getAttr(pos);
59  value == "skip" ? pc = te::xsd::SKIP : pc = te::xsd::STRICT;
60  anyAttribute->setProcessContents(pc);
61  }
62 
63  reader.next();
64 
65  // Grammar: (annotation?)
66 
67  // Annotation
68  ReadAnnotated(anyAttribute.get(), reader);
69 
70  assert(reader.getNodeType() == te::xml::END_ELEMENT);
71  reader.next();
72 
73  return anyAttribute.release();
74 }
75 
77 {
78 }
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
ProcessContents
It enumerates the possible ways that the XML processor should handle validation against the elements ...
Definition: Enums.h:123
TESERIALIZATIONEXPORT te::xsd::AnyAttribute * ReadAnyAttribute(te::xml::Reader &reader)
The XML processor must obtain the schema for the required namespaces and validate the elements (this ...
Definition: Enums.h:125
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
The XML processor does not attempt to validate any elements from the specified namespaces.
Definition: Enums.h:127
void ReadIdentifiable(te::xsd::Identifiable *identifiable, te::xml::Reader &reader)
Definition: Utils.cpp:41
It models an XML anyAttribute element.
Definition: AnyAttribute.h:49
Support for AnyAttribute serialization.
Utility methods for Schema serialization.
virtual NodeType getNodeType() const =0
It return the type of node read.
Same as strict but; if the schema cannot be obtained, no errors will occur.
Definition: Enums.h:126
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.
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