KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbean2 > bean > AllTypesBean


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.testbean2.bean;
23
24 import java.rmi.*;
25 import javax.ejb.*;
26 import java.util.Collection JavaDoc;
27 import java.util.ArrayList JavaDoc;
28
29 import org.jboss.test.testbean.interfaces.StatefulSession;
30 import org.jboss.test.testbean.interfaces.StatefulSessionHome;
31 import org.jboss.test.testbean.interfaces.StatelessSession;
32 import org.jboss.test.testbean.interfaces.StatelessSessionHome;
33 import org.jboss.test.testbean.interfaces.EnterpriseEntity;
34 import org.jboss.test.testbean.interfaces.EnterpriseEntityHome;
35 import javax.naming.Context JavaDoc;
36 import javax.naming.InitialContext JavaDoc;
37 import java.sql.Date JavaDoc;
38 import java.sql.Timestamp JavaDoc;
39 import org.jboss.test.testbean2.interfaces.MyObject;
40
41
42 public class AllTypesBean implements EntityBean {
43
44        static org.jboss.logging.Logger log =
45        org.jboss.logging.Logger.getLogger(AllTypesBean.class);
46
47    public boolean aBoolean;
48    public byte aByte;
49    public short aShort;
50    public int anInt;
51    public long aLong;
52    public float aFloat;
53    public double aDouble;
54    // public char aChar;
55
public String JavaDoc aString;
56    public Date JavaDoc aDate;
57    public Timestamp JavaDoc aTimestamp;
58    
59    public MyObject anObject;
60    
61    public StatefulSession statefulSession;
62    public StatelessSession statelessSession;
63    public EnterpriseEntity enterpriseEntity;
64    
65    public Collection JavaDoc aList;
66    
67    private EntityContext entityContext;
68    
69    
70    public String JavaDoc ejbCreate(String JavaDoc pk) throws RemoteException, CreateException {
71       return ejbCreate(true, (byte)1, (short)2, (int)3, (long)4, (float)5.6,
72          (double)7.8, /*'9',*/ pk, new Date JavaDoc(System.currentTimeMillis()),
73          new Timestamp JavaDoc(System.currentTimeMillis()), new MyObject());
74    }
75    
76    public void ejbPostCreate(String JavaDoc pk)
77    throws RemoteException, CreateException {}
78    
79    
80    public String JavaDoc ejbCreate(boolean aBoolean, byte aByte, short aShort, int anInt,
81       long aLong, float aFloat, double aDouble, /*char aChar,*/ String JavaDoc aString,
82       Date JavaDoc aDate, Timestamp JavaDoc aTimestamp, MyObject anObject )
83    
84    throws RemoteException, CreateException {
85       
86       this.aBoolean = aBoolean;
87       this.aByte = aByte;
88       this.aShort = aShort;
89       this.anInt = anInt;
90       this.aLong = aLong;
91       this.aFloat = aFloat;
92       this.aDouble = aDouble;
93       //this.aChar = aChar;
94
this.aString = aString;
95       this.aDate = aDate;
96       this.aTimestamp = aTimestamp;
97       this.anObject = anObject;
98       
99       try {
100          Context JavaDoc ctx = new InitialContext JavaDoc();
101          
102          StatefulSessionHome sfHome = (StatefulSessionHome)ctx.lookup("java:comp/env/ejb/stateful");
103          statefulSession = sfHome.create();
104          
105          StatelessSessionHome slHome = (StatelessSessionHome)ctx.lookup("java:comp/env/ejb/stateless");
106          statelessSession = slHome.create();
107          
108          EnterpriseEntityHome eeHome = (EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity");
109          try {
110             enterpriseEntity = eeHome.findByPrimaryKey(aString);
111          } catch (FinderException e) {
112             enterpriseEntity = eeHome.create(aString);
113          }
114       
115       } catch (Exception JavaDoc e) {
116          log.debug("failed", e);
117          throw new CreateException(e.getMessage());
118       }
119       
120       aList = new ArrayList JavaDoc();
121       
122       return null;
123    }
124    
125    
126    public void ejbPostCreate(boolean aBoolean, byte aByte, short aShort, int anInt,
127       long aLong, float aFloat, double aDouble, /*char aChar,*/ String JavaDoc aString,
128       Date JavaDoc aDate, Timestamp JavaDoc aTimestamp, MyObject anObject )
129    
130    throws RemoteException, CreateException {}
131    
132    public void ejbActivate() throws RemoteException {}
133    
134    public void ejbLoad() throws RemoteException {}
135    
136    public void ejbPassivate() throws RemoteException {}
137    
138    public void ejbRemove() throws RemoteException, RemoveException {}
139    
140    public void ejbStore() throws RemoteException {}
141    
142    
143    public void setEntityContext(EntityContext context) throws RemoteException {
144       entityContext = context;
145    }
146    
147    public void unsetEntityContext() throws RemoteException {
148       entityContext = null;
149    }
150    
151    
152    public String JavaDoc callBusinessMethodA() throws RemoteException {
153       // test external ejb-ref in testbeans.jar
154
return statefulSession.callBusinessMethodA();
155    }
156    
157    
158    
159    public void updateAllValues(boolean aBoolean, byte aByte, short aShort, int anInt,
160       long aLong, float aFloat, double aDouble, /*char aChar,*/ String JavaDoc aString,
161       Date JavaDoc aDate, Timestamp JavaDoc aTimestamp, MyObject anObject ) {
162       
163       this.aBoolean = aBoolean;
164       this.aByte = aByte;
165       this.aShort = aShort;
166       this.anInt = anInt;
167       this.aLong = aLong;
168       this.aFloat = aFloat;
169       this.aDouble = aDouble;
170       //this.aChar = aChar;
171
this.aString = aString;
172       this.aDate = aDate;
173       this.aTimestamp = aTimestamp;
174       this.anObject = anObject;
175       
176       try {
177          Context JavaDoc ctx = new InitialContext JavaDoc();
178          
179          EnterpriseEntityHome eeHome = (EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity");
180          try {
181             enterpriseEntity = eeHome.findByPrimaryKey(aString);
182          } catch (FinderException e) {
183             enterpriseEntity = eeHome.create(aString);
184          }
185       
186       } catch (Exception JavaDoc e) {
187          // ignore
188
}
189    
190    }
191    
192    /**
193     * @todo Remove creation of new list when value object correctly
194     * implement pass by value
195     */

196    public void addObjectToList(Object JavaDoc anObject) throws RemoteException {
197       aList = new ArrayList JavaDoc(aList);
198       aList.add(anObject);
199    }
200    
201    /**
202     * @todo Remove creation of new list when value object correctly
203     * implement pass by value
204     */

205    public void removeObjectFromList(Object JavaDoc anObject) throws RemoteException {
206       aList = new ArrayList JavaDoc(aList);
207       aList.remove(anObject);
208    }
209    
210    public Collection JavaDoc getObjectList() throws RemoteException { return aList; }
211    
212    public boolean getBoolean() throws RemoteException { return aBoolean; }
213    public byte getByte() throws RemoteException { return aByte; }
214    public short getShort() throws RemoteException { return aShort; }
215    public int getInt() throws RemoteException { return anInt; }
216    public long getLong() throws RemoteException { return aLong; }
217    public float getFloat() throws RemoteException { return aFloat; }
218    public double getDouble() throws RemoteException { return aDouble; }
219    //public char getChar() throws RemoteException { return aChar; }
220
public String JavaDoc getString() throws RemoteException { return aString; }
221    public Date JavaDoc getDate() throws RemoteException { return aDate; }
222    public Timestamp JavaDoc getTimestamp() throws RemoteException { return aTimestamp; }
223    
224    public MyObject getObject() throws RemoteException { return anObject; }
225    
226    public Handle getStateful() throws RemoteException {
227       return statefulSession.getHandle();
228    }
229    
230    public Handle getStateless() throws RemoteException {
231       return statelessSession.getHandle();
232    }
233    
234    public Handle getEntity() throws RemoteException {
235       return enterpriseEntity.getHandle();
236    }
237
238
239 }
240
Popular Tags