[Enterprise Extensions only]

BindingIterator::destroy

Overview Destroys the iterator and frees allocated memory.
Original interface CosNaming::BindingIterator Interface
Exceptions CORBA standard exceptions


Intended Usage

This operation is intended to be used by client applications. It is not typically overridden.

IDL Syntax

  void destroy();

Examples

The following examples demonstrate the usage of the CosNaming Module.

C++ Example

  // A CosNaming usage example.
  // For simplicity, error and exception checking and cleanup are ommitted.
 
  #include <CosNaming.hh>
  #include <stdlib.h>
  #include <fstream.h>
  #define filename1 "NMUTST1.OUT"
  #define filename2 "NMUTST1.OUT"
 
 
  // Make the name "vehicles"
  CosNaming::Name *vehiclesBindingName = new CosNaming::Name;
  vehiclesBindingName->length( 1 );
  (*vehiclesBindingName)[0].id   = CORBA::string_dup("vehicles");
  (*vehiclesBindingName)[0].kind = CORBA::string_dup("");
 
 
  // Create a new naming context vehiclesNamingContext and bind it to the
  // root rootNamingContext with the name "vehicles"
  CosNaming::NamingContext_ptr vehiclesNamingContext =
    rootNamingContext->bind_new_context(*vehiclesBindingName);
 
 
  // Make the name "vehicles.large"
  CosNaming::Name *largevehiclesBindingName = new CosNaming::Name;
  largevehiclesBindingName->length( 1 );
  (*largevehiclesBindingName)[0].id   = CORBA::string_dup("vehicles");
  (*largevehiclesBindingName)[0].kind = CORBA::string_dup("large");
 
 
  // create a new naming context largevehiclesNamingContext and bind
  // it to the naming context vehiclesNamingContext with the name
  // "vehicles.large"
  CosNaming::NamingContext_ptr largevehiclesNamingContext =
    vehiclesNamingContext->bind_new_context(
    *largevehiclesBindingName);
 
 
  // Make the name "vans"
  CosNaming::Name *vansBindingName = new CosNaming::Name;
  vansBindingName->length( 1 );
  (*vansBindingName)[0].id   = CORBA::string_dup("vans");
  (*vansBindingName)[0].kind = CORBA::string_dup("");
 
 
  // create a new naming context vansNamingContext and bind it to the
  // naming context vehiclesNamingContext with the name "vans"
  CosNaming::NamingContext_ptr vansNamingContext =
    vehiclesNamingContext->bind_new_context(*vansBindingName);
 
 
  // Make the name "trucks"
  CosNaming::Name *trucksBindingName = new CosNaming::Name;
  trucksBindingName->length( 1 );
  (*trucksBindingName)[0].id   = CORBA::string_dup("trucks");
  (*trucksBindingName)[0].kind = CORBA::string_dup("");
 
 
  // create a new naming context trucksNamingContext and bind it to the
  // naming context vehiclesNamingContext with the name "trucks"
  CosNaming::NamingContext_ptr trucksNamingContext =
    vehiclesNamingContext->bind_new_context(*trucksBindingName);
 
 
  // Make the name "chrysler"
  CosNaming::Name *avehicleBindingName = new CosNaming::Name;
  avehicleBindingName->length( 1 );
  (*avehicleBindingName)[0].id   = CORBA::string_dup("chrysler");
  (*avehicleBindingName)[0].kind = CORBA::string_dup("");
 
 
  // Create an object avehicleObject
  ifstream strm1(filename1);
  char refStr[2048];
  memset(refStr, 2048, '\0');
  strm1 >> refStr;
  CORBA::Object_ptr avehicleObject = orb_p->string_to_object(refStr);
 
 
  // Bind the object avehicleObject to the naming context
  // vansNamingContext with the name "chrysler"
  vansNamingContext->bind(*avehicleBindingName, avehicleObject);
 
 
  // Create another object anothervehicleObject
  ifstream strm2(filename2);
  memset(refStr, 2048, '\0');
  strm2 >> refStr;
  CORBA::Object_ptr anothervehicleObject = orb_p->string_to_object(refStr);
 
 
  // Rebind the object anothervehicleObject to the naming
  // context vansNamingContext with the name "chrysler"
  vansNamingContext->rebind(*avehicleBindingName, anothervehicleObject);
 
 
  // Bind the context vansNamingContext to the context
  // vehiclesNamingContext with the name "vans"
  largevehiclesNamingContext->bind_context(*vansBindingName,
    vansNamingContext);
 
 
  // Make the name "vans.mini"
  CosNaming::Name *miniVansBindingName = new CosNaming::Name;
  miniVansBindingName->length( 1 );
  (*miniVansBindingName)[0].id   = CORBA::string_dup("vans");
  (*miniVansBindingName)[0].kind = CORBA::string_dup("mini");
 
 
  // Rebind the context vansNamingContext to the context
  // vehiclesNamingContext with the name "vans.mini"
  largevehiclesNamingContext->rebind_context(*miniVansBindingName,
    vansNamingContext);
 
 
  // Unbind the object bound to vehiclesNamingContext with the
  // name "vans"
  largevehiclesNamingContext->unbind(*vansBindingName);
 
 
  // Unbind the object bound to vehiclesNamingContext with the
  // name "vans.mini"
  largevehiclesNamingContext->unbind(*miniVansBindingName);
 
 
  // Make the name "vehicles/vans/crysler.mini"
  CosNaming::Name *aMiniVansPathName = new CosNaming::Name;
  aMiniVansPathName->length( 3 );
  (*aMiniVansPathName)[0].id   = CORBA::string_dup("vehicles");
  (*aMiniVansPathName)[0].kind = CORBA::string_dup("");
  (*aMiniVansPathName)[1].id   = CORBA::string_dup("vans");
  (*aMiniVansPathName)[1].kind = CORBA::string_dup("");
  (*aMiniVansPathName)[2].id   = CORBA::string_dup("chrysler");
  (*aMiniVansPathName)[2].kind = CORBA::string_dup("");
 
 
  // Resolve the name from the root naming context
  rootNamingContext avehicleObject =
    rootNamingContext->resolve(*aMiniVansPathName);
 
 
  // list only one binding in the naming root context rootNamingContext
  // The remaining bindings can be retrieved from the binding iterator bi.
  CosNaming::BindingList_var bl;
  CosNaming::BindingIterator_var bi;
  vehiclesNamingContext->list(1, bl, bi);
 
 
  // Retrieve the next binding from the binding iterator
  CosNaming::Binding_var b;
  bi->next_one(b);
 
 
  // Retrieve the next 2 bindings from the binding iterator
  CosNaming::BindingList_var bl1;
  bi->next_n(2, bl1);
 
 
  // Destroy the naming context vehiclesNamingContext
  largevehiclesNamingContext->destroy();
 
 
  // Destroy the binding iterator bi
  bi->destroy();

Java Example

// Java example
 
// make the name "vehicles"
 
   org.omg.CosNaming.NameComponent[] vehiclesBindingName = 
     new org.omg.CosNaming.NameComponent[1];
   vehiclesBindingName[0] = new NameComponent();
   vehiclesBindingName[0].id = "vehicles";
   vehiclesBindingName[0].kind = "";
 
// Create a new naming context vehiclesNamingContext and bind it to the
// root rootNamingContext with the name "vehicles"
 
   org.omg.CosNaming.NamingContext vehiclesNamingContext = null;
 
   try {
      vehiclesNamingContext = 
        rootNamingContext.bind_new_context(vehiclesBindingName);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
// Make the name "vehicles.large"
 
   org.omg.CosNaming.NameComponent[] largevehiclesBindingName = 
     new org.omg.CosNaming.NameComponent[1];
   largevehiclesBindingName[0] = new NameComponent();
   largevehiclesBindingName[0].id = "vehicles";
   largevehiclesBindingName[0].kind = "large";
 
// create a new naming context largevehiclesNamingContext and bind
// it to the naming context vehiclesNamingContext with the name
// "vehicles.large"
 
   org.omg.CosNaming.NamingContext largevehiclesNamingContext = null;
 
   try {
      largevehiclesNamingContext = 
        vehiclesNamingContext.bind_new_context(largevehiclesBindingName);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Make the name "vans"
 
   org.omg.CosNaming.NameComponent[] vansBindingName = 
     new org.omg.CosNaming.NameComponent[1];
   vansBindingName[0] = new NameComponent();
   vansBindingName[0].id = "vans";
   vansBindingName[0].kind = "";
 
// create a new naming context vansNamingContext and bind it to the
// naming context vehiclesNamingContext with the name "vans"
 
   org.omg.CosNaming.NamingContext vansNamingContext = null;
 
   try {
      vansNamingContext = 
        vehiclesNamingContext.bind_new_context(vansBindingName);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Make the name "trucks"
 
   org.omg.CosNaming.NameComponent[] trucksBindingName = 
     new org.omg.CosNaming.NameComponent[1];
   trucksBindingName[0] = new NameComponent();
   trucksBindingName[0].id = "trucks";
   trucksBindingName[0].kind = "";
 
// create a new naming context trucksNamingContext and bind it to the
// naming context vehiclesNamingContext with the name "trucks"
 
   org.omg.CosNaming.NamingContext trucksNamingContext = null;
 
   try {
      trucksNamingContext = 
        vehiclesNamingContext.bind_new_context(trucksBindingName);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Make the name "chrysler"
 
   org.omg.CosNaming.NameComponent[] avehicleBindingName = 
     new org.omg.CosNaming.NameComponent[1];
   avehicleBindingName[0] = new NameComponent();
   avehicleBindingName[0].id = "chrysler";
   avehicleBindingName[0].kind = "";
 
// Create an object avehicleObject
 
   BufferedReader strm1 = null;
   String refStr = null;
 
   try {
      strm1 = new BufferedReader(
                new InputStreamReader(new FileInputStream("NMUTST1.OUT")));
      refStr=strm1.readLine();
      strm1.close();
   }
   catch (Exception e)
   {
      // do error handling
   }
 
   org.omg.CORBA.Object avehicleObject = orb.string_to_object(refStr);
 
// Bind the object avehicleObject to the naming context
// vansNamingContext with the name "chrysler"
 
   try {
      vansNamingContext.bind(avehicleBindingName, avehicleObject);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Create another object anothervehicleObject
 
   BufferedReader strm2 = null;
 
   try {
      strm2 = new BufferedReader(
                new InputStreamReader(new FileInputStream("NMUTST2.OUT")));
      refStr=strm2.readLine();
      strm2.close();
   }
   catch (Exception e)
   {
      // do error handling
   }
 
   org.omg.CORBA.Object anothervehicleObject = orb.string_to_object(refStr);
 
// Rebind the object anothervehicleObject to the naming
// context vansNamingContext with the name "chrysler"
 
   try {
      vansNamingContext.rebind(avehicleBindingName, anothervehicleObject);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Bind the context vansNamingContext to the context
// vehiclesNamingContext with the name "vans"
 
   try {
      largevehiclesNamingContext.bind_context(vansBindingName, 
        vansNamingContext);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Make the name "vans.mini"
 
   org.omg.CosNaming.NameComponent[] miniVansBindingName = 
     new org.omg.CosNaming.NameComponent[1];
   miniVansBindingName[0] = new NameComponent();
   miniVansBindingName[0].id = "vans";
   miniVansBindingName[0].kind = "mini"; 
 
// Rebind the context vansNamingContext to the context
// vehiclesNamingContext with the name "vans.mini"
 
   try {
      largevehiclesNamingContext.rebind_context(miniVansBindingName, 
        vansNamingContext);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Unbind the object bound to vehiclesNamingContext with the 
// name "vans"
 
   try {
      largevehiclesNamingContext.unbind(vansBindingName);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Unbind the object bound to vehiclesNamingContext with the
// name "vans.mini"
 
   try {
      largevehiclesNamingContext.unbind(miniVansBindingName);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Make the name "vehicles/vans/chrysler.mini"
 
   org.omg.CosNaming.NameComponent[] aMiniVansPathName = 
     new org.omg.CosNaming.NameComponent[3];
   aMiniVansPathName[0] = new NameComponent();
   aMiniVansPathName[0].id   = "vehicles";
   aMiniVansPathName[0].kind = "";
 
   aMiniVansPathName[1] = new NameComponent();
   aMiniVansPathName[1].id   = "vans";
   aMiniVansPathName[1].kind = "";
 
   aMiniVansPathName[2] = new NameComponent();
   aMiniVansPathName[2].id   = "chrysler";
   aMiniVansPathName[2].kind = "";
 
// Resolve the name from the root naming context
 
   try {
      avehicleObject = rootNamingContext.resolve(aMiniVansPathName);
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// list only one binding in the naming root context rootNamingContext
// The remaining bindings can be retrieved from the binding iterator bi.
 
   org.omg.CosNaming.BindingIterator bi;
   org.omg.CosNaming.BindingIteratorHolder bih = new BindingIteratorHolder();
 
   org.omg.CosNaming.Binding[] bl;
   org.omg.CosNaming.BindingListHolder blh = new BindingListHolder();
 
   vehiclesNamingContext.list(1, blh, bih);
   bl = blh.value;
   bi = bih.value;
 
// Retrieve the next binding from the binding iterator
 
   org.omg.CosNaming.Binding b = new Binding();
   org.omg.CosNaming.BindingHolder bh = new BindingHolder();
 
   bi.next_one(bh);
   b = bh.value;
 
// Retrieve the next 2 bindings from the binding iterator
 
   org.omg.CosNaming.Binding[] bl1;
 
   bi.next_n(2, blh);
   bl1 = blh.value;
 
// Destroy the naming context vehiclesNamingContext
 
   try {
      largevehiclesNamingContext.destroy();
   }
   catch (Exception e)
   {
      // do error handling
   }
 
 
// Destroy the binding iterator bi
 
   try {
      bi.destroy();
   }
   catch (Exception e)
   {
      // do error handling
   }