RoomValueFactory.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package com.borland.training.meetings.sessions;
- import java.util.*;
- import javax.ejb.*;
- import javax.naming.*;
- import com.borland.training.meetings.entities.*;
- class RoomValueFactory {
- private static RoomValueFactory instance = null;
- private EJBHomeFactory homeFactory;
- private RoomValueFactory() throws NamingException {
- homeFactory = EJBHomeFactory.getInstance();
- }
- public static RoomValueFactory getInstance() throws NamingException {
- if(instance == null) {
- instance = new RoomValueFactory();
- }
- return instance;
- }
- public RoomValue getRoom(String name)
- throws FinderException, NamingException {
- Room room = findRoom(name);
- return createValue(room);
- }
- public Collection getAllRooms()
- throws FinderException, NamingException {
- Collection rooms = findAllRooms();
- Collection roomValues = new Vector(rooms.size());
- Iterator iterator = rooms.iterator();
- Room room = null;
- while(iterator.hasNext()) {
- room = (Room) iterator.next();
- roomValues.add(createValue(room));
- }
- return roomValues;
- }
- // Helper method used by the factory or a manager
- public Room findRoom(String name)
- throws FinderException, NamingException {
- RoomHome home = (RoomHome) homeFactory.lookupByLocalEJBReference("Room");
- return home.findByPrimaryKey(name);
- }
- // Helper method used by the factory or a manager
- public Collection findAllRooms()
- throws FinderException, NamingException {
- RoomHome home = (RoomHome) homeFactory.lookupByLocalEJBReference("Room");
- return home.findAll();
- }
- // Helper method used by the factory
- private RoomValue createValue(Room room) {
- return new RoomValue(room.getName(),
- room.getCapacity(),
- getMeetingIds(room));
- }
- // Helper method used by the factory
- private Collection getMeetingIds(Room room) {
- Collection meetings = room.getMeetings();
- Collection meetingIds = new Vector(meetings.size());
- Iterator iterator = meetings.iterator();
- while(iterator.hasNext()) {
- Meeting meeting = (Meeting) iterator.next();
- meetingIds.add(meeting.getId());
- }
- return meetingIds;
- }
- }