EnrollmentCartEJB.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package day21ex.enrollmentcart;
- import java.util.*;
- import javax.ejb.*;
- import javax.naming.*;
- public class EnrollmentCartEJB implements SessionBean {
- private SessionContext ctx;
- private HashSet cart;
- public EnrollmentCartEJB() {
- print("The container created this instance.n");
- }
- public void setSessionContext(SessionContext ctx) {
- print("The container called the setSessionContext method ");
- print("to associate session bean instance with its context.n");
- this.ctx = ctx;
- }
- public void ejbCreate() throws CreateException {
- print("The container called the ejbCreate method.n");
- cart = new HashSet();
- }
- public void ejbActivate() {
- print("This instance has just been reactivated.n");
- }
- public void ejbPassivate() {
- print("The container intends to passivate the instance.n");
- }
- public void ejbRemove() {
- print("This instance is in the process of being removed ");
- print("by the container.n");
- }
- public void addCourses(String[] courseIds) {
- print("The container called addCourses method.n");
- if ( courseIds == null) {
- return;
- }
- for ( int i = 0; i < courseIds.length ; i ++ ) {
- print("Adding Course" + courseIds[i]);
- cart.add(courseIds[i]);
- }
- }
- public Collection getCourses() {
- print("The container called getCourses method.n");
- Iterator it = cart.iterator();
- while (it.hasNext()) {
- print((String)it.next());
- }
- return cart;
- }
- public void empty() {
- print("The container called empty method.n");
- cart.clear();
- }
- void print(String s) {
- System.out.println("EnrollmentCartEJB:"+s);
- }
- }