/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb;

import org.jboss.ejb.plugins.*;
import org.jboss.metadata.*;

/**
 * EntityDeployer provides implementations of BeanDeployer methods
 * that are specific to Entity Beans.
 *
 * @see BeanDeployer
 * @author <a href="mailto:[EMAIL PROTECTED]">Jack Bolles</a>
 */
public class EntityDeployer extends BeanDeployer {

      protected EntityDeployer(BeanMetaData bmd, ClassLoader loader,
boolean enableMetrics){
         super(bmd, loader, enableMetrics);
         container = new EntityContainer();
      }

      protected void setInstancePool()  throws DeploymentException {
         // Set instance pool
         InstancePool ip = null;
         try {
            ip = (InstancePool)cl.loadClass(conf.getInstancePool
()).newInstance();
            if(ip instanceof XmlLoadable) {
               ((XmlLoadable)ip).importXml(conf.getContainerPoolConf());
            }
         } catch(Exception e) {
            throw new DeploymentException("Missing or invalid Instance Pool
(in jboss.xml or standardjboss.xml)");
         }
         container.setInstancePool(ip);
      }

      protected void setInstanceCache() throws DeploymentException {
         // Set instance cache
         InstanceCache ic = null;
         try {
            ic = (InstanceCache)cl.loadClass(conf.getInstanceCache
()).newInstance();
            if(ic instanceof XmlLoadable) {
               ((XmlLoadable)ic).importXml(conf.getContainerCacheConf());
            }
         } catch(Exception e) {
            throw new DeploymentException("Missing or invalid Instance
Cache (in jboss.xml or standardjboss.xml)", e);
         }
         container.setInstanceCache(ic);
      }

      protected void setPersistenceManager() throws DeploymentException {
         // Set persistence manager
         if (((EntityMetaData) bean).isBMP())
         {
            try{
               //Should be BMPPersistenceManager
               ((EntityContainer)container).setPersistenceManager
((EntityPersistenceManager)cl.loadClass(conf.getPersistenceManager
()).newInstance());
            }catch (Exception exe) {
               throw new DeploymentException("Missing or invalid
Persistence Manager (in jboss.xml or standardjboss.xml)", exe);
            }
         }
         else
         {

            try{
               //Should be BMPPersistenceManager
               // CMP takes a manager and a store
               org.jboss.ejb.plugins.CMPPersistenceManager
persistenceManager = new org.jboss.ejb.plugins.CMPPersistenceManager();

               //Load the store from configuration
               persistenceManager.setPersistenceStore
((EntityPersistenceStore)cl.loadClass(conf.getPersistenceManager
()).newInstance());

               // Set the manager on the container

((EntityContainer)container).setPersistenceManager(persistenceManager);
            }catch (Exception exe) {
               throw new DeploymentException("Missing or invalid
Persistence Manager (in jboss.xml or standardjboss.xml)", exe);
            }
         }
      }

      protected void setInterceptors() throws DeploymentException {
         super.setInterceptors();
         container.addInterceptor(new EntityInstanceInterceptor());
         container.addInterceptor(new EntitySynchronizationInterceptor());
      }

   }



Reply via email to