/*
 *  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 <mico/CosRelationships.h>
#include "Ownership.h"
#include "Ownership_impl.h" 
#include <mico/Relationship_impl.h>


//#define DEBUG 1


OwnerRole_impl::OwnerRole_impl ()
  : Role_impl ()
{
}



OwnerRole_impl::OwnerRole_impl (CORBA::Object_ptr obj)
  : Role_impl (obj),
    Ownership::OwnerRole_skel (obj)
{
#if DEBUG
  cout << "  <OwnerRole_impl> constructor (restorer)\n";
#endif
}



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



OwnedByRole_impl::OwnedByRole_impl ()
  : Role_impl ()
{
}



OwnedByRole_impl::OwnedByRole_impl (CORBA::Object_ptr obj)
  : Role_impl (obj), 
    Ownership::OwnedByRole_skel (obj) 
{
#if DEBUG
  cout << "  <OwnedByRole_impl> constructor (restorer)\n";
#endif
}



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


Ownership_impl::Ownership_impl ()
  : //IdentifiableObject_impl (), 
    Relationship_impl ()
{
}



Ownership_impl::Ownership_impl (CORBA::Object_ptr obj)
  : Relationship_impl (obj),
    Ownership::Relationship_skel (obj)
{
}


Ownership_impl::Ownership_impl (CosRelationships::NamedRoles nr)
  : Relationship_impl (nr),
    Ownership::Relationship_skel ()
{
}



CORBA::Boolean
OwnerRoleLoader::restore (CORBA::Object_ptr obj)
{
#if DEBUG
  cout << "  <OwnerRoleLoader> Restoring role: " << obj->_repoid() << "\n";
#endif
  //  if (!strcmp (obj->_repoid(), "IDL:omg.org/CosRelationships/Role:1.0")) {
  if (!strcmp (obj->_repoid(), "IDL:omg.org/Ownership/OwnerRole:1.0")) {
#if DEBUG
    cout << "  <OwnerRoleLoader> Creating new OwnerRole_impl:\n";
#endif
    new OwnerRole_impl (obj);
#if DEBUG
    cout << "  <OwnerRoleLoader> Restoring done!\n";
#endif
    return TRUE;
  }

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

  return FALSE;
}



CORBA::Boolean
OwnedByRoleLoader::restore (CORBA::Object_ptr obj)
{
#if DEBUG
  cout << "  <OwnedByRoleLoader> Restoring role: " << obj->_repoid() << "\n";
#endif
  // if (!strcmp (obj->_repoid(), "IDL:omg.org/CosRelationships/Role:1.0")) {
  if (!strcmp (obj->_repoid(), "IDL:omg.org/Ownership/OwnedByRole:1.0")) {
#if DEBUG
    cout << "  <OwnedByRoleLoader> Creating new OwnedByRole_impl:\n";
#endif
    new OwnedByRole_impl (obj);
#if DEBUG
    cout << "  <OwnedByRoleLoader> Restoring done!\n";
#endif
    return TRUE;
  }

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

  return FALSE;
}




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

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

  return FALSE;
}



