1 7 8 package org.jboss.test.media.entity.ejb; 9 10 import javax.ejb.CreateException ; 11 import javax.ejb.EJBException ; 12 import javax.ejb.SessionBean ; 13 import javax.ejb.SessionContext ; 14 import javax.emb.MediaEntityLocal; 15 import javax.emb.MediaEntityLocalHome; 16 import javax.naming.Context ; 17 import javax.naming.InitialContext ; 18 19 import org.apache.log4j.Category; 20 import org.jboss.media.entity.MediaEntityBean; 21 22 33 public class EntityMediaBeanTesterBean implements SessionBean 34 { 35 private Category log = Category.getInstance(getClass()); 36 37 private MediaEntityLocalHome entityHome; 38 39 public static final String MEDIA_ENTITY_JNDI = 40 MediaEntityBean.MEDIA_ENTITY_JNDI; 41 42 45 public String createEntityMediaBean() 46 { 47 try 48 { 49 return (String ) getMediaEntityLocalHome().create().getPrimaryKey(); 50 } 51 catch (Exception e) 52 { 53 e.printStackTrace(); 54 throw new EJBException (e.getMessage()); 55 } 56 } 57 58 61 public void removeEntityMediaBean(String id) throws Exception 62 { 63 try 64 { 65 getMediaEntityLocalHome().remove(id); 66 } 67 catch (Exception e) 68 { 69 e.printStackTrace(); 70 throw new EJBException (e.getMessage()); 71 } 72 } 73 74 77 public byte[] getContent(String id) throws Exception 78 { 79 MediaEntityLocal entity = getMediaEntityLocalHome().findByPrimaryKey(id); 80 81 return entity.getContent(); 82 } 83 84 87 public void setContent(String id, byte[] content) throws Exception 88 { 89 try 90 { 91 getMediaEntityLocalHome().findByPrimaryKey(id).setContent(content); 92 } 93 catch (Exception e) 94 { 95 e.printStackTrace(); 96 throw new EJBException (e.getMessage()); 97 } 98 } 99 100 public void ejbCreate() throws CreateException 101 { 102 } 103 104 public void ejbActivate() 105 { 106 } 107 108 public void ejbPassivate() 109 { 110 } 111 112 public void ejbRemove() 113 { 114 } 115 116 public void setSessionContext(SessionContext ctx) 117 { 118 } 119 120 private MediaEntityLocalHome getMediaEntityLocalHome() 121 { 122 if (entityHome == null) 123 { 124 try 125 { 126 Context initialContext = new InitialContext (); 127 return (MediaEntityLocalHome) initialContext.lookup( 128 MEDIA_ENTITY_JNDI); 129 } 130 catch (Exception e) 131 { 132 throw new EJBException ("Could not lookup " + MEDIA_ENTITY_JNDI); 133 } 134 } 135 136 return entityHome; 137 } 138 } | Popular Tags |