1 7 8 package org.jboss.media.entity; 9 10 import java.util.Collection ; 11 import java.util.Vector ; 12 13 import javax.ejb.CreateException ; 14 import javax.ejb.EntityBean ; 15 import javax.ejb.EntityContext ; 16 import javax.ejb.RemoveException ; 17 import javax.emb.MediaEntityLocal; 18 import javax.naming.InitialContext ; 19 import javax.naming.NamingException ; 20 21 import org.jboss.ejb.plugins.keygenerator.KeyGenerator; 22 import org.jboss.ejb.plugins.keygenerator.KeyGeneratorFactory; 23 import org.jboss.logging.Logger; 24 25 58 public abstract class MediaEntityBean extends MediaEntity implements EntityBean 59 { 60 public static final String MEDIA_ENTITY_JNDI = "ejb/media/MediaEntity"; 61 62 private EntityContext entityContext; 63 64 65 private Logger log = Logger.getLogger(MediaEntityBean.class); 66 67 68 private static final String KEY_GENERATOR_JNDI = "UUIDKeyGeneratorFactory"; 69 70 72 76 public abstract String getManagedIdentity(); 77 public abstract void setManagedIdentity(String identity); 78 79 82 public abstract byte[] getManagedContent(); 83 public abstract void setManagedContent(byte[] content); 84 85 88 public abstract String getManagedLocation(); 89 public abstract void setManagedLocation(String location); 90 91 94 public abstract String getManagedDescription(); 95 public abstract void setManagedDescription(String description); 96 97 100 public abstract String getManagedName(); 101 public abstract void setManagedName(String name); 102 103 106 public abstract String getManagedMimeType(); 107 public abstract void setManagedMimeType(String mimeType); 108 109 112 public abstract long getManagedLastModified(); 113 public abstract void setManagedLastModified(long lastModified); 114 115 118 public abstract Vector getManagedListeners(); 119 public abstract void setManagedListeners(Vector listeners); 120 121 123 133 public abstract MediaEntityLocal getManagedProxy(); 134 public abstract void setManagedProxy(MediaEntityLocal proxy); 135 136 143 public abstract MediaEntityLocal getManagedPreviousVersion(); 144 public abstract void setManagedPreviousVersion(MediaEntityLocal previousVersion); 145 146 153 public abstract MediaEntityLocal getManagedNextVersion(); 154 public abstract void setManagedNextVersion(MediaEntityLocal nextVersion); 155 156 163 public abstract Collection getManagedParents(); 164 public abstract void setManagedParents(Collection parents); 165 166 173 public abstract Collection getManagedChildren(); 174 public abstract void setManagedChildren(Collection children); 175 176 183 public abstract Collection getManagedMetaDatas(); 184 public abstract void setManagedMetaDatas(Collection metadatas); 185 186 188 191 public String ejbCreate() throws CreateException 192 { 193 String identity = generateIdentity(); 194 195 setManagedIdentity(identity); 196 updateLastModified(); 197 198 return null; 199 } 200 201 204 public void ejbPostCreate() throws CreateException 205 { 206 } 207 208 210 public void ejbActivate() 211 { 212 } 213 214 public void ejbPassivate() 215 { 216 } 217 218 public void ejbRemove() throws RemoveException 219 { 220 } 221 222 public void ejbLoad() 223 { 224 } 225 226 public void ejbStore() 227 { 228 } 229 230 public void setEntityContext(EntityContext entityContext) 231 { 232 this.entityContext = entityContext; 233 } 234 235 public void unsetEntityContext() 236 { 237 entityContext = null; 238 } 239 240 242 250 private String generateIdentity() throws CreateException 251 { 252 KeyGenerator keyGenerator = null; 253 254 try 255 { 256 KeyGeneratorFactory keyGeneratorFactory = 257 (KeyGeneratorFactory) new InitialContext ().lookup( 258 KEY_GENERATOR_JNDI); 259 260 keyGenerator = keyGeneratorFactory.getKeyGenerator(); 261 262 String key = (String ) keyGenerator.generateKey(); 263 264 if (log.isDebugEnabled()) 265 { 266 log.debug("Generated identity: " + key); 267 } 268 269 return key; 270 } 271 catch (NamingException e) 272 { 273 throw new CreateException ( 274 "Error: can't find key generator factory: " 275 + KEY_GENERATOR_JNDI 276 + "; " 277 + e.getMessage()); 278 } 279 catch (Exception e) 280 { 281 throw new CreateException ( 282 "Error: can't create key generator instance; key generator factory: " 283 + KEY_GENERATOR_JNDI 284 + "; " 285 + e.getMessage()); 286 } 287 } 288 } | Popular Tags |