KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > resource > spi > work > ExecutionContext


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package javax.resource.spi.work;
25
26 import java.lang.Object JavaDoc;
27 import java.lang.Runnable JavaDoc;
28 import java.lang.Exception JavaDoc;
29 import java.lang.Throwable JavaDoc;
30
31 import javax.transaction.xa.Xid JavaDoc;
32 import javax.resource.NotSupportedException JavaDoc;
33 //import javax.resource.spi.security.SecurityContext;
34

35 /**
36  * This class models an execution context (transaction, security, etc)
37  * with which the <code>Work</code> instance must be executed.
38  * This class is provided as a convenience for easily creating
39  * <code>ExecutionContext</code> instances by extending this class
40  * and overriding only those methods of interest.
41  *
42  * <p>Some reasons why it is better for <code>ExecutionContext</code>
43  * to be a class rather than an interface:
44  * <ul><li>There is no need for a resource adapter to implement this class.
45  * It only needs to implement the context information like
46  * transaction, etc.
47  * <li>The resource adapter code does not have to change when the
48  * <code>ExecutionContext</code> class evolves. For example, more context
49  * types could be added to the <code>ExecutionContext</code> class
50  * (in the future) without forcing resource adapter implementations
51  * to change.</ul>
52  *
53  * @version 1.0
54  * @author Ram Jeyaraman
55  */

56 public class ExecutionContext {
57
58     /**
59      * transaction context.
60      */

61     private Xid JavaDoc xid;
62
63     /**
64      * transaction timeout value.
65      */

66     private long transactionTimeout = WorkManager.UNKNOWN;
67
68     /**
69      * security context.
70      */

71     //private SecurityContext securityCtx;
72

73     /**
74      * set a transaction context.
75      *
76      * @param xid transaction context.
77      */

78     public void setXid(Xid JavaDoc xid) { this.xid = xid; }
79
80     /*
81      * @return an Xid object carrying a transaction context,
82      * if any.
83      */

84     public Xid JavaDoc getXid() { return this.xid; }
85
86     /**
87      * Set the transaction timeout value for a imported transaction.
88      *
89      * @param timeout transaction timeout value in seconds. Only positive
90      * non-zero values are accepted. Other values are illegal and are
91      * rejected with a <code>NotSupportedException</code>.
92      *
93      * @throws NotSupportedException thrown to indicate an illegal timeout
94      * value.
95      */

96     public void setTransactionTimeout(long timeout)
97     throws NotSupportedException JavaDoc {
98     if (timeout > 0) {
99         this.transactionTimeout = timeout;
100     } else {
101         throw new NotSupportedException JavaDoc("Illegal timeout value");
102     }
103     }
104
105     /**
106      * Get the transaction timeout value for a imported transaction.
107      *
108      * @return the specified transaction timeout value in seconds. When no
109      * timeout value or an illegal timeout value had been specified,
110      * a value of -1 (<code>WorkManager.UNKNOWN</code>)
111      * is returned; such a transaction is excluded from regular
112      * timeout processing.
113      */

114     public long getTransactionTimeout() {
115     return this.transactionTimeout;
116     }
117
118     /**
119      * set a security context.
120      *
121      * @param securityCtx security context.
122      */

123     /*
124     public void setSecurityContext(SecurityContext securityCtx) {
125     this.securityCtx = securityCtx;
126     }
127     */

128     /*
129      * @return a <code>SecurityContext</code> object, if any.
130      */

131     /*
132     public SecurityContext getSecurityContext() { return this.securityCtx; }
133     */

134 }
135
Popular Tags