public class Client
{
public static void main(String[] args) throws Exception
{
// Store a reference to the calculator interface
HelloWorld hw = null;
// Decide whether to use a POJO or connect to an EJB
if (args.length != 1)
{
System.err.println("Usage: java org.jboss.tutorial.client.Client [-pojo|-ejb]");
System.exit(1);
}
else if (args[0].equals("-pojo"))
{
// Simply create a new POJO to act as the HelloWorld
System.out.println("Creating a new HelloWorldBean POJO");
hw = new HelloWorldBean();
}
else if (args[0].equals("-ejb"))
{
// Obtain an initial context
InitialContext ctx = new InitialContext();
// Look up a remote interface to a calculator EJB
System.out.println("Obtaining a reference to a remote HelloWorldBean EJB");
hw = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
}
else
{
System.err.println("Usage: java org.jboss.tutorial.client.Client [-pojo|-ejb]");
System.exit(1);
}
if (hw != null)
{
System.out.println("[Client] " + hw.sayHello("JBoss"));
}
}