######################################################################
##
## Copyright (c) LIFL 1999
## The GOODE team of the LIFL
## University of Lille, France
## All rights reserved
##
## The CorbaWeb script associated to the OMG IDL CORBA::Repository
## interface.
##
######################################################################

# Each action must have two arguments: the first one refers to the
# current CORBA object and the second one refers to a CorbaWeb
# ActionContext instance.

######################################################################
## This action displays the content of a CORBA::Repository.
######################################################################

proc view(repository, ac)
{
  ac.h1("Browsing the Interface Repository")

  # generates a list of the contained objects.
  generate_contents_list(repository, ac)

  # generates a form to apply the lookup method.
  generate_lookup_form(repository, ac)

  # generates a form to apply the lookup_id method.
  ac.action_form(repository, "do_lookup_id")
    ac.submit_button("Lookup by a repository ID")
    ac.text_input("an_id", 50)
  ac.end_form()
}

######################################################################
## This action lookups a contained object by its repository ID
## and views it.
######################################################################

proc do_lookup_id(repository, ac)
{
  # obtains the name of the lookup contained object.
  an_id = ac.getString("an_id")

  # calls the lookup_id method.
  contained = repository.lookup_id(an_id)

  if(CORBA.is_nil(contained)) {
    ac.println("The contained object with the repository ID `<b>" + an_id + 
               "</b>' doesn't exist!")
    ac.apply("view", repository)
  } else {
    # applies the view action on this contained object.
    ac.apply("view", contained)
  }
}

######################################################################
## Declaration of these actions into the CorbaWeb ActionRepository.
######################################################################

declareAction("view", view,
              "Views the contain of a CORBA::Repository object")

declareAction("do_lookup_id", do_lookup_id,
              "Lookups a CORBA::Contained object by its repository ID")

######################################################################
# end of file 'CorbaWeb/actions/CORBA_Repository'
######################################################################
