1 13 14 package org.ejbca.core.ejb.ra.userdatasource; 15 16 import java.io.UnsupportedEncodingException ; 17 import java.util.HashMap ; 18 19 import javax.ejb.CreateException ; 20 import javax.ejb.EJBException ; 21 22 import org.apache.log4j.Logger; 23 import org.ejbca.core.ejb.BaseEntityBean; 24 import org.ejbca.core.model.ra.userdatasource.BaseUserDataSource; 25 import org.ejbca.core.model.ra.userdatasource.CustomUserDataSourceContainer; 26 import org.ejbca.util.Base64GetHashMap; 27 import org.ejbca.util.Base64PutHashMap; 28 29 85 public abstract class UserDataSourceDataBean extends BaseEntityBean { 86 87 private static final Logger log = Logger.getLogger(UserDataSourceDataBean.class); 88 89 private BaseUserDataSource userdatasource = null; 90 91 96 public abstract Integer getId(); 97 98 100 public abstract void setId(Integer id); 101 102 106 public abstract String getName(); 107 108 111 public abstract void setName(String name); 112 113 117 public abstract int getUpdateCounter(); 118 119 122 public abstract void setUpdateCounter(int updatecounter); 123 124 127 public abstract String getData(); 128 129 131 public abstract void setData(String data); 132 133 138 public BaseUserDataSource getUserDataSource() { 139 140 if (userdatasource == null) { 141 java.beans.XMLDecoder decoder; 142 try { 143 decoder = new java.beans.XMLDecoder (new java.io.ByteArrayInputStream (getData().getBytes("UTF8"))); 144 } catch (UnsupportedEncodingException e) { 145 throw new EJBException (e); 146 } 147 HashMap h = (HashMap ) decoder.readObject(); 148 decoder.close(); 149 HashMap data = new Base64GetHashMap(h); 151 152 switch (((Integer ) (data.get(BaseUserDataSource.TYPE))).intValue()) { 153 case CustomUserDataSourceContainer.TYPE_CUSTOMUSERDATASOURCECONTAINER: 154 userdatasource = new CustomUserDataSourceContainer(); 155 break; 156 } 157 158 userdatasource.loadData(data); 159 } 160 161 return userdatasource; 162 } 163 164 169 public void setUserDataSource(BaseUserDataSource userdatasource) { 170 HashMap a = new Base64PutHashMap(); 172 a.putAll((HashMap )userdatasource.saveData()); 173 174 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 175 java.beans.XMLEncoder encoder = new java.beans.XMLEncoder (baos); 176 encoder.writeObject(a); 177 encoder.close(); 178 179 try { 180 if (log.isDebugEnabled()) { 181 log.debug("Profiledata: \n" + baos.toString("UTF8")); 182 } 183 setData(baos.toString("UTF8")); 184 } catch (UnsupportedEncodingException e) { 185 throw new EJBException (e); 186 } 187 188 this.userdatasource = userdatasource; 189 setUpdateCounter(getUpdateCounter() + 1); 190 } 191 192 193 199 public void ejbPassivate() { 200 this.userdatasource = null; 201 } 202 203 204 210 public Integer ejbCreate(Integer id, String name, BaseUserDataSource userdatasource) throws CreateException { 211 setId(id); 212 setName(name); 213 this.setUpdateCounter(0); 214 if (userdatasource != null) 215 setUserDataSource(userdatasource); 216 217 log.debug("Created User Data Source " + name); 218 return id; 219 } 220 221 public void ejbPostCreate(Integer id, String name, BaseUserDataSource userdatasource) { 222 } 224 } 225 | Popular Tags |