1 13 14 package org.ejbca.core.ejb.services; 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.services.ServiceConfiguration; 25 import org.ejbca.util.Base64GetHashMap; 26 import org.ejbca.util.Base64PutHashMap; 27 28 83 public abstract class ServiceDataBean extends BaseEntityBean { 84 85 private static final Logger log = Logger.getLogger(ServiceDataBean.class); 86 87 private ServiceConfiguration serviceConfiguration = null; 88 89 94 public abstract Integer getId(); 95 96 98 public abstract void setId(Integer id); 99 100 104 public abstract String getName(); 105 106 109 public abstract void setName(String name); 110 111 112 115 public abstract String getData(); 116 117 119 public abstract void setData(String data); 120 121 127 public ServiceConfiguration getServiceConfiguration() { 128 129 if (serviceConfiguration == null) { 130 java.beans.XMLDecoder decoder; 131 try { 132 decoder = new java.beans.XMLDecoder (new java.io.ByteArrayInputStream (getData().getBytes("UTF8"))); 133 } catch (UnsupportedEncodingException e) { 134 throw new EJBException (e); 135 } 136 HashMap h = (HashMap ) decoder.readObject(); 137 decoder.close(); 138 HashMap data = new Base64GetHashMap(h); 140 141 serviceConfiguration = new ServiceConfiguration(); 142 serviceConfiguration.loadData(data); 143 } 144 145 return serviceConfiguration; 146 } 147 148 153 public void setServiceConfiguration(ServiceConfiguration serviceConfiguration) { 154 HashMap a = new Base64PutHashMap(); 156 a.putAll((HashMap )serviceConfiguration.saveData()); 157 158 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 159 java.beans.XMLEncoder encoder = new java.beans.XMLEncoder (baos); 160 encoder.writeObject(a); 161 encoder.close(); 162 163 try { 164 if (log.isDebugEnabled()) { 165 log.debug("Service data: \n" + baos.toString("UTF8")); 166 } 167 setData(baos.toString("UTF8")); 168 } catch (UnsupportedEncodingException e) { 169 throw new EJBException (e); 170 } 171 172 this.serviceConfiguration = serviceConfiguration; 173 } 174 175 176 182 public void ejbPassivate() { 183 this.serviceConfiguration = null; 184 } 185 186 187 193 public Integer ejbCreate(Integer id, String name, ServiceConfiguration serviceConfiguration) throws CreateException { 194 setId(id); 195 setName(name); 196 197 if (serviceConfiguration != null) 198 setServiceConfiguration(serviceConfiguration); 199 200 log.debug("Created Service Configuration " + name); 201 return id; 202 } 203 204 public void ejbPostCreate(Integer id, String name, ServiceConfiguration serviceConfiguration) { 205 } 207 } 208 | Popular Tags |