FileDocCategorySizeDatePackage
CreateAddressCommand.javaAPI DocExample1544Sun Jul 20 17:40:18 BST 2003antipatterns.model

CreateAddressCommand

public class CreateAddressCommand extends Object

Fields Summary
private AddressBook[]
books
private String[]
names
Constructors Summary
Methods Summary
public voidinitialize()

    
         
        books = new AddressBook[names.length];
        
        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 bookHome =
        (AddressBookHome)PortableRemoteObject.narrow(personRef, AddressBookHome.class);
    
        try {
            for(int i = 0; i < names.length; i++) {
                books[i] = bookHome.create(names[i]);
            }
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    
public voidrunCommand()

        
        try {
            for(int i = 0; i < 1000; i++) {
                int idx = (int)(Math.random() * names.length);
                String owner = names[idx];
                books[idx].addEntry(i, owner, owner, "tester" + i, "555-0" + i);
            }
        } catch(Exception ex) {
            ex.printStackTrace();
            return;
        }