001: /*
002: * Speedo: an implementation of JDO compliant personality on top of JORM
003: * generic I/O sub-system. Copyright (C) 2001-2004 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as published by the
007: * Free Software Foundation; either version 2 of the License, or (at your
008: * option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
013: * for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation,
017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Release: 1.0
020: *
021: * Created on 27 feb. 2004 @author fmillevi@yahoo.com
022: *
023: */
024: package org.objectweb.speedo.j2eedo.database;
025:
026: import java.util.ArrayList;
027: import java.util.Collection;
028: import java.util.Iterator;
029:
030: /**
031: * This class define the Java class to access to the department's data
032: * @author fmillevi@yahoo.com
033: *
034: */
035: public class Department implements DatabaseObjectInterface {
036: private long deptid;
037: private String name;
038: private Collection employees; //element:Employee
039: private Collection projects; //element:Project
040:
041: /**
042: * Empty constructor
043: */
044: public Department() {
045: super ();
046: }
047:
048: public String getAsString() {
049: StringBuffer sb = new StringBuffer();
050: sb.append("\nDepartment (deptid:").append(this .deptid);
051: sb.append(")\n\tName:").append(this .name);
052: if (null != this .employees) {
053: sb.append("\n\tEmployees:");
054: Iterator employeeIterator = employees.iterator();
055: Employee e = null;
056: while (employeeIterator.hasNext()) {
057: e = (Employee) employeeIterator.next();
058: sb.append("\n\t\t").append(e.getFirstname())
059: .append(" ");
060: sb.append(e.getLastname());
061: }
062: }
063: if (projects != null) {
064: Iterator projectIterator = projects.iterator();
065: if (projectIterator.hasNext()) {
066: sb.append("\n\tProjects:");
067: }
068: while (projectIterator.hasNext()) {
069: sb.append("\n\t\t");
070: sb.append(((Project) projectIterator.next()).getName());
071: }
072: }
073: return sb.toString();
074: }
075:
076: /**
077: * @see org.objectweb.speedo.j2eedo.database.DatabaseObjectInterface#getId()
078: */
079: public long getId() {
080: return this .deptid;
081: }
082:
083: public Department(String itsName) {
084: this .name = itsName;
085: employees = new ArrayList();
086: projects = new ArrayList();
087: }
088:
089: /**
090: * @return Returns the deptid.
091: */
092: public long getDeptid() {
093: return deptid;
094: }
095:
096: /**
097: * @return Returns the employees.
098: */
099: public Collection getEmployees() {
100: return employees;
101: }
102:
103: /**
104: * @param employees
105: * The employees to set.
106: */
107: public void setEmployees(Collection employees) {
108: this .employees = employees;
109: }
110:
111: /**
112: * @param newEmployee
113: */
114: public void addEmployee(Employee newEmployee) {
115: employees.add(newEmployee);
116: }
117:
118: /**
119: * @param newEmployee
120: */
121: public void removeEmployee(Employee newEmployee) {
122: employees.remove(newEmployee);
123: }
124:
125: /**
126: * @return Returns the name.
127: */
128: public String getName() {
129: return name;
130: }
131:
132: /**
133: * @param name
134: * The name to set.
135: */
136: public void setName(String name) {
137: this .name = name;
138: }
139:
140: /**
141: * @return Returns the projects.
142: */
143: public Collection getProjects() {
144: return projects;
145: }
146:
147: /**
148: * @param projects
149: * The projects to set.
150: */
151: public void setProjects(Collection projects) {
152: this .projects.addAll(projects);
153: }
154:
155: /**
156: * @param newProject
157: */
158: public void addProject(Project newProject) {
159: projects.add(newProject);
160: }
161:
162: /**
163: * @param newProject
164: */
165: public void removeProject(Project newProject) {
166: projects.remove(newProject);
167: }
168: }
|