KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > web > ejb > EntityFacadeBean


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.web.ejb;
23
24 import java.security.Principal JavaDoc;
25 import java.rmi.RemoteException JavaDoc;
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.SessionBean JavaDoc;
28 import javax.ejb.SessionContext JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30
31 import org.jboss.logging.Logger;
32 import org.jboss.test.web.interfaces.InternalEntityHome;
33 import org.jboss.test.web.interfaces.InternalEntity;
34
35 /** A simple session bean for testing declarative security.
36
37  @author Scott.Stark@jboss.org
38  @version $Revision: 37755 $
39  */

40 public class EntityFacadeBean implements SessionBean JavaDoc
41 {
42    static Logger log = Logger.getLogger(EntityFacadeBean.class);
43
44    private SessionContext JavaDoc sessionContext;
45
46    public void ejbCreate() throws CreateException JavaDoc
47    {
48       log.debug("ejbCreate() called");
49    }
50
51    public void ejbActivate()
52    {
53       log.debug("ejbActivate() called");
54    }
55
56    public void ejbPassivate()
57    {
58       log.debug("ejbPassivate() called");
59    }
60
61    public void ejbRemove()
62    {
63       log.debug("ejbRemove() called");
64    }
65
66    public void setSessionContext(SessionContext JavaDoc context)
67    {
68       sessionContext = context;
69    }
70
71    public void write(int value, boolean create)
72       throws RemoteException JavaDoc
73    {
74       log.info("write, value=" + value+", create="+create);
75       Principal JavaDoc p = sessionContext.getCallerPrincipal();
76       log.debug("echo, callerPrincipal=" + p);
77       boolean isInternalUser = sessionContext.isCallerInRole("InternalUser");
78       log.debug("Caller isInternalUser: "+isInternalUser);
79       try
80       {
81          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
82          InternalEntityHome home = (InternalEntityHome) ctx.lookup("java:comp/env/ejb/InternalEntity");
83          InternalEntity bean;
84          if( create == true )
85          {
86             bean = home.create(value, value);
87          }
88          else
89          {
90             Integer JavaDoc pk = new Integer JavaDoc(value);
91             bean = home.findByPrimaryKey(pk);
92          }
93          bean.setValue(value);
94          if( create == false )
95          {
96             bean.remove();
97          }
98       }
99       catch(Exception JavaDoc e)
100       {
101          throw new RemoteException JavaDoc("Failed to access InternalEntity", e);
102       }
103    }
104 }
105
Popular Tags