1 25 26 package org.objectweb.jonas.jtests.beans.ffolder; 27 28 import java.rmi.RemoteException ; 29 import java.sql.Connection ; 30 import java.sql.SQLException ; 31 import javax.ejb.CreateException ; 32 import javax.ejb.EJBException ; 33 import javax.ejb.FinderException ; 34 import javax.ejb.SessionBean ; 35 import javax.ejb.SessionSynchronization ; 36 import javax.ejb.SessionContext ; 37 import javax.naming.Context ; 38 import javax.naming.InitialContext ; 39 import javax.naming.NamingException ; 40 import javax.rmi.PortableRemoteObject ; 41 import javax.sql.DataSource ; 42 43 48 public class FolderSY implements SessionBean , SessionSynchronization { 49 50 SessionContext ejbContext; 52 InitialContext ictx; 53 Context myEnv; 54 FileHome filehome; 55 56 59 void checkEnv(String method) { 60 61 try { 64 String value = (String ) myEnv.lookup("myname"); 65 if (!value.equals("mysession")) { 66 throw new EJBException ("FolderSY 1: " + method); 68 } 69 } catch (NamingException e) { 70 throw new EJBException ("FolderSY 2: " + method); 72 } 73 try { 76 String value = (String ) myEnv.lookup("dir1/dir2/name"); 77 if (!value.equals("sessionvalue")) { 78 throw new EJBException ("FolderSY 3: " + method); 80 } 81 } catch (NamingException e) { 82 throw new EJBException ("FolderSY 4: " + method); 84 } 85 try { 88 String value = (String ) ictx.lookup("java:comp/env/myname"); 89 if (!value.equals("mysession")) { 90 throw new EJBException ("FolderSY 6: " + method); 92 } 93 } catch (NamingException e) { 94 throw new EJBException ("FolderSY 7: " + method); 96 } 97 98 DataSource ds1 = null; 101 try { 102 ds1 = (DataSource ) PortableRemoteObject.narrow(ictx.lookup("jdbc_1"), DataSource .class); 103 } catch (NamingException e) { 104 throw new EJBException ("FolderSY 8: " + method); 106 } 107 Connection con = null; 108 if (!method.equals("afterCompletion")) { 109 try { 110 con = (Connection ) ds1.getConnection(); 111 if (con.isClosed()) { 112 throw new EJBException ("FolderSY 8a: " + method); 114 } 115 con.close(); 116 } catch (SQLException e) { 117 throw new EJBException ("FolderSY 8b: " + method); 119 } 120 } 121 122 DataSource ds2 = null; 125 try { 126 ds2 = (DataSource ) myEnv.lookup("jdbc/mydb"); 128 } catch (NamingException e) { 129 throw new EJBException ("FolderSY 9: " + method); 131 } 132 if (!method.equals("afterCompletion")) { 133 try { 134 con = (Connection ) ds2.getConnection(); 135 if (con.isClosed()) { 136 throw new EJBException ("FolderSY 9a: " + method); 138 } 139 con.close(); 140 } catch (SQLException e) { 141 throw new EJBException ("FolderSY 9b: " + method); 143 } 144 } 145 146 try { 149 Boolean value = (Boolean ) ictx.lookup("java:comp/env/bVrai"); 150 if (!value.booleanValue()) { 151 throw new EJBException ("FolderSY 10a: " + method); 153 } 154 } catch (NamingException e) { 155 throw new EJBException ("FolderSY10a: " + method); 157 } catch (ClassCastException e) { 158 throw new EJBException ("FolderSY10a1: " + method); 160 } 161 try { 162 Boolean value = (Boolean ) ictx.lookup("java:comp/env/bFaux"); 163 if (value.booleanValue()) { 164 throw new EJBException ("FolderSY 10b: " + method); 166 } 167 } catch (NamingException e) { 168 throw new EJBException ("FolderSY10b: " + method); 170 } catch (ClassCastException e) { 171 throw new EJBException ("FolderSY10b1: " + method); 173 } 174 175 } 177 178 182 public void setSessionContext(SessionContext ctx) { 183 ejbContext = ctx; 188 try { 189 ictx = new InitialContext (); 191 myEnv = (Context ) ictx.lookup("java:comp/env"); 192 filehome = (FileHome) ictx.lookup("java:comp/env/ejb/file"); 194 } catch (NamingException e) { 195 throw new EJBException ("FolderSY: Cannot get filehome:" + e); 196 } 197 checkEnv("setSessionContext"); 198 } 199 200 public void ejbRemove() { 201 checkEnv("ejbRemove"); 203 } 204 public void ejbCreate() throws CreateException { 205 checkEnv("ejbCreate"); 207 } 208 public void ejbPassivate() { 209 checkEnv("ejbPassivate"); 211 } 212 public void ejbActivate() { 213 checkEnv("ejbActivate"); 215 } 216 217 221 public void afterBegin() { 222 checkEnv("afterBegin"); 224 } 225 public void beforeCompletion() { 226 checkEnv("beforeCompletion"); 228 } 229 public void afterCompletion(boolean committed) { 230 checkEnv("afterCompletion"); 232 } 233 234 238 public File newFile(String fname) throws RemoteException , CreateException { 239 checkEnv("newFile"); 241 File ret = filehome.create(fname); 242 return ret; 243 } 244 245 public File getFile(String fname) throws RemoteException , FinderException { 246 checkEnv("getFile"); 248 File ret = filehome.findByPrimaryKey(fname); 249 return ret; 250 } 251 252 public void sendRef(Folder f) throws RemoteException { 253 } 254 255 public void sendInt(int i) throws RemoteException { 256 } 257 258 public void sendRefTS(Folder f) throws RemoteException { 259 } 260 261 public void sendIntTS(int i) throws RemoteException { 262 } 263 264 public Folder getRef(Folder f) throws RemoteException { 265 return f; 266 } 267 268 public int getInt(int i) throws RemoteException { 269 return i; 270 } 271 272 public Folder getRefTS(Folder f) throws RemoteException { 273 return f; 274 } 275 276 public int getIntTS(int i) throws RemoteException { 277 return i; 278 } 279 } 280 | Popular Tags |