LCOV - code coverage report
Current view: top level - alma/ASDM - Entity.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 54 134 40.3 %
Date: 2025-07-23 00:22:00 Functions: 12 28 42.9 %

          Line data    Source code
       1             : /*
       2             :  * ALMA - Atacama Large Millimeter Array
       3             :  * (c) European Southern Observatory, 2002
       4             :  * (c) Associated Universities Inc., 2002
       5             :  * Copyright by ESO (in the framework of the ALMA collaboration),
       6             :  * Copyright by AUI (in the framework of the ALMA collaboration),
       7             :  * All rights reserved.
       8             :  * 
       9             :  * This library is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public
      11             :  * License as published by the Free software Foundation; either
      12             :  * version 2.1 of the License, or (at your option) any later version.
      13             :  * 
      14             :  * This library is distributed in the hope that it will be useful,
      15             :  * but WITHOUT ANY WARRANTY, without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  * 
      19             :  * You should have received a copy of the GNU Lesser General Public
      20             :  * License along with this library; if not, write to the Free Software
      21             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      22             :  * MA 02111-1307  USA
      23             :  *
      24             :  * File Entity.cpp
      25             :  */
      26             : 
      27             : #include <alma/ASDM/Entity.h>
      28             : #include <alma/ASDM/OutOfBoundsException.h>
      29             : #include <alma/ASDM/InvalidArgumentException.h>
      30             : #include <alma/ASDM/InvalidDataException.h>
      31             : 
      32             : using namespace std;
      33             : 
      34             : namespace asdm {
      35             : 
      36             :   // Entity constructors
      37           0 :   Entity::Entity(const string &s) {
      38           0 :     setFromXML(s);
      39           0 :   }
      40             : 
      41             :   // Entity destructor
      42        3526 :   Entity::~Entity() { }
      43             : 
      44           0 :   bool Entity::isNull() const {
      45           0 :     return entityId.isNull();
      46             :   }
      47             : 
      48           0 :   string Entity::toString() const {
      49           0 :     return toXML();
      50             :   }
      51             : 
      52           0 :   bool Entity::equals(const Entity &x) const {
      53           0 :     return *this == x;
      54             :   }
      55             : 
      56             :   // Getters and Setters
      57             : 
      58         966 :   EntityId Entity::getEntityId() const {
      59         966 :     return entityId;
      60             :   }
      61             : 
      62           0 :   string Entity::getEntityIdEncrypted() const {
      63           0 :     return entityIdEncrypted;
      64             :   }
      65             : 
      66         703 :   string Entity::getEntityTypeName() const {
      67         703 :     return entityTypeName;
      68             :   }
      69             : 
      70           0 :   string Entity::getEntityVersion() const {
      71           0 :     return entityVersion;
      72             :   }
      73             : 
      74           0 :   string Entity::getInstanceVersion() const {
      75           0 :     return instanceVersion;
      76             :   }
      77             : 
      78        1286 :   void Entity::setEntityId(EntityId e) {
      79        1286 :     entityId = e;
      80        1286 :   }
      81             : 
      82        1286 :   void Entity::setEntityIdEncrypted(string s) {
      83        1286 :     entityIdEncrypted = s;
      84        1286 :   }
      85             : 
      86        1286 :   void Entity::setEntityTypeName(string s) {
      87        1286 :     entityTypeName = s;
      88        1286 :   }
      89             : 
      90        1286 :   void Entity::setEntityVersion(string s) {
      91        1286 :     entityVersion = s;
      92        1286 :   }
      93             : 
      94        1286 :   void Entity::setInstanceVersion(string s) {
      95        1286 :     instanceVersion = s;
      96        1286 :   }
      97             : 
      98             :   // Friend functions
      99             : 
     100           0 :   ostream & operator << ( ostream &o, const Entity &x ) {
     101           0 :     o << x.toXML();
     102           0 :     return o;
     103             :   }
     104             : 
     105           0 :   Entity Entity::getEntity(StringTokenizer &t) {
     106             :     try {
     107           0 :       string s = t.nextToken("<>");
     108           0 :       if (s == " ")
     109           0 :         s = t.nextToken();
     110           0 :       Entity e;
     111           0 :       e.setFromXML(s);
     112           0 :       return e;
     113           0 :     } catch (const OutOfBoundsException &err) {
     114           0 :       throw InvalidArgumentException("Unexpected end-of-string!");
     115           0 :     }
     116             :   }
     117             : 
     118        3249 :   Entity::Entity() : entityId() {
     119        3249 :     entityIdEncrypted = "";
     120        3249 :     entityTypeName = "";
     121        3249 :     entityVersion = "";
     122        3249 :     instanceVersion = "";
     123        3249 :   }
     124             : 
     125             : #ifndef WITHOUT_ACS
     126             :   Entity::Entity(asdmIDLTypes::IDLEntity &x) : entityId(string(x.entityId)) {
     127             :     entityIdEncrypted = string(x.entityIdEncrypted);
     128             :     entityTypeName = string(x.entityTypeName);
     129             :     entityVersion = string(x.entityVersion);
     130             :     instanceVersion = string(x.instanceVersion);
     131             :   }
     132             : #endif
     133             : 
     134           0 :   Entity::Entity(string id, string sEncrypted, string sTypeName,
     135           0 :                  string sVersion, string sInstanceVersion) : entityId(id){
     136           0 :     entityIdEncrypted = sEncrypted;
     137           0 :     entityTypeName = sTypeName;
     138           0 :     entityVersion = sVersion;
     139           0 :     instanceVersion = sInstanceVersion;
     140           0 :   }
     141             : 
     142           0 :   bool Entity::operator == (const Entity& e) const {
     143           0 :     return      entityId.getId() == e.entityId.getId() &&
     144           0 :       entityIdEncrypted == e.entityIdEncrypted &&
     145           0 :       entityTypeName == e.entityTypeName &&
     146           0 :       entityVersion == e.entityVersion &&
     147           0 :       instanceVersion == e.instanceVersion;
     148             :   }
     149             : 
     150           0 :   bool Entity::operator != (const Entity& e) const {
     151           0 :     return      entityId.getId() != e.entityId.getId() ||
     152           0 :       entityIdEncrypted != e.entityIdEncrypted ||
     153           0 :       entityTypeName != e.entityTypeName ||
     154           0 :       entityVersion != e.entityVersion ||
     155           0 :       instanceVersion != e.instanceVersion;
     156             :   }
     157             : 
     158        3515 :   string Entity::getXMLValue(string xml, string parm) const {
     159        3515 :     string::size_type n = xml.find(parm+"=",0);
     160        3515 :     if (n == string::npos)
     161           0 :       return "";
     162        3515 :     string::size_type beg = xml.find("\"",n + parm.length());
     163        3515 :     if (beg == string::npos)
     164           0 :       return "";
     165        3515 :     beg++;
     166        3515 :     string::size_type end = xml.find("\"",beg);
     167        3515 :     if (end == string::npos)
     168           0 :       return "";
     169        3515 :     return xml.substr(beg,(end - beg));
     170             :   }
     171             : 
     172           0 :   string Entity::validXML() const {
     173             :     // Check for any null values.
     174           0 :     string msg = "Null values detected in Entity " + entityId.getId();
     175           0 :     if (entityId.isNull() ||
     176           0 :         entityIdEncrypted.length() == 0 ||
     177           0 :         entityTypeName.length() == 0 ||
     178           0 :         entityVersion.length() == 0 ||
     179           0 :         instanceVersion.length() == 0)
     180           0 :       return msg;
     181             :     // Check the entityId for the correct format.
     182           0 :     return EntityId::validate(entityId.toString());
     183           0 :   }
     184             : 
     185             :   /**
     186             :    * Return the values of this Entity as an XML-formated string.
     187             :    * As an example, for the Main table in the ASDM, the toXML 
     188             :    * method would give:
     189             :    * <ul>
     190             :    * <li> &lt;Entity 
     191             :    * <li>         entityId="uid://X0000000000000079/X00000000" 
     192             :    * <li>         entityIdEncrypted="none" 
     193             :    * <li>         entityTypeName="Main" 
     194             :    * <li>         schemaVersion="1" 
     195             :    * <li>         documentVersion="1"/&gt;
     196             :    * </ul>
     197             :    * 
     198             :    * @return The values of this Entity as an XML-formated string.
     199             :    * @throws IllegalStateException if the values of this Entity do not conform to the proper XML format.
     200             :    */
     201           0 :   string Entity::toXML() const {
     202           0 :     string msg = validXML();
     203           0 :     if (msg.length() != 0) 
     204           0 :       throw InvalidDataException(msg);
     205           0 :     string s = "<Entity entityId=\"" + entityId.toString() +
     206           0 :       "\" entityIdEncrypted=\"" + entityIdEncrypted +
     207           0 :       "\" entityTypeName=\"" + entityTypeName + 
     208           0 :       "\" schemaVersion=\"" + entityVersion +
     209           0 :       "\" documentVersion=\"" + instanceVersion + "\"/>";
     210           0 :     return s;
     211           0 :   }
     212             : 
     213             : #ifndef WITHOUT_ACS
     214             :   asdmIDLTypes::IDLEntity Entity::toIDLEntity() const {
     215             :     asdmIDLTypes::IDLEntity e;
     216             :     e.entityId = CORBA::string_dup(entityId.getId().c_str());
     217             :     e.entityIdEncrypted = CORBA::string_dup(entityIdEncrypted.c_str());
     218             :     e.entityTypeName = CORBA::string_dup(entityTypeName.c_str());
     219             :     e.entityVersion = CORBA::string_dup(entityVersion.c_str());
     220             :     e.instanceVersion = CORBA::string_dup(instanceVersion.c_str());
     221             :     return e;
     222             :   }
     223             : #endif
     224             : 
     225         703 :   void Entity::setFromXML(string xml) {
     226         703 :     entityId.setId(getXMLValue(xml,"entityId"));
     227         703 :     entityIdEncrypted = getXMLValue(xml,"entityIdEncrypted");
     228         703 :     entityTypeName = getXMLValue(xml,"entityTypeName");
     229         703 :     entityVersion = getXMLValue(xml,"schemaVersion");
     230         703 :     instanceVersion = getXMLValue(xml,"documentVersion");
     231        1406 :     if (entityIdEncrypted.length() == 0 ||
     232        1406 :         entityTypeName.length() == 0 ||
     233        2109 :         entityVersion.length() == 0 ||
     234         703 :         instanceVersion.length() == 0)
     235           0 :       throw InvalidArgumentException("Null values detected in Entity " + entityId.toString());
     236         703 :   }
     237             :                 
     238           0 :   void Entity::toBin(EndianOSStream& eoss) const {
     239           0 :     entityId.toBin(eoss);
     240           0 :     eoss.writeString(entityIdEncrypted);
     241           0 :     eoss.writeString(entityTypeName);
     242           0 :     eoss.writeString(entityVersion);
     243           0 :     eoss.writeString(instanceVersion);
     244           0 :   }
     245             :         
     246          26 :   Entity Entity::fromBin(EndianIStream& eis) {
     247          26 :     Entity entity;
     248          26 :     entity.setEntityId(EntityId(eis.readString()));
     249          26 :     entity.setEntityIdEncrypted(eis.readString());
     250          26 :     entity.setEntityTypeName(eis.readString());
     251          26 :     entity.setEntityVersion(eis.readString());
     252          26 :     entity.setInstanceVersion(eis.readString());
     253          26 :     return entity;
     254           0 :   }
     255             : } // End namespace asdm

Generated by: LCOV version 1.16