KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > entity > ejb > EJBLoadBean


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.entity.ejb;
23
24 import javax.ejb.CreateException JavaDoc;
25 import javax.ejb.EntityBean JavaDoc;
26 import javax.ejb.EntityContext JavaDoc;
27 import javax.ejb.RemoveException JavaDoc;
28
29 import org.jboss.logging.Logger;
30
31 /**
32  * A bean to test whether ejb load was called.
33  *
34  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
35  * @version $Revision: 37406 $
36  */

37 public class EJBLoadBean
38    implements EntityBean JavaDoc
39 {
40    private static final Logger log = Logger.getLogger(EJBLoadBean.class);
41
42    private EntityContext JavaDoc entityContext;
43
44    private String JavaDoc name;
45
46    private boolean ejbLoadCalled = false;
47
48    private boolean active = false;
49
50    public String JavaDoc getName()
51    {
52       log.info("getName");
53       assertActive();
54       return name;
55    }
56
57    public boolean wasEJBLoadCalled()
58    {
59       log.info("wasEJBLoadCalled");
60       assertActive();
61       boolean result = ejbLoadCalled;
62       ejbLoadCalled = false;
63       return result;
64    }
65
66    public void noTransaction()
67    {
68       log.info("noTransaction");
69       assertActive();
70       ejbLoadCalled = false;
71    }
72     
73    public String JavaDoc ejbCreate(String JavaDoc name)
74       throws CreateException JavaDoc
75    {
76       assertActive();
77       log.info("ejbCreate");
78       this.name = name;
79       return name;
80    }
81     
82    public void ejbPostCreate(String JavaDoc name)
83       throws CreateException JavaDoc
84    {
85       assertActive();
86       log.info("ejbPostCreate");
87    }
88
89    public String JavaDoc ejbFindByPrimaryKey(String JavaDoc name)
90    {
91       log.info("ejbFindByPrimaryKey");
92       return name;
93    }
94     
95    public void ejbActivate()
96    {
97       log.info("ejbActivate");
98       active = true;
99    }
100     
101    public void ejbLoad()
102    {
103       log.info("ejbLoad");
104       ejbLoadCalled = true;
105       assertActive();
106    }
107     
108    public void ejbPassivate()
109    {
110       log.info("ejbPassivate");
111       assertActive();
112       active = false;
113    }
114     
115    public void ejbRemove()
116       throws RemoveException JavaDoc
117    {
118       log.info("ejbRemove");
119       assertActive();
120       active = false;
121    }
122     
123    public void ejbStore()
124    {
125       log.info("ejbStore");
126       assertActive();
127    }
128     
129    public void setEntityContext(EntityContext JavaDoc context)
130    {
131       log.info("setEntityContext");
132       entityContext = context;
133    }
134     
135    public void unsetEntityContext()
136    {
137       log.info("unsetEntityContext");
138       entityContext = null;
139    }
140
141    private void assertActive()
142    {
143       if (active == false)
144          throw new RuntimeException JavaDoc("The bean is not active");
145    }
146 }
147
Popular Tags