1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36
37 package javax.resource.spi.work;
38
39 import java.lang.Object;
40 import java.lang.Runnable;
41 import java.lang.Exception;
42 import java.lang.Throwable;
43
44 import javax.transaction.xa.Xid;
45 import javax.resource.NotSupportedException;
46 //import javax.resource.spi.security.SecurityContext;
47
48 /**
49 * This class models an execution context (transaction, security, etc)
50 * with which the <code>Work</code> instance must be executed.
51 * This class is provided as a convenience for easily creating
52 * <code>ExecutionContext</code> instances by extending this class
53 * and overriding only those methods of interest.
54 *
55 * <p>Some reasons why it is better for <code>ExecutionContext</code>
56 * to be a class rather than an interface:
57 * <ul><li>There is no need for a resource adapter to implement this class.
58 * It only needs to implement the context information like
59 * transaction, etc.
60 * <li>The resource adapter code does not have to change when the
61 * <code>ExecutionContext</code> class evolves. For example, more context
62 * types could be added to the <code>ExecutionContext</code> class
63 * (in the future) without forcing resource adapter implementations
64 * to change.</ul>
65 *
66 * @version 1.0
67 * @author Ram Jeyaraman
68 */
69 public class ExecutionContext {
70
71 /**
72 * transaction context.
73 */
74 private Xid xid;
75
76 /**
77 * transaction timeout value.
78 */
79 private long transactionTimeout = WorkManager.UNKNOWN;
80
81 /**
82 * security context.
83 */
84 //private SecurityContext securityCtx;
85
86 /**
87 * set a transaction context.
88 *
89 * @param xid transaction context.
90 */
91 public void setXid(Xid xid) { this.xid = xid; }
92
93 /*
94 * @return an Xid object carrying a transaction context,
95 * if any.
96 */
97 public Xid getXid() { return this.xid; }
98
99 /**
100 * Set the transaction timeout value for a imported transaction.
101 *
102 * @param timeout transaction timeout value in seconds. Only positive
103 * non-zero values are accepted. Other values are illegal and are
104 * rejected with a <code>NotSupportedException</code>.
105 *
106 * @throws NotSupportedException thrown to indicate an illegal timeout
107 * value.
108 */
109 public void setTransactionTimeout(long timeout)
110 throws NotSupportedException {
111 if (timeout > 0) {
112 this.transactionTimeout = timeout;
113 } else {
114 throw new NotSupportedException("Illegal timeout value");
115 }
116 }
117
118 /**
119 * Get the transaction timeout value for a imported transaction.
120 *
121 * @return the specified transaction timeout value in seconds. When no
122 * timeout value or an illegal timeout value had been specified,
123 * a value of -1 (<code>WorkManager.UNKNOWN</code>)
124 * is returned; such a transaction is excluded from regular
125 * timeout processing.
126 */
127 public long getTransactionTimeout() {
128 return this.transactionTimeout;
129 }
130
131 /**
132 * set a security context.
133 *
134 * @param securityCtx security context.
135 */
136 /*
137 public void setSecurityContext(SecurityContext securityCtx) {
138 this.securityCtx = securityCtx;
139 }
140 */
141 /*
142 * @return a <code>SecurityContext</code> object, if any.
143 */
144 /*
145 public SecurityContext getSecurityContext() { return this.securityCtx; }
146 */
147 }