64 while (!_protos.empty())
73 NCMLElement::Factory::addPrototype(
const NCMLElement* proto)
79 ProtoList::iterator existingIt = findPrototype(typeName);
80 if (existingIt != _protos.end())
82 BESDEBUG(
"ncml",
"WARNING: Already got NCMLElement prototype for type=" << typeName <<
" so replacing with new one." << endl);
84 _protos.erase(existingIt);
89 _protos.push_back(proto);
92 NCMLElement::Factory::ProtoList::iterator
93 NCMLElement::Factory::findPrototype(
const std::string& elementTypeName)
95 ProtoList::iterator it = _protos.end();
96 ProtoList::iterator endIt = _protos.end();
97 for (it = _protos.begin(); it != endIt; ++it)
99 if ((*it)->getTypeName() == elementTypeName)
108 NCMLElement::Factory::initialize()
111 addPrototype(
new RemoveElement());
112 addPrototype(
new ExplicitElement());
113 addPrototype(
new ReadMetadataElement());
114 addPrototype(
new NetcdfElement());
115 addPrototype(
new AttributeElement());
116 addPrototype(
new VariableElement());
117 addPrototype(
new ValuesElement());
118 addPrototype(
new DimensionElement());
119 addPrototype(
new AggregationElement());
120 addPrototype(
new VariableAggElement());
121 addPrototype(
new ScanElement());
128 ProtoList::const_iterator it = findPrototype(eltTypeName);
129 if (it == _protos.end())
131 BESDEBUG(
"ncml",
"NCMLElement::Factory cannot find prototype for element type=" << eltTypeName << endl);
138 newElt->setParser(&parser);
139 newElt->setAttributes(attrs);
154 : RCObjectInterface()
156 , _parser(proto._parser)
185 "Got non-whitespace for element content and didn't expect it. Element=" +
toString() +
" content=\"" +
192 const vector<string>& validAttrs,
193 vector<string>* pInvalidAttrs ,
200 vector<string> myInvalidAttrs;
203 pInvalidAttrs = &myInvalidAttrs;
214 if (printInvalid || throwOnError)
216 std::ostringstream oss;
217 oss <<
"Got invalid attribute for element = " <<
getTypeName();
218 oss <<
" The invalid attributes were: {";
219 for (
unsigned int i=0; i<pInvalidAttrs->size(); ++i)
221 oss << (*pInvalidAttrs)[i];
222 if (i < pInvalidAttrs->size()-1) oss <<
", ";
227 BESDEBUG(
"ncml", oss.str() << endl);
242 return ( (attrValue.empty())?(
""):(
" " + attrName +
"=\"" + attrValue +
"\""));
249 for (
unsigned int i=0; i<validAttrs.size(); ++i)
251 if (attr == validAttrs[i])
262 const std::vector<string>& validAttrs,
263 std::vector<string>* pInvalidAttributes)
265 if (pInvalidAttributes)
267 pInvalidAttributes->resize(0);
272 for (it = attrMap.
begin(); it != endIt; ++it)
274 const string& attr = it->localname;
278 if (pInvalidAttributes)
280 pInvalidAttributes->push_back(attr);
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...
XMLAttributeMap::const_iterator begin() const
static bool areAllAttributesValid(const XMLAttributeMap &attrMap, const std::vector< string > &validAttrs, std::vector< string > *pInvalidAttributes=0)
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
static bool isAllWhitespace(const std::string &str)
Is all the string whitespace as defined by chars in WHITESPACE ?
#define NCML_ASSERT_MSG(cond, msg)
int getParseLineNumber() const
Get the line of the NCML file the parser is currently parsing.
static std::string printAttributeIfNotEmpty(const std::string &attrName, const std::string &attrValue)
Helper for subclasses implementing toString().
virtual std::string toString() const =0
Return a string describing the element.
#define THROW_NCML_PARSE_ERROR(parseLine, msg)
A reference to an RCObject which automatically ref() and deref() on creation and destruction.
void setParser(NCMLParser *p)
A base class for a simple reference counted object.
NCMLElement(NCMLParser *p)
Base class for NcML element concrete classes.
int line() const
Return the current parse line number.
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.
XMLAttributeMap::const_iterator end() const
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.
vector< XMLAttribute >::const_iterator const_iterator
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
static bool isValidAttribute(const std::vector< string > &validAttrs, const string &attr)