| 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 | // last updated: 03/11/05 |
|---|
| 27 | // coder: tuan pham |
|---|
| 28 | // optimise constructors and fix transcode leaks |
|---|
| 29 | #ifdef HAVE_STRING_H |
|---|
| 30 | #include <string.h> |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | #include "ossie/Port.h" |
|---|
| 34 | |
|---|
| 35 | #define mdel(x) if (x!=NULL) delete x, x=NULL; |
|---|
| 36 | #define sweetd(x) if (x!=NULL) delete []x, x=NULL; |
|---|
| 37 | |
|---|
| 38 | Port::Port(): |
|---|
| 39 | root(NULL), findBy(NULL), |
|---|
| 40 | ifComponentInstantiationRef(false), |
|---|
| 41 | ifDeviceThatLoadedThisComponentRef(false), |
|---|
| 42 | ifDeviceUsedByThisComponentRef(false), |
|---|
| 43 | ifFindBy(false), |
|---|
| 44 | componentInstantiationRefId(NULL), |
|---|
| 45 | deviceThatLoadedThisComponentRefId(NULL), |
|---|
| 46 | deviceUsedByThisComponentRefId(NULL), |
|---|
| 47 | deviceUsedByThisComponentRefUsesRefId(NULL) |
|---|
| 48 | {} |
|---|
| 49 | |
|---|
| 50 | Port::Port (DOMElement * element): |
|---|
| 51 | root(element), findBy(NULL), |
|---|
| 52 | ifComponentInstantiationRef(false), |
|---|
| 53 | ifDeviceThatLoadedThisComponentRef(false), |
|---|
| 54 | ifDeviceUsedByThisComponentRef(false), |
|---|
| 55 | ifFindBy(false), |
|---|
| 56 | componentInstantiationRefId(NULL), |
|---|
| 57 | deviceThatLoadedThisComponentRefId(NULL), |
|---|
| 58 | deviceUsedByThisComponentRefId(NULL), |
|---|
| 59 | deviceUsedByThisComponentRefUsesRefId(NULL) |
|---|
| 60 | { |
|---|
| 61 | this->parseElement(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | Port::Port (const Port & _port): |
|---|
| 66 | root(_port.root), findBy(NULL), |
|---|
| 67 | ifComponentInstantiationRef(_port.ifComponentInstantiationRef), |
|---|
| 68 | ifDeviceThatLoadedThisComponentRef(_port.ifDeviceThatLoadedThisComponentRef), |
|---|
| 69 | ifDeviceUsedByThisComponentRef(_port.ifDeviceUsedByThisComponentRef), |
|---|
| 70 | ifFindBy(_port.ifFindBy), |
|---|
| 71 | componentInstantiationRefId(NULL), |
|---|
| 72 | deviceThatLoadedThisComponentRefId(NULL), |
|---|
| 73 | deviceUsedByThisComponentRefId(NULL), |
|---|
| 74 | deviceUsedByThisComponentRefUsesRefId(NULL) |
|---|
| 75 | { |
|---|
| 76 | this->findBy = new FindBy (_port.root); |
|---|
| 77 | |
|---|
| 78 | this->componentInstantiationRefId = |
|---|
| 79 | new char[strlen (_port.componentInstantiationRefId) + 1]; |
|---|
| 80 | strcpy(this->componentInstantiationRefId, _port.componentInstantiationRefId); |
|---|
| 81 | |
|---|
| 82 | this->deviceThatLoadedThisComponentRefId = |
|---|
| 83 | new char[strlen (_port.deviceThatLoadedThisComponentRefId) + 1]; |
|---|
| 84 | strcpy (this->deviceThatLoadedThisComponentRefId, _port.deviceThatLoadedThisComponentRefId); |
|---|
| 85 | |
|---|
| 86 | this->deviceUsedByThisComponentRefId = |
|---|
| 87 | new char[strlen (_port.deviceUsedByThisComponentRefId) + 1]; |
|---|
| 88 | strcpy (this->deviceUsedByThisComponentRefId, _port.deviceUsedByThisComponentRefId); |
|---|
| 89 | |
|---|
| 90 | this->deviceUsedByThisComponentRefUsesRefId = |
|---|
| 91 | new char[strlen (_port.deviceUsedByThisComponentRefUsesRefId) + 1]; |
|---|
| 92 | strcpy (this->deviceUsedByThisComponentRefUsesRefId, _port.deviceUsedByThisComponentRefUsesRefId); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | Port::~Port() |
|---|
| 97 | { |
|---|
| 98 | root->release(); // it is safer to let the parser or whoever passes the DOMElement calls release() --Tuan |
|---|
| 99 | mdel(findBy); |
|---|
| 100 | sweetd(componentInstantiationRefId); |
|---|
| 101 | sweetd(deviceThatLoadedThisComponentRefId); |
|---|
| 102 | sweetd(deviceUsedByThisComponentRefId); |
|---|
| 103 | sweetd(deviceUsedByThisComponentRefUsesRefId); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | void Port::parseElement() |
|---|
| 108 | { |
|---|
| 109 | this->parsePort(this->root); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | // \todo implement exception handling for parsePort |
|---|
| 114 | void Port::parsePort (DOMElement * _elem) |
|---|
| 115 | { |
|---|
| 116 | this->parseComponentInstantiationRef (_elem); |
|---|
| 117 | |
|---|
| 118 | if (!this->ifComponentInstantiationRef) |
|---|
| 119 | { |
|---|
| 120 | this->parseDeviceThatLoadedThisComponentRef (_elem); |
|---|
| 121 | |
|---|
| 122 | if (!this->ifDeviceThatLoadedThisComponentRef) |
|---|
| 123 | { |
|---|
| 124 | this->parseDeviceUsedByThisComponentRef (_elem); |
|---|
| 125 | |
|---|
| 126 | if (!this->ifDeviceUsedByThisComponentRef) |
|---|
| 127 | { |
|---|
| 128 | this->parseFindBy (_elem); |
|---|
| 129 | |
|---|
| 130 | if (!this->ifFindBy) |
|---|
| 131 | { |
|---|
| 132 | // string msg = "[Port:parsePort] Invalid XML port"; |
|---|
| 133 | // throw new InvalidProfile( msg ); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | void Port::parseComponentInstantiationRef(DOMElement * _elem) |
|---|
| 142 | { |
|---|
| 143 | tmpXMLStr = XMLString::transcode("componentinstantiationref"); |
|---|
| 144 | DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 145 | sweetd(tmpXMLStr); |
|---|
| 146 | |
|---|
| 147 | if (nodeList->getLength() != 0) |
|---|
| 148 | { |
|---|
| 149 | DOMElement *elem = (DOMElement *) nodeList->item(0); |
|---|
| 150 | |
|---|
| 151 | tmpXMLStr = XMLString::transcode("refid"); |
|---|
| 152 | const XMLCh *refId = elem->getAttribute(tmpXMLStr); |
|---|
| 153 | sweetd(tmpXMLStr); |
|---|
| 154 | |
|---|
| 155 | this->componentInstantiationRefId = XMLString::transcode(refId); |
|---|
| 156 | this->ifComponentInstantiationRef = true; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | void Port::parseDeviceThatLoadedThisComponentRef (DOMElement * _elem) |
|---|
| 162 | { |
|---|
| 163 | tmpXMLStr = XMLString::transcode("devicethatloadedthiscomponentref"); |
|---|
| 164 | DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 165 | sweetd(tmpXMLStr); |
|---|
| 166 | |
|---|
| 167 | if (nodeList->getLength () != 0) |
|---|
| 168 | { |
|---|
| 169 | DOMElement *elem = (DOMElement*) nodeList->item (0); |
|---|
| 170 | |
|---|
| 171 | tmpXMLStr = XMLString::transcode("refid"); |
|---|
| 172 | const XMLCh* refId = elem->getAttribute(tmpXMLStr); |
|---|
| 173 | sweetd(tmpXMLStr); |
|---|
| 174 | |
|---|
| 175 | this->deviceThatLoadedThisComponentRefId = XMLString::transcode(refId); |
|---|
| 176 | this->ifDeviceThatLoadedThisComponentRef = true; |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | void Port::parseFindBy(DOMElement * _elem) |
|---|
| 182 | { |
|---|
| 183 | tmpXMLStr = XMLString::transcode("findby"); |
|---|
| 184 | DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 185 | sweetd(tmpXMLStr); |
|---|
| 186 | |
|---|
| 187 | if (nodeList->getLength () != 0) |
|---|
| 188 | { |
|---|
| 189 | DOMElement *elem = (DOMElement *) nodeList->item (0); |
|---|
| 190 | |
|---|
| 191 | this->findBy = new FindBy(elem); |
|---|
| 192 | this->ifFindBy = true; |
|---|
| 193 | } |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | void Port::parseDeviceUsedByThisComponentRef(DOMElement * _elem) |
|---|
| 198 | { |
|---|
| 199 | tmpXMLStr = XMLString::transcode("deviceusedbythiscomponentref"); |
|---|
| 200 | DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 201 | sweetd(tmpXMLStr); |
|---|
| 202 | |
|---|
| 203 | if (nodeList->getLength() != 0) |
|---|
| 204 | { |
|---|
| 205 | DOMElement* elem = (DOMElement*) nodeList->item(0); |
|---|
| 206 | |
|---|
| 207 | tmpXMLStr = XMLString::transcode("refid"); |
|---|
| 208 | const XMLCh *refId = elem->getAttribute (XMLString::transcode ("refid")); |
|---|
| 209 | sweetd(tmpXMLStr); |
|---|
| 210 | tmpXMLStr = XMLString::transcode("usesrefid"); |
|---|
| 211 | const XMLCh *refUsesId = elem->getAttribute (XMLString::transcode ("usesrefid")); |
|---|
| 212 | sweetd(tmpXMLStr); |
|---|
| 213 | |
|---|
| 214 | this->deviceUsedByThisComponentRefId = XMLString::transcode(refId); |
|---|
| 215 | this->deviceUsedByThisComponentRefUsesRefId =XMLString::transcode(refUsesId); |
|---|
| 216 | this->ifDeviceUsedByThisComponentRef = true; |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | XMLCh* Port::tmpXMLStr = NULL; |
|---|