What is the VBJ 4.x equivalent of the VBC++ VISUtil::to ior() method?

From Support
Jump to: navigation, search

Question:

In VBC++ there are VISUtil class methods  to_ior() and to_string()  to convert between stringified IORs and IOR structures.  These are defined in the vutil.h header file.

Are there any equivalent methods in VBJ 4x?

Answer:

The methods needed to convert between java.lang.String
and com.visigenic.vbroker.IOP.IOR are available in VisiBroker
ORB classes and are shown below.

These methods are not formally exposed as an ORB API, so
they should be used with the caution that it may be changed
without notice and are not guaranteed to exist in future releases
of the product.

// Class: com.inprise.vbroker.orb.ORB
//
// Method: public IORValue string_to_ior(String iorString)
//
// Example:

java.lang.String iorString =  orb.object_to_string(manager);
com.inprise.vbroker.IOP.IORValue ior =
        ((com.inprise.vbroker.orb.ORB)orb).string_to_ior(iorString);
 

//
// Class: com.visigenic.vbroker.orb.ORB
//
// Method: public org.omg.CORBA.Object iorToObject(IORValue ior)
//
// Example:

org.omg.CORBA.Object obj =
        ((com.inprise.vbroker.orb.ORB)orb).iorToObject(ior);
java.lang.String refString = orb.object_to_string(obj);

How does the application  get to the profile body
structure?   The string_to_ior() method creates an ior
that is populated with the appropriate ProfileBodyValue instances.

This particular example reads the IOR structure directly from a
stringified IOR read from a file.

import java.io.*;
import org.omg.PortableServer.*;
import com.inprise.vbroker.IOP.*;
import com.inprise.vbroker.IIOP.*;
 
...

      org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
...

String iorString = null;
try {

  LineNumberReader input =
        new LineNumberReader(new FileReader("test.ior"));
  iorString = input.readLine();
  input.close();
} catch (java.io.IOException e) {
  e.printStackTrace();
  System.exit(0);
}

IORValue ior = ((com.inprise.vbroker.orb.ORB)orb).string_to_ior(iorString);
System.out.println(ior);
System.out.println("Interoperable Object Reference:");
System.out.println("  Type ID: " + ior.type_id);
System.out.println("  Contains " + ior.profiles.length +
                  ((ior.profiles.length == 1) ? " profile." : " profiles."));
for (int i = 0; i < ior.profiles.length; i++) {
  System.out.println("  Profile " + i + " - " +
                    ((ior.profiles[i].tag() == TAG_INTERNET_IOP.value) ?
                    "TAG_INTERNET_IOP" : "(not IIOP)"));
  if (ior.profiles[i].tag() == TAG_INTERNET_IOP.value) {
    ProfileBodyValue iiop = (ProfileBodyValue) ior.profiles[i];
    System.out.println("IIOP Profile:");
    System.out.println("    version: " + iiop.version.major +
                  "." + iiop.version.minor);
    System.out.println("    host: " + iiop.host);
    int port = (int) iiop.port;
    if (iiop.port < 0) port += 65536;
    System.out.println("    port: " + port);
    System.out.println("    Object Key: " + iiop.object_key);
    if (iiop.version.minor > 0 && iiop.components != null) {
       for (int j = 0; j < iiop.components.length; j++) {
        System.out.println("    " + iiop.components[j].tag());
       } // for components
    } // if components
  } // if TAG_INTERNET_IOP
} // for profiles

Note: The conversion for the port number ( if (iiop.port < 0) port += 65536) is to allow for large port numbers assigned by some hosts (such as Solaris). The OMG IDL definition for the ProfileBody defines the port as an unsigned short. Because there is no support in the Java language for unsigned types, theapplication is responsible for ensuring that large unsigned IDL type values are handled correctly as negative integers in Java. The port number is large enough that java thinks it is a negative short. The conversion changes the negative short into an equivalent positive integer using integer arithmetic.

[This information was verified against VBJ 4.0]
 



Article originally contributed by