diff options
author | Matthew Newhook <matthew@zeroc.com> | 2005-09-13 02:25:11 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2005-09-13 02:25:11 +0000 |
commit | 13c1478b4bf220e3c08055f7af39281e2f5d8875 (patch) | |
tree | 2d80b77591f870688270b6637678eddb3e1c6196 /java/demo/IcePack/hello/Client.java | |
parent | updates. (diff) | |
download | ice-13c1478b4bf220e3c08055f7af39281e2f5d8875.tar.bz2 ice-13c1478b4bf220e3c08055f7af39281e2f5d8875.tar.xz ice-13c1478b4bf220e3c08055f7af39281e2f5d8875.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=335
Diffstat (limited to 'java/demo/IcePack/hello/Client.java')
-rw-r--r-- | java/demo/IcePack/hello/Client.java | 333 |
1 files changed, 161 insertions, 172 deletions
diff --git a/java/demo/IcePack/hello/Client.java b/java/demo/IcePack/hello/Client.java index f2e73d43ff0..3f308bf8868 100644 --- a/java/demo/IcePack/hello/Client.java +++ b/java/demo/IcePack/hello/Client.java @@ -9,193 +9,182 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { - private static void + private void menu() { - System.out.println( - "usage:\n" + - "c: create a hello object\n" + - "d: destroy the current hello object\n" + - "s: set the current hello object\n" + - "r: set the current hello object to a random hello object\n" + - "S: show the name of the current hello object\n" + - "t: send greeting\n" + - "x: exit\n" + - "?: help\n"); + System.out.println( + "usage:\n" + + "c: create a hello object\n" + + "d: destroy the current hello object\n" + + "s: set the current hello object\n" + + "r: set the current hello object to a random hello object\n" + + "S: show the name of the current hello object\n" + + "t: send greeting\n" + + "x: exit\n" + + "?: help\n"); } - private static int - run(String[] args, Ice.Communicator communicator) - throws Ice.UserException + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + try + { + IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator().stringToProxy("IcePack/Query")); + // + // Get an object implementing the HelloFactory interface. + // + HelloFactoryPrx factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory")); - IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator.stringToProxy("IcePack/Query")); + // + // By default we create a Hello object named 'Foo'. + // + HelloPrx hello; + try + { + hello = factory.find("Foo"); + } + catch(NameNotExistException ex) + { + hello = factory.create("Foo"); + } - // - // Get an object implementing the HelloFactory interface. - // - HelloFactoryPrx factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory")); + menu(); - // - // By default we create a Hello object named 'Foo'. - // - HelloPrx hello; - try - { - hello = factory.find("Foo"); - } - catch(NameNotExistException ex) - { - hello = factory.create("Foo"); - } + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - menu(); + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("t")) + { + hello.sayHello(); + } + else if(line.equals("c")) + { + System.out.print("name: "); + System.out.flush(); + String name = in.readLine(); + if(name != null && name.length() > 0) + { + try + { + hello = factory.find(name); + System.out.println("Hello object named '" + name + "' already exists"); + } + catch(NameNotExistException ex) + { + try + { + factory = HelloFactoryPrxHelper.checkedCast( + query.findObjectByType("::Demo::HelloFactory")); + hello = factory.create(name); + } + catch(IcePack.ObjectNotExistException e) + { + } + } + } + } + else if(line.equals("d")) + { + if(Ice.Util.identityToString(hello.ice_getIdentity()).equals("Foo")) + { + System.out.println("Can't delete the default Hello object named 'Foo'"); + } + else + { + hello.destroy(); - java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - - String line = null; - do - { - try - { - System.out.print("==> "); - System.out.flush(); - line = in.readLine(); - if(line == null) - { - break; - } - if(line.equals("t")) - { - hello.sayHello(); - } - else if(line.equals("c")) - { - System.out.print("name: "); - System.out.flush(); - String name = in.readLine(); - if(name != null && name.length() > 0) - { - try - { - hello = factory.find(name); - System.out.println("Hello object named '" + name + "' already exists"); - } - catch(NameNotExistException ex) - { - factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory")); - hello = factory.create(name); - } - } - } - else if(line.equals("d")) - { - if(Ice.Util.identityToString(hello.ice_getIdentity()).equals("Foo")) - { - System.out.println("Can't delete the default Hello object named 'Foo'"); - } - else - { - hello.destroy(); - - try - { - hello = factory.find("Foo"); - } - catch(NameNotExistException ex) - { - hello = factory.create("Foo"); - } - } - } - else if(line.equals("s")) - { - System.out.print("name: "); - System.out.flush(); - String name = in.readLine(); - if(name != null && name.length() > 0) - { - try - { - hello = HelloPrxHelper.checkedCast(factory.find(name)); - } - catch(NameNotExistException ex) - { - System.out.println("This name doesn't exist"); - } - } - } - else if(line.equals("r")) - { - hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); - } - else if(line.equals("S")) - { - System.out.println(Ice.Util.identityToString(hello.ice_getIdentity())); - } - else if(line.equals("x")) - { - // Nothing to do - } - else if(line.equals("?")) - { - menu(); - } - else - { - System.out.println("unknown command `" + line + "'"); - menu(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - while(!line.equals("x")); - - return 0; + try + { + hello = factory.find("Foo"); + } + catch(NameNotExistException ex) + { + hello = factory.create("Foo"); + } + } + } + else if(line.equals("s")) + { + System.out.print("name: "); + System.out.flush(); + String name = in.readLine(); + if(name != null && name.length() > 0) + { + try + { + hello = HelloPrxHelper.checkedCast(factory.find(name)); + } + catch(NameNotExistException ex) + { + System.out.println("This name doesn't exist"); + } + } + } + else if(line.equals("r")) + { + hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); + } + else if(line.equals("S")) + { + System.out.println(Ice.Util.identityToString(hello.ice_getIdentity())); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + } + catch(NameExistsException e) + { + e.printStackTrace(); + return 1; + } + catch(IcePack.ObjectNotExistException e) + { + e.printStackTrace(); + return 1; + } + + return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Exception ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config"); + System.exit(status); } } |