Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateful » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     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    */
   17   package org.apache.openejb.core.stateful;
   18   
   19   import javax.transaction.UserTransaction;
   20   import javax.xml.rpc.handler.MessageContext;
   21   
   22   import org.apache.openejb.core.BaseSessionContext;
   23   import org.apache.openejb.core.Operation;
   24   import org.apache.openejb.core.ThreadContext;
   25   import org.apache.openejb.spi.SecurityService;
   26   
   27   
   28   /**
   29    * @version $Rev: 688602 $ $Date: 2008-08-24 19:39:06 -0700 (Sun, 24 Aug 2008) $
   30    */
   31   public class StatefulContext extends BaseSessionContext {
   32   
   33       protected final static State[] states = new State[Operation.values().length];
   34       
   35       public static State[] getStates() {
   36           return states;
   37       }
   38   
   39       public StatefulContext(SecurityService securityService, UserTransaction userTransaction) {
   40           super(securityService, userTransaction);
   41       }
   42   
   43       protected State getState() {
   44           Operation operation = ThreadContext.getThreadContext().getCurrentOperation();
   45           State state = states[operation.ordinal()];
   46   
   47           if (state == null) throw new IllegalArgumentException("Invalid operation " + operation + " for this context");
   48   
   49           return state;
   50       }
   51   
   52       /**
   53        * PostConstruct, Pre-Destroy lifecycle callback interceptor methods
   54        */
   55       public static class LifecycleStatefulSessionState extends SessionState {
   56   
   57           public MessageContext getMessageContext() throws IllegalStateException {
   58               throw new IllegalStateException();
   59           }
   60   
   61           public Class getInvokedBusinessInterface() {
   62               throw new IllegalStateException();
   63           }
   64   
   65           public void setRollbackOnly() throws IllegalStateException {
   66               throw new IllegalStateException();
   67           }
   68   
   69           public boolean getRollbackOnly() throws IllegalStateException {
   70               throw new IllegalStateException();
   71           }
   72   
   73           public boolean isMessageContextAccessAllowed() {
   74               return false;
   75           }
   76   
   77           public boolean isTimerAccessAllowed() {
   78               return false;
   79           }
   80   
   81           public boolean isTimerMethodAllowed() {
   82               return false;
   83           }
   84       }
   85   
   86       /**
   87        * afterBegin
   88        * beforeCompletion
   89        */
   90       public static class BeforeCompletion extends SessionState {
   91   
   92           public Class getInvokedBusinessInterface() {
   93               throw new IllegalStateException();
   94           }
   95   
   96           public MessageContext getMessageContext() throws IllegalStateException {
   97               throw new IllegalStateException();
   98           }
   99   
  100           public boolean isMessageContextAccessAllowed() {
  101               return false;
  102           }
  103       }
  104   
  105       /**
  106        * afterCompletion
  107        */
  108       public static class AfterCompletion extends SessionState {
  109           public MessageContext getMessageContext() throws IllegalStateException {
  110               throw new IllegalStateException();
  111           }
  112   
  113           public Class getInvokedBusinessInterface() {
  114               throw new IllegalStateException();
  115           }
  116   
  117           public void setRollbackOnly() throws IllegalStateException {
  118               throw new IllegalStateException();
  119           }
  120   
  121           public boolean getRollbackOnly() throws IllegalStateException {
  122               throw new IllegalStateException();
  123           }
  124   
  125           public boolean isUserTransactionAccessAllowed() {
  126               return false;
  127           }
  128   
  129           public boolean isMessageContextAccessAllowed() {
  130               return false;
  131           }
  132   
  133           public boolean isJNDIAccessAllowed() {
  134               return false;
  135           }
  136   
  137           public boolean isEntityManagerFactoryAccessAllowed() {
  138               return false;
  139           }
  140   
  141           public boolean isEntityManagerAccessAllowed() {
  142               return false;
  143           }
  144   
  145           public boolean isTimerAccessAllowed() {
  146               return false;
  147           }
  148   
  149           public boolean isTimerMethodAllowed() {
  150               return false;
  151           }
  152       }
  153   
  154       static {
  155           states[Operation.INJECTION.ordinal()] = new InjectionSessionState();
  156           states[Operation.CREATE.ordinal()] = new LifecycleStatefulSessionState();
  157           states[Operation.BUSINESS.ordinal()] = new BusinessSessionState();
  158           states[Operation.AFTER_BEGIN.ordinal()] = new BeforeCompletion();
  159           states[Operation.BEFORE_COMPLETION.ordinal()] = new BeforeCompletion();
  160           states[Operation.AFTER_COMPLETION.ordinal()] = new AfterCompletion();
  161           states[Operation.TIMEOUT.ordinal()] = new TimeoutSessionState();
  162           states[Operation.PRE_DESTROY.ordinal()] = new LifecycleStatefulSessionState();
  163           states[Operation.REMOVE.ordinal()] = new LifecycleStatefulSessionState();
  164           states[Operation.POST_CONSTRUCT.ordinal()] = new LifecycleStatefulSessionState();
  165       }
  166   
  167   }

Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » core » stateful » [javadoc | source]