MeetingValueFactory.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.*;
- class MeetingValueFactory {
- private static MeetingValueFactory instance = null;
- private EJBHomeFactory homeFactory;
- private MeetingValueFactory() throws NamingException {
- homeFactory = EJBHomeFactory.getInstance();
- }
- public static MeetingValueFactory getInstance() throws NamingException {
- if(instance == null) {
- instance = new MeetingValueFactory();
- }
- return instance;
- }
- public MeetingValue getMeeting(Long id)
- throws FinderException, NamingException {
- Meeting meeting = findMeeting(id);
- return createValue(meeting);
- }
- public Collection getMeetingsOfAttendee(Long id)
- throws FinderException, NamingException {
- Collection meetings = findMeetingsOfAttendee(id);
- return createValues(meetings);
- }
- public Collection getAllMeetings()
- throws FinderException, NamingException {
- Collection meetings = findAllMeetings();
- return createValues(meetings);
- }
- // Helper method used by the factory or a manager
- public Meeting findMeeting(Long id)
- throws FinderException, NamingException {
- MeetingHome home = (MeetingHome) homeFactory.lookupByLocalEJBReference("Meeting");
- return home.findByPrimaryKey(id);
- }
- // Helper method used by the factory or a manager
- public Collection findMeetingsOfAttendee(Long id)
- throws FinderException, NamingException {
- AttendeeHome home = (AttendeeHome) homeFactory.lookupByLocalEJBReference("Attendee");
- Attendee attendee = home.findByPrimaryKey(id);
- return attendee.getMeetings();
- }
- // Helper method used by the factory or a manager
- public Collection findAllMeetings()
- throws FinderException, NamingException {
- MeetingHome home = (MeetingHome) homeFactory.lookupByLocalEJBReference("Meeting");
- return home.findAll();
- }
- // Helper method used by the factory
- private MeetingValue createValue(Meeting meeting) {
- return new MeetingValue(meeting.getId(),
- meeting.getTopic(),
- meeting.getStartTime(),
- meeting.getFinishTime(),
- meeting.getRoom().getName(),
- getAttendeeIds(meeting));
- }
- // Helper method used by the factory
- private Collection createValues(Collection meetings) {
- Collection meetingValues = new Vector(meetings.size());
- Iterator iterator = meetings.iterator();
- Meeting meeting = null;
- while(iterator.hasNext()) {
- meeting = (Meeting) iterator.next();
- meetingValues.add(createValue(meeting));
- }
- return meetingValues;
- }
- // Helper method used by the factory
- private Collection getAttendeeIds(Meeting meeting) {
- Collection attendees = meeting.getAttendees();
- Collection attendeeIds = new Vector(attendees.size());
- Iterator iterator = attendees.iterator();
- Attendee attendee = null;
- while(iterator.hasNext()) {
- attendee = (Attendee) iterator.next();
- attendeeIds.add(attendee.getId());
- }
- return attendeeIds;
- }
- }