DepartmentEJB.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package bible.ejb.entity.cmp;
- import java.util.*;
- import javax.ejb.*;
- import javax.naming.*;
- abstract public class DepartmentEJB implements EntityBean
- {
- private EntityContext ctx;
- public void setEntityContext(EntityContext ctx) {
- this.ctx = ctx;
- }
- public void unsetEntityContext() {
- this.ctx = null;
- }
- abstract public Integer getId();
- abstract public void setId(Integer id);
- abstract public String getName();
- abstract public void setName(String val);
- abstract public Collection getCourses();
- abstract public void setCourses(Collection courses);
- public void ejbActivate() {
- }
- public void ejbPassivate() {
- }
- public void ejbLoad() {
- }
- public void ejbStore() {
- }
- public void ejbRemove() throws RemoveException
- {
- }
- public Integer ejbCreate(DepartmentVO dept)
- throws CreateException
- {
- setDepartmentData(dept);
- return null;
- }
- public void ejbPostCreate(DepartmentVO dept)
- throws CreateException
- {
- }
- public void addCourse(CourseVO courseData) throws NamingException, CreateException
- {
- Context ctx = new InitialContext();
- CourseLocalHome courseHome = (CourseLocalHome) ctx.lookup("cmp.Course");
- CourseLocal course = courseHome.create(courseData);
- getCourses().add(course);
- }
- public CourseVO[] getAllCourses()
- {
- Collection courses = getCourses();
- CourseVO[] courseArray = new CourseVO[courses.size()];
- Iterator courseIterator = courses.iterator();
- for (int i=0; courseIterator.hasNext(); i++)
- {
- CourseLocal course = (CourseLocal) courseIterator.next();
- courseArray[i] = course.getCourseData();
- }
- return courseArray;
- }
- public DepartmentVO getDepartmentData()
- {
- DepartmentVO dept = new DepartmentVO(this.getId());
- dept.setName(this.getName());
- return dept;
- }
- public void setDepartmentData(DepartmentVO dept)
- {
- setName(dept.getName());
- }
- }