FileDocCategorySizeDatePackage
AddressBookBean.javaAPI DocExample2300Sun Jul 20 18:36:40 BST 2003antipatterns.ejbs

AddressBookBean

public class AddressBookBean extends Object implements javax.ejb.SessionBean

Fields Summary
private SessionContext
context
private String
userName
private LocalAddressBookEntryHome
abeHome
Constructors Summary
Methods Summary
public voidaddEntry(int id, java.lang.String owner, java.lang.String firstName, java.lang.String lastName, java.lang.String phoneNumber)

        abeHome.create(id, owner, firstName, lastName, phoneNumber);
    
public voidejbActivate()

        init();
    
public voidejbCreate(java.lang.String userName)

        this.userName = userName;
        init();
    
public voidejbPassivate()

 abeHome = null; 
public voidejbRemove()

 abeHome = null;
public PeopleDTOfindByName(java.lang.String firstName, java.lang.String lastName)

        Collection c = null;
        
        if (firstName != null && lastName != null) {
            c = abeHome.findByName(userName, firstName, lastName);
        } else if (firstName != null) {
            c = abeHome.findByFirstName(userName, firstName);
        } else if (lastName != null) {
            c = abeHome.findByLastName(userName, lastName);
        } else {
            c = abeHome.findAll(userName);
        }
        
        return (getDTOFromCollection(c));
    
private PeopleDTOgetDTOFromCollection(java.util.Collection people)

        PeopleDTO dto = new PeopleDTO();
        
        for (Iterator i = people.iterator(); i.hasNext();) {
            LocalAddressBookEntry entry = (LocalAddressBookEntry)i.next();
            
            dto.addPerson(new Person(entry.getFirstName(), 
                                     entry.getLastName(),
                                     entry.getPhoneNumber()));
        }
        
        return dto;
    
private voidinit()

        try {
            InitialContext ic = new InitialContext();
            abeHome =
            (LocalAddressBookEntryHome)ic.lookup("java:comp/env/ejb/local/AddressBookEntry");
        } catch(Exception ex) {
            throw new EJBException("Error activating", ex);
        }
    
public voidsetSessionContext(SessionContext aContext)

        context=aContext;