1 26 27 package org.objectweb.alarm.beans; 28 29 import java.rmi.RemoteException ; 30 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 import javax.rmi.PortableRemoteObject ; 35 36 41 public class ViewProxy { 42 43 46 private Context ictx = null; 47 48 51 private ViewHome vh = null; 52 53 56 private View ejbview = null; 57 58 61 private String myprofil = null; 62 63 66 private String errorMessage = null; 67 68 72 private void init() { 73 try { 75 ictx = new InitialContext (); 76 vh = (ViewHome) PortableRemoteObject.narrow(ictx.lookup("viewhome"), ViewHome.class); 77 } catch (NamingException e) { 78 errorMessage = "ViewProxy : Cannot get ViewHome:" + e.toString(); 79 return; 80 } 81 82 try { 84 ejbview = vh.create(); 85 } catch (Exception e) { 86 errorMessage = "ViewProxy : Cannot create EJB:" + e.toString(); 87 } 88 } 89 90 93 public ViewProxy() { 94 init(); 95 } 96 97 100 public String [] getProfils() { 101 String [] ret = new String [0]; 102 if (ejbview == null) { 103 errorMessage += "ViewProxy : Not initialized?"; 104 return ret; 105 } 106 try { 107 ret = ejbview.getProfils(); 108 errorMessage = null; 109 } catch (RemoteException e) { 110 errorMessage = "ViewProxy : Cannot get Profil list:" + e.toString(); 111 } 112 return ret; 113 } 114 115 118 public String getProfil() { 119 errorMessage = null; 120 return myprofil; 121 } 122 123 127 public void setProfil(String p) { 128 try { 129 ejbview.setProfil(p); 130 errorMessage = null; 131 myprofil = p; 133 } catch (RemoteException e) { 134 errorMessage = "ViewProxy : Cannot set Profil:" + e.toString(); 135 } 136 } 137 138 141 public AlarmData[] getNewAlarms() { 142 AlarmData[] ret = null; 143 try { 144 ret = ejbview.getNewAlarms(); 145 errorMessage = null; 146 } catch (RemoteException e) { 147 errorMessage = "ViewProxy : Cannot get new alarms:" + e.toString(); 148 } 149 return ret; 150 } 151 152 155 public AlarmData[] getAllAlarms() { 156 AlarmData[] ret = null; 157 try { 158 ret = ejbview.getAllAlarms(); 159 errorMessage = null; 160 } catch (RemoteException e) { 161 errorMessage = "ViewProxy : Cannot get all alarms:" + e.toString(); 162 } 163 return ret; 164 } 165 166 170 public int alarmLevel(String profilName) { 171 int level = 0; 172 try { 173 level = ejbview.alarmLevel(profilName); 174 errorMessage = null; 175 } catch (RemoteException e) { 176 errorMessage = "ViewProxy : Cannot get AlarmLevel:" + e.toString(); 177 } 178 return level; 179 } 180 181 184 public String getErrorMessage() { 185 return errorMessage; 186 } 187 188 192 public void forgetAlarm(String pk) { 193 try { 194 ejbview.forgetAlarm(pk); 195 errorMessage = null; 196 } catch (RemoteException e) { 197 errorMessage = "ViewProxy : Cannot forget Alarm:" + e.toString(); 198 } 199 } 200 201 207 public String newProfil(String device, String level) { 208 String ret = null; 209 try { 210 ret = ejbview.newProfil(device, level); 211 errorMessage = null; 212 } catch (RemoteException e) { 213 errorMessage = "ViewProxy : Cannot create Profil:" + e.toString(); 214 } 215 return ret; 216 } 217 218 222 public void removeProfil(String profil) { 223 try { 224 ejbview.removeProfil(profil); 225 errorMessage = null; 226 } catch (RemoteException e) { 227 errorMessage = "ViewProxy : Cannot remove Profil:" + e.toString(); 228 } 229 } 230 } | Popular Tags |