KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > common > TestServer


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

22
23 import org.omg.CORBA.*;
24 import org.omg.PortableServer.*;
25 import java.io.*;
26
27 import org.apache.avalon.framework.configuration.Configurable;
28 import org.apache.avalon.framework.configuration.Configuration;
29 import org.apache.avalon.framework.logger.Logger;
30
31 /**
32  * A server program that can set up an arbitrary CORBA servant.
33  * The program takes the name of the servant class to use from
34  * the command line. It then creates an instance of this class,
35  * using its no-arg constructor (which must exist). It registers
36  * the instance with the POA, and prints the resulting IOR to
37  * standard output. If anything goes wrong, a message starting
38  * with the string "ERROR" is instead written to standard output.
39  * <p>
40  * This program is intended to be used with a
41  * {@link ClientServerSetup ClientServerSetup}. To read and process
42  * the <code>TestServer</code>'s output from another program such as
43  * the above, JacORB's normal diagnostic messages should be completely
44  * silenced. This must be done using the normal configuration settings,
45  * e.g. from the command line (see
46  * {@link ClientServerSetup#setUp ClientServerSetup.setUp()} for an
47  * example).
48  * <p>
49  * @author Andre Spiegel <spiegel@gnu.org>
50  * @version $Id: TestServer.java,v 1.5 2004/04/28 12:37:29 brose Exp $
51  */

52 public class TestServer
53 {
54     public static void main (String JavaDoc[] args)
55     {
56         Logger logger = null;
57         try
58         {
59             //init ORB
60
ORB orb = ORB.init( args, null );
61
62             Configuration config = ((org.jacorb.orb.ORB)orb).getConfiguration();
63             logger = ((org.jacorb.config.Configuration)config).getNamedLogger("TestServer");
64
65             //init POA
66
POA poa =
67                 POAHelper.narrow( orb.resolve_initial_references( "RootPOA" ));
68             poa.the_POAManager().activate();
69
70             String JavaDoc className = args[0];
71             Class JavaDoc servantClass = Class.forName (className);
72             Servant servant = ( Servant ) servantClass.newInstance();
73
74             if (servant instanceof Configurable)
75                 ((Configurable)servant).configure (((org.jacorb.orb.ORB)orb).getConfiguration());
76
77             // create the object reference
78
org.omg.CORBA.Object JavaDoc obj = poa.servant_to_reference( servant );
79
80             System.out.println ("SERVER IOR: " + orb.object_to_string(obj));
81             System.out.flush();
82
83             logger.debug("Entering ORB event loop" );
84
85             // wait for requests
86
orb.run();
87         }
88         catch( Exception JavaDoc e )
89         {
90             if (logger != null)
91                 logger.fatalError ("TestServer error ", e);
92             else
93                 System.err.println ("TestServer error " + e);
94         }
95     }
96 }
97
Popular Tags