KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lateralnz > panther > wrapper > SessionContextWrapper


1 /* ====================================================================
2  * The LateralNZ Software License, Version 1.0
3  *
4  * Copyright (c) 2003 LateralNZ. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by
21  * LateralNZ (http://www.lateralnz.org/) and other third parties."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "LateralNZ" must not be used to endorse or promote
26  * products derived from this software without prior written
27  * permission. For written permission, please
28  * contact oss@lateralnz.org.
29  *
30  * 5. Products derived from this software may not be called "Panther",
31  * or "Lateral" or "LateralNZ", nor may "PANTHER" or "LATERAL" or
32  * "LATERALNZ" appear in their name, without prior written
33  * permission of LateralNZ.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of LateralNZ. For more
51  * information on Lateral, please see http://www.lateralnz.com/ or
52  * http://www.lateralnz.org
53  *
54  */

55 package org.lateralnz.panther.wrapper;
56
57 import java.security.Identity JavaDoc;
58 import java.security.Principal JavaDoc;
59 import java.util.Properties JavaDoc;
60 import javax.ejb.EJBHome JavaDoc;
61 import javax.ejb.EJBLocalHome JavaDoc;
62 import javax.ejb.EJBLocalObject JavaDoc;
63 import javax.ejb.EJBObject JavaDoc;
64 import javax.transaction.Status JavaDoc;
65 import javax.transaction.TransactionManager JavaDoc;
66 import javax.transaction.UserTransaction JavaDoc;
67
68 import org.apache.log4j.Logger;
69
70 import org.lateralnz.common.util.JNDIUtils;
71
72 /**
73  * simple wrapper for session context. At the moment this only supports the method
74  * "setRollbackOnly"
75  *
76  * @author J R Briggs
77  */

78 public class SessionContextWrapper implements javax.ejb.SessionContext JavaDoc {
79   private static final Logger log = Logger.getLogger(SessionContextWrapper.class.getName());
80   private SessionBeanHome sbw;
81   private TransactionManager JavaDoc tm;
82   private UserTransaction JavaDoc ut;
83   
84   public SessionContextWrapper(SessionBeanHome sbw) {
85     this.sbw = sbw;
86     try {
87       this.tm = (TransactionManager JavaDoc)JNDIUtils.get("java:/TransactionManager");
88     }
89     catch (Exception JavaDoc e) {
90       log.error(e);
91     }
92     
93     try {
94       this.ut = (UserTransaction JavaDoc)JNDIUtils.get("java:comp/UserTransaction");
95     }
96     catch (Exception JavaDoc e) {
97       log.error(e);
98     }
99   }
100   
101   public Identity JavaDoc getCallerIdentity() {
102     return null;
103   }
104   
105   public Principal JavaDoc getCallerPrincipal() {
106     return null;
107   }
108   
109   public EJBHome JavaDoc getEJBHome() {
110     return sbw;
111   }
112   
113   public EJBLocalHome JavaDoc getEJBLocalHome() {
114     throw new UnsupportedOperationException JavaDoc();
115   }
116   
117   public Properties JavaDoc getEnvironment() {
118     return null;
119   }
120   
121   public boolean getRollbackOnly() {
122     try {
123       if (tm == null) {
124         return false;
125       }
126       else {
127         return tm.getStatus() == Status.STATUS_MARKED_ROLLBACK;
128       }
129     }
130     catch (Exception JavaDoc e) {
131       log.error(e);
132       return false;
133     }
134   }
135   
136   public UserTransaction JavaDoc getUserTransaction() {
137     return ut;
138   }
139   
140   public boolean isCallerInRole(String JavaDoc str) {
141     return false;
142   }
143   
144   public boolean isCallerInRole(Identity JavaDoc identity) {
145     return false;
146   }
147   
148   public void setRollbackOnly() {
149     try {
150       if (tm != null) {
151         tm.setRollbackOnly();
152       }
153     }
154     catch (Exception JavaDoc e) {
155       e.printStackTrace();
156     }
157   }
158   
159   public EJBLocalObject JavaDoc getEJBLocalObject() {
160     return null;
161   }
162   
163   public EJBObject JavaDoc getEJBObject() {
164     return null;
165   }
166 }
Popular Tags