bes  Updated for version 3.20.6
ReadMetadataElement.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 "ReadMetadataElement.h"
30 #include "NetcdfElement.h"
31 #include "NCMLDebug.h"
32 #include "NCMLParser.h"
33 #include "NCMLUtil.h"
34 
35 namespace ncml_module {
36 
37 const string ReadMetadataElement::_sTypeName = "readMetadata";
38 const vector<string> ReadMetadataElement::_sValidAttributes = vector<string>();
39 
40 ReadMetadataElement::ReadMetadataElement() :
41  RCObjectInterface(), NCMLElement(0)
42 {
43 }
44 
45 ReadMetadataElement::ReadMetadataElement(const ReadMetadataElement& proto) :
46  RCObjectInterface(), NCMLElement(proto)
47 {
48 }
49 
50 ReadMetadataElement::~ReadMetadataElement()
51 {
52 }
53 
54 const string&
55 ReadMetadataElement::getTypeName() const
56 {
57  return _sTypeName;
58 }
59 
61 ReadMetadataElement::clone() const
62 {
63  return new ReadMetadataElement(*this);
64 }
65 
66 void ReadMetadataElement::setAttributes(const XMLAttributeMap& attrs)
67 {
68  // make sure that none are specifed, basically. We'll list them out in here if we get any
69  // which is why this rather than check map size and throw.
70  validateAttributes(attrs, _sValidAttributes);
71 }
72 
73 void ReadMetadataElement::handleBegin()
74 {
75  if (!_parser->isScopeNetcdf()) {
76  THROW_NCML_PARSE_ERROR(_parser->getParseLineNumber(), "Got <readMetadata/> while not within <netcdf>");
77  }
78  NetcdfElement* dataset = _parser->getCurrentDataset();
79  VALID_PTR(dataset);
80 
81  // Like Highlander, there can be only one!
82  if (dataset->getProcessedMetadataDirective()) {
83  THROW_NCML_PARSE_ERROR(_parser->getParseLineNumber(),
84  "Got " + toString() + " element but we already got a metadata directive"
85  " for the current dataset! Only one may be specified.");
86  }
87  dataset->setProcessedMetadataDirective();
88 }
89 
90 void ReadMetadataElement::handleContent(const string& content)
91 {
92  if (!NCMLUtil::isAllWhitespace(content)) {
93  THROW_NCML_PARSE_ERROR(_parser->getParseLineNumber(),
94  "Got non-whitespace for element content and didn't expect it."
95  " Element=" + toString() + " content=\"" + content + "\"");
96  }
97 }
98 
99 void ReadMetadataElement::handleEnd()
100 {
101 }
102 
103 string ReadMetadataElement::toString() const
104 {
105  return "<" + _sTypeName + ">";
106 }
107 }
ncml_module::NetcdfElement
Concrete class for NcML <netcdf> element.
Definition: NetcdfElement.h:62
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:93
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
ncml_module::ReadMetadataElement
Concrete class for NcML <readMetadata> element.
Definition: ReadMetadataElement.h:43