KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > omb > FrontSFR


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: FrontSFR.java,v 1.12 2004/12/17 15:08:35 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.relation.omb;
27
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.EJBException JavaDoc;
30 import javax.ejb.FinderException JavaDoc;
31 import javax.ejb.SessionBean JavaDoc;
32 import javax.ejb.SessionContext JavaDoc;
33 import javax.naming.Context JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36 import javax.rmi.PortableRemoteObject JavaDoc;
37
38 import org.objectweb.jonas.common.Log;
39 import org.objectweb.util.monolog.api.BasicLevel;
40 import org.objectweb.util.monolog.api.Logger;
41
42
43 /**
44  * Frontal Session bean.
45  */

46 public class FrontSFR implements SessionBean JavaDoc {
47
48     static private Logger logger = null;
49     SessionContext JavaDoc ejbContext;
50     private AHomeLocal ahl = null;
51     private BHomeLocal bhl = null;
52
53     // ------------------------------------------------------------------
54
// SessionBean implementation
55
// ------------------------------------------------------------------
56

57
58     public void setSessionContext(SessionContext JavaDoc ctx) {
59         if (logger == null) {
60             logger = Log.getLogger("org.objectweb.jonas_tests");
61         }
62         logger.log(BasicLevel.DEBUG, "");
63         ejbContext = ctx;
64         try {
65             Context JavaDoc ictx = new InitialContext JavaDoc();
66             ahl = (AHomeLocal) ictx.lookup("java:comp/env/ejb/a");
67             bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b");
68         } catch (NamingException JavaDoc e) {
69             throw new EJBException JavaDoc("Impossible to fetch the ", e);
70         }
71     }
72         
73
74     public void ejbRemove() {
75         logger.log(BasicLevel.DEBUG, "");
76     }
77         
78
79     public void ejbCreate() throws CreateException JavaDoc {
80         logger.log(BasicLevel.DEBUG, "");
81     }
82
83     public void ejbCreate(String JavaDoc pka, String JavaDoc pkb) throws CreateException JavaDoc {
84         logger.log(BasicLevel.DEBUG, "");
85         try {
86             ALocal al = ahl.create(pka);
87             BLocal bl = bhl.create(pkb);
88             al.getB().add(bl);
89             bhl.findByName(pkb, al.getId());
90         } catch (Exception JavaDoc e) {
91             throw new CreateException JavaDoc("ejbCreate failed " + e);
92         }
93     }
94
95     public void ejbPassivate() {
96         logger.log(BasicLevel.DEBUG, "");
97     }
98
99     public void ejbActivate() {
100         logger.log(BasicLevel.DEBUG, "");
101     }
102     
103     // ------------------------------------------------------------------
104
// Front implementation
105
// ------------------------------------------------------------------
106

107     /**
108      * method1
109      */

110     public void method1() {
111         logger.log(BasicLevel.DEBUG, "");
112     }
113
114     /**
115      * method2
116      */

117     public void method2(java.lang.String JavaDoc s) {
118         logger.log(BasicLevel.DEBUG, "");
119     }
120     
121     /**
122      * Ensure the javax.ejb.EJBException is thrown when trying
123      * to invoke an accessor method on a deleted entitybean object
124      */

125     public void testRemove1() {
126         logger.log(BasicLevel.DEBUG, "");
127         ALocal ax9;
128         try {
129             ax9 = ahl.create("ax9");
130             ax9.remove();
131         } catch (Exception JavaDoc e) {
132             throw new EJBException JavaDoc("Initial state creation problem: " + e);
133         }
134         try {
135             ax9.getId();
136             throw new EJBException JavaDoc("entity was not deleted, expected EJBException");
137         } catch (EJBException JavaDoc e) {
138             // Pass
139
} catch (Exception JavaDoc e) {
140             throw new EJBException JavaDoc("Caught unexpected exception: " + e);
141         }
142     }
143  
144     /**
145      * Ensure the IllegalArgumentException is thrown when trying
146      * to set a collection cmr-field to a wrong relationship type
147      */

148     public void testSetCmrWithDeleted() {
149         logger.log(BasicLevel.DEBUG, "");
150         BLocal b0;
151         try {
152             b0 = bhl.findByPrimaryKey("b0");
153         } catch (Exception JavaDoc e) {
154             throw new EJBException JavaDoc("Initial state creation problem: " + e);
155         }
156         try {
157             b0.testSetCmrWithDeleted();
158         } catch (Exception JavaDoc e) {
159             throw new EJBException JavaDoc("Caugth unexpected exception: " + e);
160         }
161     }
162     
163     /**
164      * Ensure the IllegalArgumentException is thrown when trying
165      * to set a collection cmr-field to a wrong relationship type
166      */

167     public void testSetCmrWithWrongType() {
168         logger.log(BasicLevel.DEBUG, "");
169         ALocal a0;
170         try {
171             a0 = ahl.findByPrimaryKey("a0");
172         } catch (FinderException JavaDoc e) {
173             throw new EJBException JavaDoc("Initial state creation problem: " + e);
174         }
175         try {
176             a0.getB().add(a0);
177         } catch (IllegalArgumentException JavaDoc e) {
178             // Pass
179
return;
180         } catch (Exception JavaDoc e) {
181             throw new EJBException JavaDoc("Caugth unexpected exception: " + e);
182         }
183         throw new EJBException JavaDoc("Expected IllegalArgumentException");
184     }
185 }
186
187
Popular Tags