bes  Updated for version 3.20.6
NCMLElement.h
1 // This file is part of the "NcML Module" project, a BES module designed
3 // to allow NcML files to be used to be used as a wrapper to add
4 // AIS to existing datasets of any format.
5 //
6 // Copyright (c) 2009 OPeNDAP, Inc.
7 // Author: Michael Johnson <m.johnson@opendap.org>
8 //
9 // For more information, please also see the main website: http://opendap.org/
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26 //
27 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29 #ifndef __NCML_MODULE__NCMLELEMENT_H__
30 #define __NCML_MODULE__NCMLELEMENT_H__
31 
32 #include <iostream>
33 #include "RCObject.h"
34 #include "XMLHelpers.h"
35 #include <string>
36 #include <vector>
37 
38 using agg_util::RCPtr;
39 using agg_util::RCObject;
41 
42 namespace ncml_module {
43 // FDecls
44 class NCMLParser;
45 
62 public:
63 
71  class Factory {
72  public:
73  Factory();
74  ~Factory();
75 
84  RCPtr<NCMLElement> makeElement(const std::string& eltTypeName, const XMLAttributeMap& attrs,
85  NCMLParser& parser);
86 
87  private:
88  // Interface
89 
91  void initialize();
92 
93  private:
94  // Possible prototypes we can create from. Uses getTypeName() for match.
95  typedef std::vector<const NCMLElement*> ProtoList;
96 
102  void addPrototype(const NCMLElement* proto);
103 
105  ProtoList::iterator findPrototype(const std::string& elementTypeName);
106 
107  ProtoList _protos;
108  };
109 
110 protected:
111  // Abstract: Only subclasses can create these
112  explicit NCMLElement(NCMLParser* p);
113 
114  NCMLElement(const NCMLElement& proto);
115 
116 private:
117  // Disallow assignment for now
118  NCMLElement& operator=(const NCMLElement& rhs);
119 
120 public:
121  virtual ~NCMLElement();
122 
123  void setParser(NCMLParser* p);
124 
126  int line() const;
127 
130  virtual const std::string& getTypeName() const = 0;
131 
135  virtual NCMLElement* clone() const = 0;
136 
140  virtual void setAttributes(const XMLAttributeMap& attrs) = 0;
141 
148  virtual bool validateAttributes(const XMLAttributeMap& attrs, const std::vector<std::string>& validAttrs,
149  std::vector<std::string>* pInvalidAttrs = 0, bool printInvalid = true, bool throwOnError = true);
150 
155  virtual void handleBegin() = 0;
156 
162  virtual void handleContent(const std::string& content);
163 
165  virtual void handleEnd() = 0;
166 
168  virtual std::string toString() const = 0;
169 
174  static std::string printAttributeIfNotEmpty(const std::string& attrName, const std::string& attrValue);
175 
177  static bool isValidAttribute(const std::vector<std::string>& validAttrs, const std::string& attr);
178 
182  static bool areAllAttributesValid(const XMLAttributeMap& attrMap, const std::vector<std::string>& validAttrs,
183  std::vector<std::string>* pInvalidAttributes = 0);
184 
185 protected:
186  // data rep
187  NCMLParser* _parser;
188 };
189 
190 }
191 
193 inline std::ostream &
194 operator<<(std::ostream &strm, const ncml_module::NCMLElement &obj)
195 {
196  strm << obj.toString();
197  return strm;
198 }
199 
200 #endif /* __NCML_MODULE__NCMLELEMENT_H__ */
ncml_module::NCMLElement::handleEnd
virtual void handleEnd()=0
ncml_module::NCMLElement::Factory::makeElement
RCPtr< NCMLElement > makeElement(const std::string &eltTypeName, const XMLAttributeMap &attrs, NCMLParser &parser)
Definition: NCMLElement.cc:117
ncml_module::NCMLElement::handleBegin
virtual void handleBegin()=0
ncml_module::NCMLElement::printAttributeIfNotEmpty
static std::string printAttributeIfNotEmpty(const std::string &attrName, const std::string &attrValue)
Definition: NCMLElement.cc:212
ncml_module::NCMLElement::handleContent
virtual void handleContent(const std::string &content)
Definition: NCMLElement.cc:165
ncml_module::NCMLElement::line
int line() const
Definition: NCMLElement.cc:160
ncml_module::NCMLParser
Definition: NCMLParser.h:158
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:93
agg_util::RCObject
A base class for a simple reference counted object.
Definition: RCObject.h:164
agg_util::RCObjectPool
Definition: RCObject.h:57
ncml_module::NCMLElement::Factory
Definition: NCMLElement.h:71
ncml_module::NCMLElement::areAllAttributesValid
static bool areAllAttributesValid(const XMLAttributeMap &attrMap, const std::vector< std::string > &validAttrs, std::vector< std::string > *pInvalidAttributes=0)
Definition: NCMLElement.cc:229
ncml_module::NCMLElement
Base class for NcML element concrete classes.
Definition: NCMLElement.h:61
ncml_module::NCMLElement::toString
virtual std::string toString() const =0
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
agg_util::RCPtr
A reference to an RCObject which automatically ref() and deref() on creation and destruction.
Definition: RCObject.h:284
ncml_module::NCMLElement::getTypeName
virtual const std::string & getTypeName() const =0
ncml_module::NCMLElement::clone
virtual NCMLElement * clone() const =0
ncml_module::NCMLElement::isValidAttribute
static bool isValidAttribute(const std::vector< std::string > &validAttrs, const std::string &attr)
Definition: NCMLElement.cc:217
ncml_module::NCMLElement::validateAttributes
virtual bool validateAttributes(const XMLAttributeMap &attrs, const std::vector< std::string > &validAttrs, std::vector< std::string > *pInvalidAttrs=0, bool printInvalid=true, bool throwOnError=true)
Definition: NCMLElement.cc:174
ncml_module::NCMLElement::setAttributes
virtual void setAttributes(const XMLAttributeMap &attrs)=0