1 13 14 package org.ejbca.core.model.ra.userdatasource; 15 16 import java.io.ByteArrayInputStream ; 17 import java.io.IOException ; 18 import java.util.Collection ; 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 import java.util.Properties ; 22 23 import javax.ejb.EJBException ; 24 25 import org.ejbca.core.model.log.Admin; 26 27 28 29 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 45 protected static final String CLASSPATH = "classpath"; 46 protected static final String PROPERTYDATA = "propertydata"; 47 48 49 50 public CustomUserDataSourceContainer(){ 51 super(); 52 data.put(TYPE, new Integer (TYPE_CUSTOMUSERDATASOURCECONTAINER)); 53 setClassPath(""); 54 setPropertyData(""); 55 } 56 57 61 public String getClassPath(){ 62 return (String ) data.get(CLASSPATH); 63 } 64 65 68 public void setClassPath(String classpath){ 69 data.put(CLASSPATH, classpath); 70 } 71 72 75 public String getPropertyData(){ 76 return (String ) data.get(PROPERTYDATA); 77 } 78 79 82 public void setPropertyData(String propertydata){ 83 data.put(PROPERTYDATA, propertydata); 84 } 85 86 public Properties getProperties() throws IOException { 87 Properties prop = new Properties (); 88 prop.load(new ByteArrayInputStream (getPropertyData().getBytes())); 89 return prop; 90 } 91 92 93 94 95 private ICustomUserDataSource getCustomUserDataSource() { 97 if(customuserdatasource == null){ 98 try{ 99 Class implClass = Class.forName( getClassPath() ); 100 Object obj = implClass.newInstance(); 101 this.customuserdatasource = (ICustomUserDataSource) obj; 102 this.customuserdatasource.init(getProperties()); 103 }catch(ClassNotFoundException e){ 104 throw new EJBException (e); 105 } 106 catch(IllegalAccessException iae){ 107 throw new EJBException (iae); 108 } 109 catch(IOException ioe){ 110 throw new EJBException (ioe); 111 } 112 catch(InstantiationException ie){ 113 throw new EJBException (ie); 114 } 115 } 116 117 return customuserdatasource; 118 } 119 120 123 public Object clone() throws CloneNotSupportedException { 124 CustomUserDataSourceContainer clone = new CustomUserDataSourceContainer(); 125 HashMap clonedata = (HashMap ) clone.saveData(); 126 127 Iterator i = (data.keySet()).iterator(); 128 while(i.hasNext()){ 129 Object 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 145 public Collection fetch(Admin admin, String searchstring) throws UserDataSourceException { 146 return getCustomUserDataSource().fetch(admin,searchstring); 147 } 148 149 152 public void testConnection(Admin admin) throws UserDataSourceConnectionException { 153 getCustomUserDataSource().testConnection(admin); 154 } 155 156 160 public Object saveData() { 161 this.customuserdatasource = null; 162 return super.saveData(); 163 } 164 165 166 167 } 168 | Popular Tags |