bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
NCMLElement.h
1
2// 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
38using agg_util::RCPtr;
41
42namespace ncml_module {
43// FDecls
44class NCMLParser;
45
61class NCMLElement: public agg_util::RCObject {
62public:
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
110protected:
111 // Abstract: Only subclasses can create these
112 explicit NCMLElement(NCMLParser* p);
113
114 NCMLElement(const NCMLElement& proto);
115
116private:
117 // Disallow assignment for now
118 NCMLElement& operator=(const NCMLElement& rhs);
119
120public:
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
185protected:
186 // data rep
187 NCMLParser* _parser;
188};
189
190}
191
193inline std::ostream &
194operator<<(std::ostream &strm, const ncml_module::NCMLElement &obj)
195{
196 strm << obj.toString();
197 return strm;
198}
199
200#endif /* __NCML_MODULE__NCMLELEMENT_H__ */
A base class for a simple reference counted object.
Definition RCObject.h:165
A reference to an RCObject which automatically ref() and deref() on creation and destruction.
Definition RCObject.h:284
RCPtr< NCMLElement > makeElement(const std::string &eltTypeName, const XMLAttributeMap &attrs, NCMLParser &parser)
Base class for NcML element concrete classes.
Definition NCMLElement.h:61
static std::string printAttributeIfNotEmpty(const std::string &attrName, const std::string &attrValue)
virtual void setAttributes(const XMLAttributeMap &attrs)=0
static bool isValidAttribute(const std::vector< std::string > &validAttrs, const std::string &attr)
virtual NCMLElement * clone() const =0
virtual const std::string & getTypeName() const =0
virtual void handleContent(const std::string &content)
virtual std::string toString() const =0
virtual void handleBegin()=0
virtual void handleEnd()=0
virtual bool validateAttributes(const XMLAttributeMap &attrs, const std::vector< std::string > &validAttrs, std::vector< std::string > *pInvalidAttrs=0, bool printInvalid=true, bool throwOnError=true)
static bool areAllAttributesValid(const XMLAttributeMap &attrMap, const std::vector< std::string > &validAttrs, std::vector< std::string > *pInvalidAttributes=0)
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...