01: // ========================================================================
02: // $Id: Transaction.java 1106 2006-10-17 17:00:06Z janb $
03: // Copyright 2006 Mort Bay Consulting Pty. Ltd.
04: // ------------------------------------------------------------------------
05: // Licensed under the Apache License, Version 2.0 (the "License");
06: // you may not use this file except in compliance with the License.
07: // You may obtain a copy of the License at
08: // http://www.apache.org/licenses/LICENSE-2.0
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14: // ========================================================================
15:
16: package org.mortbay.jetty.plus.naming;
17:
18: import javax.naming.Context;
19: import javax.naming.InitialContext;
20: import javax.naming.LinkRef;
21: import javax.naming.NameNotFoundException;
22: import javax.naming.NamingException;
23: import javax.transaction.UserTransaction;
24:
25: import org.mortbay.log.Log;
26: import org.mortbay.naming.NamingUtil;
27:
28: /**
29: * Transaction
30: *
31: * Class to represent a JTA UserTransaction impl.
32: *
33: *
34: */
35: public class Transaction extends NamingEntry {
36: public static final String USER_TRANSACTION = "UserTransaction";
37:
38: public static Transaction getTransaction(int scopeType)
39: throws NamingException {
40: return (Transaction) lookupNamingEntry(scopeType,
41: Transaction.class, USER_TRANSACTION);
42: }
43:
44: public Transaction(UserTransaction userTransaction)
45: throws NamingException {
46: super (USER_TRANSACTION, userTransaction);
47: }
48:
49: public void bindToEnv() throws NamingException {
50: InitialContext ic = new InitialContext();
51: Context env = (Context) ic.lookup("java:comp");
52: Log.debug("Binding java:comp/" + getJndiName() + " to "
53: + absoluteObjectNameString);
54: NamingUtil.bind(env, getJndiName(), new LinkRef(
55: absoluteObjectNameString));
56: }
57:
58: /**
59: * Unbind this Transaction from a java:comp
60: */
61: public void unbindEnv() {
62: try {
63: InitialContext ic = new InitialContext();
64: Context env = (Context) ic.lookup("java:comp");
65: Log.debug("Unbinding java:comp/" + getJndiName());
66: env.unbind(getJndiName());
67: } catch (NamingException e) {
68: Log.warn(e);
69: }
70: }
71:
72: }
|