FileDocCategorySizeDatePackage
AddressBookCommand.javaAPI DocExample2215Sun Jul 20 18:43:22 BST 2003antipatterns.model

AddressBookCommand

public class AddressBookCommand extends Object implements PersonCommand

Fields Summary
private static final String
ADDRESSBOOK_ATTR
private String
firstName
private String
lastName
private String
owner
private List
people
private AddressBook
addressBook
Constructors Summary
public AddressBookCommand(String owner)

    
       
        this.owner = owner;
    
Methods Summary
public java.util.ListgetPeople()

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

        addressBook = (AddressBook)session.getAttribute(owner + "-" + ADDRESSBOOK_ATTR);
        if (addressBook == null) {
            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/AddressBook");
            
            AddressBookHome addressBookHome =
            (AddressBookHome)PortableRemoteObject.narrow(personRef,
            AddressBookHome.class);
            
            try {
                System.out.println("Creating new book: " + owner);
                addressBook = addressBookHome.create(owner);
                session.setAttribute(owner + "-" + ADDRESSBOOK_ATTR, addressBook);
            } catch(Exception ex) {
                ex.printStackTrace();
            }
        }
    
public voidrunCommand()

        try {
            PeopleDTO peopleDto = addressBook.findByName(firstName, lastName);
            people = peopleDto.getPeople();
            
        } catch(Exception ex) {
            ex.printStackTrace();
            return;
        }
        
    
public voidsetFirstName(java.lang.String firstName)

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

        this.lastName = lastName;