org.openpermis.examples.ejb.client
Class HelloWorldClient

java.lang.Object
  extended by org.openpermis.examples.ejb.client.HelloWorldClient
All Implemented Interfaces:
Runnable

public class HelloWorldClient
extends Object
implements Runnable

Java client that prompts the user for a name and executes the hello world service.

The client uses the configured naming context and tries to access the hello world service from the EJB name passed on the command line. (The name at which the EJB is registered at the naming context usually corresponds to the EAR name when deploying to a EJB3 container.)

The intresting part of this example, namely the call to the EJB is perfomed in method execute(String). The rest of this client deals with a simple user interface.

See Also:
execute(String)
Since:
0.3.0

Field Summary
private static String SERVICE
          The service context location.
private  String serviceName
          The context location of the HelloWorldServiceRemote.
private static String[] USER_CHOICES
          The users offered at the chooser.
 
Constructor Summary
HelloWorldClient(String serviceName)
          Creates a new hello world client that connects to the specified service.
 
Method Summary
private  String chooseUser()
          Displays a prompt to choose a user for the hello world service.
private  void execute(String user)
          Retrieves the hello message for the specified user.
private  HelloWorldServiceRemote getHelloWorldService()
          Performs a lookup of the hello world service.
static void main(String[] args)
          Starts the hello world EJB client.
 void run()
          Starts the hello world EJB client.
private  void showMessage(String message, boolean error)
          Displays a message box.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE

private static final String SERVICE
The service context location.

Constant Field Value:
"/HelloWorldService/remote"
See Also:
execute(String), Constant Field Values
Since:
0.3.0

USER_CHOICES

private static final String[] USER_CHOICES
The users offered at the chooser.

Since:
0.3.0

serviceName

private final String serviceName
The context location of the HelloWorldServiceRemote.

Since:
0.3.0
Constructor Detail

HelloWorldClient

public HelloWorldClient(String serviceName)
Creates a new hello world client that connects to the specified service.

Parameters:
serviceName - the context location of the HelloWorldServiceRemote.
Since:
0.3.0
Method Detail

main

public static void main(String[] args)
Starts the hello world EJB client.

Pass the name of the EJB as the first argument to the client.

Parameters:
args - the application arguments containing the EJB name as the first argument.
See Also:
run()
Since:
0.3.0

showMessage

private void showMessage(String message,
                         boolean error)
Displays a message box.

Parameters:
message - the message to display.
error - true if the message to display is an error message.
Since:
0.3.0

chooseUser

private String chooseUser()
Displays a prompt to choose a user for the hello world service.

Returns:
the user chosen or null if aborted.
Since:
0.3.0

getHelloWorldService

private HelloWorldServiceRemote getHelloWorldService()
                                              throws NamingException
Performs a lookup of the hello world service.

Returns:
the hello world service.
Throws:
NamingException - if the service lookup fails.
Since:
0.3.0

execute

private void execute(String user)
Retrieves the hello message for the specified user.

Parameters:
user - the user name to pass to the hello world service.
Since:
0.3.0

run

public void run()
Starts the hello world EJB client.

Prompts for a user name and executes the hello world service.

Specified by:
run in interface Runnable
Since:
0.3.0


PERMIS Role Based Access Control 0.4.0 (Build 15)
2009/05/20 08:15:52
Copyright (c) 2002-2007 Ergon Informatik AG