Line data Source code
1 :
2 : /*
3 : * ALMA - Atacama Large Millimeter Array
4 : * (c) European Southern Observatory, 2002
5 : * (c) Associated Universities Inc., 2002
6 : * Copyright by ESO (in the framework of the ALMA collaboration),
7 : * Copyright by AUI (in the framework of the ALMA collaboration),
8 : * All rights reserved.
9 : *
10 : * This library is free software; you can redistribute it and/or
11 : * modify it under the terms of the GNU Lesser General Public
12 : * License as published by the Free software Foundation; either
13 : * version 2.1 of the License, or (at your option) any later version.
14 : *
15 : * This library is distributed in the hope that it will be useful,
16 : * but WITHOUT ANY WARRANTY, without even the implied warranty of
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 : * Lesser General Public License for more details.
19 : *
20 : * You should have received a copy of the GNU Lesser General Public
21 : * License along with this library; if not, write to the Free Software
22 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 : * MA 02111-1307 USA
24 : *
25 : * Warning!
26 : * --------------------------------------------------------------------
27 : * | This is generated code! Do not modify this file. |
28 : * | If you do, all changes will be lost when the file is re-generated. |
29 : * --------------------------------------------------------------------
30 : *
31 : * File DelayModelVariableParametersTable.cpp
32 : */
33 : #include <alma/ASDM/ConversionException.h>
34 : #include <alma/ASDM/DuplicateKey.h>
35 : #include <alma/ASDM/OutOfBoundsException.h>
36 :
37 : using asdm::ConversionException;
38 : using asdm::DuplicateKey;
39 : using asdm::OutOfBoundsException;
40 :
41 : #include <alma/ASDM/ASDM.h>
42 : #include <alma/ASDM/DelayModelVariableParametersTable.h>
43 : #include <alma/ASDM/DelayModelVariableParametersRow.h>
44 : #include <alma/ASDM/Parser.h>
45 :
46 : using asdm::ASDM;
47 : using asdm::DelayModelVariableParametersTable;
48 : using asdm::DelayModelVariableParametersRow;
49 : using asdm::Parser;
50 :
51 : #include <iostream>
52 : #include <fstream>
53 : #include <iterator>
54 : #include <sstream>
55 : #include <set>
56 : #include <algorithm>
57 : using namespace std;
58 :
59 : #include <alma/ASDM/Misc.h>
60 : using namespace asdm;
61 :
62 : #include <libxml/parser.h>
63 : #include <libxml/tree.h>
64 :
65 : #ifndef WITHOUT_BOOST
66 : #include "boost/filesystem/operations.hpp"
67 : #include <boost/algorithm/string.hpp>
68 : #else
69 : #include <sys/stat.h>
70 : #endif
71 :
72 : namespace asdm {
73 : // The name of the entity we will store in this table.
74 : static string entityNameOfDelayModelVariableParameters = "DelayModelVariableParameters";
75 :
76 : // An array of string containing the names of the columns of this table.
77 : // The array is filled in the order : key, required value, optional value.
78 : //
79 : static string attributesNamesOfDelayModelVariableParameters_a[] = {
80 :
81 : "delayModelVariableParametersId"
82 :
83 :
84 : , "time"
85 :
86 : , "ut1_utc"
87 :
88 : , "iat_utc"
89 :
90 : , "timeType"
91 :
92 : , "gstAtUt0"
93 :
94 : , "earthRotationRate"
95 :
96 : , "polarOffsets"
97 :
98 : , "polarOffsetsType"
99 :
100 : , "delayModelFixedParametersId"
101 :
102 :
103 : , "nutationInLongitude"
104 :
105 : , "nutationInLongitudeRate"
106 :
107 : , "nutationInObliquity"
108 :
109 : , "nutationInObliquityRate"
110 :
111 : };
112 :
113 : // A vector of string whose content is a copy of the strings in the array above.
114 : //
115 : static vector<string> attributesNamesOfDelayModelVariableParameters_v (attributesNamesOfDelayModelVariableParameters_a, attributesNamesOfDelayModelVariableParameters_a + sizeof(attributesNamesOfDelayModelVariableParameters_a) / sizeof(attributesNamesOfDelayModelVariableParameters_a[0]));
116 :
117 : // An array of string containing the names of the columns of this table.
118 : // The array is filled in the order where the names would be read by default in the XML header of a file containing
119 : // the table exported in binary mode.
120 : //
121 : static string attributesNamesInBinOfDelayModelVariableParameters_a[] = {
122 :
123 : "delayModelVariableParametersId" , "time" , "ut1_utc" , "iat_utc" , "timeType" , "gstAtUt0" , "earthRotationRate" , "polarOffsets" , "polarOffsetsType" , "delayModelFixedParametersId"
124 : ,
125 : "nutationInLongitude" , "nutationInLongitudeRate" , "nutationInObliquity" , "nutationInObliquityRate"
126 :
127 : };
128 :
129 : // A vector of string whose content is a copy of the strings in the array above.
130 : //
131 : static vector<string> attributesNamesInBinOfDelayModelVariableParameters_v(attributesNamesInBinOfDelayModelVariableParameters_a, attributesNamesInBinOfDelayModelVariableParameters_a + sizeof(attributesNamesInBinOfDelayModelVariableParameters_a) / sizeof(attributesNamesInBinOfDelayModelVariableParameters_a[0]));
132 :
133 :
134 : // The array of attributes (or column) names that make up key key.
135 : //
136 : string keyOfDelayModelVariableParameters_a[] = {
137 :
138 : "delayModelVariableParametersId"
139 :
140 : };
141 :
142 : // A vector of strings which are copies of those stored in the array above.
143 : vector<string> keyOfDelayModelVariableParameters_v(keyOfDelayModelVariableParameters_a, keyOfDelayModelVariableParameters_a + sizeof(keyOfDelayModelVariableParameters_a) / sizeof(keyOfDelayModelVariableParameters_a[0]));
144 :
145 : /**
146 : * Return the list of field names that make up key key
147 : * as a const reference to a vector of strings.
148 : */
149 0 : const vector<string>& DelayModelVariableParametersTable::getKeyName() {
150 0 : return keyOfDelayModelVariableParameters_v;
151 : }
152 :
153 :
154 110 : DelayModelVariableParametersTable::DelayModelVariableParametersTable(ASDM &c) : container(c) {
155 :
156 : // Define a default entity.
157 110 : entity.setEntityId(EntityId("uid://X0/X0/X0"));
158 110 : entity.setEntityIdEncrypted("na");
159 110 : entity.setEntityTypeName("DelayModelVariableParametersTable");
160 110 : entity.setEntityVersion("1");
161 110 : entity.setInstanceVersion("1");
162 :
163 : // Archive XML
164 110 : archiveAsBin = false;
165 :
166 : // File XML
167 110 : fileAsBin = false;
168 :
169 : // By default the table is considered as present in memory
170 110 : presentInMemory = true;
171 :
172 : // By default there is no load in progress
173 110 : loadInProgress = false;
174 110 : }
175 :
176 : /**
177 : * A destructor for DelayModelVariableParametersTable.
178 : */
179 220 : DelayModelVariableParametersTable::~DelayModelVariableParametersTable() {
180 110 : for (unsigned int i = 0; i < privateRows.size(); i++)
181 0 : delete(privateRows.at(i));
182 220 : }
183 :
184 : /**
185 : * Container to which this table belongs.
186 : */
187 0 : ASDM &DelayModelVariableParametersTable::getContainer() const {
188 0 : return container;
189 : }
190 :
191 : /**
192 : * Return the number of rows in the table.
193 : */
194 39 : unsigned int DelayModelVariableParametersTable::size() const {
195 39 : if (presentInMemory)
196 39 : return privateRows.size();
197 : else
198 0 : return declaredSize;
199 : }
200 :
201 : /**
202 : * Return the name of this table.
203 : */
204 2635 : string DelayModelVariableParametersTable::getName() const {
205 2635 : return entityNameOfDelayModelVariableParameters;
206 : }
207 :
208 : /**
209 : * Return the name of this table.
210 : */
211 0 : string DelayModelVariableParametersTable::name() {
212 0 : return entityNameOfDelayModelVariableParameters;
213 : }
214 :
215 : /**
216 : * Return the the names of the attributes (or columns) of this table.
217 : */
218 0 : const vector<string>& DelayModelVariableParametersTable::getAttributesNames() { return attributesNamesOfDelayModelVariableParameters_v; }
219 :
220 : /**
221 : * Return the the names of the attributes (or columns) of this table as they appear by default
222 : * in an binary export of this table.
223 : */
224 0 : const vector<string>& DelayModelVariableParametersTable::defaultAttributesNamesInBin() { return attributesNamesInBinOfDelayModelVariableParameters_v; }
225 :
226 : /**
227 : * Return this table's Entity.
228 : */
229 0 : Entity DelayModelVariableParametersTable::getEntity() const {
230 0 : return entity;
231 : }
232 :
233 : /**
234 : * Set this table's Entity.
235 : */
236 0 : void DelayModelVariableParametersTable::setEntity(Entity e) {
237 0 : this->entity = e;
238 0 : }
239 :
240 : //
241 : // ====> Row creation.
242 : //
243 :
244 : /**
245 : * Create a new row.
246 : */
247 0 : DelayModelVariableParametersRow *DelayModelVariableParametersTable::newRow() {
248 0 : return new DelayModelVariableParametersRow (*this);
249 : }
250 :
251 :
252 : /**
253 : * Create a new row initialized to the specified values.
254 : * @return a pointer on the created and initialized row.
255 :
256 : * @param time
257 :
258 : * @param ut1_utc
259 :
260 : * @param iat_utc
261 :
262 : * @param timeType
263 :
264 : * @param gstAtUt0
265 :
266 : * @param earthRotationRate
267 :
268 : * @param polarOffsets
269 :
270 : * @param polarOffsetsType
271 :
272 : * @param delayModelFixedParametersId
273 :
274 : */
275 0 : DelayModelVariableParametersRow* DelayModelVariableParametersTable::newRow(ArrayTime time, double ut1_utc, double iat_utc, DifferenceTypeMod::DifferenceType timeType, Angle gstAtUt0, AngularRate earthRotationRate, std::vector<double > polarOffsets, DifferenceTypeMod::DifferenceType polarOffsetsType, Tag delayModelFixedParametersId){
276 0 : DelayModelVariableParametersRow *row = new DelayModelVariableParametersRow(*this);
277 :
278 0 : row->setTime(time);
279 :
280 0 : row->setUt1_utc(ut1_utc);
281 :
282 0 : row->setIat_utc(iat_utc);
283 :
284 0 : row->setTimeType(timeType);
285 :
286 0 : row->setGstAtUt0(gstAtUt0);
287 :
288 0 : row->setEarthRotationRate(earthRotationRate);
289 :
290 0 : row->setPolarOffsets(polarOffsets);
291 :
292 0 : row->setPolarOffsetsType(polarOffsetsType);
293 :
294 0 : row->setDelayModelFixedParametersId(delayModelFixedParametersId);
295 :
296 0 : return row;
297 : }
298 :
299 :
300 :
301 0 : DelayModelVariableParametersRow* DelayModelVariableParametersTable::newRow(DelayModelVariableParametersRow* row) {
302 0 : return new DelayModelVariableParametersRow(*this, row);
303 : }
304 :
305 : //
306 : // Append a row to its table.
307 : //
308 :
309 :
310 :
311 :
312 : /**
313 : * Look up the table for a row whose noautoincrementable attributes are matching their
314 : * homologues in *x. If a row is found this row else autoincrement *x.delayModelVariableParametersId,
315 : * add x to its table and returns x.
316 : *
317 : * @returns a pointer on a DelayModelVariableParametersRow.
318 : * @param x. A pointer on the row to be added.
319 : */
320 :
321 :
322 0 : DelayModelVariableParametersRow* DelayModelVariableParametersTable::add(DelayModelVariableParametersRow* x) {
323 :
324 0 : DelayModelVariableParametersRow* aRow = lookup(
325 :
326 0 : x->getTime()
327 : ,
328 : x->getUt1_utc()
329 : ,
330 : x->getIat_utc()
331 : ,
332 : x->getTimeType()
333 : ,
334 0 : x->getGstAtUt0()
335 : ,
336 0 : x->getEarthRotationRate()
337 : ,
338 0 : x->getPolarOffsets()
339 : ,
340 : x->getPolarOffsetsType()
341 : ,
342 0 : x->getDelayModelFixedParametersId()
343 :
344 : );
345 0 : if (aRow) return aRow;
346 :
347 :
348 :
349 : // Autoincrement delayModelVariableParametersId
350 0 : x->setDelayModelVariableParametersId(Tag(size(), TagType::DelayModelVariableParameters));
351 :
352 0 : row.push_back(x);
353 0 : privateRows.push_back(x);
354 0 : x->isAdded(true);
355 0 : return x;
356 : }
357 :
358 :
359 :
360 0 : void DelayModelVariableParametersTable::addWithoutCheckingUnique(DelayModelVariableParametersRow * x) {
361 0 : if (getRowByKey(
362 0 : x->getDelayModelVariableParametersId()
363 0 : ) != (DelayModelVariableParametersRow *) 0)
364 0 : throw DuplicateKey("Dupicate key exception in ", "DelayModelVariableParametersTable");
365 0 : row.push_back(x);
366 0 : privateRows.push_back(x);
367 0 : x->isAdded(true);
368 0 : }
369 :
370 :
371 :
372 :
373 : //
374 : // A private method to append a row to its table, used by input conversion
375 : // methods, with row uniqueness.
376 : //
377 :
378 :
379 : /**
380 : * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
381 : * Check if *x verifies the key uniqueness rule and throw an exception if not.
382 : * Append x to its table.
383 : * @param x a pointer on the row to be appended.
384 : * @returns a pointer on x.
385 : * @throws DuplicateKey
386 :
387 : * @throws UniquenessViolationException
388 :
389 : */
390 0 : DelayModelVariableParametersRow* DelayModelVariableParametersTable::checkAndAdd(DelayModelVariableParametersRow* x, bool skipCheckUniqueness) {
391 0 : if (!skipCheckUniqueness) {
392 :
393 :
394 0 : if (lookup(
395 :
396 0 : x->getTime()
397 : ,
398 : x->getUt1_utc()
399 : ,
400 : x->getIat_utc()
401 : ,
402 : x->getTimeType()
403 : ,
404 0 : x->getGstAtUt0()
405 : ,
406 0 : x->getEarthRotationRate()
407 : ,
408 0 : x->getPolarOffsets()
409 : ,
410 : x->getPolarOffsetsType()
411 : ,
412 0 : x->getDelayModelFixedParametersId()
413 :
414 0 : )) throw UniquenessViolationException();
415 :
416 :
417 : }
418 :
419 0 : if (getRowByKey(
420 :
421 0 : x->getDelayModelVariableParametersId()
422 :
423 0 : )) throw DuplicateKey("Duplicate key exception in ", "DelayModelVariableParametersTable");
424 :
425 0 : row.push_back(x);
426 0 : privateRows.push_back(x);
427 0 : x->isAdded(true);
428 0 : return x;
429 : }
430 :
431 :
432 :
433 : //
434 : // A private method to brutally append a row to its table, without checking for row uniqueness.
435 : //
436 :
437 0 : void DelayModelVariableParametersTable::append(DelayModelVariableParametersRow *x) {
438 0 : privateRows.push_back(x);
439 0 : x->isAdded(true);
440 0 : }
441 :
442 :
443 :
444 :
445 :
446 0 : vector<DelayModelVariableParametersRow *> DelayModelVariableParametersTable::get() {
447 0 : checkPresenceInMemory();
448 0 : return privateRows;
449 : }
450 :
451 0 : const vector<DelayModelVariableParametersRow *>& DelayModelVariableParametersTable::get() const {
452 0 : const_cast<DelayModelVariableParametersTable&>(*this).checkPresenceInMemory();
453 0 : return privateRows;
454 : }
455 :
456 :
457 :
458 :
459 :
460 :
461 :
462 :
463 : /*
464 : ** Returns a DelayModelVariableParametersRow* given a key.
465 : ** @return a pointer to the row having the key whose values are passed as parameters, or 0 if
466 : ** no row exists for that key.
467 : **
468 : */
469 0 : DelayModelVariableParametersRow* DelayModelVariableParametersTable::getRowByKey(Tag delayModelVariableParametersId) {
470 0 : checkPresenceInMemory();
471 0 : DelayModelVariableParametersRow* aRow = 0;
472 0 : for (unsigned int i = 0; i < privateRows.size(); i++) {
473 0 : aRow = row.at(i);
474 :
475 :
476 0 : if (aRow->delayModelVariableParametersId != delayModelVariableParametersId) continue;
477 :
478 :
479 0 : return aRow;
480 : }
481 0 : return 0;
482 : }
483 :
484 :
485 :
486 : /**
487 : * Look up the table for a row whose all attributes except the autoincrementable one
488 : * are equal to the corresponding parameters of the method.
489 : * @return a pointer on this row if any, 0 otherwise.
490 : *
491 :
492 : * @param time.
493 :
494 : * @param ut1_utc.
495 :
496 : * @param iat_utc.
497 :
498 : * @param timeType.
499 :
500 : * @param gstAtUt0.
501 :
502 : * @param earthRotationRate.
503 :
504 : * @param polarOffsets.
505 :
506 : * @param polarOffsetsType.
507 :
508 : * @param delayModelFixedParametersId.
509 :
510 : */
511 0 : DelayModelVariableParametersRow* DelayModelVariableParametersTable::lookup(ArrayTime time, double ut1_utc, double iat_utc, DifferenceTypeMod::DifferenceType timeType, Angle gstAtUt0, AngularRate earthRotationRate, std::vector<double > polarOffsets, DifferenceTypeMod::DifferenceType polarOffsetsType, Tag delayModelFixedParametersId) {
512 : DelayModelVariableParametersRow* aRow;
513 0 : for (unsigned int i = 0; i < privateRows.size(); i++) {
514 0 : aRow = privateRows.at(i);
515 0 : if (aRow->compareNoAutoInc(time, ut1_utc, iat_utc, timeType, gstAtUt0, earthRotationRate, polarOffsets, polarOffsetsType, delayModelFixedParametersId)) return aRow;
516 : }
517 0 : return 0;
518 : }
519 :
520 :
521 :
522 :
523 :
524 :
525 :
526 : #ifndef WITHOUT_ACS
527 : using asdmIDL::DelayModelVariableParametersTableIDL;
528 : #endif
529 :
530 : #ifndef WITHOUT_ACS
531 : // Conversion Methods
532 :
533 : DelayModelVariableParametersTableIDL *DelayModelVariableParametersTable::toIDL() {
534 : DelayModelVariableParametersTableIDL *x = new DelayModelVariableParametersTableIDL ();
535 : unsigned int nrow = size();
536 : x->row.length(nrow);
537 : vector<DelayModelVariableParametersRow*> v = get();
538 : for (unsigned int i = 0; i < nrow; ++i) {
539 : //x->row[i] = *(v[i]->toIDL());
540 : v[i]->toIDL(x->row[i]);
541 : }
542 : return x;
543 : }
544 :
545 : void DelayModelVariableParametersTable::toIDL(asdmIDL::DelayModelVariableParametersTableIDL& x) const {
546 : unsigned int nrow = size();
547 : x.row.length(nrow);
548 : vector<DelayModelVariableParametersRow*> v = get();
549 : for (unsigned int i = 0; i < nrow; ++i) {
550 : v[i]->toIDL(x.row[i]);
551 : }
552 : }
553 : #endif
554 :
555 : #ifndef WITHOUT_ACS
556 : void DelayModelVariableParametersTable::fromIDL(DelayModelVariableParametersTableIDL x) {
557 : unsigned int nrow = x.row.length();
558 : for (unsigned int i = 0; i < nrow; ++i) {
559 : DelayModelVariableParametersRow *tmp = newRow();
560 : tmp->setFromIDL(x.row[i]);
561 : // checkAndAdd(tmp);
562 : add(tmp);
563 : }
564 : }
565 : #endif
566 :
567 :
568 0 : string DelayModelVariableParametersTable::toXML() {
569 0 : string buf;
570 :
571 0 : buf.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> ");
572 0 : buf.append("<DelayModelVariableParametersTable xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dmvp=\"http://Alma/XASDM/DelayModelVariableParametersTable\" xsi:schemaLocation=\"http://Alma/XASDM/DelayModelVariableParametersTable http://almaobservatory.org/XML/XASDM/4/DelayModelVariableParametersTable.xsd\" schemaVersion=\"4\" schemaRevision=\"-1\">\n");
573 :
574 0 : buf.append(entity.toXML());
575 0 : string s = container.getEntity().toXML();
576 : // Change the "Entity" tag to "ContainerEntity".
577 0 : buf.append("<Container" + s.substr(1,s.length() - 1)+" ");
578 0 : vector<DelayModelVariableParametersRow*> v = get();
579 0 : for (unsigned int i = 0; i < v.size(); ++i) {
580 : try {
581 0 : buf.append(v[i]->toXML());
582 0 : } catch (const NoSuchRow &e) {
583 : }
584 0 : buf.append(" ");
585 : }
586 0 : buf.append("</DelayModelVariableParametersTable> ");
587 0 : return buf;
588 : }
589 :
590 :
591 0 : string DelayModelVariableParametersTable::getVersion() const {
592 0 : return version;
593 : }
594 :
595 :
596 0 : void DelayModelVariableParametersTable::fromXML(string& tableInXML) {
597 : //
598 : // Look for a version information in the schemaVersion of the XML
599 : //
600 : xmlDoc *doc;
601 : #if LIBXML_VERSION >= 20703
602 0 : doc = xmlReadMemory(tableInXML.data(), tableInXML.size(), "XMLTableHeader.xml", NULL, XML_PARSE_NOBLANKS|XML_PARSE_HUGE);
603 : #else
604 : doc = xmlReadMemory(tableInXML.data(), tableInXML.size(), "XMLTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
605 : #endif
606 0 : if ( doc == NULL )
607 0 : throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "DelayModelVariableParameters");
608 :
609 0 : xmlNode* root_element = xmlDocGetRootElement(doc);
610 0 : if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
611 0 : throw ConversionException("Failed to retrieve the root element in the DOM structure.", "DelayModelVariableParameters");
612 :
613 0 : xmlChar * propValue = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
614 0 : if ( propValue != 0 ) {
615 0 : version = string( (const char*) propValue);
616 0 : xmlFree(propValue);
617 : }
618 :
619 0 : Parser xml(tableInXML);
620 0 : if (!xml.isStr("<DelayModelVariableParametersTable"))
621 0 : error();
622 : // cout << "Parsing a DelayModelVariableParametersTable" << endl;
623 0 : string s = xml.getElement("<Entity","/>");
624 0 : if (s.length() == 0)
625 0 : error();
626 0 : Entity e;
627 0 : e.setFromXML(s);
628 0 : if (e.getEntityTypeName() != "DelayModelVariableParametersTable")
629 0 : error();
630 0 : setEntity(e);
631 : // Skip the container's entity; but, it has to be there.
632 0 : s = xml.getElement("<ContainerEntity","/>");
633 0 : if (s.length() == 0)
634 0 : error();
635 :
636 : // Get each row in the table.
637 0 : s = xml.getElementContent("<row>","</row>");
638 : DelayModelVariableParametersRow *row;
639 0 : if (getContainer().checkRowUniqueness()) {
640 : try {
641 0 : while (s.length() != 0) {
642 0 : row = newRow();
643 0 : row->setFromXML(s);
644 0 : checkAndAdd(row);
645 0 : s = xml.getElementContent("<row>","</row>");
646 : }
647 :
648 : }
649 0 : catch (const DuplicateKey &e1) {
650 0 : throw ConversionException(e1.getMessage(),"DelayModelVariableParametersTable");
651 : }
652 0 : catch (const UniquenessViolationException &e1) {
653 0 : throw ConversionException(e1.getMessage(),"DelayModelVariableParametersTable");
654 : }
655 0 : catch (...) {
656 : // cout << "Unexpected error in DelayModelVariableParametersTable::checkAndAdd called from DelayModelVariableParametersTable::fromXML " << endl;
657 : }
658 : }
659 : else {
660 : try {
661 0 : while (s.length() != 0) {
662 0 : row = newRow();
663 0 : row->setFromXML(s);
664 0 : addWithoutCheckingUnique(row);
665 0 : s = xml.getElementContent("<row>","</row>");
666 : }
667 : }
668 0 : catch (const DuplicateKey &e1) {
669 0 : throw ConversionException(e1.getMessage(),"DelayModelVariableParametersTable");
670 : }
671 0 : catch (...) {
672 : // cout << "Unexpected error in DelayModelVariableParametersTable::addWithoutCheckingUnique called from DelayModelVariableParametersTable::fromXML " << endl;
673 : }
674 : }
675 :
676 :
677 0 : if (!xml.isStr("</DelayModelVariableParametersTable>"))
678 0 : error();
679 :
680 : //Does not change the convention defined in the model.
681 : //archiveAsBin = false;
682 : //fileAsBin = false;
683 :
684 : // clean up the xmlDoc pointer
685 0 : if ( doc != NULL ) xmlFreeDoc(doc);
686 :
687 0 : }
688 :
689 :
690 0 : void DelayModelVariableParametersTable::error() {
691 0 : throw ConversionException("Invalid xml document","DelayModelVariableParameters");
692 : }
693 :
694 :
695 0 : string DelayModelVariableParametersTable::MIMEXMLPart(const asdm::ByteOrder* byteOrder) {
696 0 : string UID = getEntity().getEntityId().toString();
697 0 : string withoutUID = UID.substr(6);
698 0 : string containerUID = getContainer().getEntity().getEntityId().toString();
699 0 : ostringstream oss;
700 0 : oss << "<?xml version='1.0' encoding='ISO-8859-1'?>";
701 0 : oss << "\n";
702 0 : oss << "<DelayModelVariableParametersTable xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dmvp=\"http://Alma/XASDM/DelayModelVariableParametersTable\" xsi:schemaLocation=\"http://Alma/XASDM/DelayModelVariableParametersTable http://almaobservatory.org/XML/XASDM/4/DelayModelVariableParametersTable.xsd\" schemaVersion=\"4\" schemaRevision=\"-1\">\n";
703 0 : oss<< "<Entity entityId='"<<UID<<"' entityIdEncrypted='na' entityTypeName='DelayModelVariableParametersTable' schemaVersion='1' documentVersion='1'/>\n";
704 0 : oss<< "<ContainerEntity entityId='"<<containerUID<<"' entityIdEncrypted='na' entityTypeName='ASDM' schemaVersion='1' documentVersion='1'/>\n";
705 0 : oss << "<BulkStoreRef file_id='"<<withoutUID<<"' byteOrder='"<<byteOrder->toString()<<"' />\n";
706 0 : oss << "<Attributes>\n";
707 :
708 0 : oss << "<delayModelVariableParametersId/>\n";
709 0 : oss << "<time/>\n";
710 0 : oss << "<ut1_utc/>\n";
711 0 : oss << "<iat_utc/>\n";
712 0 : oss << "<timeType/>\n";
713 0 : oss << "<gstAtUt0/>\n";
714 0 : oss << "<earthRotationRate/>\n";
715 0 : oss << "<polarOffsets/>\n";
716 0 : oss << "<polarOffsetsType/>\n";
717 0 : oss << "<delayModelFixedParametersId/>\n";
718 :
719 0 : oss << "<nutationInLongitude/>\n";
720 0 : oss << "<nutationInLongitudeRate/>\n";
721 0 : oss << "<nutationInObliquity/>\n";
722 0 : oss << "<nutationInObliquityRate/>\n";
723 0 : oss << "</Attributes>\n";
724 0 : oss << "</DelayModelVariableParametersTable>\n";
725 :
726 0 : return oss.str();
727 : }
728 :
729 0 : string DelayModelVariableParametersTable::toMIME(const asdm::ByteOrder* byteOrder) {
730 0 : EndianOSStream eoss(byteOrder);
731 :
732 0 : string UID = getEntity().getEntityId().toString();
733 :
734 : // The MIME Header
735 0 : eoss <<"MIME-Version: 1.0";
736 0 : eoss << "\n";
737 0 : eoss << "Content-Type: Multipart/Related; boundary='MIME_boundary'; type='text/xml'; start= '<header.xml>'";
738 0 : eoss <<"\n";
739 0 : eoss <<"Content-Description: Correlator";
740 0 : eoss <<"\n";
741 0 : eoss <<"alma-uid:" << UID;
742 0 : eoss <<"\n";
743 0 : eoss <<"\n";
744 :
745 : // The MIME XML part header.
746 0 : eoss <<"--MIME_boundary";
747 0 : eoss <<"\n";
748 0 : eoss <<"Content-Type: text/xml; charset='ISO-8859-1'";
749 0 : eoss <<"\n";
750 0 : eoss <<"Content-Transfer-Encoding: 8bit";
751 0 : eoss <<"\n";
752 0 : eoss <<"Content-ID: <header.xml>";
753 0 : eoss <<"\n";
754 0 : eoss <<"\n";
755 :
756 : // The MIME XML part content.
757 0 : eoss << MIMEXMLPart(byteOrder);
758 :
759 : // The MIME binary part header
760 0 : eoss <<"--MIME_boundary";
761 0 : eoss <<"\n";
762 0 : eoss <<"Content-Type: binary/octet-stream";
763 0 : eoss <<"\n";
764 0 : eoss <<"Content-ID: <content.bin>";
765 0 : eoss <<"\n";
766 0 : eoss <<"\n";
767 :
768 : // The MIME binary content
769 0 : entity.toBin(eoss);
770 0 : container.getEntity().toBin(eoss);
771 0 : eoss.writeInt((int) privateRows.size());
772 0 : for (unsigned int i = 0; i < privateRows.size(); i++) {
773 0 : privateRows.at(i)->toBin(eoss);
774 : }
775 :
776 : // The closing MIME boundary
777 0 : eoss << "\n--MIME_boundary--";
778 0 : eoss << "\n";
779 :
780 0 : return eoss.str();
781 : }
782 :
783 :
784 0 : void DelayModelVariableParametersTable::setFromMIME(const string & mimeMsg) {
785 0 : string xmlPartMIMEHeader = "Content-ID: <header.xml>\n\n";
786 :
787 0 : string binPartMIMEHeader = "--MIME_boundary\nContent-Type: binary/octet-stream\nContent-ID: <content.bin>\n\n";
788 :
789 : // Detect the XML header.
790 0 : string::size_type loc0 = mimeMsg.find(xmlPartMIMEHeader, 0);
791 0 : if ( loc0 == string::npos) {
792 : // let's try with CRLFs
793 0 : xmlPartMIMEHeader = "Content-ID: <header.xml>\r\n\r\n";
794 0 : loc0 = mimeMsg.find(xmlPartMIMEHeader, 0);
795 0 : if ( loc0 == string::npos )
796 0 : throw ConversionException("Failed to detect the beginning of the XML header", "DelayModelVariableParameters");
797 : }
798 :
799 0 : loc0 += xmlPartMIMEHeader.size();
800 :
801 : // Look for the string announcing the binary part.
802 0 : string::size_type loc1 = mimeMsg.find( binPartMIMEHeader, loc0 );
803 :
804 0 : if ( loc1 == string::npos ) {
805 0 : throw ConversionException("Failed to detect the beginning of the binary part", "DelayModelVariableParameters");
806 : }
807 :
808 : //
809 : // Extract the xmlHeader and analyze it to find out what is the byte order and the sequence
810 : // of attribute names.
811 : //
812 0 : string xmlHeader = mimeMsg.substr(loc0, loc1-loc0);
813 : xmlDoc *doc;
814 0 : doc = xmlReadMemory(xmlHeader.data(), xmlHeader.size(), "BinaryTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
815 0 : if ( doc == NULL )
816 0 : throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "DelayModelVariableParameters");
817 :
818 : // This vector will be filled by the names of all the attributes of the table
819 : // in the order in which they are expected to be found in the binary representation.
820 : //
821 0 : vector<string> attributesSeq;
822 :
823 0 : xmlNode* root_element = xmlDocGetRootElement(doc);
824 0 : if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
825 0 : throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "DelayModelVariableParameters");
826 :
827 0 : const ByteOrder* byteOrder=0;
828 0 : if ( string("ASDMBinaryTable").compare((const char*) root_element->name) == 0) {
829 : // Then it's an "old fashioned" MIME file for tables.
830 : // Just try to deserialize it with Big_Endian for the bytes ordering.
831 0 : byteOrder = asdm::ByteOrder::Big_Endian;
832 :
833 : //
834 : // Let's consider a default order for the sequence of attributes.
835 : //
836 :
837 :
838 0 : attributesSeq.push_back("delayModelVariableParametersId") ;
839 :
840 0 : attributesSeq.push_back("time") ;
841 :
842 0 : attributesSeq.push_back("ut1_utc") ;
843 :
844 0 : attributesSeq.push_back("iat_utc") ;
845 :
846 0 : attributesSeq.push_back("timeType") ;
847 :
848 0 : attributesSeq.push_back("gstAtUt0") ;
849 :
850 0 : attributesSeq.push_back("earthRotationRate") ;
851 :
852 0 : attributesSeq.push_back("polarOffsets") ;
853 :
854 0 : attributesSeq.push_back("polarOffsetsType") ;
855 :
856 0 : attributesSeq.push_back("delayModelFixedParametersId") ;
857 :
858 :
859 0 : attributesSeq.push_back("nutationInLongitude") ;
860 :
861 0 : attributesSeq.push_back("nutationInLongitudeRate") ;
862 :
863 0 : attributesSeq.push_back("nutationInObliquity") ;
864 :
865 0 : attributesSeq.push_back("nutationInObliquityRate") ;
866 :
867 :
868 :
869 :
870 : // And decide that it has version == "2"
871 0 : version = "2";
872 : }
873 0 : else if (string("DelayModelVariableParametersTable").compare((const char*) root_element->name) == 0) {
874 : // It's a new (and correct) MIME file for tables.
875 : //
876 : // 1st ) Look for a BulkStoreRef element with an attribute byteOrder.
877 : //
878 0 : xmlNode* bulkStoreRef = 0;
879 0 : xmlNode* child = root_element->children;
880 :
881 0 : if (xmlHasProp(root_element, (const xmlChar*) "schemaVersion")) {
882 0 : xmlChar * value = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
883 0 : version = string ((const char *) value);
884 0 : xmlFree(value);
885 : }
886 :
887 : // Skip the two first children (Entity and ContainerEntity).
888 0 : bulkStoreRef = (child == 0) ? 0 : ( (child->next) == 0 ? 0 : child->next->next );
889 :
890 0 : if ( bulkStoreRef == 0 || (bulkStoreRef->type != XML_ELEMENT_NODE) || (string("BulkStoreRef").compare((const char*) bulkStoreRef->name) != 0))
891 0 : throw ConversionException ("Could not find the element '/DelayModelVariableParametersTable/BulkStoreRef'. Invalid XML header '"+ xmlHeader + "'.", "DelayModelVariableParameters");
892 :
893 : // We found BulkStoreRef, now look for its attribute byteOrder.
894 0 : _xmlAttr* byteOrderAttr = 0;
895 0 : for (struct _xmlAttr* attr = bulkStoreRef->properties; attr; attr = attr->next)
896 0 : if (string("byteOrder").compare((const char*) attr->name) == 0) {
897 0 : byteOrderAttr = attr;
898 0 : break;
899 : }
900 :
901 0 : if (byteOrderAttr == 0)
902 0 : throw ConversionException("Could not find the element '/DelayModelVariableParametersTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader +"'.", "DelayModelVariableParameters");
903 :
904 0 : string byteOrderValue = string((const char*) byteOrderAttr->children->content);
905 0 : if (!(byteOrder = asdm::ByteOrder::fromString(byteOrderValue)))
906 0 : throw ConversionException("No valid value retrieved for the element '/DelayModelVariableParametersTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader + "'.", "DelayModelVariableParameters");
907 :
908 : //
909 : // 2nd) Look for the Attributes element and grab the names of the elements it contains.
910 : //
911 0 : xmlNode* attributes = bulkStoreRef->next;
912 0 : if ( attributes == 0 || (attributes->type != XML_ELEMENT_NODE) || (string("Attributes").compare((const char*) attributes->name) != 0))
913 0 : throw ConversionException ("Could not find the element '/DelayModelVariableParametersTable/Attributes'. Invalid XML header '"+ xmlHeader + "'.", "DelayModelVariableParameters");
914 :
915 0 : xmlNode* childOfAttributes = attributes->children;
916 :
917 0 : while ( childOfAttributes != 0 && (childOfAttributes->type == XML_ELEMENT_NODE) ) {
918 0 : attributesSeq.push_back(string((const char*) childOfAttributes->name));
919 0 : childOfAttributes = childOfAttributes->next;
920 : }
921 : }
922 : // Create an EndianISStream from the substring containing the binary part.
923 0 : EndianISStream eiss(mimeMsg.substr(loc1+binPartMIMEHeader.size()), byteOrder);
924 :
925 0 : entity = Entity::fromBin((EndianIStream&) eiss);
926 :
927 : // We do nothing with that but we have to read it.
928 0 : Entity containerEntity = Entity::fromBin((EndianIStream&) eiss);
929 :
930 : // Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.
931 0 : int numRows = ((EndianIStream&) eiss).readInt();
932 0 : if ((numRows != -1) // Then these are *not* data produced at the EVLA.
933 0 : && ((unsigned int) numRows != this->declaredSize )) { // Then the declared size (in ASDM.xml) is not equal to the one
934 : // written into the binary representation of the table.
935 0 : cout << "The a number of rows ('"
936 : << numRows
937 0 : << "') declared in the binary representation of the table is different from the one declared in ASDM.xml ('"
938 0 : << this->declaredSize
939 0 : << "'). I'll proceed with the value declared in ASDM.xml"
940 0 : << endl;
941 : }
942 :
943 0 : if (getContainer().checkRowUniqueness()) {
944 : try {
945 0 : for (uint32_t i = 0; i < this->declaredSize; i++) {
946 0 : DelayModelVariableParametersRow* aRow = DelayModelVariableParametersRow::fromBin((EndianIStream&) eiss, *this, attributesSeq);
947 0 : checkAndAdd(aRow);
948 : }
949 : }
950 0 : catch (const DuplicateKey &e) {
951 : throw ConversionException("Error while writing binary data , the message was "
952 0 : + e.getMessage(), "DelayModelVariableParameters");
953 : }
954 0 : catch (const TagFormatException &e) {
955 : throw ConversionException("Error while reading binary data , the message was "
956 0 : + e.getMessage(), "DelayModelVariableParameters");
957 : }
958 : }
959 : else {
960 0 : for (uint32_t i = 0; i < this->declaredSize; i++) {
961 0 : DelayModelVariableParametersRow* aRow = DelayModelVariableParametersRow::fromBin((EndianIStream&) eiss, *this, attributesSeq);
962 0 : append(aRow);
963 : }
964 : }
965 : //Does not change the convention defined in the model.
966 : //archiveAsBin = true;
967 : //fileAsBin = true;
968 0 : if ( doc != NULL ) xmlFreeDoc(doc);
969 :
970 0 : }
971 :
972 0 : void DelayModelVariableParametersTable::setUnknownAttributeBinaryReader(const string& attributeName, BinaryAttributeReaderFunctor* barFctr) {
973 : //
974 : // Is this attribute really unknown ?
975 : //
976 0 : for (vector<string>::const_iterator iter = attributesNamesOfDelayModelVariableParameters_v.begin(); iter != attributesNamesOfDelayModelVariableParameters_v.end(); iter++) {
977 0 : if ((*iter).compare(attributeName) == 0)
978 0 : throw ConversionException("the attribute '"+attributeName+"' is known you can't override the way it's read in the MIME binary file containing the table.", "DelayModelVariableParameters");
979 : }
980 :
981 : // Ok then register the functor to activate when an unknown attribute is met during the reading of a binary table?
982 0 : unknownAttributes2Functors[attributeName] = barFctr;
983 0 : }
984 :
985 0 : BinaryAttributeReaderFunctor* DelayModelVariableParametersTable::getUnknownAttributeBinaryReader(const string& attributeName) const {
986 0 : map<string, BinaryAttributeReaderFunctor*>::const_iterator iter = unknownAttributes2Functors.find(attributeName);
987 0 : return (iter == unknownAttributes2Functors.end()) ? 0 : iter->second;
988 : }
989 :
990 :
991 0 : void DelayModelVariableParametersTable::toFile(string directory) {
992 0 : if (!directoryExists(directory.c_str()) &&
993 0 : !createPath(directory.c_str())) {
994 0 : throw ConversionException("Could not create directory " , directory);
995 : }
996 :
997 0 : string fileName = directory + "/DelayModelVariableParameters.xml";
998 0 : ofstream tableout(fileName.c_str(),ios::out|ios::trunc);
999 0 : if (tableout.rdstate() == ostream::failbit)
1000 0 : throw ConversionException("Could not open file " + fileName + " to write ", "DelayModelVariableParameters");
1001 0 : if (fileAsBin)
1002 0 : tableout << MIMEXMLPart();
1003 : else
1004 0 : tableout << toXML() << endl;
1005 0 : tableout.close();
1006 0 : if (tableout.rdstate() == ostream::failbit)
1007 0 : throw ConversionException("Could not close file " + fileName, "DelayModelVariableParameters");
1008 :
1009 0 : if (fileAsBin) {
1010 : // write the bin serialized
1011 0 : string fileName = directory + "/DelayModelVariableParameters.bin";
1012 0 : ofstream tableout(fileName.c_str(),ios::out|ios::trunc);
1013 0 : if (tableout.rdstate() == ostream::failbit)
1014 0 : throw ConversionException("Could not open file " + fileName + " to write ", "DelayModelVariableParameters");
1015 0 : tableout << toMIME() << endl;
1016 0 : tableout.close();
1017 0 : if (tableout.rdstate() == ostream::failbit)
1018 0 : throw ConversionException("Could not close file " + fileName, "DelayModelVariableParameters");
1019 : }
1020 0 : }
1021 :
1022 :
1023 0 : void DelayModelVariableParametersTable::setFromFile(const string& directory) {
1024 : #ifndef WITHOUT_BOOST
1025 : if (boost::filesystem::exists(boost::filesystem::path(uniqSlashes(directory + "/DelayModelVariableParameters.xml"))))
1026 : setFromXMLFile(directory);
1027 : else if (boost::filesystem::exists(boost::filesystem::path(uniqSlashes(directory + "/DelayModelVariableParameters.bin"))))
1028 : setFromMIMEFile(directory);
1029 : #else
1030 : // alternative in Misc.h
1031 0 : if (file_exists(uniqSlashes(directory + "/DelayModelVariableParameters.xml")))
1032 0 : setFromXMLFile(directory);
1033 0 : else if (file_exists(uniqSlashes(directory + "/DelayModelVariableParameters.bin")))
1034 0 : setFromMIMEFile(directory);
1035 : #endif
1036 : else
1037 0 : throw ConversionException("No file found for the DelayModelVariableParameters table", "DelayModelVariableParameters");
1038 0 : }
1039 :
1040 :
1041 0 : void DelayModelVariableParametersTable::setFromMIMEFile(const string& directory) {
1042 0 : string tablePath ;
1043 :
1044 0 : tablePath = directory + "/DelayModelVariableParameters.bin";
1045 0 : ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
1046 0 : if (!tablefile.is_open()) {
1047 0 : throw ConversionException("Could not open file " + tablePath, "DelayModelVariableParameters");
1048 : }
1049 : // Read in a stringstream.
1050 0 : stringstream ss; ss << tablefile.rdbuf();
1051 :
1052 0 : if (tablefile.rdstate() == istream::failbit || tablefile.rdstate() == istream::badbit) {
1053 0 : throw ConversionException("Error reading file " + tablePath,"DelayModelVariableParameters");
1054 : }
1055 :
1056 : // And close.
1057 0 : tablefile.close();
1058 0 : if (tablefile.rdstate() == istream::failbit)
1059 0 : throw ConversionException("Could not close file " + tablePath,"DelayModelVariableParameters");
1060 :
1061 0 : setFromMIME(ss.str());
1062 0 : }
1063 : /*
1064 : void DelayModelVariableParametersTable::openMIMEFile (const string& directory) {
1065 :
1066 : // Open the file.
1067 : string tablePath ;
1068 : tablePath = directory + "/DelayModelVariableParameters.bin";
1069 : ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
1070 : if (!tablefile.is_open())
1071 : throw ConversionException("Could not open file " + tablePath, "DelayModelVariableParameters");
1072 :
1073 : // Locate the xmlPartMIMEHeader.
1074 : string xmlPartMIMEHeader = "CONTENT-ID: <HEADER.XML>\n\n";
1075 : CharComparator comparator;
1076 : istreambuf_iterator<char> BEGIN(tablefile.rdbuf());
1077 : istreambuf_iterator<char> END;
1078 : istreambuf_iterator<char> it = search(BEGIN, END, xmlPartMIMEHeader.begin(), xmlPartMIMEHeader.end(), comparator);
1079 : if (it == END)
1080 : throw ConversionException("failed to detect the beginning of the XML header", "DelayModelVariableParameters");
1081 :
1082 : // Locate the binaryPartMIMEHeader while accumulating the characters of the xml header.
1083 : string binPartMIMEHeader = "--MIME_BOUNDARY\nCONTENT-TYPE: BINARY/OCTET-STREAM\nCONTENT-ID: <CONTENT.BIN>\n\n";
1084 : string xmlHeader;
1085 : CharCompAccumulator compaccumulator(&xmlHeader, 100000);
1086 : ++it;
1087 : it = search(it, END, binPartMIMEHeader.begin(), binPartMIMEHeader.end(), compaccumulator);
1088 : if (it == END)
1089 : throw ConversionException("failed to detect the beginning of the binary part", "DelayModelVariableParameters");
1090 :
1091 : cout << xmlHeader << endl;
1092 : //
1093 : // We have the xmlHeader , let's parse it.
1094 : //
1095 : xmlDoc *doc;
1096 : doc = xmlReadMemory(xmlHeader.data(), xmlHeader.size(), "BinaryTableHeader.xml", NULL, XML_PARSE_NOBLANKS);
1097 : if ( doc == NULL )
1098 : throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "DelayModelVariableParameters");
1099 :
1100 : // This vector will be filled by the names of all the attributes of the table
1101 : // in the order in which they are expected to be found in the binary representation.
1102 : //
1103 : vector<string> attributesSeq(attributesNamesInBinOfDelayModelVariableParameters_v);
1104 :
1105 : xmlNode* root_element = xmlDocGetRootElement(doc);
1106 : if ( root_element == NULL || root_element->type != XML_ELEMENT_NODE )
1107 : throw ConversionException("Failed to parse the xmlHeader into a DOM structure.", "DelayModelVariableParameters");
1108 :
1109 : const ByteOrder* byteOrder=0;
1110 : if ( string("ASDMBinaryTable").compare((const char*) root_element->name) == 0) {
1111 : // Then it's an "old fashioned" MIME file for tables.
1112 : // Just try to deserialize it with Big_Endian for the bytes ordering.
1113 : byteOrder = asdm::ByteOrder::Big_Endian;
1114 :
1115 : // And decide that it has version == "2"
1116 : version = "2";
1117 : }
1118 : else if (string("DelayModelVariableParametersTable").compare((const char*) root_element->name) == 0) {
1119 : // It's a new (and correct) MIME file for tables.
1120 : //
1121 : // 1st ) Look for a BulkStoreRef element with an attribute byteOrder.
1122 : //
1123 : xmlNode* bulkStoreRef = 0;
1124 : xmlNode* child = root_element->children;
1125 :
1126 : if (xmlHasProp(root_element, (const xmlChar*) "schemaVersion")) {
1127 : xmlChar * value = xmlGetProp(root_element, (const xmlChar *) "schemaVersion");
1128 : version = string ((const char *) value);
1129 : xmlFree(value);
1130 : }
1131 :
1132 : // Skip the two first children (Entity and ContainerEntity).
1133 : bulkStoreRef = (child == 0) ? 0 : ( (child->next) == 0 ? 0 : child->next->next );
1134 :
1135 : if ( bulkStoreRef == 0 || (bulkStoreRef->type != XML_ELEMENT_NODE) || (string("BulkStoreRef").compare((const char*) bulkStoreRef->name) != 0))
1136 : throw ConversionException ("Could not find the element '/DelayModelVariableParametersTable/BulkStoreRef'. Invalid XML header '"+ xmlHeader + "'.", "DelayModelVariableParameters");
1137 :
1138 : // We found BulkStoreRef, now look for its attribute byteOrder.
1139 : _xmlAttr* byteOrderAttr = 0;
1140 : for (struct _xmlAttr* attr = bulkStoreRef->properties; attr; attr = attr->next)
1141 : if (string("byteOrder").compare((const char*) attr->name) == 0) {
1142 : byteOrderAttr = attr;
1143 : break;
1144 : }
1145 :
1146 : if (byteOrderAttr == 0)
1147 : throw ConversionException("Could not find the element '/DelayModelVariableParametersTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader +"'.", "DelayModelVariableParameters");
1148 :
1149 : string byteOrderValue = string((const char*) byteOrderAttr->children->content);
1150 : if (!(byteOrder = asdm::ByteOrder::fromString(byteOrderValue)))
1151 : throw ConversionException("No valid value retrieved for the element '/DelayModelVariableParametersTable/BulkStoreRef/@byteOrder'. Invalid XML header '" + xmlHeader + "'.", "DelayModelVariableParameters");
1152 :
1153 : //
1154 : // 2nd) Look for the Attributes element and grab the names of the elements it contains.
1155 : //
1156 : xmlNode* attributes = bulkStoreRef->next;
1157 : if ( attributes == 0 || (attributes->type != XML_ELEMENT_NODE) || (string("Attributes").compare((const char*) attributes->name) != 0))
1158 : throw ConversionException ("Could not find the element '/DelayModelVariableParametersTable/Attributes'. Invalid XML header '"+ xmlHeader + "'.", "DelayModelVariableParameters");
1159 :
1160 : xmlNode* childOfAttributes = attributes->children;
1161 :
1162 : while ( childOfAttributes != 0 && (childOfAttributes->type == XML_ELEMENT_NODE) ) {
1163 : attributesSeq.push_back(string((const char*) childOfAttributes->name));
1164 : childOfAttributes = childOfAttributes->next;
1165 : }
1166 : }
1167 : // Create an EndianISStream from the substring containing the binary part.
1168 : EndianIFStream eifs(&tablefile, byteOrder);
1169 :
1170 : entity = Entity::fromBin((EndianIStream &) eifs);
1171 :
1172 : // We do nothing with that but we have to read it.
1173 : Entity containerEntity = Entity::fromBin((EndianIStream &) eifs);
1174 :
1175 : // Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.
1176 : int numRows = eifs.readInt();
1177 : if ((numRows != -1) // Then these are *not* data produced at the EVLA.
1178 : && ((unsigned int) numRows != this->declaredSize )) { // Then the declared size (in ASDM.xml) is not equal to the one
1179 : // written into the binary representation of the table.
1180 : cout << "The a number of rows ('"
1181 : << numRows
1182 : << "') declared in the binary representation of the table is different from the one declared in ASDM.xml ('"
1183 : << this->declaredSize
1184 : << "'). I'll proceed with the value declared in ASDM.xml"
1185 : << endl;
1186 : }
1187 : // clean up xmlDoc pointer
1188 : if ( doc != NULL ) xmlFreeDoc(doc);
1189 : }
1190 : */
1191 :
1192 :
1193 0 : void DelayModelVariableParametersTable::setFromXMLFile(const string& directory) {
1194 0 : string tablePath ;
1195 :
1196 0 : tablePath = directory + "/DelayModelVariableParameters.xml";
1197 :
1198 : /*
1199 : ifstream tablefile(tablePath.c_str(), ios::in|ios::binary);
1200 : if (!tablefile.is_open()) {
1201 : throw ConversionException("Could not open file " + tablePath, "DelayModelVariableParameters");
1202 : }
1203 : // Read in a stringstream.
1204 : stringstream ss;
1205 : ss << tablefile.rdbuf();
1206 :
1207 : if (tablefile.rdstate() == istream::failbit || tablefile.rdstate() == istream::badbit) {
1208 : throw ConversionException("Error reading file '" + tablePath + "'", "DelayModelVariableParameters");
1209 : }
1210 :
1211 : // And close
1212 : tablefile.close();
1213 : if (tablefile.rdstate() == istream::failbit)
1214 : throw ConversionException("Could not close file '" + tablePath + "'", "DelayModelVariableParameters");
1215 :
1216 : // Let's make a string out of the stringstream content and empty the stringstream.
1217 : string xmlDocument = ss.str(); ss.str("");
1218 :
1219 : // Let's make a very primitive check to decide
1220 : // whether the XML content represents the table
1221 : // or refers to it via a <BulkStoreRef element.
1222 : */
1223 :
1224 0 : string xmlDocument;
1225 : try {
1226 0 : xmlDocument = getContainer().getXSLTransformer()(tablePath);
1227 0 : if (getenv("ASDM_DEBUG")) cout << "About to read " << tablePath << endl;
1228 : }
1229 0 : catch (const XSLTransformerException &e) {
1230 0 : throw ConversionException("Caugth an exception whose message is '" + e.getMessage() + "'.", "DelayModelVariableParameters");
1231 : }
1232 :
1233 0 : if (xmlDocument.find("<BulkStoreRef") != string::npos)
1234 0 : setFromMIMEFile(directory);
1235 : else
1236 0 : fromXML(xmlDocument);
1237 0 : }
1238 :
1239 :
1240 :
1241 :
1242 :
1243 :
1244 :
1245 :
1246 :
1247 :
1248 0 : void DelayModelVariableParametersTable::autoIncrement(string key, DelayModelVariableParametersRow* x) {
1249 0 : map<string, int>::iterator iter;
1250 0 : if ((iter=noAutoIncIds.find(key)) == noAutoIncIds.end()) {
1251 : // There is not yet a combination of the non autoinc attributes values in the hashtable
1252 :
1253 : // Initialize delayModelVariableParametersId to Tag(0).
1254 0 : x->setDelayModelVariableParametersId(Tag(0, TagType::DelayModelVariableParameters));
1255 :
1256 : // Record it in the map.
1257 0 : noAutoIncIds.insert(make_pair(key, 0));
1258 : }
1259 : else {
1260 : // There is already a combination of the non autoinc attributes values in the hashtable
1261 : // Increment its value.
1262 0 : int n = iter->second + 1;
1263 :
1264 : // Initialize delayModelVariableParametersId to Tag(n).
1265 0 : x->setDelayModelVariableParametersId(Tag(n, TagType::DelayModelVariableParameters));
1266 :
1267 : // Record it in the map.
1268 0 : noAutoIncIds.insert(make_pair(key, n));
1269 : }
1270 0 : }
1271 :
1272 : } // End namespace asdm
1273 :
|