KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > usecases > service > ProjectService


1 package net.sourceforge.formview.usecases.service;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import net.sourceforge.formview.usecases.dto.DeveloperDTO;
9 import net.sourceforge.formview.usecases.dto.ManagerDTO;
10 import net.sourceforge.formview.usecases.dto.ProjectDTO;
11
12 public class ProjectService {
13     
14     private static int projectIdIncrement = 0;
15     private static Map JavaDoc projectsDTOMap = new HashMap JavaDoc();
16     private static Map JavaDoc managersDTOMap = new HashMap JavaDoc();
17     
18     static {
19         // Populate default list of Project
20
for (int i=0; i< 10; i++) {
21             projectIdIncrement++;
22             // Manager
23
ManagerDTO manager = new ManagerDTO(String.valueOf(projectIdIncrement), "Manager name " + String.valueOf(projectIdIncrement));
24             
25             // Developers
26
Collection JavaDoc developers = new ArrayList JavaDoc();
27             for(int j=0; j< 5; j++) {
28                 developers.add(new DeveloperDTO(String.valueOf(j), "Developer name " + String.valueOf(j)));
29             }
30             
31             managersDTOMap.put(String.valueOf(projectIdIncrement), manager);
32             createProject(new ProjectDTO(String.valueOf(projectIdIncrement),
33                                          "Project name" + String.valueOf(projectIdIncrement),
34                                          "01/01/2006" ,
35                                          manager, developers));
36         }
37         
38     }
39     
40     
41     public static ProjectDTO findProjectById(String JavaDoc projectId) {
42         return (ProjectDTO)projectsDTOMap.get(projectId);
43     }
44     
45     public static Collection JavaDoc findAllProject() {
46         return projectsDTOMap.values();
47     }
48     
49     public static void createProject(ProjectDTO projectDTO) {
50         String JavaDoc projectId = String.valueOf(projectIdIncrement++);
51         projectDTO.setId(String.valueOf(projectId));
52         projectsDTOMap.put(projectId, projectDTO);
53     }
54
55     public static ProjectDTO updateProject(ProjectDTO projectDTO) {
56         String JavaDoc projectId = projectDTO.getId();
57         return (ProjectDTO)projectsDTOMap.put(projectId, projectDTO);
58     }
59     
60     /**
61      * Return All manager DTO.
62      * @return
63      */

64     public static Collection JavaDoc findAllManager() {
65         return managersDTOMap.values();
66     }
67     
68     public static ManagerDTO findManagerById(String JavaDoc managerId) {
69         return (ManagerDTO)managersDTOMap.get(managerId);
70     }
71     
72     
73 }
74
75
Popular Tags