Use the Mobile Action design pattern.
- By Roger L. Cauvin
- June 24, 2001
Java To Go!
Empower your EJB clients with mobile actions
Roger L. Cauvin
Listing 3. Use the Mobile Action design pattern.
public class FindByNameAction implements EmployeeAction,
Serializable
{
public FindByNameAction(String targetName)
{
setTargetName(targetName);
}
public Object perform(IEmployeeStorage employeeStorage) throws
ActionException
{
Vector employees = null;
try
{
employees = employeeStorage.retrieveEmployees();
}
catch (RetrievalException retrievalException)
{
throw new ActionException(retrievalException);
}
String targetName = getTargetName();
Employee employee = null;
Enumeration enumeration = employees.elements();
boolean wasFound = false;
while (!wasFound && enumeration.hasMoreElements())
{
employee = (Employee) enumeration.nextElement();
wasFound = targetName.equals(employee.getName());
}
return wasFound ? employee : null;
}
... code for getTargetName, setTargetName, etc. ...
}
About the Author
Roger L. Cauvin is a software engineer at KLA-Tencor, Austin, TX. He can be contacted at [email protected].