RoomManager.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package com.borland.training.meetings.sessions;
- import javax.ejb.*;
- import javax.naming.*;
- import java.util.*;
- import com.borland.training.meetings.entities.*;
- class RoomManager {
- private static RoomManager instance = null;
- private EJBHomeFactory homeFactory;
- private RoomValueFactory roomValueFactory;
- private RoomManager() throws NamingException {
- homeFactory = EJBHomeFactory.getInstance();
- roomValueFactory = RoomValueFactory.getInstance();
- }
- public static RoomManager getInstance() throws NamingException {
- if(instance == null) {
- instance = new RoomManager();
- }
- return instance;
- }
- public String createRoom(RoomValue roomValue)
- throws FinderException, NamingException {
- try {
- RoomHome roomHome =
- (RoomHome) homeFactory.lookupByLocalEJBReference("Room");
- Room room = roomHome.create(roomValue.getName(),
- roomValue.getCapacity());
- return room.getName();
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- public void updateRoom(RoomValue roomValue)
- throws FinderException, NamingException {
- try {
- Room room = roomValueFactory.findRoom(roomValue.getName());
- room.setCapacity(roomValue.getCapacity());
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- public void removeRoom(String name)
- throws FinderException, NamingException {
- try {
- Room room = roomValueFactory.findRoom(name);
- room.remove();
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- public void removeAllRooms()
- throws FinderException, NamingException {
- try {
- Collection rooms = roomValueFactory.findAllRooms();
- Iterator iterator = rooms.iterator();
- Room room = null;
- while(iterator.hasNext()) {
- room = (Room) iterator.next();
- room.remove();
- }
- }
- catch(Exception e) {
- throw new EJBException(e);
- }
- }
- }