| 1 | /******************************************************************************* |
|---|
| 2 | |
|---|
| 3 | Copyright 2004, Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Parser. |
|---|
| 6 | |
|---|
| 7 | OSSIE Parser is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the Lesser GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE Parser is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | Lesser GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the Lesser GNU General Public License |
|---|
| 18 | along with OSSIE Parser; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | Even though all code is original, the architecture of the OSSIE Parser is based |
|---|
| 22 | on the architecture of the CRC's SCA Reference Implementation (SCARI) |
|---|
| 23 | see: http://www.crc.ca/en/html/rmsc/home/sdr/projects/scari |
|---|
| 24 | |
|---|
| 25 | *********************************************************************************/ |
|---|
| 26 | |
|---|
| 27 | #include "ossie/UsesPort.h" |
|---|
| 28 | |
|---|
| 29 | #define mdel(x) if (x!=NULL) delete x, x=NULL; |
|---|
| 30 | #define sweetd(x) if (x!=NULL) delete []x, x=NULL; |
|---|
| 31 | |
|---|
| 32 | UsesPort::UsesPort(): |
|---|
| 33 | Port(), |
|---|
| 34 | identifier(NULL) |
|---|
| 35 | {} |
|---|
| 36 | |
|---|
| 37 | UsesPort::UsesPort(DOMElement * _root): |
|---|
| 38 | Port(_root), |
|---|
| 39 | identifier(NULL) |
|---|
| 40 | { |
|---|
| 41 | this->parseElement(); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | // copy constructor |
|---|
| 45 | UsesPort::UsesPort(const UsesPort & _up): |
|---|
| 46 | Port(_up.root), |
|---|
| 47 | identifier(NULL) |
|---|
| 48 | { |
|---|
| 49 | this->root = _up.root; |
|---|
| 50 | this->findBy = new FindBy (_up.root); |
|---|
| 51 | |
|---|
| 52 | this->ifComponentInstantiationRef = _up.ifComponentInstantiationRef; |
|---|
| 53 | this->ifDeviceThatLoadedThisComponentRef = |
|---|
| 54 | _up.ifDeviceThatLoadedThisComponentRef; |
|---|
| 55 | this->ifDeviceUsedByThisComponentRef = _up.ifDeviceUsedByThisComponentRef; |
|---|
| 56 | this->ifFindBy = _up.ifFindBy; |
|---|
| 57 | |
|---|
| 58 | this->identifier = new char[strlen (_up.identifier) + 1]; |
|---|
| 59 | strcpy (this->identifier, _up.identifier); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | UsesPort::~UsesPort() |
|---|
| 64 | { |
|---|
| 65 | sweetd(identifier); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | void UsesPort::parseElement() |
|---|
| 70 | { |
|---|
| 71 | Port::parseElement(); // call the base class first |
|---|
| 72 | this->parseID(root); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | void UsesPort::parseID(DOMElement * _elem) |
|---|
| 77 | { |
|---|
| 78 | tmpXMLStr = XMLString::transcode("usesidentifier"); |
|---|
| 79 | DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 80 | XMLString::release(&tmpXMLStr); |
|---|
| 81 | |
|---|
| 82 | if (nodeList->getLength () != 0) |
|---|
| 83 | identifier = this->getTextNode((DOMElement *) nodeList->item (0)); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | char* UsesPort::getTextNode(DOMElement * _node) |
|---|
| 88 | { |
|---|
| 89 | DOMNodeList* nodeList = _node->getChildNodes(); |
|---|
| 90 | |
|---|
| 91 | if (nodeList->getLength () == 0) |
|---|
| 92 | { |
|---|
| 93 | char* astr = new char[strlen("Not Specified") +1]; |
|---|
| 94 | strcpy(astr, "Not Specified"); |
|---|
| 95 | return astr; |
|---|
| 96 | } |
|---|
| 97 | else return XMLString::transcode(nodeList->item (0)->getNodeValue ()); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | // \note this should be const char* UsesPort::getID() const |
|---|
| 101 | char* UsesPort::getID() const |
|---|
| 102 | { |
|---|
| 103 | return identifier; |
|---|
| 104 | } |
|---|
| 105 | XMLCh* UsesPort::tmpXMLStr = NULL; |
|---|