KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > alarm > beans > ViewProxy


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: JOnAS Team
22  * --------------------------------------------------------------------------
23  * $Id: ViewProxy.java,v 1.4 2004/04/09 12:56:41 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.alarm.beans;
28
29 import java.rmi.RemoteException JavaDoc;
30
31 import javax.naming.Context JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import javax.rmi.PortableRemoteObject JavaDoc;
35
36 /**
37  * proxy used to access the "View" session bean. must be instantiated by JSP's
38  * with a tag like this: <jsp:useBean id="myview" scope=session
39  * class=org.objectweb.alarm.beans.ViewProxy >
40  */

41 public class ViewProxy {
42
43 /**
44  * Initial context
45  */

46     private Context JavaDoc ictx = null;
47
48     /**
49      * Home of the bean View
50      */

51     private ViewHome vh = null;
52
53     /**
54      * Bean View
55      */

56     private View ejbview = null;
57
58     /**
59      * Name of my profil
60      */

61     private String JavaDoc myprofil = null;
62
63     /**
64      * Error message
65      */

66     private String JavaDoc errorMessage = null;
67
68     /**
69      * Init procedure
70      * Gets the bean and create one
71      */

72     private void init() {
73         // Get the ViewHome
74
try {
75             ictx = new InitialContext JavaDoc();
76             vh = (ViewHome) PortableRemoteObject.narrow(ictx.lookup("viewhome"), ViewHome.class);
77         } catch (NamingException JavaDoc e) {
78             errorMessage = "ViewProxy : Cannot get ViewHome:" + e.toString();
79             return;
80         }
81
82         // Create the Session Bean
83
try {
84             ejbview = vh.create();
85         } catch (Exception JavaDoc e) {
86             errorMessage = "ViewProxy : Cannot create EJB:" + e.toString();
87         }
88     }
89
90     /**
91      * constructor: Create here the EJB session.
92      */

93     public ViewProxy() {
94         init();
95     }
96
97     /**
98      * @return RO attribute: Get all Profils already created by Alarm Manager.
99      */

100     public String JavaDoc[] getProfils() {
101         String JavaDoc[] ret = new String JavaDoc[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 JavaDoc e) {
110             errorMessage = "ViewProxy : Cannot get Profil list:" + e.toString();
111         }
112         return ret;
113     }
114
115     /**
116      * @return RW attribute: Profil used.
117      */

118     public String JavaDoc getProfil() {
119         errorMessage = null;
120         return myprofil;
121     }
122
123     /**
124      * Set the current profil
125      * @param p the name of the profil
126      */

127     public void setProfil(String JavaDoc p) {
128         try {
129             ejbview.setProfil(p);
130             errorMessage = null;
131             // keep it on local for efficiency
132
myprofil = p;
133         } catch (RemoteException JavaDoc e) {
134             errorMessage = "ViewProxy : Cannot set Profil:" + e.toString();
135         }
136     }
137
138     /**
139      * @return RO attribute: list of new alarms on the current Profil
140      */

141     public AlarmData[] getNewAlarms() {
142         AlarmData[] ret = null;
143         try {
144             ret = ejbview.getNewAlarms();
145             errorMessage = null;
146         } catch (RemoteException JavaDoc e) {
147             errorMessage = "ViewProxy : Cannot get new alarms:" + e.toString();
148         }
149         return ret;
150     }
151
152     /**
153      * @return RO attribute: list of all alarms on the current Profil
154      */

155     public AlarmData[] getAllAlarms() {
156         AlarmData[] ret = null;
157         try {
158             ret = ejbview.getAllAlarms();
159             errorMessage = null;
160         } catch (RemoteException JavaDoc e) {
161             errorMessage = "ViewProxy : Cannot get all alarms:" + e.toString();
162         }
163         return ret;
164     }
165
166     /**
167      * @param profilName the name of the profil
168      * @return the maximum level of alarm for this Profil.
169      */

170     public int alarmLevel(String JavaDoc profilName) {
171         int level = 0;
172         try {
173             level = ejbview.alarmLevel(profilName);
174             errorMessage = null;
175         } catch (RemoteException JavaDoc e) {
176             errorMessage = "ViewProxy : Cannot get AlarmLevel:" + e.toString();
177         }
178         return level;
179     }
180
181     /**
182      * @return error message if any
183      */

184     public String JavaDoc getErrorMessage() {
185         return errorMessage;
186     }
187
188     /**
189      * Forget this Alarm because it has been treated.
190      * @param pk primary key
191      */

192     public void forgetAlarm(String JavaDoc pk) {
193         try {
194             ejbview.forgetAlarm(pk);
195             errorMessage = null;
196         } catch (RemoteException JavaDoc e) {
197             errorMessage = "ViewProxy : Cannot forget Alarm:" + e.toString();
198         }
199     }
200
201     /**
202      * Creates a new Profil
203      * @param device the name of the device
204      * @param level the severity level
205      * @return the newly created profil
206      */

207     public String JavaDoc newProfil(String JavaDoc device, String JavaDoc level) {
208         String JavaDoc ret = null;
209         try {
210             ret = ejbview.newProfil(device, level);
211             errorMessage = null;
212         } catch (RemoteException JavaDoc e) {
213             errorMessage = "ViewProxy : Cannot create Profil:" + e.toString();
214         }
215         return ret;
216     }
217
218     /**
219      * remove a Profil
220      * @param profil name of the profil to remove
221      */

222     public void removeProfil(String JavaDoc profil) {
223         try {
224             ejbview.removeProfil(profil);
225             errorMessage = null;
226         } catch (RemoteException JavaDoc e) {
227             errorMessage = "ViewProxy : Cannot remove Profil:" + e.toString();
228         }
229     }
230 }
Popular Tags