KickJava   Java API By Example, From Geeks To Geeks.

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


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.ByteArrayInputStream JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import javax.ejb.EJBException JavaDoc;
24
25 import org.ejbca.core.model.log.Admin;
26
27
28
29 /**
30  * CustomUserDataSourceContainer is a class handling a custom user data source. It is used
31  * to store and retrieve custom user data source configuration to database.
32  *
33  *
34  * @version $Id: CustomUserDataSourceContainer.java,v 1.1 2006/07/20 17:47:26 herrvendil Exp $
35  */

36 public class CustomUserDataSourceContainer extends BaseUserDataSource{
37     private ICustomUserDataSource customuserdatasource = null;
38     
39     public static final float LATEST_VERSION = 1;
40     
41     public static final int TYPE_CUSTOMUSERDATASOURCECONTAINER = 1;
42     
43     // Default Values
44

45     protected static final String JavaDoc CLASSPATH = "classpath";
46     protected static final String JavaDoc PROPERTYDATA = "propertydata";
47         
48     
49     
50     public CustomUserDataSourceContainer(){
51         super();
52         data.put(TYPE, new Integer JavaDoc(TYPE_CUSTOMUSERDATASOURCECONTAINER));
53         setClassPath("");
54         setPropertyData("");
55     }
56     
57     // Public Methods
58
/**
59      * Returns the class path of custom publisher used.
60      */

61     public String JavaDoc getClassPath(){
62         return (String JavaDoc) data.get(CLASSPATH);
63     }
64
65     /**
66      * Sets the class path of custom publisher used.
67      */

68     public void setClassPath(String JavaDoc classpath){
69       data.put(CLASSPATH, classpath);
70     }
71
72     /**
73      * Returns the propertydata used to configure this custom publisher.
74      */

75     public String JavaDoc getPropertyData(){
76         return (String JavaDoc) data.get(PROPERTYDATA);
77     }
78
79     /**
80      * Sets the propertydata used to configure this custom publisher.
81      */

82     public void setPropertyData(String JavaDoc propertydata){
83         data.put(PROPERTYDATA, propertydata);
84     }
85     
86     public Properties JavaDoc getProperties() throws IOException JavaDoc{
87         Properties JavaDoc prop = new Properties JavaDoc();
88         prop.load(new ByteArrayInputStream JavaDoc(getPropertyData().getBytes()));
89         return prop;
90     }
91   
92     
93
94     
95     // Private methods
96
private ICustomUserDataSource getCustomUserDataSource() {
97         if(customuserdatasource == null){
98             try{
99                 Class JavaDoc implClass = Class.forName( getClassPath() );
100                 Object JavaDoc obj = implClass.newInstance();
101                 this.customuserdatasource = (ICustomUserDataSource) obj;
102                 this.customuserdatasource.init(getProperties());
103             }catch(ClassNotFoundException JavaDoc e){
104                 throw new EJBException JavaDoc(e);
105             }
106             catch(IllegalAccessException JavaDoc iae){
107                 throw new EJBException JavaDoc(iae);
108             }
109             catch(IOException JavaDoc ioe){
110                 throw new EJBException JavaDoc(ioe);
111             }
112             catch(InstantiationException JavaDoc ie){
113                 throw new EJBException JavaDoc(ie);
114             }
115         }
116         
117         return customuserdatasource;
118     }
119         
120     /**
121      * @see org.ejbca.core.model.ra.userdatasource.BaseUserDataSource#clone()
122      */

123     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
124         CustomUserDataSourceContainer clone = new CustomUserDataSourceContainer();
125         HashMap JavaDoc clonedata = (HashMap JavaDoc) clone.saveData();
126
127         Iterator JavaDoc i = (data.keySet()).iterator();
128         while(i.hasNext()){
129             Object JavaDoc key = i.next();
130             clonedata.put(key, data.get(key));
131         }
132
133         clone.loadData(clonedata);
134         return clone;
135         }
136
137
138     public float getLatestVersion() {
139         return LATEST_VERSION;
140     }
141
142     /**
143      * @see org.ejbca.core.model.ra.userdatasource.BaseUserDataSource
144      */

145     public Collection JavaDoc fetch(Admin admin, String JavaDoc searchstring) throws UserDataSourceException {
146         return getCustomUserDataSource().fetch(admin,searchstring);
147     }
148     
149     /**
150      * @see org.ejbca.core.model.ra.userdatasource.BaseUserDataSource
151      */

152     public void testConnection(Admin admin) throws UserDataSourceConnectionException {
153         getCustomUserDataSource().testConnection(admin);
154     }
155     
156     /**
157      * Resets the current custom user data source
158      * @see org.ejbca.core.model.UpgradeableDataHashMap#saveData()
159      */

160     public Object JavaDoc saveData() {
161         this.customuserdatasource = null;
162         return super.saveData();
163     }
164
165
166
167 }
168
Popular Tags