KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > hardtoken > profiles > HardTokenProfileProxy


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.core.model.hardtoken.profiles;
15
16 import java.rmi.RemoteException JavaDoc;
17 import java.util.HashMap JavaDoc;
18
19 import org.ejbca.core.ejb.hardtoken.IHardTokenSessionRemote;
20 import org.ejbca.core.model.log.Admin;
21
22 /**
23  * A class used by PrimeCard clients to improve performance by caching hard token
24  * profiles locally, and only updating from database when the hard token profiles
25  * have been edited.
26  *
27  * This is needed since hard token profiles contains print image template data
28  * and by removing the need to retrieving the profile for each card processed
29  * the network load will decrease dramatically.
30  *
31  * @version $Id: HardTokenProfileProxy.java,v 1.1 2006/01/17 20:31:52 anatom Exp $
32  */

33 public class HardTokenProfileProxy {
34
35     /** Creates a new instance of HardTokenProfileProxy */
36     public HardTokenProfileProxy(Admin admin, IHardTokenSessionRemote hardtokensession){
37                     
38       this.hardtokensession = hardtokensession;
39       this.profilestore = new HashMap JavaDoc();
40       this.updatecount = new HashMap JavaDoc();
41       this.admin = admin;
42
43     }
44
45  
46     /**
47      * Method that first check the local store if the profile is upto date.
48      *
49      * @param profileid the id of the hard token profile.
50      * @return the hardtokenprofile or null if no profile exists with give id.
51      */

52     public HardTokenProfile getHardTokenProfile(int profileid) throws RemoteException JavaDoc {
53       HardTokenProfile returnval = null;
54       Integer JavaDoc id = new Integer JavaDoc(profileid);
55       int count = 0;
56
57       if(updatecount.get(id) == null ||
58         (count = hardtokensession.getHardTokenProfileUpdateCount(admin, profileid)) > ((Integer JavaDoc) updatecount.get(id)).intValue()){
59         returnval = hardtokensession.getHardTokenProfile(admin, profileid);
60         profilestore.put(id, returnval);
61         updatecount.put(id, new Integer JavaDoc(count));
62       }
63       return returnval;
64     }
65
66     // Private fields
67
private HashMap JavaDoc profilestore;
68     private HashMap JavaDoc updatecount;
69     private IHardTokenSessionRemote hardtokensession;
70     private Admin admin;
71
72 }
73
Popular Tags