KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > configuration > AdminPreferenceDataHandler


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.web.admin.configuration;
15
16 import java.rmi.RemoteException JavaDoc;
17
18 import javax.ejb.CreateException JavaDoc;
19 import javax.naming.InitialContext JavaDoc;
20 import javax.naming.NamingException JavaDoc;
21
22 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionHome;
23 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionRemote;
24 import org.ejbca.core.model.log.Admin;
25 import org.ejbca.core.model.ra.raadmin.AdminPreference;
26
27 /**
28  * A class handling the storage of a admins preferences. Currently all admin preferences are
29  * saved to a database.
30  *
31  * @author Philip Vendil
32  * @version $Id: AdminPreferenceDataHandler.java,v 1.1 2006/01/17 20:32:19 anatom Exp $
33  */

34 public class AdminPreferenceDataHandler implements java.io.Serializable JavaDoc {
35
36     /** Creates a new instance of AdminPreferences */
37     public AdminPreferenceDataHandler(Admin administrator) throws RemoteException JavaDoc, NamingException JavaDoc, CreateException JavaDoc {
38         InitialContext JavaDoc jndicontext = new InitialContext JavaDoc();
39         IRaAdminSessionHome raadminsessionhome = (IRaAdminSessionHome) javax.rmi.PortableRemoteObject.narrow(jndicontext.lookup("RaAdminSession"),
40                                                IRaAdminSessionHome.class);
41         raadminsession = raadminsessionhome.create();
42         this.administrator = administrator;
43     }
44
45     /** Retrieves the admin from the database or null if the admin doesn't exists. */
46     public AdminPreference getAdminPreference(String JavaDoc certificatefingerprint) {
47      AdminPreference returnvalue=null;
48
49       try{
50          returnvalue = raadminsession.getAdminPreference(administrator, certificatefingerprint);
51       }catch(Exception JavaDoc e) {
52          returnvalue=null;
53       }
54       return returnvalue;
55     }
56
57     /** Adds a admin preference to the database */
58     public void addAdminPreference(String JavaDoc certificatefingerprint, AdminPreference adminpreference)
59                                   throws AdminExistsException, RemoteException JavaDoc {
60       if(!raadminsession.addAdminPreference(administrator, certificatefingerprint, adminpreference))
61         throw new AdminExistsException("Admin already exists in the database.");
62     }
63
64     /** Changes the admin preference for the given admin. */
65     public void changeAdminPreference(String JavaDoc certificatefingerprint, AdminPreference adminpreference)
66                               throws AdminDoesntExistException, RemoteException JavaDoc {
67       if(!raadminsession.changeAdminPreference(administrator, certificatefingerprint, adminpreference))
68         throw new AdminDoesntExistException("Admin doesn't exists in the database.");
69
70     }
71     
72     /** Changes the admin preference for the given admin, without performing any logging. */
73     public void changeAdminPreferenceNoLog(String JavaDoc certificatefingerprint, AdminPreference adminpreference)
74                               throws AdminDoesntExistException, RemoteException JavaDoc {
75       if(!raadminsession.changeAdminPreferenceNoLog(administrator, certificatefingerprint, adminpreference))
76         throw new AdminDoesntExistException("Admin doesn't exists in the database.");
77
78     }
79
80     /** Checks if admin preference exists in database. */
81     public boolean existsAdminPreference(String JavaDoc certificatefingerprint) throws RemoteException JavaDoc {
82       return raadminsession.existsAdminPreference(administrator, certificatefingerprint);
83
84     }
85     
86     /** Returns the default administrator preference. */
87     public AdminPreference getDefaultAdminPreference() throws RemoteException JavaDoc{
88       return raadminsession.getDefaultAdminPreference(administrator);
89     }
90     
91     /** Saves the default administrator preference. */
92     public void saveDefaultAdminPreference(AdminPreference adminpreference) throws RemoteException JavaDoc{
93       raadminsession.saveDefaultAdminPreference(administrator, adminpreference);
94     }
95     
96     
97     private IRaAdminSessionRemote raadminsession;
98     private Admin administrator;
99 }
100
Popular Tags