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 org.apache.openejb.InterfaceType;
   20   import org.apache.openejb.DeploymentInfo;
   21   import org.apache.openejb.Container;
   22   import org.apache.openejb.core.ivm.EjbObjectProxyHandler;
   23   import org.apache.openejb.util.proxy.ProxyManager;
   24   
   25   import java.lang.reflect.Method;
   26   import java.rmi.RemoteException;
   27   import java.util.List;
   28   import java.io.Serializable;
   29   
   30   public class StatefulEjbObjectHandler extends EjbObjectProxyHandler {
   31   
   32       public StatefulEjbObjectHandler(DeploymentInfo deploymentInfo, Object pk, InterfaceType interfaceType, List<Class> interfaces) {
   33           super(deploymentInfo, pk, interfaceType, interfaces);
   34       }
   35   
   36       public Object getRegistryId() {
   37           return new RegistryId(container, deploymentID, primaryKey);
   38       }
   39   
   40       protected Object getPrimaryKey(Method method, Object[] args, Object proxy) throws Throwable {
   41           throw new RemoteException("Session objects are private resources and do not have primary keys");
   42       }
   43   
   44       protected Object isIdentical(Method method, Object[] args, Object proxy) throws Throwable {
   45           checkAuthorization(method);
   46   
   47           if (args.length != 1) {
   48               throw new IllegalArgumentException("Expected one argument to isIdentical, but received " + args.length);
   49           }
   50   
   51           Object that = args[0];
   52           Object invocationHandler = ProxyManager.getInvocationHandler(that);
   53   
   54           if (invocationHandler instanceof StatefulEjbObjectHandler) {
   55               StatefulEjbObjectHandler handler = (StatefulEjbObjectHandler) invocationHandler;
   56   
   57               /*
   58               * The registry id is a compound key composed of the bean's primary key, deployment id, and
   59               * container id.  It uniquely identifies the entity bean that is proxied by the EntityEjbObjectHandler
   60               * within the IntraVM.
   61               */
   62               return this.getRegistryId().equals(handler.getRegistryId());
   63           }
   64   
   65           return false;
   66       }
   67   
   68       protected Object remove(Class interfce, Method method, Object[] args, Object proxy) throws Throwable {
   69           checkAuthorization(method);
   70           Object value = container.invoke(deploymentID, interfaceType, interfce, method, args, primaryKey);
   71   
   72           invalidateAllHandlers(getRegistryId());
   73           return value;
   74       }
   75   
   76       public static class RegistryId implements Serializable {
   77           private static final long serialVersionUID = 5037368364299042022L;
   78   
   79           private final Object containerId;
   80           private final Object deploymentId;
   81           private final Object primaryKey;
   82   
   83           public RegistryId(Container container, Object deploymentId, Object primaryKey) {
   84               if (container == null) throw new NullPointerException("container is null");
   85               if (deploymentId == null) throw new NullPointerException("deploymentId is null");
   86   
   87               this.containerId = container.getContainerID();
   88               this.deploymentId = deploymentId;
   89               this.primaryKey = primaryKey;
   90           }
   91   
   92           public boolean equals(Object o) {
   93               if (this == o) return true;
   94               if (o == null || getClass() != o.getClass()) return false;
   95   
   96               RegistryId that = (RegistryId) o;
   97   
   98               return containerId.equals(that.containerId) &&
   99                       deploymentId.equals(that.deploymentId) &&
  100                       !(primaryKey != null ? !primaryKey.equals(that.primaryKey) : that.primaryKey != null);
  101           }
  102   
  103           public int hashCode() {
  104               int result;
  105               result = containerId.hashCode();
  106               result = 31 * result + deploymentId.hashCode();
  107               result = 31 * result + (primaryKey != null ? primaryKey.hashCode() : 0);
  108               return result;
  109           }
  110   
  111   
  112           public String toString() {
  113               return "[" + containerId + ", " + deploymentId + ", " + primaryKey + "]";
  114           }
  115           
  116           public Object getPrimaryKey() {
  117               return primaryKey; 
  118           }
  119       }
  120   }

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