01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.core.stateless;
17:
18: import javax.transaction.TransactionManager;
19: import javax.transaction.UserTransaction;
20:
21: import org.apache.openejb.core.BaseSessionContext;
22: import org.apache.openejb.core.Operation;
23: import org.apache.openejb.core.ThreadContext;
24: import org.apache.openejb.spi.SecurityService;
25:
26: /**
27: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
28: */
29: public class StatelessContext extends BaseSessionContext {
30:
31: protected final static State[] states = new State[Operation
32: .values().length];
33:
34: public static State[] getStates() {
35: return states;
36: }
37:
38: public StatelessContext(TransactionManager transactionManager,
39: SecurityService securityService) {
40: super (transactionManager, securityService);
41: }
42:
43: public StatelessContext(TransactionManager transactionManager,
44: SecurityService securityService,
45: UserTransaction userTransaction) {
46: super (transactionManager, securityService, userTransaction);
47: }
48:
49: protected State getState() {
50: Operation operation = ThreadContext.getThreadContext()
51: .getCurrentOperation();
52: State state = states[operation.ordinal()];
53:
54: if (state == null)
55: throw new IllegalArgumentException("Invalid operation "
56: + operation + " for this context");
57:
58: return state;
59: }
60:
61: /**
62: * Business method from web service endpoint
63: */
64: private static class BusinessWsStatelessState extends SessionState {
65: public Class getInvokedBusinessInterface() {
66: throw new IllegalStateException();
67: }
68: }
69:
70: static {
71: states[Operation.INJECTION.ordinal()] = new InjectionSessionState();
72: states[Operation.CREATE.ordinal()] = new LifecycleSessionState();
73: states[Operation.BUSINESS.ordinal()] = new BusinessSessionState();
74: states[Operation.BUSINESS_WS.ordinal()] = new BusinessWsStatelessState();
75: states[Operation.TIMEOUT.ordinal()] = new TimeoutSessionState();
76: states[Operation.POST_CONSTRUCT.ordinal()] = new PostConstructSessionState();
77: states[Operation.PRE_DESTROY.ordinal()] = new LifecycleSessionState();
78: }
79:
80: }
|