31#include "NCMLElement.h"
32#include "NCMLParser.h"
35#include "AggregationElement.h"
36#include "AttributeElement.h"
37#include "DimensionElement.h"
38#include "ExplicitElement.h"
39#include "NetcdfElement.h"
40#include "ReadMetadataElement.h"
41#include "RemoveElement.h"
42#include "ScanElement.h"
43#include "ValuesElement.h"
44#include "VariableAggElement.h"
45#include "VariableElement.h"
54NCMLElement::Factory::Factory() :
60NCMLElement::Factory::~Factory()
63 while (!_protos.empty()) {
64 const NCMLElement* proto = _protos.back();
70void NCMLElement::Factory::addPrototype(
const NCMLElement* proto)
75 const string& typeName = proto->getTypeName();
76 ProtoList::iterator existingIt = findPrototype(typeName);
77 if (existingIt != _protos.end()) {
79 "WARNING: Already got NCMLElement prototype for type=" << typeName <<
" so replacing with new one." << endl);
80 const NCMLElement* oldOne = *existingIt;
81 _protos.erase(existingIt);
86 _protos.push_back(proto);
89NCMLElement::Factory::ProtoList::iterator NCMLElement::Factory::findPrototype(
const std::string& elementTypeName)
91 ProtoList::iterator it = _protos.end();
92 ProtoList::iterator endIt = _protos.end();
93 for (it = _protos.begin(); it != endIt; ++it) {
94 if ((*it)->getTypeName() == elementTypeName) {
101void NCMLElement::Factory::initialize()
104 addPrototype(
new RemoveElement());
105 addPrototype(
new ExplicitElement());
106 addPrototype(
new ReadMetadataElement());
107 addPrototype(
new NetcdfElement());
108 addPrototype(
new AttributeElement());
109 addPrototype(
new VariableElement());
110 addPrototype(
new ValuesElement());
111 addPrototype(
new DimensionElement());
112 addPrototype(
new AggregationElement());
113 addPrototype(
new VariableAggElement());
114 addPrototype(
new ScanElement());
120 ProtoList::const_iterator it = findPrototype(eltTypeName);
121 if (it == _protos.end())
123 BESDEBUG(
"ncml",
"NCMLElement::Factory cannot find prototype for element type=" << eltTypeName << endl);
128 VALID_PTR(newElt.get());
130 newElt->setParser(&parser);
131 newElt->setAttributes(attrs);
143NCMLElement::NCMLElement(
const NCMLElement& proto) :
144 RCObjectInterface(),
RCObject(proto), _parser(proto._parser)
148NCMLElement::~NCMLElement()
153void NCMLElement::setParser(NCMLParser* p)
156 NCML_ASSERT_MSG(!_parser,
"NCMLElement::setParser() called more than once. Logic bug!");
169 "Got non-whitespace for element content and didn't expect it. Element=" +
toString() +
" content=\""
175 vector<string>* pInvalidAttrs ,
bool printInvalid ,
bool throwOnError )
180 vector<string> myInvalidAttrs;
181 if (!pInvalidAttrs) {
182 pInvalidAttrs = &myInvalidAttrs;
184 VALID_PTR(pInvalidAttrs);
192 if (printInvalid || throwOnError) {
193 std::ostringstream oss;
194 oss <<
"Got invalid attribute for element = " <<
getTypeName();
195 oss <<
" The invalid attributes were: {";
196 for (
unsigned int i = 0; i < pInvalidAttrs->size(); ++i) {
197 oss << (*pInvalidAttrs)[i];
198 if (i < pInvalidAttrs->size() - 1) oss <<
", ";
202 BESDEBUG(
"ncml", oss.str() << endl);
214 return ((attrValue.empty()) ? (
"") : (
" " + attrName +
"=\"" + attrValue +
"\""));
220 for (
unsigned int i = 0; i < validAttrs.size(); ++i) {
221 if (attr == validAttrs[i]) {
230 std::vector<string>* pInvalidAttributes)
232 if (pInvalidAttributes) {
233 pInvalidAttributes->resize(0);
236 XMLAttributeMap::const_iterator it;
237 XMLAttributeMap::const_iterator endIt = attrMap.end();
238 for (it = attrMap.begin(); it != endIt; ++it) {
239 const string& attr = it->localname;
242 if (pInvalidAttributes) {
243 pInvalidAttributes->push_back(attr);
A base class for a simple reference counted object.
A reference to an RCObject which automatically ref() and deref() on creation and destruction.
Base class for NcML element concrete classes.
virtual void handleContent(const std::string &content)
static bool isValidAttribute(const std::vector< std::string > &validAttrs, const std::string &attr)
virtual bool validateAttributes(const XMLAttributeMap &attrs, const std::vector< std::string > &validAttrs, std::vector< std::string > *pInvalidAttrs=0, bool printInvalid=true, bool throwOnError=true)
virtual const std::string & getTypeName() const =0
virtual std::string toString() const =0
static std::string printAttributeIfNotEmpty(const std::string &attrName, const std::string &attrValue)
static bool areAllAttributesValid(const XMLAttributeMap &attrMap, const std::vector< std::string > &validAttrs, std::vector< std::string > *pInvalidAttributes=0)
int getParseLineNumber() const
static bool isAllWhitespace(const std::string &str)
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...