001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: JOnAS Team
022: * --------------------------------------------------------------------------
023: * $Id: ViewProxy.java 8307 2006-04-27 13:36:00Z durieuxp $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.alarm.beans;
026:
027: import java.rmi.RemoteException;
028:
029: import javax.naming.Context;
030: import javax.naming.InitialContext;
031: import javax.naming.NamingException;
032: import javax.rmi.PortableRemoteObject;
033:
034: /**
035: * proxy used to access the "View" session bean. must be instantiated by JSP's
036: * with a tag like this: <jsp:useBean id="myview" scope=session
037: * class=org.objectweb.alarm.beans.ViewProxy >
038: */
039: public class ViewProxy {
040:
041: /**
042: * Initial context
043: */
044: private Context ictx = null;
045:
046: /**
047: * Home of the bean View
048: */
049: private ViewHome vh = null;
050:
051: /**
052: * Bean View
053: */
054: private View ejbview = null;
055:
056: /**
057: * Name of my profil
058: */
059: private String myprofil = null;
060:
061: /**
062: * Error message
063: */
064: private String errorMessage = null;
065:
066: private View getEjbView() {
067: if (ejbview == null) {
068: // Create the Session Bean
069: try {
070: ejbview = vh.create();
071: } catch (Exception e) {
072: errorMessage = "ViewProxy : Cannot create EJB:"
073: + e.toString();
074: }
075: }
076: return ejbview;
077: }
078:
079: /**
080: * Init procedure
081: * Gets the bean and create one
082: */
083: private void init() {
084: // Get the ViewHome
085: try {
086: ictx = new InitialContext();
087: vh = (ViewHome) PortableRemoteObject.narrow(ictx
088: .lookup("viewhome"), ViewHome.class);
089: } catch (NamingException e) {
090: errorMessage = "ViewProxy : Cannot get ViewHome:"
091: + e.toString();
092: return;
093: }
094: getEjbView();
095: }
096:
097: /**
098: * constructor: Create here the EJB session.
099: */
100: public ViewProxy() {
101: init();
102: }
103:
104: /**
105: * @return RO attribute: Get all Profils already created by Alarm Manager.
106: */
107: public String[] getProfils() {
108: String[] ret = new String[0];
109: try {
110: ret = getEjbView().getProfils();
111: errorMessage = null;
112: } catch (RemoteException e) {
113: errorMessage = "ViewProxy : Cannot get Profil list:"
114: + e.toString();
115: ejbview = null;
116: }
117: return ret;
118: }
119:
120: /**
121: * @return RW attribute: Profil used.
122: */
123: public String getProfil() {
124: errorMessage = null;
125: return myprofil;
126: }
127:
128: /**
129: * Set the current profil
130: * @param p the name of the profil
131: */
132: public void setProfil(String p) {
133: try {
134: getEjbView().setProfil(p);
135: errorMessage = null;
136: // keep it on local for efficiency
137: myprofil = p;
138: } catch (RemoteException e) {
139: errorMessage = "ViewProxy : Cannot set Profil:"
140: + e.toString();
141: ejbview = null;
142: }
143: }
144:
145: /**
146: * @return RO attribute: list of new alarms on the current Profil
147: */
148: public AlarmData[] getNewAlarms() {
149: AlarmData[] ret = null;
150: try {
151: ret = getEjbView().getNewAlarms();
152: errorMessage = null;
153: } catch (RemoteException e) {
154: errorMessage = "ViewProxy : Cannot get new alarms:"
155: + e.toString();
156: ejbview = null;
157: }
158: return ret;
159: }
160:
161: /**
162: * @return RO attribute: list of all alarms on the current Profil
163: */
164: public AlarmData[] getAllAlarms() {
165: AlarmData[] ret = null;
166: try {
167: ret = getEjbView().getAllAlarms();
168: errorMessage = null;
169: } catch (RemoteException e) {
170: errorMessage = "ViewProxy : Cannot get all alarms:"
171: + e.toString();
172: ejbview = null;
173: }
174: return ret;
175: }
176:
177: /**
178: * @param profilName the name of the profil
179: * @return the maximum level of alarm for this Profil.
180: */
181: public int alarmLevel(String profilName) {
182: int level = 0;
183: try {
184: level = getEjbView().alarmLevel(profilName);
185: errorMessage = null;
186: } catch (RemoteException e) {
187: errorMessage = "ViewProxy : Cannot get AlarmLevel:"
188: + e.toString();
189: ejbview = null;
190: }
191: return level;
192: }
193:
194: /**
195: * @return error message if any
196: */
197: public String getErrorMessage() {
198: return errorMessage;
199: }
200:
201: /**
202: * Forget this Alarm because it has been treated.
203: * @param pk primary key
204: */
205: public void forgetAlarm(String pk) {
206: try {
207: getEjbView().forgetAlarm(pk);
208: errorMessage = null;
209: } catch (RemoteException e) {
210: errorMessage = "ViewProxy : Cannot forget Alarm:"
211: + e.toString();
212: ejbview = null;
213: }
214: }
215:
216: /**
217: * Creates a new Profil
218: * @param device the name of the device
219: * @param level the severity level
220: * @return the newly created profil
221: */
222: public String newProfil(String device, String level) {
223: String ret = null;
224: try {
225: ret = getEjbView().newProfil(device, level);
226: errorMessage = null;
227: } catch (RemoteException e) {
228: errorMessage = "ViewProxy : Cannot create Profil:"
229: + e.toString();
230: ejbview = null;
231: }
232: return ret;
233: }
234:
235: /**
236: * remove a Profil
237: * @param profil name of the profil to remove
238: */
239: public void removeProfil(String profil) {
240: try {
241: getEjbView().removeProfil(profil);
242: errorMessage = null;
243: } catch (RemoteException e) {
244: errorMessage = "ViewProxy : Cannot remove Profil:"
245: + e.toString();
246: ejbview = null;
247: }
248: }
249: }
|