KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > j2eedo > database > Department


1 /*
2  * Speedo: an implementation of JDO compliant personality on top of JORM
3  * generic I/O sub-system. Copyright (C) 2001-2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Release: 1.0
20  *
21  * Created on 27 f�vr. 2004 @author fmillevi@yahoo.com
22  *
23  */

24 package org.objectweb.speedo.j2eedo.database;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * This class define the Java class to access to the department's data
32  * @author fmillevi@yahoo.com
33  *
34  */

35 public class Department implements DatabaseObjectInterface {
36     private long deptid;
37     private String JavaDoc name;
38     private Collection JavaDoc employees; //element:Employee
39
private Collection JavaDoc projects; //element:Project
40

41     /**
42      * Empty constructor
43      */

44     public Department() {
45         super();
46     }
47
48     public String JavaDoc getAsString() {
49         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
50         sb.append("\nDepartment (deptid:").append(this.deptid);
51         sb.append(")\n\tName:").append(this.name);
52         if (null != this.employees) {
53             sb.append("\n\tEmployees:");
54             Iterator JavaDoc employeeIterator = employees.iterator();
55             Employee e = null;
56             while (employeeIterator.hasNext()) {
57                 e = (Employee) employeeIterator.next();
58                 sb.append("\n\t\t").append(e.getFirstname()).append(" ");
59                 sb.append(e.getLastname());
60             }
61         }
62         if (projects != null) {
63             Iterator JavaDoc projectIterator = projects.iterator();
64             if (projectIterator.hasNext()) {
65                 sb.append("\n\tProjects:");
66             }
67             while (projectIterator.hasNext()) {
68                 sb.append("\n\t\t");
69                 sb.append(((Project) projectIterator.next()).getName());
70             }
71         }
72         return sb.toString();
73     }
74     /**
75      * @see org.objectweb.speedo.j2eedo.database.DatabaseObjectInterface#getId()
76      */

77     public long getId() {
78         return this.deptid;
79     }
80
81     public Department(String JavaDoc itsName) {
82         this.name = itsName;
83         employees = new ArrayList JavaDoc();
84         projects = new ArrayList JavaDoc();
85     }
86     /**
87      * @return Returns the deptid.
88      */

89     public long getDeptid() {
90         return deptid;
91     }
92
93     /**
94      * @return Returns the employees.
95      */

96     public Collection JavaDoc getEmployees() {
97         return employees;
98     }
99
100     /**
101      * @param employees
102      * The employees to set.
103      */

104     public void setEmployees(Collection JavaDoc employees) {
105         this.employees = employees;
106     }
107
108     /**
109      * @param newEmployee
110      */

111     public void addEmployee(Employee newEmployee) {
112         employees.add(newEmployee);
113     }
114
115     /**
116      * @param newEmployee
117      */

118     public void removeEmployee(Employee newEmployee) {
119         employees.remove(newEmployee);
120     }
121
122     /**
123      * @return Returns the name.
124      */

125     public String JavaDoc getName() {
126         return name;
127     }
128
129     /**
130      * @param name
131      * The name to set.
132      */

133     public void setName(String JavaDoc name) {
134         this.name = name;
135     }
136
137     /**
138      * @return Returns the projects.
139      */

140     public Collection JavaDoc getProjects() {
141         return projects;
142     }
143
144     /**
145      * @param projects
146      * The projects to set.
147      */

148     public void setProjects(Collection JavaDoc projects) {
149         this.projects.addAll(projects);
150     }
151
152     /**
153      * @param newProject
154      */

155     public void addProject(Project newProject) {
156         projects.add(newProject);
157     }
158     /**
159      * @param newProject
160      */

161     public void removeProject(Project newProject) {
162         projects.remove(newProject);
163     }
164 }
Popular Tags