OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
NCMLElement.h
Go to the documentation of this file.
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 {
46  // FDecls
47  class NCMLParser;
48 
65  {
66  public:
67 
75  class Factory
76  {
77  public:
78  Factory();
79  ~Factory();
80 
89  RCPtr<NCMLElement> makeElement(const std::string& eltTypeName, const XMLAttributeMap& attrs, NCMLParser& parser);
90 
91  private: // Interface
92 
94  void initialize();
95 
96  private:
97  // Possible prototypes we can create from. Uses getTypeName() for match.
98  typedef std::vector<const NCMLElement*> ProtoList;
99 
105  void addPrototype(const NCMLElement* proto);
106 
108  ProtoList::iterator findPrototype(const std::string& elementTypeName);
109 
110  ProtoList _protos;
111  };
112 
113  protected:
114  // Abstract: Only subclasses can create these
115  explicit NCMLElement(NCMLParser* p);
116 
117  NCMLElement(const NCMLElement& proto);
118 
119  private:
120  // Disallow assignment for now
121  NCMLElement& operator=(const NCMLElement& rhs);
122 
123  public:
124  virtual ~NCMLElement();
125 
126  void setParser(NCMLParser* p);
127 
129  int line() const;
130 
133  virtual const std::string& getTypeName() const = 0;
134 
138  virtual NCMLElement* clone() const = 0;
139 
143  virtual void setAttributes(const XMLAttributeMap& attrs) = 0;
144 
151  virtual bool validateAttributes(const XMLAttributeMap& attrs,
152  const vector<string>& validAttrs,
153  vector<string>* pInvalidAttrs = 0,
154  bool printInvalid = true,
155  bool throwOnError = true);
156 
161  virtual void handleBegin() = 0;
162 
168  virtual void handleContent(const std::string& content);
169 
171  virtual void handleEnd() = 0;
172 
174  virtual std::string toString() const = 0;
175 
180  static std::string printAttributeIfNotEmpty(const std::string& attrName, const std::string& attrValue);
181 
183  static bool isValidAttribute(const std::vector<string>& validAttrs, const string& attr);
184 
188  static bool areAllAttributesValid(const XMLAttributeMap& attrMap,
189  const std::vector<string>& validAttrs,
190  std::vector<string>* pInvalidAttributes=0);
191 
192  protected: // data rep
194  };
195 
196 }
197 
199 inline std::ostream &
200 operator<<( std::ostream &strm, const ncml_module::NCMLElement &obj )
201 {
202  strm << obj.toString();
203  return strm ;
204 }
205 
206 
207 #endif /* __NCML_MODULE__NCMLELEMENT_H__ */
virtual void handleBegin()=0
Handle a begin on this element.
virtual bool validateAttributes(const XMLAttributeMap &attrs, const vector< string > &validAttrs, vector< string > *pInvalidAttrs=0, bool printInvalid=true, bool throwOnError=true)
Check that the given attributes are all in the valid set, otherwise fill in *pInvalidAttrs with the p...
Definition: NCMLElement.cc:191
virtual void setAttributes(const XMLAttributeMap &attrs)=0
Set the attributes of this from the map.
Factory class for the NcML elements.
Definition: NCMLElement.h:75
static bool areAllAttributesValid(const XMLAttributeMap &attrMap, const std::vector< string > &validAttrs, std::vector< string > *pInvalidAttributes=0)
Definition: NCMLElement.cc:261
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
A monitoring "pool" class for created RCObject's which allows us to forcibly delete any RCOBject's re...
Definition: RCObject.h:58
virtual void handleEnd()=0
Handle the closing of this element.
static std::string printAttributeIfNotEmpty(const std::string &attrName, const std::string &attrValue)
Helper for subclasses implementing toString().
Definition: NCMLElement.cc:240
virtual std::string toString() const =0
Return a string describing the element.
A reference to an RCObject which automatically ref() and deref() on creation and destruction.
Definition: RCObject.h:279
void setParser(NCMLParser *p)
Definition: NCMLElement.cc:166
A base class for a simple reference counted object.
Definition: RCObject.h:162
NCMLElement(NCMLParser *p)
Definition: NCMLElement.cc:147
Base class for NcML element concrete classes.
Definition: NCMLElement.h:64
int line() const
Return the current parse line number.
Definition: NCMLElement.cc:174
virtual const std::string & getTypeName() const =0
Return the type of the element, which should be: the same as ConcreteClassName::getTypeName() ...
virtual void handleContent(const std::string &content)
Handle the characters content for the element.
Definition: NCMLElement.cc:180
RCPtr< NCMLElement > makeElement(const std::string &eltTypeName, const XMLAttributeMap &attrs, NCMLParser &parser)
Create an element of the proper type with the given AttrMap for its defined attributes.
Definition: NCMLElement.cc:126
std::ostream & operator<<(std::ostream &strm, const ncml_module::NCMLElement &obj)
Output obj.toString() to the stream.
Definition: NCMLElement.h:200
virtual NCMLElement * clone() const =0
Make and return a copy of this.
static bool isValidAttribute(const std::vector< string > &validAttrs, const string &attr)
Definition: NCMLElement.cc:246