KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > UpgradeableDataHashMap


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;
15
16 import java.util.HashMap JavaDoc;
17
18
19
20 /**
21  * UpgradeableDataHashMap is an class implementing the IUpgradeableData intended to be extended by
22  * classes saving it's data to a database in BLOB form.
23  *
24  * @version $Id: UpgradeableDataHashMap.java,v 1.4 2006/05/28 14:21:11 anatom Exp $
25  *
26  * @see org.ejbca.core.model.IUpgradeableData
27  */

28 public abstract class UpgradeableDataHashMap implements IUpgradeableData, java.io.Serializable JavaDoc {
29     /**
30      * Determines if a de-serialized file is compatible with this class.
31      *
32      * Maintainers must change this value if and only if the new version
33      * of this class is not compatible with old versions. See Sun docs
34      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
35      * /serialization/spec/version.doc.html> details. </a>
36      *
37      */

38     private static final long serialVersionUID = -1766329888474901945L;
39     
40     /**
41      * Creates a new UpgradeableDataHashMap object.
42      */

43     public UpgradeableDataHashMap() {
44         data = new HashMap JavaDoc();
45         data.put(VERSION, new Float JavaDoc(getLatestVersion()));
46     }
47
48     /**
49      * Should return a constant containing the latest available version of the class.
50      *
51      * @return DOCUMENT ME!
52      */

53     public abstract float getLatestVersion();
54
55     /**
56      * Function returning the current version of the class data.
57      *
58      * @return DOCUMENT ME!
59      */

60     public float getVersion() {
61         return ((Float JavaDoc) data.get(VERSION)).floatValue();
62     }
63
64     /**
65      * Function sending the data to be saved to the database.
66      *
67      * @return DOCUMENT ME!
68      */

69     public Object JavaDoc saveData() {
70         return data;
71     }
72
73     /**
74      * Function loading saved data into to data structure.
75      *
76      * @param data DOCUMENT ME!
77      */

78     public void loadData(Object JavaDoc data) {
79         this.data = (HashMap JavaDoc) data;
80         
81         if(Float.compare(getLatestVersion(), getVersion()) > 0) {
82             upgrade();
83         }
84     }
85
86     /**
87      * Function that should handle the update if of the data in the class so it's up to date with
88      * the latest version. An update is only done when needed.
89      */

90     public abstract void upgrade();
91
92     protected HashMap JavaDoc data;
93     public static final String JavaDoc VERSION = "version";
94 }
95
Popular Tags