1 26 27 package org.objectweb.alarm.beans; 28 29 import java.rmi.RemoteException ; 30 import java.util.Collection ; 31 32 import javax.ejb.SessionBean ; 33 import javax.ejb.SessionContext ; 34 35 41 public class ViewBean implements SessionBean { 42 43 46 private static transient AlarmManager alarmManager = null; 47 48 51 private Profil prof = null; 52 53 58 public void setSessionContext(SessionContext ctx) { 59 60 } 61 62 66 public void ejbRemove() { 67 } 68 69 72 public void ejbCreate() { 73 alarmManager = AlarmManager.getInstance(); 75 } 76 77 81 public void ejbPassivate() { 82 } 83 84 88 public void ejbActivate() { 89 } 90 91 95 public AlarmData[] getAllAlarms() throws RemoteException { 96 if (prof == null) { 97 throw new RemoteException ("No Profil defined for this session"); 98 } 99 Collection alist = prof.getAlarms(true); 100 return (AlarmData[]) alist.toArray(new AlarmData[0]); 101 } 102 103 107 public AlarmData[] getNewAlarms() throws RemoteException { 108 if (prof == null) { 109 throw new RemoteException ("No Profil defined for this session"); 110 } 111 Collection alist = prof.getAlarms(false); 112 return (AlarmData[]) alist.toArray(new AlarmData[0]); 113 } 114 115 118 public String [] getProfils() { 119 return alarmManager.getProfilNames(); 120 } 121 122 127 public void setProfil(String name) throws RemoteException { 128 if (name == null) { 129 prof = null; 130 return; 131 } 132 prof = alarmManager.getProfil(name); 133 if (prof == null) { 134 throw new RemoteException ("This Profil does not exist yet: " + name); 135 } 136 } 137 138 143 public int alarmLevel(String name) throws RemoteException { 144 Profil prof = alarmManager.getProfil(name); 145 if (prof == null) { 146 throw new RemoteException ("This Profil does not exist yet: " + name); 147 } 148 return prof.getCurrentLevel(); 149 } 150 151 156 public void forgetAlarm(String pk) throws RemoteException { 157 alarmManager.forgetAlarm(pk); 158 } 159 160 167 public String newProfil(String device, String level) throws RemoteException { 168 169 if (device.length() == 0) { 171 throw new RemoteException ("null device string"); 172 } 173 if (!level.startsWith("S") && !level.startsWith("W") && !level.startsWith("I")) { 174 throw new RemoteException ("severity must be one of S|W|I"); 175 } 176 177 prof = alarmManager.newProfil(device, level); 178 if (prof == null) { 179 return null; 180 } 181 return prof.getName(); 182 } 183 184 189 public void removeProfil(String name) throws RemoteException { 190 if (name == null) { 191 return; 192 } 193 boolean ok = alarmManager.delProfil(name); 194 if (!ok) { 195 throw new RemoteException ("This Profil does not exist yet: " + name); 196 } 197 } 198 } | Popular Tags |