/*
 *  MICO --- an Open Source CORBA implementation
 *  Copyright (c) 1997-2001 by The Mico Team
 *
 *  This file was automatically generated. DO NOT EDIT!
 */

#include "CorbaFriendlySession.h"


using namespace std;

//--------------------------------------------------------
//  Implementation of stubs
//--------------------------------------------------------

/*
 * Base interface for class CorbaFriendlySession
 */

examples::CorbaFriendlySession::~CorbaFriendlySession()
{
}

void *
examples::CorbaFriendlySession::_narrow_helper( const char *_repoid )
{
  if( strcmp( _repoid, "RMI:examples.CorbaFriendlySession:0000000000000000" ) == 0 )
    return (void *)this;
  {
    void *_p;
    if ((_p = javax::ejb::EJBObject::_narrow_helper( _repoid )))
      return _p;
  }
  return NULL;
}

examples::CorbaFriendlySession_ptr
examples::CorbaFriendlySession::_narrow( CORBA::Object_ptr _obj )
{
  examples::CorbaFriendlySession_ptr _o;
  if( !CORBA::is_nil( _obj ) ) {
    void *_p;
    if( (_p = _obj->_narrow_helper( "RMI:examples.CorbaFriendlySession:0000000000000000" )))
      return _duplicate( (examples::CorbaFriendlySession_ptr) _p );
    if (!strcmp (_obj->_repoid(), "RMI:examples.CorbaFriendlySession:0000000000000000") || _obj->_is_a_remote ("RMI:examples.CorbaFriendlySession:0000000000000000")) {
      _o = new examples::CorbaFriendlySession_stub;
      _o->CORBA::Object::operator=( *_obj );
      return _o;
    }
  }
  return _nil();
}

examples::CorbaFriendlySession_ptr
examples::CorbaFriendlySession::_narrow( CORBA::AbstractBase_ptr _obj )
{
  return _narrow (_obj->_to_object());
}

class _Marshaller_examples_CorbaFriendlySession : public ::CORBA::StaticTypeInfo {
    typedef examples::CorbaFriendlySession_ptr _MICO_T;
  public:
    StaticValueType create () const;
    void assign (StaticValueType dst, const StaticValueType src) const;
    void free (StaticValueType) const;
    void release (StaticValueType) const;
    ::CORBA::Boolean demarshal (::CORBA::DataDecoder&, StaticValueType) const;
    void marshal (::CORBA::DataEncoder &, StaticValueType) const;
};


::CORBA::StaticValueType _Marshaller_examples_CorbaFriendlySession::create() const
{
  return (StaticValueType) new _MICO_T( 0 );
}

void _Marshaller_examples_CorbaFriendlySession::assign( StaticValueType d, const StaticValueType s ) const
{
  *(_MICO_T*) d = ::examples::CorbaFriendlySession::_duplicate( *(_MICO_T*) s );
}

void _Marshaller_examples_CorbaFriendlySession::free( StaticValueType v ) const
{
  ::CORBA::release( *(_MICO_T *) v );
  delete (_MICO_T*) v;
}

void _Marshaller_examples_CorbaFriendlySession::release( StaticValueType v ) const
{
  ::CORBA::release( *(_MICO_T *) v );
}

::CORBA::Boolean _Marshaller_examples_CorbaFriendlySession::demarshal( ::CORBA::DataDecoder &dc, StaticValueType v ) const
{
  ::CORBA::Object_ptr obj;
  if (!::CORBA::_stc_Object->demarshal(dc, &obj))
    return FALSE;
  *(_MICO_T *) v = ::examples::CorbaFriendlySession::_narrow( obj );
  ::CORBA::Boolean ret = ::CORBA::is_nil (obj) || !::CORBA::is_nil (*(_MICO_T *)v);
  ::CORBA::release (obj);
  return ret;
}

void _Marshaller_examples_CorbaFriendlySession::marshal( ::CORBA::DataEncoder &ec, StaticValueType v ) const
{
  ::CORBA::Object_ptr obj = *(_MICO_T *) v;
  ::CORBA::_stc_Object->marshal( ec, &obj );
}

::CORBA::StaticTypeInfo *_marshaller_examples_CorbaFriendlySession;


/*
 * Stub interface for class CorbaFriendlySession
 */

examples::CorbaFriendlySession_stub::~CorbaFriendlySession_stub()
{
}

#ifndef MICO_CONF_NO_POA

void *
POA_examples::CorbaFriendlySession::_narrow_helper (const char * repoid)
{
  void * p;
  if (strcmp (repoid, "RMI:examples.CorbaFriendlySession:0000000000000000") == 0) {
    return (void *) this;
  }
  if ((p = POA_javax::ejb::EJBObject::_narrow_helper (repoid)) != NULL) 
  {
    return p;
  }
  return NULL;
}

POA_examples::CorbaFriendlySession *
POA_examples::CorbaFriendlySession::_narrow (PortableServer::Servant serv) 
{
  void * p;
  if ((p = serv->_narrow_helper ("RMI:examples.CorbaFriendlySession:0000000000000000")) != NULL) {
    serv->_add_ref ();
    return (POA_examples::CorbaFriendlySession *) p;
  }
  return NULL;
}

examples::CorbaFriendlySession_stub_clp::CorbaFriendlySession_stub_clp ()
{
}

examples::CorbaFriendlySession_stub_clp::CorbaFriendlySession_stub_clp (PortableServer::POA_ptr poa, CORBA::Object_ptr obj)
  : CORBA::Object(*obj), MICO_SCOPE(PortableServer,StubBase) (poa)
{
}

examples::CorbaFriendlySession_stub_clp::~CorbaFriendlySession_stub_clp ()
{
}

#endif // MICO_CONF_NO_POA

org::omg::boxedIDL::examples::corba::DataObject* examples::CorbaFriendlySession_stub::echo( org::omg::boxedIDL::examples::corba::DataObject* _par_arg0 )
{
  CORBA::StaticAny _sa_arg0( _marshaller_org_omg_boxedIDL_examples_corba_DataObject, &_par_arg0 );
  org::omg::boxedIDL::examples::corba::DataObject* _res;
  CORBA::StaticAny __res( _marshaller_org_omg_boxedIDL_examples_corba_DataObject, &_res );

  CORBA::StaticRequest __req( this, "echo" );
  __req.add_in_arg( &_sa_arg0 );
  __req.set_result( &__res );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
  return _res;
}


#ifndef MICO_CONF_NO_POA

org::omg::boxedIDL::examples::corba::DataObject*
examples::CorbaFriendlySession_stub_clp::echo( org::omg::boxedIDL::examples::corba::DataObject* _par_arg0 )
{
  PortableServer::Servant _serv = _preinvoke ();
  if (_serv) {
    POA_examples::CorbaFriendlySession * _myserv = POA_examples::CorbaFriendlySession::_narrow (_serv);
    if (_myserv) {
      org::omg::boxedIDL::examples::corba::DataObject* __res;

      org::omg::boxedIDL::examples::corba::DataObject* _copy_of_par_arg0;
      _copy_of_par_arg0 = org::omg::boxedIDL::examples::corba::DataObject::_downcast (_par_arg0->_copy_value());
      #ifdef HAVE_EXCEPTIONS
      try {
      #endif
        __res = _myserv->echo(_copy_of_par_arg0);
      #ifdef HAVE_EXCEPTIONS
      }
      catch (...) {
        _myserv->_remove_ref();
        _postinvoke();
        throw;
      }
      #endif

      _myserv->_remove_ref();
      _postinvoke ();
      CORBA::remove_ref (_copy_of_par_arg0);
      org::omg::boxedIDL::examples::corba::DataObject* __res2 = org::omg::boxedIDL::examples::corba::DataObject::_downcast (__res->_copy_value ());
      CORBA::remove_ref (__res);
      return __res2;
    }
    _postinvoke ();
  }

  return examples::CorbaFriendlySession_stub::echo(_par_arg0);
}

#endif // MICO_CONF_NO_POA

org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* examples::CorbaFriendlySession_stub::echoSequence( org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* _par_arg0 )
{
  CORBA::StaticAny _sa_arg0( _marshaller_org_omg_boxedRMI_org_omg_boxedIDL_examples_corba_seq1_DataObject, &_par_arg0 );
  org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* _res;
  CORBA::StaticAny __res( _marshaller_org_omg_boxedRMI_org_omg_boxedIDL_examples_corba_seq1_DataObject, &_res );

  CORBA::StaticRequest __req( this, "echoSequence" );
  __req.add_in_arg( &_sa_arg0 );
  __req.set_result( &__res );

  __req.invoke();

  mico_sii_throw( &__req, 
    0);
  return _res;
}


#ifndef MICO_CONF_NO_POA

org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject*
examples::CorbaFriendlySession_stub_clp::echoSequence( org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* _par_arg0 )
{
  PortableServer::Servant _serv = _preinvoke ();
  if (_serv) {
    POA_examples::CorbaFriendlySession * _myserv = POA_examples::CorbaFriendlySession::_narrow (_serv);
    if (_myserv) {
      org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* __res;

      org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* _copy_of_par_arg0;
      _copy_of_par_arg0 = org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject::_downcast (_par_arg0->_copy_value());
      #ifdef HAVE_EXCEPTIONS
      try {
      #endif
        __res = _myserv->echoSequence(_copy_of_par_arg0);
      #ifdef HAVE_EXCEPTIONS
      }
      catch (...) {
        _myserv->_remove_ref();
        _postinvoke();
        throw;
      }
      #endif

      _myserv->_remove_ref();
      _postinvoke ();
      CORBA::remove_ref (_copy_of_par_arg0);
      org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* __res2 = org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject::_downcast (__res->_copy_value ());
      CORBA::remove_ref (__res);
      return __res2;
    }
    _postinvoke ();
  }

  return examples::CorbaFriendlySession_stub::echoSequence(_par_arg0);
}

#endif // MICO_CONF_NO_POA

struct __tc_init_CORBAFRIENDLYSESSION {
  __tc_init_CORBAFRIENDLYSESSION()
  {
    _marshaller_examples_CorbaFriendlySession = new _Marshaller_examples_CorbaFriendlySession;
  }
};

static __tc_init_CORBAFRIENDLYSESSION __init_CORBAFRIENDLYSESSION;

//--------------------------------------------------------
//  Implementation of skeletons
//--------------------------------------------------------

// PortableServer Skeleton Class for interface examples::CorbaFriendlySession
POA_examples::CorbaFriendlySession::~CorbaFriendlySession()
{
}

::examples::CorbaFriendlySession_ptr
POA_examples::CorbaFriendlySession::_this ()
{
  CORBA::Object_var obj = PortableServer::ServantBase::_this();
  return ::examples::CorbaFriendlySession::_narrow (obj);
}

CORBA::Boolean
POA_examples::CorbaFriendlySession::_is_a (const char * repoid)
{
  if (strcmp (repoid, "RMI:examples.CorbaFriendlySession:0000000000000000") == 0) {
    return TRUE;
  }
  if (POA_javax::ejb::EJBObject::_is_a (repoid)) {
    return TRUE;
  }
  return FALSE;
}

CORBA::InterfaceDef_ptr
POA_examples::CorbaFriendlySession::_get_interface ()
{
  CORBA::InterfaceDef_ptr ifd = PortableServer::ServantBase::_get_interface ("RMI:examples.CorbaFriendlySession:0000000000000000");

  if (CORBA::is_nil (ifd)) {
    mico_throw (CORBA::OBJ_ADAPTER (0, CORBA::COMPLETED_NO));
  }

  return ifd;
}

CORBA::RepositoryId
POA_examples::CorbaFriendlySession::_primary_interface (const PortableServer::ObjectId &, PortableServer::POA_ptr)
{
  return CORBA::string_dup ("RMI:examples.CorbaFriendlySession:0000000000000000");
}

CORBA::Object_ptr
POA_examples::CorbaFriendlySession::_make_stub (PortableServer::POA_ptr poa, CORBA::Object_ptr obj)
{
  return new ::examples::CorbaFriendlySession_stub_clp (poa, obj);
}

bool
POA_examples::CorbaFriendlySession::dispatch (CORBA::StaticServerRequest_ptr __req)
{
  #ifdef HAVE_EXCEPTIONS
  try {
  #endif
    if( strcmp( __req->op_name(), "echo" ) == 0 ) {
      ::org::omg::boxedIDL::examples::corba::DataObject_var _par_arg0;
      CORBA::StaticAny _sa_arg0( _marshaller_org_omg_boxedIDL_examples_corba_DataObject, &_par_arg0._for_demarshal() );

      ::org::omg::boxedIDL::examples::corba::DataObject* _res;
      CORBA::StaticAny __res( _marshaller_org_omg_boxedIDL_examples_corba_DataObject, &_res );
      __req->add_in_arg( &_sa_arg0 );
      __req->set_result( &__res );

      if( !__req->read_args() )
        return true;

      _res = echo( _par_arg0.inout() );
      __req->write_results();
      CORBA::remove_ref( _res );
      return true;
    }
    if( strcmp( __req->op_name(), "echoSequence" ) == 0 ) {
      ::org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject_var _par_arg0;
      CORBA::StaticAny _sa_arg0( _marshaller_org_omg_boxedRMI_org_omg_boxedIDL_examples_corba_seq1_DataObject, &_par_arg0._for_demarshal() );

      ::org::omg::boxedRMI::org::omg::boxedIDL::examples::corba::seq1_DataObject* _res;
      CORBA::StaticAny __res( _marshaller_org_omg_boxedRMI_org_omg_boxedIDL_examples_corba_seq1_DataObject, &_res );
      __req->add_in_arg( &_sa_arg0 );
      __req->set_result( &__res );

      if( !__req->read_args() )
        return true;

      _res = echoSequence( _par_arg0.inout() );
      __req->write_results();
      CORBA::remove_ref( _res );
      return true;
    }
  #ifdef HAVE_EXCEPTIONS
  } catch( CORBA::SystemException_catch &_ex ) {
    __req->set_exception( _ex->_clone() );
    __req->write_results();
    return true;
  } catch( ... ) {
    CORBA::UNKNOWN _ex (CORBA::OMGVMCID | 1, CORBA::COMPLETED_MAYBE);
    __req->set_exception (_ex->_clone());
    __req->write_results ();
    return true;
  }
  #endif

  if (POA_javax::ejb::EJBObject::dispatch (__req)) {
    return true;
  }

  return false;
}

void
POA_examples::CorbaFriendlySession::invoke (CORBA::StaticServerRequest_ptr __req)
{
  if (dispatch (__req)) {
      return;
  }

  CORBA::Exception * ex = 
    new CORBA::BAD_OPERATION (0, CORBA::COMPLETED_NO);
  __req->set_exception (ex);
  __req->write_results();
}

