EmployeeRegistryBeanpublic class EmployeeRegistryBean extends Object implements SerializableThis class is an example of an application specific interface
to a data source (faked here, but it could be a database). It
contains methods for authenticating a user, and retrieving and
updating user information. |
Fields Summary |
---|
private Map | dataSource |
Methods Summary |
---|
public EmployeeBean | authenticate(java.lang.String username, java.lang.String password)Returns an EmployeeBean if the specified user name and password
match an employee in the database, otherwise null.
EmployeeBean empInfo = getEmployee(username);
if (empInfo != null && empInfo.getPassword().equals(password)) {
return empInfo;
}
return null;
| public EmployeeBean | getEmployee(java.lang.String username)Returns an EmployeeBean initialized with the information
found in the database for the specified employee, or null if
not found.
return (EmployeeBean) dataSource.get(username);
| public void | saveEmployee(EmployeeBean empInfo)Inserts the information about the specified employee, or
updates the information if it's already defined.
dataSource.put(empInfo.getUsername(), empInfo);
| public void | setDataSource(java.util.Map dataSource)Sets the dataSource property value.
if (dataSource != null) {
Iterator i = dataSource.entrySet().iterator();
while (i.hasNext()) {
Map.Entry me = (Map.Entry) i.next();
}
}
this.dataSource = dataSource;
|
|