Coverage Report - org.openpermis.examples.ejb.client.HelloWorldCLClient
 
Classes in this File Line Coverage Branch Coverage Complexity
HelloWorldCLClient
0%
0/18
0%
0/4
2.333
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.examples.ejb.client;
 11  
 
 12  
 import javax.naming.InitialContext;
 13  
 import javax.naming.NamingException;
 14  
 
 15  
 import org.openpermis.examples.ejb.server.HelloWorldException;
 16  
 import org.openpermis.examples.ejb.server.HelloWorldServiceRemote;
 17  
 
 18  
 
 19  
 /**
 20  
  * <p>Java client that can be invoked from the command line.</p>
 21  
  * <p>The client uses the configured naming context and tries to access the hello world service
 22  
  * from the EJB name passed on the command line. (The name at which the EJB is registered at
 23  
  * the naming context usually corresponds to the EAR name when deploying to a EJB3 container.)</p>
 24  
  * <p>The rest of this client deals with a simple user interface.</p>
 25  
  * <p>For the sake of simplicity error handling is very simple 
 26  
  * @since 0.4.0
 27  
  */
 28  
 public final class HelloWorldCLClient {
 29  
 
 30  
         //---- Static
 31  
         
 32  
         /**
 33  
          * The service context location.
 34  
          * @since 0.4.0
 35  
          */
 36  
         private static final String SERVICE = "/HelloWorldService/remote";
 37  
 
 38  
         /**
 39  
          * The users used.
 40  
          * @since 0.4.0
 41  
          */
 42  0
         private static final String[] USER_CHOICES = new String[] {
 43  
                 "cn=john,o=post,c=ch",
 44  
                 "cn=sara,o=post,c=ch"
 45  
         };
 46  
         
 47  
         /**
 48  
          * Starts the hello world EJB client.
 49  
          * <p>Pass the name of the EJB as the first argument to the client.</p>
 50  
          * @param args the application arguments containing the EJB name as the first argument.
 51  
          * @since new
 52  
          */
 53  
         public static void main (String[] args) {
 54  
                 
 55  0
                 if (args.length == 0) {
 56  0
                         System.out.println("Usage: HelloWorldClient ejb-name");
 57  0
                         System.exit(0);
 58  
                 }
 59  
 
 60  
                 try {
 61  0
                         final HelloWorldServiceRemote service = 
 62  
                                 createService(args[0]);
 63  0
                         for (String name : USER_CHOICES) {
 64  0
                                 System.out.print("  " + name + ": ");
 65  
                                 try {
 66  0
                                         System.out.println(service.getHelloMessage(name));
 67  0
                                 } catch (HelloWorldException e) {
 68  0
                                         System.out.println("<" + e.getMessage() + ">");
 69  0
                                 }
 70  
                         }
 71  0
                 } catch (NamingException e) {
 72  0
                         e.printStackTrace();
 73  0
                 }
 74  0
         }
 75  
 
 76  
         /**
 77  
          * Creates the {@link HelloWorldServiceRemote}.
 78  
          * @param ejbName the name of the ejb.
 79  
          * @return the HelloWorld service.
 80  
          * @throws NamingException if name could not be resolved.
 81  
          * @since 0.4.0
 82  
          */
 83  
         public static HelloWorldServiceRemote createService (String ejbName) throws NamingException {
 84  0
                 return (HelloWorldServiceRemote) new InitialContext().lookup(ejbName + SERVICE);
 85  
         }
 86  
 
 87  
         //---- Constructors
 88  
         
 89  
         /**
 90  
          * Objects of this class cannot be instantiated.
 91  
          * @since 0.4.0
 92  
          */
 93  
         private HelloWorldCLClient () {
 94  0
                 super();
 95  0
         }
 96  
 
 97  
 }