00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef ddx_parser_h
00027 #define ddx_parser_h
00028
00029 #include <string>
00030 #include <map>
00031 #include <stack>
00032
00033 #include <libxml/parserInternals.h>
00034
00035 #ifndef ddx_exceptions_h
00036 #include "DDXExceptions.h"
00037 #endif
00038
00039 #ifndef _dds_h
00040 #include "DDS.h"
00041 #endif
00042
00043 #ifndef _basetype_h
00044 #include "BaseType.h"
00045 #endif
00046
00047 #ifndef base_type_factory_h
00048 #include "BaseTypeFactory.h"
00049 #endif
00050
00076 class DDXParser
00077 {
00078 private:
00081 enum ParseState {
00082 parser_start,
00083
00084 inside_dataset,
00085
00086 inside_attribute_container,
00087 inside_attribute,
00088 inside_attribute_value,
00089
00090 inside_alias,
00091
00092
00093 inside_simple_type,
00094
00095 inside_array,
00096 inside_dimension,
00097
00098 inside_grid,
00099 inside_map,
00100
00101 inside_structure,
00102 inside_sequence,
00103
00104 inside_blob_href,
00105
00106 parser_unknown,
00107 parser_error
00108 };
00109
00110 BaseTypeFactory *d_factory;
00111
00112
00113 stack<ParseState> s;
00114 stack<BaseType*> bt_stack;
00115 stack<AttrTable*> at_stack;
00116
00117
00118 string error_msg;
00119 xmlParserCtxtPtr ctxt;
00120
00121
00122 DDS *dds;
00123 string *blob_href;
00124
00125
00126 string dods_attr_name;
00127 string dods_attr_type;
00128 string char_data;
00129 map<string, string> attributes;
00130
00131
00132 void set_state(DDXParser::ParseState state);
00133 DDXParser::ParseState get_state() const;
00134 void pop_state();
00135
00136
00137 BaseType *factory(Type t, const string &name);
00138
00139
00140 void cleanup_parse(xmlParserCtxtPtr &context) const;
00141
00148 void transfer_attrs(const char **attrs);
00149 bool check_required_attribute(const string &attr);
00150
00151 void process_attribute_element(const char **attrs);
00152 void process_attribute_alias(const char **attrs);
00153
00154 void process_variable(Type t, ParseState s, const char **attrs);
00155
00156 void process_dimension(const char **attrs);
00157 void process_blob(const char **attrs);
00158
00159 bool is_attribute_or_alias(const char *name, const char **attrs);
00160 bool is_variable(const char *name, const char **attrs);
00161
00162 void finish_variable(const char *tag, Type t, const char *expected);
00164
00166 DDXParser()
00167 {}
00168
00169 public:
00170 DDXParser(BaseTypeFactory *factory) : d_factory(factory)
00171 {}
00172
00173 void intern(const string &document, DDS *dest_dds, string *blob);
00174 void intern_stream(FILE *in, DDS *dds, string *blob);
00175
00176 static void ddx_start_document(DDXParser *parser);
00177 static void ddx_end_document(DDXParser *parser);
00178 static void ddx_start_element(DDXParser *parser, const char *name,
00179 const char **attrs);
00180 static void ddx_end_element(DDXParser *parser, const char *name);
00181 static void characters(DDXParser *parser, const xmlChar *ch, int len);
00182 static xmlEntityPtr ddx_get_entity(DDXParser *parser,
00183 const xmlChar *name);
00184 static void ddx_fatal_error(DDXParser *parser, const char *msg, ...);
00185 };
00186
00187 #endif // ddx_parser_h