package org.laughingpanda.ejb_migration_example; import java.util.List; import java.io.PrintStream; import java.text.MessageFormat; import java.rmi.RemoteException; /** * @author Timo Rantalaiho */ public class PersonFinderApp { private ServiceLocator serviceLocator = new ServiceLocatorImpl(); private static PersonFinderApp instance = new PersonFinderApp(); private static PrintStream out = System.out; public static void main(String... args) { if (args.length < 1) { throw new IllegalArgumentException("Please supply a search term as a command-line parameter"); } String searchTerm = args[0]; List results = instance.findPersons(new SearchParameters(searchTerm)); for (Person result : results) { try { out.println(MessageFormat.format("{0}, {1} {2} ({3})", result, result.getFirstName(), result.getLastName(), result.getUserName())); } catch (RemoteException e) { throw new RuntimeException(e); } } } public List findPersons(SearchParameters searchParameters) { try { return serviceLocator.getPersonFinder().findPersons(searchParameters); } catch (java.rmi.RemoteException e) { throw new RuntimeException(e); } } public void setServiceLocator(ServiceLocator serviceLocator) { this.serviceLocator = serviceLocator; } static void setInstance(PersonFinderApp instance) { PersonFinderApp.instance = instance; } static void setOut(PrintStream out) { PersonFinderApp.out = out; } }