/*
 *  Demo of COSS Relationship Service
 *  Copyright (C) 1998 Karel Gardas
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Send comments and/or bug reports to:
 *                 mico@informatik.uni-frankfurt.de
 *  or to my private e-mail:
 *                 gardask@alpha.inf.upol.cz
 */


#include <fstream.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#include <mico/CosRelationships.h>
#include "Containment.h"
#include "Containment_impl.h" 
#include <mico/Relationship_impl.h>


//#define DEBUG 1


ContainsRole_impl::ContainsRole_impl ()
  : Role_impl ()
{
}



ContainsRole_impl::ContainsRole_impl (CORBA::Object_ptr obj)
  : Role_impl (obj),
    Containment::ContainsRole_skel (obj)
{
#if DEBUG
  cout << "  <ContainsRole_impl> constructor (restorer)\n";
#endif
}



ContainsRole_impl::ContainsRole_impl (CosRelationships::RelatedObject_ptr obj,
				      CORBA::Long card)
  : Role_impl (obj, card),
    Containment::ContainsRole_skel ()
{
#if DEBUG
  cout << "  <ContainsRole_impl> constructor with params\n";
#endif
}



ContainedInRole_impl::ContainedInRole_impl ()
  : Role_impl ()
{
}



ContainedInRole_impl::ContainedInRole_impl (CORBA::Object_ptr obj)
  : Role_impl (obj), 
    Containment::ContainedInRole_skel (obj) 
{
#if DEBUG
  cout << "  <ContainedInRole_impl> constructor (restorer)\n";
#endif
}



ContainedInRole_impl::ContainedInRole_impl 
(CosRelationships::RelatedObject_ptr obj,
 CORBA::Long card)
  : Role_impl (obj, card),
    Containment::ContainedInRole_skel ()
{
#if DEBUG
  cout << "  <ContainedInRole_impl> constructor with params\n";
#endif
}


Containment_impl::Containment_impl ()
  : Relationship_impl ()
{
}



Containment_impl::Containment_impl (CORBA::Object_ptr obj)
  : Relationship_impl (obj),
    Containment::Relationship_skel (obj)
{
}


Containment_impl::Containment_impl (CosRelationships::NamedRoles nr)
  : Relationship_impl (nr),
    Containment::Relationship_skel ()
{
}



CORBA::Boolean
Containment_impl::_save_object ()
{
  CORBA::ORB_ptr orb = _orb(); 

#if DEBUG
  cout << "  <Containment_impl> _save_object (): " << _ident () << "\n";
  cout << "  <Containment_impl> _save_object (): " 
       << Relationship_impl::_ident () << "\n";
#endif

  Relationship_impl::_save_object ();
  return TRUE;

}


CORBA::Boolean
ContainsRoleLoader::restore (CORBA::Object_ptr obj)
{
#if DEBUG
  cout << "  <ContainsRoleLoader> Restoring role: " << obj->_repoid() << "\n";
#endif
  if (!strcmp (obj->_repoid(), "IDL:omg.org/Containment/ContainsRole:1.0")) {
#if DEBUG
    cout << "  <ContainsRoleLoader> Creating new ContainsRole_impl:\n";
#endif
    new ContainsRole_impl (obj);
#if DEBUG
    cout << "  <ContainsRoleLoader> Restoring done!\n";
#endif
    return TRUE;
  }

#if DEBUG
  cout << "  <ContainsRoleLoader> cannot restore " << obj->_repoid() 
       << " objects" << endl;
#endif

  return FALSE;
}



CORBA::Boolean
ContainedInRoleLoader::restore (CORBA::Object_ptr obj)
{
#if DEBUG
  cout << "  <ContainedInRoleLoader> Restoring role: " << obj->_repoid() 
       << "\n";
#endif
  if (!strcmp (obj->_repoid(), "IDL:omg.org/Containment/ContainedInRole:1.0")) {
#if DEBUG
    cout << "  <ContainedInRoleLoader> Creating new ContainedInRole_impl:\n";
#endif
    new ContainedInRole_impl (obj);
#if DEBUG
    cout << "  <ContainedInRoleLoader> Restoring done!\n";
#endif
    return TRUE;
  }

#if DEBUG
  cout << "  <ContainedInRoleLoader> cannot restore " << obj->_repoid() 
       << " objects" << endl;
#endif

  return FALSE;
}




CORBA::Boolean
ContainmentLoader::restore (CORBA::Object_ptr obj)
{
#if DEBUG
  cout << "  <ContainmentLoader> Restoring relationship: " << obj->_repoid() 
       << "\n";
#endif
  if (!strcmp (obj->_repoid(), "IDL:omg.org/Containment/Relationship:1.0")) {
#if DEBUG
    cout << "  <ContainmentLoader> Creating new Containment_impl:\n";
#endif
    new Containment_impl (obj);
#if DEBUG
    cout << "  <ContainmentLoader> Restoring done!\n";
#endif
    return TRUE;
  }

#if DEBUG
  cout << "  <ContainmentLoader> cannot restore " << obj->_repoid() 
       << " objects" << endl;
#endif

  return FALSE;
}



