package examples.ejb.subclass.child; import javax.naming.*; import javax.ejb.*; import java.rmi.RemoteException; import java.util.Hashtable; /** * This class illustrates using an EJBean that subclasses from a * another bean. * * * @author Copyright (c) 1998 by WebLogic, Inc. All Rights Reserved. * @author Copyright (c) 1998-1999 by BEA WebXpress. All Rights Reserved. */ public class Client { static String url = "t3://localhost:7001"; static String user = null; static String password = null; /** * Runs this example from the command line. Example: *

* java examples.ejb.subclass.child.Client "t3://localhost:7001" scott tiger *

* The parameters are optional, but if any are supplied, * they are interpreted in this order: *

* @param url URL such as "t3://localhost:7001" of Server * @param user User name, default null * @param password User password, default null */ public static void main(String[] args) { System.out.println("\nBegin child.Client...\n"); // Parse the argument list if ((args == null) || (args.length == 0)) {} else for (int i = 0; i < args.length; i++) { switch(i) { case 0: url = args[i]; break; case 1: user = args[i]; break; case 2: password = args[i]; break; default: } } try { Context ctx = getInitialContext(); ChildHome childHome = (ChildHome) ctx.lookup("child.ChildHome"); System.out.println("Creating child...\n"); Child child = childHome.create(); // Call a method that's unique to the Child bean System.out.println("Step 1 of 4: Calling Child's \"childSaysHello()\" method...\n"); System.out.println(child.childSaysHello()); // Call a method of the Parent bean that is overloaded System.out.println("\nStep 2 of 4: Calling Child's \"parentSaysHello()\" method...\n"); System.out.println(child.parentSaysHello()); // Call a method of the Parent bean that was not overloaded System.out.println("\nStep 3 of 4: Calling Child's \"parentMethodOnly()\" method...\n"); System.out.println(child.parentMethodOnly()); // Call a method of the Child bean that calls a Parent bean System.out.println("\nStep 4 of 4: Calling Child's \"callParentBean()\" method...\n"); System.out.println(child.callParentBean()); } catch (Exception e) { System.out.println(":::::::::::::: Error :::::::::::::::::"); e.printStackTrace(); } System.out.println("\nEnd child.Client...\n"); } /** * Gets an initial context. * * @return Context * @exception java.lang.Exception if there is * an error in getting a Context */ static public Context getInitialContext() throws Exception { Hashtable h = new Hashtable(); h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); h.put(Context.PROVIDER_URL, url); if (user != null) { System.out.println ("user: " + user); h.put(Context.SECURITY_PRINCIPAL, user); if (password == null) password = ""; h.put(Context.SECURITY_CREDENTIALS, password); } return new InitialContext(h); } }