Home » openejb-3.1.2-src » org.apache » openejb » core » cmp » [javadoc | source]

    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.core.cmp;
   19   
   20   import org.apache.openejb.RpcContainer;
   21   import org.apache.openejb.core.CoreDeploymentInfo;
   22   import org.apache.openejb.core.entity.EntityEjbHomeHandler;
   23   import org.apache.openejb.util.proxy.ProxyManager;
   24   
   25   import javax.ejb.EJBHome;
   26   import javax.ejb.EJBLocalHome;
   27   import javax.ejb.EntityBean;
   28   
   29   public class ProxyFactory {
   30       private final CoreDeploymentInfo deploymentInfo;
   31       private final KeyGenerator keyGenerator;
   32       private final Class remoteInterface;
   33       private final EntityEjbHomeHandler remoteHandler;
   34       private final Class localInterface;
   35       private final EntityEjbHomeHandler localHandler;
   36   
   37       public ProxyFactory(CoreDeploymentInfo deploymentInfo) {
   38           this.deploymentInfo = deploymentInfo;
   39           keyGenerator = deploymentInfo.getKeyGenerator();
   40   
   41           remoteInterface = deploymentInfo.getRemoteInterface();
   42           if (remoteInterface != null) {
   43               EJBHome homeProxy = deploymentInfo.getEJBHome();
   44               remoteHandler = (EntityEjbHomeHandler) ProxyManager.getInvocationHandler(homeProxy);
   45           } else {
   46               remoteHandler = null;
   47           }
   48   
   49           localInterface = deploymentInfo.getLocalInterface();
   50           if (localInterface != null) {
   51               EJBLocalHome localHomeProxy = deploymentInfo.getEJBLocalHome();
   52               localHandler = (EntityEjbHomeHandler) ProxyManager.getInvocationHandler(localHomeProxy);
   53           } else {
   54               localHandler = null;
   55           }
   56       }
   57   
   58       public Object createRemoteProxy(EntityBean bean, RpcContainer container) {
   59           // The KeyGenerator creates a new primary key and populates its fields with the
   60           // primary key fields of the bean instance.  Each deployment has its own KeyGenerator.
   61           Object primaryKey = keyGenerator.getPrimaryKey(bean);
   62   
   63           // create the proxy
   64           Object proxy = remoteHandler.createProxy(primaryKey);
   65           return proxy;
   66       }
   67   
   68       public Object createLocalProxy(EntityBean bean, RpcContainer container) {
   69           // The KeyGenerator creates a new primary key and populates its fields with the
   70           // primary key fields of the bean instance.  Each deployment has its own KeyGenerator.
   71           Object primaryKey = keyGenerator.getPrimaryKey(bean);
   72   
   73           // create the proxy
   74           Object proxy = localHandler.createProxy(primaryKey);
   75           return proxy;
   76   
   77       }
   78   }

Home » openejb-3.1.2-src » org.apache » openejb » core » cmp » [javadoc | source]