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