KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > util > PingObject


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.orb.util;
22
23 /**
24  * @version $Id: PingObject.java,v 1.10 2004/05/06 12:40:00 nicolas Exp $
25  */

26
27 import org.jacorb.orb.ParsedIOR;
28 import java.io.*;
29
30 public class PingObject
31 {
32     public static void main( String JavaDoc args[] )
33     {
34         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args,null);
35         String JavaDoc iorString = null;
36
37         if( args.length < 1 || args.length > 2 )
38         {
39             System.err.println("Usage: java org.jacorb.orb.util.PingObject [ ior_str | -f filename ]");
40             System.exit( 1 );
41         }
42
43         if( args[0].equals("-f"))
44         {
45             try
46             {
47                 BufferedReader br = new BufferedReader( new FileReader( args[1] ));
48                 iorString = br.readLine();
49             }
50             catch ( IOException ioe )
51             {
52                 ioe.printStackTrace();
53                 System.exit(1);
54             }
55         }
56         else
57         {
58             iorString = args[0];
59         }
60
61         org.omg.CORBA.Object JavaDoc o = orb.string_to_object( iorString );
62
63         if( o == null )
64         {
65             System.out.println("Could not convert " + iorString + " to an object");
66         }
67         else
68         {
69             try
70             {
71                 System.out.println("Object exists: " + (!o._non_existent()));
72             }
73             catch (org.omg.CORBA.SystemException JavaDoc e)
74             {
75                 System.out.println("Object not reachable! (Exception: " + e + ")");
76             }
77
78         }
79     }
80 }
81
Popular Tags