KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ra > ExtendedInformation


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.ra;
15
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 import org.apache.log4j.Logger;
20 import org.ejbca.core.model.InternalResources;
21 import org.ejbca.core.model.UpgradeableDataHashMap;
22
23
24 /**
25  * The model representation of Exended Information about a user. It's used for non-searchable data about a user,
26  * like a image, in an effort to minimize the need for database alterations
27  *
28  * @author Philip Vendil
29  * @version $Id: ExtendedInformation.java,v 1.10.2.1 2007/02/11 18:50:03 herrvendil Exp $
30  */

31 public class ExtendedInformation extends UpgradeableDataHashMap implements java.io.Serializable JavaDoc, Cloneable JavaDoc {
32     private static final Logger log = Logger.getLogger(ExtendedInformation.class);
33     /** Internal localization of logs and errors */
34     private static final InternalResources intres = InternalResources.getInstance();
35
36     /**
37      * Determines if a de-serialized file is compatible with this class.
38      *
39      * Maintainers must change this value if and only if the new version
40      * of this class is not compatible with old versions. See Sun docs
41      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
42      * /serialization/spec/version.doc.html> details. </a>
43      *
44      */

45     private static final long serialVersionUID = 3981761824188420319L;
46     
47     public static final float LATEST_VERSION = 1;
48
49     public static final int TYPE_BASIC = 0;
50     public static final int TYPE_SCEPRA = 1;
51     
52     public static final String JavaDoc TYPE = "type";
53
54     // protected fields.
55
protected static final String JavaDoc SUBJECTDIRATTRIBUTES = "subjectdirattributes";
56
57     protected static final String JavaDoc XKMSREVOCATIONCODEIDENTIFIER = "revocationcodeidentifier";
58     protected static final String JavaDoc CUSTOMDATA = "customdata_";
59     
60     
61     // Public constants
62

63     // Wait for fields to use with this class.
64

65     // Public methods.
66
/** Creates a new instance of EndEntity Profile */
67     public ExtendedInformation() {
68         setType(TYPE_BASIC);
69         data.put(SUBJECTDIRATTRIBUTES, "");
70     }
71
72     public String JavaDoc getSubjectDirectoryAttributes(){
73         String JavaDoc ret = (String JavaDoc) data.get(SUBJECTDIRATTRIBUTES);
74         if (ret == null) {
75             ret = "";
76         }
77         return ret;
78     }
79     public void setSubjectDirectoryAttributes(String JavaDoc subjdirattr) {
80       if(subjdirattr==null)
81         data.put(SUBJECTDIRATTRIBUTES,"");
82       else
83         data.put(SUBJECTDIRATTRIBUTES,subjdirattr);
84     }
85     
86     /**
87      * Returns the revocation code identifier primarily used
88      * in the XKMS protocol to let the end user revoke his certificate.
89      *
90      *
91      * The method is autoupgradable
92      *
93      * @returns The code or null if no revocationcode have been set.
94      */

95     public String JavaDoc getRevocationCodeIdentifier(){
96         String JavaDoc retval = (String JavaDoc) data.get(XKMSREVOCATIONCODEIDENTIFIER);
97         
98
99         
100         return retval;
101     }
102     
103     
104     /**
105      *
106      *
107      * @param revocationCodeIdentifier the string saved
108      */

109     public void setRevocationCodeIdentifier(String JavaDoc revocationCodeIdentifier) {
110         String JavaDoc value = revocationCodeIdentifier;
111                 
112         data.put(XKMSREVOCATIONCODEIDENTIFIER,value);
113
114     }
115     
116     /**
117      * Special method used to retrieve customly set userdata
118      *
119      * @returns The data or null if no such data have been set for the user
120      */

121     public String JavaDoc getCustomData(String JavaDoc key){
122         String JavaDoc retval = (String JavaDoc) data.get(CUSTOMDATA + key);
123         
124
125         
126         return retval;
127     }
128     
129     
130     /**
131      *
132      * @param customly defined key to store the data with
133      * @param the string representation of the data
134      */

135     public void setCustomData(String JavaDoc key, String JavaDoc value) {
136         data.put(CUSTOMDATA + key,value);
137     }
138     
139     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
140       ExtendedInformation clone = new ExtendedInformation();
141       HashMap JavaDoc clonedata = (HashMap JavaDoc) clone.saveData();
142
143       Iterator JavaDoc i = (data.keySet()).iterator();
144       while(i.hasNext()){
145         Object JavaDoc key = i.next();
146         clonedata.put(key, data.get(key));
147       }
148
149       clone.loadData(clonedata);
150       return clone;
151     }
152
153     /** Implemtation of UpgradableDataHashMap function getLatestVersion */
154     public float getLatestVersion(){
155        return LATEST_VERSION;
156     }
157
158     /** Implemtation of UpgradableDataHashMap function upgrade. */
159
160     public void upgrade(){
161         if(Float.compare(LATEST_VERSION, getVersion()) != 0) {
162             // New version of the class, upgrade
163
String JavaDoc msg = intres.getLocalizedMessage("ra.extendedinfoupgrade", new Float JavaDoc(getVersion()));
164             log.info(msg);
165             
166             if(data.get(SUBJECTDIRATTRIBUTES) == null){
167                 data.put(SUBJECTDIRATTRIBUTES, "");
168             }
169
170             data.put(VERSION, new Float JavaDoc(LATEST_VERSION));
171         }
172     }
173     
174     /**
175      * Method that returns the classpath to the this or inheriting classes.
176      * @return String containing the classpath.
177      */

178     public int getType(){
179         return ((Integer JavaDoc) data.get(TYPE)).intValue();
180     }
181     
182     /**
183      * Method used to specify which kind of object that should be created during
184      * deserialization process.
185      *
186      * Inheriting class should call 'setClassPath(this) in it's constructor.
187      *
188      * @param object
189      */

190     protected void setType(int type){
191        data.put(TYPE,new Integer JavaDoc(type));
192     }
193
194 }
195
Popular Tags