bes  Updated for version 3.20.5
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 std::string;
39 using std::vector;
40 using agg_util::RCPtr;
41 using agg_util::RCObject;
43 
44 namespace ncml_module {
45 // FDecls
46 class NCMLParser;
47 
64 public:
65 
73  class Factory {
74  public:
75  Factory();
76  ~Factory();
77 
86  RCPtr<NCMLElement> makeElement(const std::string& eltTypeName, const XMLAttributeMap& attrs,
87  NCMLParser& parser);
88 
89  private:
90  // Interface
91 
93  void initialize();
94 
95  private:
96  // Possible prototypes we can create from. Uses getTypeName() for match.
97  typedef std::vector<const NCMLElement*> ProtoList;
98 
104  void addPrototype(const NCMLElement* proto);
105 
107  ProtoList::iterator findPrototype(const std::string& elementTypeName);
108 
109  ProtoList _protos;
110  };
111 
112 protected:
113  // Abstract: Only subclasses can create these
114  explicit NCMLElement(NCMLParser* p);
115 
116  NCMLElement(const NCMLElement& proto);
117 
118 private:
119  // Disallow assignment for now
120  NCMLElement& operator=(const NCMLElement& rhs);
121 
122 public:
123  virtual ~NCMLElement();
124 
125  void setParser(NCMLParser* p);
126 
128  int line() const;
129 
132  virtual const std::string& getTypeName() const = 0;
133 
137  virtual NCMLElement* clone() const = 0;
138 
142  virtual void setAttributes(const XMLAttributeMap& attrs) = 0;
143 
150  virtual bool validateAttributes(const XMLAttributeMap& attrs, const vector<string>& validAttrs,
151  vector<string>* pInvalidAttrs = 0, bool printInvalid = true, bool throwOnError = true);
152 
157  virtual void handleBegin() = 0;
158 
164  virtual void handleContent(const std::string& content);
165 
167  virtual void handleEnd() = 0;
168 
170  virtual std::string toString() const = 0;
171 
176  static std::string printAttributeIfNotEmpty(const std::string& attrName, const std::string& attrValue);
177 
179  static bool isValidAttribute(const std::vector<string>& validAttrs, const string& attr);
180 
184  static bool areAllAttributesValid(const XMLAttributeMap& attrMap, const std::vector<string>& validAttrs,
185  std::vector<string>* pInvalidAttributes = 0);
186 
187 protected:
188  // data rep
189  NCMLParser* _parser;
190 };
191 
192 }
193 
195 inline std::ostream &
196 operator<<(std::ostream &strm, const ncml_module::NCMLElement &obj)
197 {
198  strm << obj.toString();
199  return strm;
200 }
201 
202 #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::validateAttributes
virtual bool validateAttributes(const XMLAttributeMap &attrs, const vector< string > &validAttrs, vector< string > *pInvalidAttrs=0, bool printInvalid=true, bool throwOnError=true)
Definition: NCMLElement.cc:174
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:159
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:96
ncml_module::NCMLElement::areAllAttributesValid
static bool areAllAttributesValid(const XMLAttributeMap &attrMap, const std::vector< string > &validAttrs, std::vector< string > *pInvalidAttributes=0)
Definition: NCMLElement.cc:229
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:73
ncml_module::NCMLElement
Base class for NcML element concrete classes.
Definition: NCMLElement.h:63
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< string > &validAttrs, const string &attr)
Definition: NCMLElement.cc:217
ncml_module::NCMLElement::setAttributes
virtual void setAttributes(const XMLAttributeMap &attrs)=0