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