/*
 *  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 "Reference.h"
#include "Reference_impl.h" 
#include <mico/Relationship_impl.h>


//#define DEBUG 1


ReferencesRole_impl::ReferencesRole_impl ()
  : Role_impl ()
{
}



ReferencesRole_impl::ReferencesRole_impl (CORBA::Object_ptr obj)
  : Role_impl (obj),
    Reference::ReferencesRole_skel (obj)
{
#if DEBUG
  cout << "  <ReferencesRole_impl> constructor (restorer)\n";
#endif
}



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



ReferencedByRole_impl::ReferencedByRole_impl ()
  : Role_impl ()
{
}



ReferencedByRole_impl::ReferencedByRole_impl (CORBA::Object_ptr obj)
  : Role_impl (obj), 
    Reference::ReferencedByRole_skel (obj) 
{
#if DEBUG
  cout << "  <ReferencedByRole_impl> constructor (restorer)\n";
#endif
}



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


Reference_impl::Reference_impl ()
  : Relationship_impl ()
{
}



Reference_impl::Reference_impl (CORBA::Object_ptr obj)
  : Relationship_impl (obj),
    Reference::Relationship_skel (obj)
{
}


Reference_impl::Reference_impl (CosRelationships::NamedRoles nr)
  : Relationship_impl (nr),
    Reference::Relationship_skel ()
{
}



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

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

  Relationship_impl::_save_object ();
  return TRUE;

}


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

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

  return FALSE;
}



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

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

  return FALSE;
}




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

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

  return FALSE;
}



