# Automatically generated sample implementation code # PLEASE EDIT PLEASE EDIT PLEASE EDIT. # Generated on Fri Aug 14 11:02:41 1998 with the following command: # /usr/home/irving/bin/idl2perl -o . --impl copex.idl use Copex::OnDemand_types; use Copex::OnDemand_skel; # IDL:Copex/OnDemand:1.0 package Copex::OnDemand_impl; use COPE::CORBA::Servant @Copex::OnDemand_impl::ISA=qw(CORBA::BOA::_Servant); sub _skelname($) { 'Copex::OnDemand_skel' } use COPE::CORBA::Exception; use Experimental::Exception; use vars '@loaded', '@unloaded'; my $default_servant; @unloaded = qw(Charles Malcolm Tim Andy Sarathy Chip); # Helper method to determine whether an object is loaded or not, # and load it if required sub _find_object($) { my ($self) = @_; # The default servant is only invoked if the BOA can't find a real # servant corresponding to the oid. So, if we're not the default # servant, we don't need to do any more work here. if ($self != $default_servant) { return $self; } # Find the oid in our list of unloaded objects my $oid = $CORBA::BOA::_The_Boa->servant_to_id($self); my $i; for ($i = 0; $i < @unloaded; $i+=1) { if ($oid eq $unloaded[$i]) { # Found it! # In a real server, we'd get all the info out of the database # and build a Perl object out of it... # take this oid out of the unloaded list splice @unloaded, $i, 1; my $obj = Copex::OnDemand_impl->new($oid); # and put the object into the loaded list push @loaded, $obj; return $obj; } } # If we haven't found the object yet, it doesn't exist throw new CORBA::OBJECT_NOT_EXIST minor => 0, completed=> Corba::CompletionStatus::COMPLETED_NO; } sub new { my($class, $oid) = @_; my $self = bless {'oid' => $oid}, $class; $CORBA::BOA::_The_Boa->activate_object_with_id($oid, $self); return $self; } # IDL:Copex/OnDemand/GetId:1.0 sub GetId ($) { my($self) = @_; # Every object method needs to first make sure a real instance is loaded # You could get around this by making the default servant a separate # class, and using an AUTOLOAD method to instantiate the real object # and then call the appropriate method on it. $self = $self->_find_object(); return $self->{'oid'}; } # Set up the default handler sub init() { # Note that a reference to the servant is stored in a package variable # so that we can compare things to it in _find_object... $default_servant = bless {}, 'Copex::OnDemand_impl'; $CORBA::BOA::_The_Boa->activate_object($default_servant); $CORBA::BOA::_The_Boa->set_servant($default_servant->_interface, $default_servant); } 1;