bes  Updated for version 3.20.6
VariableAggElement.cc
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 #include "VariableAggElement.h"
30 #include "AggregationElement.h"
31 #include "NCMLDebug.h"
32 #include "NCMLParser.h"
33 #include "NCMLUtil.h"
34 
35 namespace ncml_module {
36 const string VariableAggElement::_sTypeName = "variableAgg";
37 const vector<string> VariableAggElement::_sValidAttributes = getValidAttributes();
38 
39 VariableAggElement::VariableAggElement() :
40  RCObjectInterface(), NCMLElement(0), _name("")
41 {
42 }
43 
44 VariableAggElement::VariableAggElement(const VariableAggElement& proto) :
45  RCObjectInterface(), NCMLElement(proto), _name(proto._name)
46 {
47 }
48 
49 VariableAggElement::~VariableAggElement()
50 {
51  _name.clear();
52 }
53 
54 const string&
56 {
57  return _sTypeName;
58 }
59 
62 {
63  return new VariableAggElement(*this);
64 }
65 
67 {
68  validateAttributes(attrs, _sValidAttributes);
69  _name = attrs.getValueForLocalNameOrDefault("name", "");
70 }
71 
73 {
74  VALID_PTR(_parser);
75 
76  // Make sure the name is not empty or this is uselss.
77  if (_name.empty()) {
78  THROW_NCML_PARSE_ERROR(_parser->getParseLineNumber(),
79  "Cannot have variableAgg@name empty! Scope=" + _parser->getScopeString());
80  }
81 
82  // Also make sure we are the direct child of an aggregation or it's an error as well!
83  if (!_parser->isScopeAggregation()) {
84  THROW_NCML_PARSE_ERROR(_parser->getParseLineNumber(),
85  "Got a variableAgg element not as a direct child of an aggregation! elt=" + toString() + " at scope="
86  + _parser->getScopeString());
87  }
88 
90  parentAgg.addAggregationVariable(_name);
91  parentAgg.setVariableAggElement(); // let the agg know we're adding to it.
92 }
93 
95 {
96 }
97 
99 {
100  return (string("<") + _sTypeName + printAttributeIfNotEmpty("name", _name) + "/>");
101 }
102 
105 {
106  AggregationElement* pAgg = dynamic_cast<AggregationElement*>(_parser->getCurrentElement());
107  NCML_ASSERT_MSG(pAgg, "VariableAggElement::getParentAggregation(): "
108  "Expected current top of stack was AggregationElement*, but it wasn't! Logic error!");
109  return *pAgg;
110 }
111 
113 
114 vector<string> VariableAggElement::getValidAttributes()
115 {
116  vector<string> validAttrs;
117  validAttrs.reserve(1);
118  validAttrs.push_back("name");
119  return validAttrs;
120 }
121 }
ncml_module::VariableAggElement::getParentAggregation
AggregationElement & getParentAggregation() const
Definition: VariableAggElement.cc:104
ncml_module::NCMLElement::printAttributeIfNotEmpty
static std::string printAttributeIfNotEmpty(const std::string &attrName, const std::string &attrValue)
Definition: NCMLElement.cc:212
ncml_module::AggregationElement::addAggregationVariable
void addAggregationVariable(const string &name)
Definition: AggregationElement.cc:267
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:93
ncml_module::VariableAggElement
Element for the <variableAgg> element child of an <aggregation>.
Definition: VariableAggElement.h:41
ncml_module::VariableAggElement::setAttributes
virtual void setAttributes(const XMLAttributeMap &attrs)
Definition: VariableAggElement.cc:66
ncml_module::AggregationElement
Definition: AggregationElement.h:61
ncml_module::AggregationElement::setVariableAggElement
void setVariableAggElement()
Definition: AggregationElement.cc:321
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
ncml_module::VariableAggElement::getTypeName
virtual const std::string & getTypeName() const
Definition: VariableAggElement.cc:55
ncml_module::XMLAttributeMap::getValueForLocalNameOrDefault
const std::string getValueForLocalNameOrDefault(const std::string &localname, const std::string &defVal="") const
Definition: XMLHelpers.cc:181
ncml_module::VariableAggElement::handleBegin
virtual void handleBegin()
Definition: VariableAggElement.cc:72
ncml_module::NCMLParser::getParseLineNumber
int getParseLineNumber() const
Definition: NCMLParser.cc:200
ncml_module::VariableAggElement::clone
virtual VariableAggElement * clone() const
Definition: VariableAggElement.cc:61
ncml_module::VariableAggElement::handleEnd
virtual void handleEnd()
Definition: VariableAggElement.cc:94
ncml_module::NCMLElement::validateAttributes
virtual bool validateAttributes(const XMLAttributeMap &attrs, const std::vector< std::string > &validAttrs, std::vector< std::string > *pInvalidAttrs=0, bool printInvalid=true, bool throwOnError=true)
Definition: NCMLElement.cc:174
ncml_module::VariableAggElement::toString
virtual std::string toString() const
Definition: VariableAggElement.cc:98