FileDocCategorySizeDatePackage
EJBPersonCommand.javaAPI DocExample2225Sun Jul 20 17:39:58 BST 2003antipatterns.model

EJBPersonCommand

public class EJBPersonCommand extends Object implements PersonCommand

Fields Summary
private String
firstName
private String
lastName
private Vector
people
private EJBPersonHome
personHome
Constructors Summary
Methods Summary
public java.util.ListgetPeople()

        return people;
    
public voidinitialize(javax.servlet.http.HttpSession session)

 
        Hashtable properties = new Properties();
        //properties.put(Context.INITIAL_CONTEXT_FACTORY,
        //   "com.sun.jndi.cosnaming.CNCtxFactory");
        //properties.put(Context.PROVIDER_URL, "iiop://wgs97-74:1050");
        
        InitialContext ic = new InitialContext(properties);
        Object personRef = ic.lookup("ejb/EJBPerson");
        
        personHome =
        (EJBPersonHome)PortableRemoteObject.narrow(personRef, EJBPersonHome.class);
        
        people = new Vector();
    
public voidrunCommand()

        
        try {
            Collection ejbpeople = null;

            if (firstName != null & lastName != null) {
                ejbpeople = personHome.findByName(firstName, lastName);
            } else if (firstName != null) {
                ejbpeople = personHome.findByFirstName(firstName);
            } else if (lastName != null) {
                ejbpeople = personHome.findByLastName(lastName);
            } else {
                ejbpeople = personHome.findAll();
            }
            
            for(Iterator i = ejbpeople.iterator(); i.hasNext();) {
                EJBPerson ejbPerson = (EJBPerson)i.next();
                people.add(new Person(ejbPerson.getFirstName(),
                                      ejbPerson.getLastName(),
                                      ejbPerson.getPhoneNumber()));
            }
        } catch(Exception ex) {
            ex.printStackTrace();
            return;
        }
        
    
public voidsetFirstName(java.lang.String firstName)

        this.firstName = firstName;
    
public voidsetLastName(java.lang.String lastName)

        this.lastName = lastName;