RoomManager.java
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package com.borland.training.meetings.sessions;
  2. import javax.ejb.*;
  3. import javax.naming.*;
  4. import java.util.*;
  5. import com.borland.training.meetings.entities.*;
  6. class RoomManager {
  7.   private static RoomManager instance = null;
  8.   private EJBHomeFactory homeFactory;
  9.   private RoomValueFactory roomValueFactory;
  10.   private RoomManager() throws NamingException {
  11.     homeFactory = EJBHomeFactory.getInstance();
  12.     roomValueFactory = RoomValueFactory.getInstance();
  13.   }
  14.   public static RoomManager getInstance() throws NamingException {
  15.     if(instance == null) {
  16.       instance = new RoomManager();
  17.     }
  18.     return instance;
  19.   }
  20.   public String createRoom(RoomValue roomValue)
  21.     throws FinderException, NamingException {
  22.     try {
  23.       RoomHome roomHome =
  24.         (RoomHome) homeFactory.lookupByLocalEJBReference("Room");
  25.       Room room = roomHome.create(roomValue.getName(),
  26.         roomValue.getCapacity());
  27.       return room.getName();
  28.     }
  29.     catch(Exception e) {
  30.       throw new EJBException(e);
  31.     }
  32.   }
  33.   public void updateRoom(RoomValue roomValue)
  34.     throws FinderException, NamingException {
  35.     try {
  36.       Room room = roomValueFactory.findRoom(roomValue.getName());
  37.       room.setCapacity(roomValue.getCapacity());
  38.     }
  39.     catch(Exception e) {
  40.       throw new EJBException(e);
  41.     }
  42.   }
  43.   public void removeRoom(String name)
  44.     throws FinderException, NamingException {
  45.     try {
  46.       Room room = roomValueFactory.findRoom(name);
  47.       room.remove();
  48.     }
  49.     catch(Exception e) {
  50.       throw new EJBException(e);
  51.     }
  52.   }
  53.   public void removeAllRooms()
  54.     throws FinderException, NamingException {
  55.     try {
  56.       Collection rooms = roomValueFactory.findAllRooms();
  57.       Iterator iterator = rooms.iterator();
  58.       Room room = null;
  59.       while(iterator.hasNext()) {
  60.         room = (Room) iterator.next();
  61.         room.remove();
  62.       }
  63.     }
  64.     catch(Exception e) {
  65.       throw new EJBException(e);
  66.     }
  67.   }
  68. }