KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbean > bean > EnterpriseEntityBean


1
2 //Title: telkel
3
//Version:
4
//Copyright: Copyright (c) 1999
5
//Author: Marc Fleury
6
//Company: telkel
7

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

29 package org.jboss.test.testbean.bean;
30
31 import java.rmi.*;
32 import javax.ejb.*;
33
34 import org.jboss.test.testbean.interfaces.EnterpriseEntityHome;
35 import org.jboss.test.testbean.interfaces.EnterpriseEntity;
36
37 public class EnterpriseEntityBean implements EntityBean {
38    org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
39   private EntityContext entityContext;
40   public String JavaDoc name;
41   public int otherField = 0;
42                                                             
43
44   public String JavaDoc ejbCreate(String JavaDoc name) throws RemoteException, CreateException {
45
46        log.debug("EntityBean.ejbCreate("+name+") called");
47        this.name = name;
48        return null;
49   }
50
51   public String JavaDoc ejbCreateMETHOD(String JavaDoc name) throws RemoteException, CreateException {
52
53        log.debug("EntityBean.ejbCreateMETHOD("+name+") called");
54        this.name = name;
55        return null;
56   }
57
58   public void ejbPostCreate(String JavaDoc name) throws RemoteException, CreateException {
59
60        log.debug("EntityBean.ejbPostCreate("+name+") called");
61        
62        EJBObject ejbObject = entityContext.getEJBObject();
63        
64        if (ejbObject == null) {
65            log.debug("******************************* NULL EJBOBJECT in ejbPostCreate");
66        }
67        else {
68             log.debug("&&&&&&&&&&&&&&&& EJBObject found in ejbPostCreate id is "+ejbObject.getPrimaryKey());
69        }
70
71   }
72
73   public void ejbPostCreateMETHOD(String JavaDoc name) throws RemoteException, CreateException {
74
75        log.debug("EntityBean.ejbPostCreateMETHOD("+name+") called");
76        
77        EJBObject ejbObject = entityContext.getEJBObject();
78        
79        if (ejbObject == null) {
80            log.debug("******************************* NULL EJBOBJECT in ejbPostCreateMETHOD");
81        }
82        else {
83             log.debug("&&&&&&&&&&&&&&&& EJBObject found in ejbPostCreateMETHOD id is "+ejbObject.getPrimaryKey());
84        }
85
86   }
87
88   public void ejbActivate() throws RemoteException {
89     log.debug("EntityBean.ejbActivate() called");
90   }
91
92   public void ejbLoad() throws RemoteException {
93    log.debug("EntityBean.ejbLoad() called");
94   }
95
96   public void ejbPassivate() throws RemoteException {
97
98      log.debug("EntityBean.ejbPassivate() called");
99   }
100
101   public void ejbRemove() throws RemoteException, RemoveException {
102    log.debug("EntityBean.ejbRemove() called "+hashCode());
103   }
104
105   public void ejbStore() throws RemoteException {
106       
107    log.debug("EntityBean.ejbStore() called "+hashCode());
108   }
109
110   public String JavaDoc callBusinessMethodA() {
111
112      log.debug("EntityBean.callBusinessMethodA() called");
113      return "EntityBean.callBusinessMethodA() called, my primaryKey is "+
114             entityContext.getPrimaryKey().toString();
115   }
116   
117   public String JavaDoc callBusinessMethodB() {
118
119      log.debug("EntityBean.callBusinessMethodB() called");
120      
121      EJBObject ejbObject = entityContext.getEJBObject();
122      
123      if (ejbObject == null)
124         return "NULL EJBOBJECT";
125      
126      else
127         return ejbObject.toString();
128   }
129   
130   
131    public String JavaDoc callBusinessMethodB(String JavaDoc words) {
132     
133       log.debug("EntityBean.callBusinessMethodB(String) called");
134      
135      EJBObject ejbObject = entityContext.getEJBObject();
136      
137      if (ejbObject == null)
138         return "NULL EJBOBJECT";
139      
140      else
141         return ejbObject.toString()+ " words "+words;
142   
143     }
144   public void setOtherField(int value) {
145       
146     log.debug("EntityBean.setOtherField("+value+")");
147     otherField = value;
148   }
149   
150   public int getOtherField() {
151      log.debug("EntityBean.getOtherField() called");
152      return otherField;
153  }
154   
155   public EnterpriseEntity createEntity(String JavaDoc newName) throws RemoteException {
156
157     log.debug("EntityBean.createEntity() called");
158     EnterpriseEntity newBean;
159     try{
160         EJBObject ejbObject = entityContext.getEJBObject();
161         if (ejbObject == null)
162         log.debug("************************** NULL EJBOBJECT");
163         else
164         log.debug("************************** OK EJBOBJECT");
165         
166         EnterpriseEntityHome home = (EnterpriseEntityHome)entityContext.getEJBObject().getEJBHome();
167         newBean = (EnterpriseEntity)home.create(newName);
168
169     
170     }catch(Exception JavaDoc e)
171     {
172         log.debug("failed", e);
173         throw new RemoteException("create entity did not work check messages");
174     }
175      
176      return newBean;
177   }
178   
179   public void setEntityContext(EntityContext context) throws RemoteException {
180      log.debug("EntityBean.setSessionContext() called");
181      entityContext = context;
182   }
183
184   public void unsetEntityContext() throws RemoteException {
185      log.debug("EntityBean.unsetSessionContext() called");
186     entityContext = null;
187   }
188 }
189
Popular Tags