meetingvaluefactory.java
来自「100多M的J2EE培训内容」· Java 代码 · 共 104 行
JAVA
104 行
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; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?