001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.core.stateful;
017:
018: import javax.transaction.TransactionManager;
019: import javax.transaction.UserTransaction;
020: import javax.xml.rpc.handler.MessageContext;
021:
022: import org.apache.openejb.core.BaseSessionContext;
023: import org.apache.openejb.core.Operation;
024: import org.apache.openejb.core.ThreadContext;
025: import org.apache.openejb.core.RestrictedUserTransaction;
026: import org.apache.openejb.spi.SecurityService;
027:
028: import java.security.Principal;
029:
030: /**
031: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
032: */
033: public class StatefulContext extends BaseSessionContext {
034:
035: protected final static State[] states = new State[Operation
036: .values().length];
037:
038: public static State[] getStates() {
039: return states;
040: }
041:
042: public StatefulContext(TransactionManager transactionManager,
043: SecurityService securityService) {
044: super (transactionManager, securityService);
045: }
046:
047: public StatefulContext(TransactionManager transactionManager,
048: SecurityService securityService,
049: UserTransaction userTransaction) {
050: super (transactionManager, securityService, userTransaction);
051: }
052:
053: protected State getState() {
054: Operation operation = ThreadContext.getThreadContext()
055: .getCurrentOperation();
056: State state = states[operation.ordinal()];
057:
058: if (state == null)
059: throw new IllegalArgumentException("Invalid operation "
060: + operation + " for this context");
061:
062: return state;
063: }
064:
065: /**
066: * PostConstruct, Pre-Destroy lifecycle callback interceptor methods
067: */
068: public static class LifecycleStatefulSessionState extends
069: SessionState {
070:
071: public MessageContext getMessageContext()
072: throws IllegalStateException {
073: throw new IllegalStateException();
074: }
075:
076: public Class getInvokedBusinessInterface() {
077: throw new IllegalStateException();
078: }
079:
080: public void setRollbackOnly(
081: TransactionManager transactionManager)
082: throws IllegalStateException {
083: throw new IllegalStateException();
084: }
085:
086: public boolean getRollbackOnly(
087: TransactionManager transactionManager)
088: throws IllegalStateException {
089: throw new IllegalStateException();
090: }
091:
092: public boolean isMessageContextAccessAllowed() {
093: return false;
094: }
095:
096: public boolean isTimerAccessAllowed() {
097: return false;
098: }
099:
100: public boolean isTimerMethodAllowed() {
101: return false;
102: }
103: }
104:
105: /**
106: * afterBegin
107: * beforeCompletion
108: */
109: public static class BeforeCompletion extends SessionState {
110:
111: public Class getInvokedBusinessInterface() {
112: throw new IllegalStateException();
113: }
114:
115: public MessageContext getMessageContext()
116: throws IllegalStateException {
117: throw new IllegalStateException();
118: }
119:
120: public boolean isMessageContextAccessAllowed() {
121: return false;
122: }
123: }
124:
125: /**
126: * afterCompletion
127: */
128: public static class AfterCompletion extends SessionState {
129: public MessageContext getMessageContext()
130: throws IllegalStateException {
131: throw new IllegalStateException();
132: }
133:
134: public Class getInvokedBusinessInterface() {
135: throw new IllegalStateException();
136: }
137:
138: public void setRollbackOnly(
139: TransactionManager transactionManager)
140: throws IllegalStateException {
141: throw new IllegalStateException();
142: }
143:
144: public boolean getRollbackOnly(
145: TransactionManager transactionManager)
146: throws IllegalStateException {
147: throw new IllegalStateException();
148: }
149:
150: public boolean isUserTransactionAccessAllowed() {
151: return false;
152: }
153:
154: public boolean isMessageContextAccessAllowed() {
155: return false;
156: }
157:
158: public boolean isJNDIAccessAllowed() {
159: return false;
160: }
161:
162: public boolean isEntityManagerFactoryAccessAllowed() {
163: return false;
164: }
165:
166: public boolean isEntityManagerAccessAllowed() {
167: return false;
168: }
169:
170: public boolean isTimerAccessAllowed() {
171: return false;
172: }
173:
174: public boolean isTimerMethodAllowed() {
175: return false;
176: }
177: }
178:
179: static {
180: states[Operation.INJECTION.ordinal()] = new InjectionSessionState();
181: states[Operation.CREATE.ordinal()] = new LifecycleStatefulSessionState();
182: states[Operation.BUSINESS.ordinal()] = new BusinessSessionState();
183: states[Operation.AFTER_BEGIN.ordinal()] = new BeforeCompletion();
184: states[Operation.BEFORE_COMPLETION.ordinal()] = new BeforeCompletion();
185: states[Operation.AFTER_COMPLETION.ordinal()] = new AfterCompletion();
186: states[Operation.TIMEOUT.ordinal()] = new TimeoutSessionState();
187: states[Operation.PRE_DESTROY.ordinal()] = new LifecycleStatefulSessionState();
188: states[Operation.REMOVE.ordinal()] = new LifecycleStatefulSessionState();
189: states[Operation.POST_CONSTRUCT.ordinal()] = new LifecycleStatefulSessionState();
190: }
191:
192: }
|