Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.util.Properties;
- import org.omg.CORBA.ORB;
- import org.omg.CosNaming.Binding;
- import org.omg.CosNaming.BindingHolder;
- import org.omg.CosNaming.BindingIteratorHolder;
- import org.omg.CosNaming.BindingListHolder;
- import org.omg.CosNaming.BindingType;
- import org.omg.CosNaming.NameComponent;
- import org.omg.CosNaming.NamingContextExt;
- import org.omg.CosNaming.NamingContextExtHelper;
- public class Client {
- private String[] theArgs;
- private ORB theOrb;
- private File f;
- private BufferedReader br;
- private Properties props;
- protected NamingContextExt theRoot;
- public Client(String args[]) {
- theArgs = args;
- try {
- if (args.length == 0) {
- // initialize the ORB.
- theOrb = ORB.init(args, null);
- // init buffer for reading object references from file:
- f = new File("NS_Ref");
- br = new BufferedReader(new FileReader(f));
- } else {
- props = new Properties();
- props.put("org.omg.CORBA.ORBInitialHost", args[0]);
- props.put("org.omg.CORBA.ORBInitialPort", args[1]);
- // initialize the ORB.
- theOrb = ORB.init(args, props);
- // init root of name service:
- theRoot = NamingContextExtHelper.narrow(theOrb
- .resolve_initial_references("NameService"));
- }
- } catch (Exception ex) {
- System.err.println(ex);
- }
- }
- public org.omg.CORBA.Object getObjectReference(String objName) {
- org.omg.CORBA.Object obj = null;
- try {
- if (objName == null) {
- // get object reference from file
- obj = theOrb.string_to_object(br.readLine());
- } else {
- obj = theRoot.resolve(theRoot.to_name(objName));
- }
- } catch (Exception ex) {
- System.err.println(ex);
- }
- return obj;
- }
- protected void closeBuffer() {
- try {
- br.close();
- } catch (Exception ex) {
- System.err.println(ex);
- }
- }
- public void list(NamingContextExt nCxt, String indent)
- {
- try {
- BindingListHolder bListHolder = new BindingListHolder(
- new Binding[0]);
- BindingIteratorHolder bItrHolder = new BindingIteratorHolder();
- nCxt.list(0, bListHolder, bItrHolder);
- BindingHolder bHolder = new BindingHolder();
- if (bItrHolder.value == null)
- return;
- while (bItrHolder.value.next_one(bHolder)) {
- String stringName = theRoot
- .to_string(bHolder.value.binding_name);
- System.out.print(indent + stringName);
- if (bHolder.value.binding_type.value() == BindingType._ncontext) {
- String _indent = indent + "\t";
- System.out.println("/");
- NameComponent[] name = nCxt.to_name(stringName);
- NamingContextExt sub_context = NamingContextExtHelper
- .narrow(nCxt.resolve(name));
- list(sub_context, _indent);
- } else
- System.out.println();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement