KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > media > entity > ejb > EntityMediaBeanTesterBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.test.media.entity.ejb;
9
10 import javax.ejb.CreateException JavaDoc;
11 import javax.ejb.EJBException JavaDoc;
12 import javax.ejb.SessionBean JavaDoc;
13 import javax.ejb.SessionContext JavaDoc;
14 import javax.emb.MediaEntityLocal;
15 import javax.emb.MediaEntityLocalHome;
16 import javax.naming.Context JavaDoc;
17 import javax.naming.InitialContext JavaDoc;
18
19 import org.apache.log4j.Category;
20 import org.jboss.media.entity.MediaEntityBean;
21
22 /**
23  * Session Bean to test Media Entity Beans.
24  *
25  * @version <tt>$Revision: 1.1 $</tt>
26  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo Argüello</a>
27  *
28  * @ejb.bean type="Stateless" name="EntityMediaBeanTester" jndi-name="ejb/EntityMediaBeanTester"
29  * @ejb.ejb-ref ejb-name="MediaEntity" view-type="local"
30  * @ejb.transaction type="Required"
31  * @ejb.transaction-type type="Container"
32  */

33 public class EntityMediaBeanTesterBean implements SessionBean JavaDoc
34 {
35    private Category log = Category.getInstance(getClass());
36
37    private MediaEntityLocalHome entityHome;
38
39    public static final String JavaDoc MEDIA_ENTITY_JNDI =
40       MediaEntityBean.MEDIA_ENTITY_JNDI;
41
42    /**
43     * @ejb:interface-method view-type="remote"
44     */

45    public String JavaDoc createEntityMediaBean()
46    {
47       try
48       {
49          return (String JavaDoc) getMediaEntityLocalHome().create().getPrimaryKey();
50       }
51       catch (Exception JavaDoc e)
52       {
53          e.printStackTrace();
54          throw new EJBException JavaDoc(e.getMessage());
55       }
56    }
57
58    /**
59     * @ejb:interface-method view-type="remote"
60     */

61    public void removeEntityMediaBean(String JavaDoc id) throws Exception JavaDoc
62    {
63       try
64       {
65          getMediaEntityLocalHome().remove(id);
66       }
67       catch (Exception JavaDoc e)
68       {
69          e.printStackTrace();
70          throw new EJBException JavaDoc(e.getMessage());
71       }
72    }
73
74    /**
75     * @ejb:interface-method view-type="remote"
76     */

77    public byte[] getContent(String JavaDoc id) throws Exception JavaDoc
78    {
79       MediaEntityLocal entity = getMediaEntityLocalHome().findByPrimaryKey(id);
80
81       return entity.getContent();
82    }
83
84    /**
85     * @ejb:interface-method view-type="remote"
86     */

87    public void setContent(String JavaDoc id, byte[] content) throws Exception JavaDoc
88    {
89       try
90       {
91          getMediaEntityLocalHome().findByPrimaryKey(id).setContent(content);
92       }
93       catch (Exception JavaDoc e)
94       {
95          e.printStackTrace();
96          throw new EJBException JavaDoc(e.getMessage());
97       }
98    }
99
100    public void ejbCreate() throws CreateException JavaDoc
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 JavaDoc ctx)
117    {
118    }
119
120    private MediaEntityLocalHome getMediaEntityLocalHome()
121    {
122       if (entityHome == null)
123       {
124          try
125          {
126             Context JavaDoc initialContext = new InitialContext JavaDoc();
127             return (MediaEntityLocalHome) initialContext.lookup(
128                MEDIA_ENTITY_JNDI);
129          }
130          catch (Exception JavaDoc e)
131          {
132             throw new EJBException JavaDoc("Could not lookup " + MEDIA_ENTITY_JNDI);
133          }
134       }
135
136       return entityHome;
137    }
138 }
Popular Tags