KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > faults > EmployeeInfo


1 package samples.faults;
2
3 import samples.faults.Employee;
4
5 import java.util.Collection JavaDoc;
6 import java.util.HashMap JavaDoc;
7
8 public class EmployeeInfo {
9     static HashMap JavaDoc map = new HashMap JavaDoc();
10     static {
11         Employee emp = new Employee();
12         emp.setEmployeeID("#001");
13         emp.setEmployeeName("Bill Gates");
14         map.put(emp.getEmployeeID(), emp);
15     }
16
17     public void addEmployee(Employee in) {
18         map.put(in.getEmployeeID(), in);
19     }
20
21     public Employee getEmployee(java.lang.String JavaDoc id) throws NoSuchEmployeeFault {
22         Employee emp = (Employee) map.get(id);
23         if (emp == null) {
24             NoSuchEmployeeFault fault = new NoSuchEmployeeFault();
25             fault.setInfo("Could not find employee:" + id);
26             throw fault;
27         }
28         return emp;
29     }
30
31     public Employee[] getEmployees() {
32         Collection JavaDoc values = map.values();
33         Employee[] emps = new Employee[values.size()];
34         values.toArray(emps);
35         return emps;
36     }
37 }
38
Popular Tags