LCOV - code coverage report
Current view: top level - alma/ASDM - Entity.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 134 0.0 %
Date: 2024-10-04 18:58:15 Functions: 0 28 0.0 %

          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           0 :   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           0 :   EntityId Entity::getEntityId() const {
      59           0 :     return entityId;
      60             :   }
      61             : 
      62           0 :   string Entity::getEntityIdEncrypted() const {
      63           0 :     return entityIdEncrypted;
      64             :   }
      65             : 
      66           0 :   string Entity::getEntityTypeName() const {
      67           0 :     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           0 :   void Entity::setEntityId(EntityId e) {
      79           0 :     entityId = e;
      80           0 :   }
      81             : 
      82           0 :   void Entity::setEntityIdEncrypted(string s) {
      83           0 :     entityIdEncrypted = s;
      84           0 :   }
      85             : 
      86           0 :   void Entity::setEntityTypeName(string s) {
      87           0 :     entityTypeName = s;
      88           0 :   }
      89             : 
      90           0 :   void Entity::setEntityVersion(string s) {
      91           0 :     entityVersion = s;
      92           0 :   }
      93             : 
      94           0 :   void Entity::setInstanceVersion(string s) {
      95           0 :     instanceVersion = s;
      96           0 :   }
      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           0 :   Entity::Entity() : entityId() {
     119           0 :     entityIdEncrypted = "";
     120           0 :     entityTypeName = "";
     121           0 :     entityVersion = "";
     122           0 :     instanceVersion = "";
     123           0 :   }
     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           0 :   string Entity::getXMLValue(string xml, string parm) const {
     159           0 :     string::size_type n = xml.find(parm+"=",0);
     160           0 :     if (n == string::npos)
     161           0 :       return "";
     162           0 :     string::size_type beg = xml.find("\"",n + parm.length());
     163           0 :     if (beg == string::npos)
     164           0 :       return "";
     165           0 :     beg++;
     166           0 :     string::size_type end = xml.find("\"",beg);
     167           0 :     if (end == string::npos)
     168           0 :       return "";
     169           0 :     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           0 :   void Entity::setFromXML(string xml) {
     226           0 :     entityId.setId(getXMLValue(xml,"entityId"));
     227           0 :     entityIdEncrypted = getXMLValue(xml,"entityIdEncrypted");
     228           0 :     entityTypeName = getXMLValue(xml,"entityTypeName");
     229           0 :     entityVersion = getXMLValue(xml,"schemaVersion");
     230           0 :     instanceVersion = getXMLValue(xml,"documentVersion");
     231           0 :     if (entityIdEncrypted.length() == 0 ||
     232           0 :         entityTypeName.length() == 0 ||
     233           0 :         entityVersion.length() == 0 ||
     234           0 :         instanceVersion.length() == 0)
     235           0 :       throw InvalidArgumentException("Null values detected in Entity " + entityId.toString());
     236           0 :   }
     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           0 :   Entity Entity::fromBin(EndianIStream& eis) {
     247           0 :     Entity entity;
     248           0 :     entity.setEntityId(EntityId(eis.readString()));
     249           0 :     entity.setEntityIdEncrypted(eis.readString());
     250           0 :     entity.setEntityTypeName(eis.readString());
     251           0 :     entity.setEntityVersion(eis.readString());
     252           0 :     entity.setInstanceVersion(eis.readString());
     253           0 :     return entity;
     254           0 :   }
     255             : } // End namespace asdm

Generated by: LCOV version 1.16