1 13 14 package org.ejbca.core.ejb.ca.publisher; 15 16 import org.apache.log4j.Logger; 17 import org.ejbca.core.ejb.BaseEntityBean; 18 import org.ejbca.core.model.ca.publisher.ActiveDirectoryPublisher; 19 import org.ejbca.core.model.ca.publisher.BasePublisher; 20 import org.ejbca.core.model.ca.publisher.CustomPublisherContainer; 21 import org.ejbca.core.model.ca.publisher.LdapPublisher; 22 import org.ejbca.core.model.ca.publisher.LdapSearchPublisher; 23 import org.ejbca.util.Base64GetHashMap; 24 import org.ejbca.util.Base64PutHashMap; 25 26 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBException ; 29 import java.io.UnsupportedEncodingException ; 30 import java.util.HashMap ; 31 32 88 public abstract class PublisherDataBean extends BaseEntityBean { 89 90 private static final Logger log = Logger.getLogger(PublisherDataBean.class); 91 92 private BasePublisher publisher = null; 93 94 99 public abstract Integer getId(); 100 101 103 public abstract void setId(Integer id); 104 105 109 public abstract String getName(); 110 111 114 public abstract void setName(String name); 115 116 120 public abstract int getUpdateCounter(); 121 122 125 public abstract void setUpdateCounter(int updatecounter); 126 127 130 public abstract String getData(); 131 132 134 public abstract void setData(String data); 135 136 141 public BasePublisher getPublisher() { 142 143 if (publisher == null) { 144 java.beans.XMLDecoder decoder; 145 try { 146 decoder = new java.beans.XMLDecoder (new java.io.ByteArrayInputStream (getData().getBytes("UTF8"))); 147 } catch (UnsupportedEncodingException e) { 148 throw new EJBException (e); 149 } 150 HashMap h = (HashMap) decoder.readObject(); 151 decoder.close(); 152 HashMap data = new Base64GetHashMap(h); 154 155 switch (((Integer ) (data.get(BasePublisher.TYPE))).intValue()) { 156 case LdapPublisher.TYPE_LDAPPUBLISHER: 157 publisher = new LdapPublisher(); 158 break; 159 case LdapSearchPublisher.TYPE_LDAPSEARCHPUBLISHER: 160 publisher = new LdapSearchPublisher(); 161 break; 162 case ActiveDirectoryPublisher.TYPE_ADPUBLISHER: 163 publisher = new ActiveDirectoryPublisher(); 164 break; 165 case CustomPublisherContainer.TYPE_CUSTOMPUBLISHERCONTAINER: 166 publisher = new CustomPublisherContainer(); 167 break; 168 } 169 170 publisher.loadData(data); 171 } 172 173 return publisher; 174 } 175 176 181 public void setPublisher(BasePublisher publisher) { 182 HashMap a = new Base64PutHashMap(); 184 a.putAll((HashMap)publisher.saveData()); 185 186 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 187 java.beans.XMLEncoder encoder = new java.beans.XMLEncoder (baos); 188 encoder.writeObject(a); 189 encoder.close(); 190 191 try { 192 if (log.isDebugEnabled()) { 193 log.debug("Profiledata: \n" + baos.toString("UTF8")); 194 } 195 setData(baos.toString("UTF8")); 196 } catch (UnsupportedEncodingException e) { 197 throw new EJBException (e); 198 } 199 200 this.publisher = publisher; 201 setUpdateCounter(getUpdateCounter() + 1); 202 } 203 204 205 211 public void ejbPassivate() { 212 this.publisher = null; 213 } 214 215 216 222 public Integer ejbCreate(Integer id, String name, BasePublisher publisher) throws CreateException { 223 setId(id); 224 setName(name); 225 this.setUpdateCounter(0); 226 if (publisher != null) 227 setPublisher(publisher); 228 229 log.debug("Created Hard Token Profile " + name); 230 return id; 231 } 232 233 public void ejbPostCreate(Integer id, String name, BasePublisher publisher) { 234 } 236 } 237 | Popular Tags |