AttendeeManager.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:3k
源码类别:
Java编程
开发平台:
Java
- package com.borland.training.meetings.sessions;
- import java.util.*;
- import javax.ejb.*;
- import javax.naming.*;
- import com.borland.training.meetings.entities.*;
- import com.borland.training.meetings.sessions.*;
- class AttendeeManager {
- private static AttendeeManager instance = null;
- private AttendeeValueFactory attendeeValueFactory;
- private MeetingValueFactory meetingValueFactory;
- private EJBHomeFactory homeFactory;
- private AttendeeManager() throws NamingException {
- homeFactory = EJBHomeFactory.getInstance();
- attendeeValueFactory = AttendeeValueFactory.getInstance();
- meetingValueFactory = MeetingValueFactory.getInstance();
- }
- public static AttendeeManager getInstance() throws NamingException {
- if(instance == null) {
- instance = new AttendeeManager();
- }
- return instance;
- }
- public Long createAttendee(AttendeeValue attendeeValue)
- throws FinderException, NamingException {
- try {
- AttendeeHome attendeeHome =
- (AttendeeHome) homeFactory.lookupByLocalEJBReference("Attendee");
- Attendee attendee = attendeeHome.create(attendeeValue.getName(),
- attendeeValue.getPosition(),
- attendeeValue.getTitle(),
- attendeeValue.getPhone(),
- attendeeValue.getEmail());
- return attendee.getId();
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- // Updating the attendee's meeting list is not supported here.
- // This functionality is provided by the Meeting bean.
- public void updateAttendee(AttendeeValue attendeeValue)
- throws FinderException, NamingException {
- try {
- Attendee attendee = attendeeValueFactory.findAttendee(attendeeValue.getId());
- attendee.setName(attendeeValue.getName());
- attendee.setPosition(attendeeValue.getPosition());
- attendee.setTitle(attendeeValue.getTitle());
- attendee.setPhone(attendeeValue.getPhone());
- attendee.setEmail(attendeeValue.getEmail());
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- public void removeAttendee(Long id)
- throws FinderException, NamingException {
- try {
- Attendee attendee = attendeeValueFactory.findAttendee(id);
- attendee.remove();
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- public void removeAllAttendees()
- throws FinderException, NamingException {
- try {
- Collection attendees = attendeeValueFactory.findAllAttendees();
- Iterator iterator = attendees.iterator();
- Attendee attendee = null;
- while(iterator.hasNext()) {
- attendee = (Attendee) iterator.next();
- attendee.remove();
- }
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- }