KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ra > userdatasource > BaseUserDataSource


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.userdatasource;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.HashSet JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import org.ejbca.core.model.UpgradeableDataHashMap;
24 import org.ejbca.core.model.log.Admin;
25
26
27
28 /**
29  * BaseUserDataSource is a basic class that should be inherited by all types
30  * of userdatasources in the system.
31  *
32  * Contains data like description, applicable CAs and modifyable fields.
33  *
34  *
35  * @version $Id: BaseUserDataSource.java,v 1.1 2006/07/20 17:47:26 herrvendil Exp $
36  */

37 public abstract class BaseUserDataSource extends UpgradeableDataHashMap implements Serializable JavaDoc, Cloneable JavaDoc {
38     // Default Values
39

40
41     public static final String JavaDoc TRUE = "true";
42     public static final String JavaDoc FALSE = "false";
43     
44     /** Constant indicating that any CA can be used with this user data source.*/
45     public static final int ANYCA = -1;
46
47     // Protected Constants.
48
public static final String JavaDoc TYPE = "type";
49     
50     protected static final String JavaDoc DESCRIPTION = "DESCRIPTION";
51     protected static final String JavaDoc APPLICABLECAS = "APPLICABLECAS";
52     protected static final String JavaDoc MODIFYABLEFIELDS = "MODIFYABLEFIELDS";
53         
54     // Public Methods
55

56     /**
57      * Creates a new instance of CertificateProfile
58      */

59     public BaseUserDataSource() {
60       setDescription("");
61       
62       ArrayList JavaDoc applicablecas = new ArrayList JavaDoc();
63       setApplicableCAs(applicablecas);
64       
65       HashSet JavaDoc modifyableFields = new HashSet JavaDoc();
66       for(int i=0; i< UserDataSourceVO.AVAILABLEMODIFYABLEFIELDS.length; i++){
67           modifyableFields.add(new Integer JavaDoc(UserDataSourceVO.AVAILABLEMODIFYABLEFIELDS[i]));
68       }
69       setModifiableFields(modifyableFields);
70   
71     }
72
73     // Public Methods mostly used by PrimeCard
74
/**
75      * Returns the description of publisher
76      */

77     public String JavaDoc getDescription() { return (String JavaDoc) data.get(DESCRIPTION);}
78
79     /**
80      * Sets the description.
81      */

82     public void setDescription(String JavaDoc description){ data.put(DESCRIPTION, description); }
83
84     /**
85      * Returns a Collections of caids (Integer), indicating which CAs the user data source should
86      * be applicable to.
87      *
88      * If it contains the constant ANYCA then the user data source is applicable to all CAs
89      */

90     public Collection JavaDoc getApplicableCAs(){
91       return (Collection JavaDoc) data.get(APPLICABLECAS);
92     }
93     
94     /**
95      * Saves the list of CAs the user data source is applicable to.
96      *
97      * @param applicablecas a Collection of caids (Integer)
98      */

99     
100     public void setApplicableCAs(Collection JavaDoc applicablecas){
101       data.put(APPLICABLECAS, applicablecas);
102     }
103     
104     /**
105      *
106      * @return true if user data source is applicable for all CAs
107      */

108     public boolean isApplicableToAnyCA(){
109         return ((Collection JavaDoc) data.get(APPLICABLECAS)).contains(new Integer JavaDoc(ANYCA));
110     }
111     
112     /**
113      * Returns a Set of UserDataSourceVO.ISMODIFYABLE_ and DNFIELDExtractor constants (Integer) constants (All definded in the UserDataSourceVO.AVAILABLEMODIFYABLEFIELDS,
114      * indicating if the field should be modifyable by the CA or not.
115      *
116      */

117     public Set JavaDoc getModifiableFields(){
118       return (Set JavaDoc) data.get(MODIFYABLEFIELDS);
119     }
120     
121     /**
122      * Saves the set of which fields of the CA that should be modifyable by the RA or not.
123      * The set should only contain UserDataSourceVO.ISMODIFYABLE_ and DNFIELDExtractor constants (Integer)
124      */

125     
126     public void setModifiableFields(Set JavaDoc modifiableFields){
127       data.put(MODIFYABLEFIELDS, modifiableFields);
128     }
129     
130     /**
131      * Method that returns the fetched UserDataSourceVOs with the isModifyableset set.
132      * This method should be used by external UserDataSource callers
133      */

134     public Collection JavaDoc fetchUserDataSourceVOs(Admin admin, String JavaDoc searchstring) throws UserDataSourceException{
135         Collection JavaDoc result = fetch(admin,searchstring);
136         
137         Set JavaDoc isModifyable = getModifiableFields();
138         Iterator JavaDoc iter = result.iterator();
139         while(iter.hasNext()){
140             UserDataSourceVO next = (UserDataSourceVO) iter.next();
141             next.setIsModifyableSet(isModifyable);
142         }
143         return result;
144     }
145     
146     // Abstact methods.
147

148     /**
149      * Searches for userdata given the searchstring
150      *
151      * @param searchstring the string the user data source should use to look for the data.
152      *
153      * @return a collection of UserDataSourceVO, returns an Empty Collection if no userdata could be found
154      *
155      * @throws UserDataSourceException if a communication or other error occurs.
156      */

157     protected abstract Collection JavaDoc fetch(Admin admin, String JavaDoc searchstring) throws UserDataSourceException;
158     
159
160     
161     /**
162      * Method used to test the connection to a user data source.
163      *
164      * @param admin the administrator perfoming the test
165      * @throws UserDataSourceConnectionException when a connection couldn't be set up correctly in any way.
166      */

167     public abstract void testConnection(Admin admin) throws UserDataSourceConnectionException;
168     
169
170     public abstract Object JavaDoc clone() throws CloneNotSupportedException JavaDoc;
171
172     
173     public abstract float getLatestVersion();
174
175     
176     public void upgrade(){
177         // Performing upgrade rutines
178
}
179     
180     
181
182 }
183
Popular Tags