| 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 DELPTR(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 | // copy constructor |
|---|
| 65 | // deep copy |
|---|
| 66 | Port::Port (const Port &aPort): |
|---|
| 67 | root(aPort.root), findBy(NULL), |
|---|
| 68 | ifComponentInstantiationRef(aPort.ifComponentInstantiationRef), |
|---|
| 69 | ifDeviceThatLoadedThisComponentRef(aPort.ifDeviceThatLoadedThisComponentRef), |
|---|
| 70 | ifDeviceUsedByThisComponentRef(aPort.ifDeviceUsedByThisComponentRef), |
|---|
| 71 | ifFindBy(aPort.ifFindBy), |
|---|
| 72 | componentInstantiationRefId(NULL), |
|---|
| 73 | deviceThatLoadedThisComponentRefId(NULL), |
|---|
| 74 | deviceUsedByThisComponentRefId(NULL), |
|---|
| 75 | deviceUsedByThisComponentRefUsesRefId(NULL) |
|---|
| 76 | { |
|---|
| 77 | this->findBy = new FindBy (aPort.root); |
|---|
| 78 | |
|---|
| 79 | this->componentInstantiationRefId = |
|---|
| 80 | new char[strlen (aPort.componentInstantiationRefId) + 1]; |
|---|
| 81 | strcpy(this->componentInstantiationRefId, aPort.componentInstantiationRefId); |
|---|
| 82 | |
|---|
| 83 | this->deviceThatLoadedThisComponentRefId = |
|---|
| 84 | new char[strlen (aPort.deviceThatLoadedThisComponentRefId) + 1]; |
|---|
| 85 | strcpy (this->deviceThatLoadedThisComponentRefId, |
|---|
| 86 | aPort.deviceThatLoadedThisComponentRefId); |
|---|
| 87 | |
|---|
| 88 | this->deviceUsedByThisComponentRefId = |
|---|
| 89 | new char[strlen (aPort.deviceUsedByThisComponentRefId) + 1]; |
|---|
| 90 | strcpy (this->deviceUsedByThisComponentRefId, aPort.deviceUsedByThisComponentRefId); |
|---|
| 91 | |
|---|
| 92 | this->deviceUsedByThisComponentRefUsesRefId = |
|---|
| 93 | new char[strlen (aPort.deviceUsedByThisComponentRefUsesRefId) + 1]; |
|---|
| 94 | strcpy (this->deviceUsedByThisComponentRefUsesRefId, |
|---|
| 95 | aPort.deviceUsedByThisComponentRefUsesRefId); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | Port::~Port() |
|---|
| 100 | { |
|---|
| 101 | // it is safer to let the parser |
|---|
| 102 | // or whoever passes the DOMElement calls release() --Tuan |
|---|
| 103 | // root->release(); |
|---|
| 104 | |
|---|
| 105 | DELPTR(findBy); |
|---|
| 106 | sweetd(componentInstantiationRefId); |
|---|
| 107 | sweetd(deviceThatLoadedThisComponentRefId); |
|---|
| 108 | sweetd(deviceUsedByThisComponentRefId); |
|---|
| 109 | sweetd(deviceUsedByThisComponentRefUsesRefId); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | void Port::parseElement() |
|---|
| 114 | { |
|---|
| 115 | parsePort(root); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | // \todo implement exception handling for parsePort |
|---|
| 120 | void Port::parsePort (DOMElement * _elem) |
|---|
| 121 | { |
|---|
| 122 | this->parseComponentInstantiationRef (_elem); |
|---|
| 123 | |
|---|
| 124 | if (!this->ifComponentInstantiationRef) |
|---|
| 125 | { |
|---|
| 126 | this->parseDeviceThatLoadedThisComponentRef (_elem); |
|---|
| 127 | |
|---|
| 128 | if (!this->ifDeviceThatLoadedThisComponentRef) |
|---|
| 129 | { |
|---|
| 130 | this->parseDeviceUsedByThisComponentRef (_elem); |
|---|
| 131 | |
|---|
| 132 | if (!this->ifDeviceUsedByThisComponentRef) |
|---|
| 133 | { |
|---|
| 134 | this->parseFindBy (_elem); |
|---|
| 135 | |
|---|
| 136 | if (!this->ifFindBy) |
|---|
| 137 | { |
|---|
| 138 | // string msg = "[Port:parsePort] Invalid XML port"; |
|---|
| 139 | // throw new InvalidProfile( msg ); |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | void Port::parseComponentInstantiationRef(DOMElement * _elem) |
|---|
| 148 | { |
|---|
| 149 | tmpXMLStr = XMLString::transcode("componentinstantiationref"); |
|---|
| 150 | DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 151 | XMLString::release(&tmpXMLStr); |
|---|
| 152 | |
|---|
| 153 | if (nodeList->getLength() != 0) |
|---|
| 154 | { |
|---|
| 155 | DOMElement *elem = (DOMElement *) nodeList->item(0); |
|---|
| 156 | |
|---|
| 157 | tmpXMLStr = XMLString::transcode("refid"); |
|---|
| 158 | const XMLCh *refId = elem->getAttribute(tmpXMLStr); |
|---|
| 159 | XMLString::release(&tmpXMLStr); |
|---|
| 160 | |
|---|
| 161 | this->componentInstantiationRefId = XMLString::transcode(refId); |
|---|
| 162 | this->ifComponentInstantiationRef = true; |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | void Port::parseDeviceThatLoadedThisComponentRef (DOMElement * _elem) |
|---|
| 168 | { |
|---|
| 169 | tmpXMLStr = XMLString::transcode("devicethatloadedthiscomponentref"); |
|---|
| 170 | DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 171 | XMLString::release(&tmpXMLStr); |
|---|
| 172 | |
|---|
| 173 | if (nodeList->getLength () != 0) |
|---|
| 174 | { |
|---|
| 175 | DOMElement *elem = (DOMElement*) nodeList->item (0); |
|---|
| 176 | |
|---|
| 177 | tmpXMLStr = XMLString::transcode("refid"); |
|---|
| 178 | const XMLCh* refId = elem->getAttribute(tmpXMLStr); |
|---|
| 179 | XMLString::release(&tmpXMLStr); |
|---|
| 180 | |
|---|
| 181 | this->deviceThatLoadedThisComponentRefId = XMLString::transcode(refId); |
|---|
| 182 | this->ifDeviceThatLoadedThisComponentRef = true; |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | void Port::parseFindBy(DOMElement * _elem) |
|---|
| 188 | { |
|---|
| 189 | tmpXMLStr = XMLString::transcode("findby"); |
|---|
| 190 | DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 191 | XMLString::release(&tmpXMLStr); |
|---|
| 192 | |
|---|
| 193 | if (nodeList->getLength () != 0) |
|---|
| 194 | { |
|---|
| 195 | DOMElement *elem = (DOMElement *) nodeList->item (0); |
|---|
| 196 | |
|---|
| 197 | this->findBy = new FindBy(elem); |
|---|
| 198 | this->ifFindBy = true; |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | void Port::parseDeviceUsedByThisComponentRef(DOMElement * _elem) |
|---|
| 204 | { |
|---|
| 205 | tmpXMLStr = XMLString::transcode("deviceusedbythiscomponentref"); |
|---|
| 206 | DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 207 | XMLString::release(&tmpXMLStr); |
|---|
| 208 | |
|---|
| 209 | if (nodeList->getLength() != 0) |
|---|
| 210 | { |
|---|
| 211 | DOMElement* elem = (DOMElement*) nodeList->item(0); |
|---|
| 212 | |
|---|
| 213 | tmpXMLStr = XMLString::transcode("refid"); |
|---|
| 214 | const XMLCh *refId = elem->getAttribute(tmpXMLStr); |
|---|
| 215 | XMLString::release(&tmpXMLStr); |
|---|
| 216 | tmpXMLStr = XMLString::transcode("usesrefid"); |
|---|
| 217 | const XMLCh *refUsesId = elem->getAttribute(tmpXMLStr); |
|---|
| 218 | XMLString::release(&tmpXMLStr); |
|---|
| 219 | |
|---|
| 220 | this->deviceUsedByThisComponentRefId = XMLString::transcode(refId); |
|---|
| 221 | this->deviceUsedByThisComponentRefUsesRefId =XMLString::transcode(refUsesId); |
|---|
| 222 | this->ifDeviceUsedByThisComponentRef = true; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | XMLCh* Port::tmpXMLStr = NULL; |
|---|