AttendeeValueFactory.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 AttendeeValueFactory {
- private static AttendeeValueFactory instance = null;
- private EJBHomeFactory homeFactory;
- private AttendeeValueFactory() throws NamingException {
- homeFactory = EJBHomeFactory.getInstance();
- }
- public static AttendeeValueFactory getInstance() throws NamingException {
- if(instance == null) {
- instance = new AttendeeValueFactory();
- }
- return instance;
- }
- public AttendeeValue getAttendee(Long id)
- throws FinderException, NamingException {
- Attendee attendee = findAttendee(id);
- return createValue(attendee);
- }
- public Collection getAttendeesByName(String name)
- throws FinderException, NamingException {
- Collection attendees = findAttendeesByName(name);
- return createValues(attendees);
- }
- public Collection getAllAttendees()
- throws FinderException, NamingException {
- Collection attendees = findAllAttendees();
- return createValues(attendees);
- }
- // Helper method used by the factory or a manager
- public Attendee findAttendee(Long id)
- throws FinderException, NamingException {
- AttendeeHome home = (AttendeeHome) homeFactory.lookupByLocalEJBReference("Attendee");
- return home.findByPrimaryKey(id);
- }
- // Helper method used by the factory or a manager
- public Collection findAllAttendees()
- throws FinderException, NamingException {
- AttendeeHome home = (AttendeeHome) homeFactory.lookupByLocalEJBReference("Attendee");
- return home.findAll();
- }
- // Helper method used by the factory or a manager
- public Collection findAttendeesByName(String name)
- throws FinderException, NamingException {
- AttendeeHome home = (AttendeeHome) homeFactory.lookupByLocalEJBReference("Attendee");
- return home.findByName(name);
- }
- // Helper method used by the factory.
- private AttendeeValue createValue(Attendee attendee) {
- return new AttendeeValue(attendee.getId(),
- attendee.getName(),
- attendee.getPosition(),
- attendee.getTitle(),
- attendee.getPhone(),
- attendee.getEmail(),
- getMeetingIds(attendee));
- }
- // Helper method used by the factory.
- private Collection createValues(Collection attendees) {
- Collection attendeeValues = new Vector(attendees.size());
- Iterator iterator = attendees.iterator();
- Attendee attendee = null;
- while(iterator.hasNext()) {
- attendee = (Attendee) iterator.next();
- attendeeValues.add(createValue(attendee));
- }
- return attendeeValues;
- }
- // Helper method used by the factory
- private Collection getMeetingIds(Attendee attendee) {
- Collection meetings = attendee.getMeetings();
- Collection meetingIds = new Vector(meetings.size());
- Iterator iterator = meetings.iterator();
- Meeting meeting = null;
- while(iterator.hasNext()) {
- meeting = (Meeting) iterator.next();
- meetingIds.add(meeting.getId());
- }
- return meetingIds;
- }
- }