Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package org.jboss.ejb3;
  /*     */ 
  /*     */ import java.io.BufferedInputStream;
  /*     */ import java.io.DataInputStream;
  /*     */ import java.io.InputStream;
  /*     */ import java.util.ArrayList;
  /*     */ import java.util.Collection;
  /*     */ import java.util.HashMap;
  /*     */ import java.util.Iterator;
 /*     */ import java.util.LinkedHashMap;
 /*     */ import java.util.List;
 /*     */ import java.util.Map;
 /*     */ import java.util.Properties;
 /*     */ import  javassist.bytecode.ClassFile;
 /*     */ import javax.management.MBeanServer;
 /*     */ import javax.management.ObjectName;
 /*     */ import javax.naming.InitialContext;
 /*     */ import javax.naming.NameNotFoundException;
 /*     */ import javax.naming.NamingException;
 /*     */ import javax.persistence.Entity;
 /*     */ import  org.hibernate.ejb.packaging.PersistenceMetadata;
 /*     */ import org.jboss.ejb3.deployers.Ejb3Deployer;
 /*     */ import org.jboss.ejb3.javaee.JavaEEComponent;
 /*     */ import org.jboss.ejb3.javaee.JavaEEModule;
 /*     */ import org.jboss.logging.Logger;
 /*     */ import org.jboss.virtual.VirtualFile;
 /*     */ 
 /*     */ public abstract class Ejb3Deployment
 /*     */   implements JavaEEModule
 /*     */ {
 /*     */   private static final Logger log;
 /*     */   public static final String ACTUAL_ENTITY_MANAGER_FACTORY_CONTEXT = "java:/ActualEntityManagerFactories";
 /*     */   public static final String MANAGED_ENTITY_FACTORY_CONTEXT = "java:/managedEntityFactories";
 /*     */   private JBossMetaData metaData;
 /*     */   private PersistenceUnitsMetaData persistenceUnitsMetaData;
 /*     */   protected DeploymentUnit unit;
 /*     */   protected Ejb3Deployer deployer;
 /*  89 */   protected LinkedHashMap<ObjectNameContainerejbContainers = new LinkedHashMap();
 /*     */   protected boolean hasEntities;
 /*  93 */   protected List<StringexplicitEntityClasses = new ArrayList();
 /*     */ 
 /*  95 */   protected List<PersistenceUnitDeploymentpersistenceUnitDeployments = new ArrayList();
 /*     */ 
 /*  97 */   protected String defaultSLSBDomain = "Stateless Bean";
 /*     */ 
 /*  99 */   protected String defaultSFSBDomain = "Stateful Bean";
 /*     */ 
 /* 101 */   protected String defaultMDBDomain = "Message Driven Bean";
 /*     */ 
 /* 103 */   protected String defaultConsumerDomain = "Consumer Bean";
 /*     */ 
 /* 105 */   protected String defaultServiceDomain = "Service Bean";
 /*     */   protected InitialContext initialContext;
 /*     */   protected KernelAbstraction kernelAbstraction;
 /*     */   protected MBeanServer mbeanServer;
 /*     */   protected DeploymentScope deploymentScope;
 /*     */   protected EjbModuleEjbResolver ejbRefResolver;
 /*     */   protected MessageDestinationResolver messageDestinationResolver;
 /*     */   PolicyConfiguration pc;
 /*     */ 
 /*     */   public Ejb3Deployment(DeploymentUnit unitDeploymentScope deploymentScopeJBossMetaData metaDataPersistenceUnitsMetaData persistenceUnitsMetaDataEjb3Deployer deployer)
 /*     */   {
 /* 128 */     assert (unit != null) : "unit is null";
 /* 129 */     assert (deployer != null) : "deployer is null";
 /*     */ 
 /* 131 */     this. = unit;
 /* 132 */     this. = deployer;
 /* 133 */     this. = deploymentScope;
 /* 134 */     this. = metaData;
 /* 135 */     this. = persistenceUnitsMetaData;
 /*     */     try
 /*     */     {
 /* 138 */       this. = InitialContextFactory.getInitialContext(unit.getJndiProperties());
 /*     */     }
 /*     */     catch (NamingException e)
 /*     */     {
 /* 142 */       throw new RuntimeException(e);
 /*     */     }
 /* 144 */     this. = new EjbModuleEjbResolver(deploymentScopeunit.getShortName(), this.this);
 /* 145 */     this. = new EjbModulePersistenceUnitResolver(this.deploymentScopethis.);
 /*     */ 
/* 147 */     MessageDestinationsMetaData destinations = null;
/* 148 */     if ((metaData != null) && (metaData.getAssemblyDescriptor() != null))
/* 149 */       destinations = metaData.getAssemblyDescriptor().getMessageDestinations();
/* 150 */     this. = new MessageDestinationResolver(deploymentScopedestinations);
/*     */   }
/*     */ 
/*     */   public JavaEEApplication getApplication()
/*     */   {
/* 155 */     return this.;
/*     */   }
/*     */ 
/*     */   public DeploymentScope getEar()
/*     */   {
/* 160 */     return this.;
/*     */   }
/*     */ 
/*     */   public KernelAbstraction getKernelAbstraction()
/*     */   {
/* 165 */     return this.;
/*     */   }
/*     */ 
/*     */   public MBeanServer getMbeanServer()
/*     */   {
/* 170 */     return this.;
/*     */   }
/*     */ 
/*     */   public void setMbeanServer(MBeanServer mbeanServer)
/*     */   {
/* 175 */     this. = mbeanServer;
/*     */   }
/*     */ 
/*     */   public DeploymentUnit getDeploymentUnit()
/*     */   {
/* 180 */     return this.;
/*     */   }
/*     */ 
/*     */   public String getDefaultSLSBDomain()
/*     */   {
/* 185 */     return this.;
/*     */   }
/*     */ 
/*     */   public Ejb3Deployer getDeployer()
/*     */   {
/* 190 */     return this.;
/*     */   }
/*     */ 
/*     */   public CacheFactoryRegistry getCacheFactoryRegistry()
/*     */   {
/* 195 */     return getDeployer().getCacheFactoryRegistry();
/*     */   }
/*     */ 
/*     */   {
/* 200 */     return getDeployer().getRemoteProxyFactoryRegistry();
/*     */   }
/*     */ 
/*     */   {
/* 205 */     return getDeployer().getPersistenceManagerFactoryRegistry();
/*     */   }
/*     */ 
/*     */   public String getScopeKernelName()
/*     */   {
/* 216 */     String scopedKernelName = "";
/* 217 */     if (this. != null)
/* 218 */       scopedKernelName = scopedKernelName + ",ear=" + this..getShortName();
/* 219 */     scopedKernelName = scopedKernelName + ",jar=" + this..getShortName();
/* 220 */     return scopedKernelName;
/*     */   }
/*     */ 
/*     */   public void setDefaultSLSBDomain(String defaultSLSBDomain)
/*     */   {
/* 230 */     this. = defaultSLSBDomain;
/*     */   }
/*     */ 
/*     */   public String getDefaultSFSBDomain()
/*     */   {
/* 235 */     return this.;
/*     */   }
/*     */ 
/*     */   public String getDefaultConsumerDomain()
/*     */   {
/* 240 */     return this.;
/*     */   }
/*     */ 
/*     */   public void setDefaultSFSBDomain(String defaultSFSBDomain)
/*     */   {
/* 250 */     this. = defaultSFSBDomain;
/*     */   }
/*     */ 
/*     */   public String getDefaultMDBDomain()
/*     */   {
/* 255 */     return this.;
/*     */   }
/*     */ 
/*     */   public void setDefaultMDBDomain(String defaultMDBDomain)
/*     */   {
/* 265 */     this. = defaultMDBDomain;
/*     */   }
/*     */ 
/*     */   public String getDefaultServiceDomain()
/*     */   {
/* 270 */     return this.;
/*     */   }
/*     */ 
/*     */   public void setDefaultServiceDomain(String defaultServiceDomain)
/*     */   {
/* 280 */     this. = defaultServiceDomain;
/*     */   }
/*     */ 
/*     */   protected String getJaccContextId()
/*     */   {
/* 285 */     return this..getShortName();
/*     */   }
/*     */ 
/*     */   public Container getContainer(ObjectName name)
/*     */   {
/* 290 */     return (Container)this..get(name);
/*     */   }
/*     */ 
/*     */   public Map getEjbContainers()
/*     */   {
/* 295 */     return this.;
/*     */   }
/*     */ 
/*     */   {
/* 300 */     return this..getPersistenceUnitDeployment(unitName);
/*     */   }
/*     */ 
/*     */   {
/* 305 */     return this..getPersistenceUnitDeploymentInternal(unitName);
/*     */   }
/*     */ 
/*     */   {
/* 310 */     return this.;
/*     */   }
/*     */ 
/*     */   public EJBContainer getEjbContainer(String ejbLinkClass businessIntf)
/*     */   {
/* 315 */     return this..getEjbContainer(ejbLinkbusinessIntf);
/*     */   }
/*     */ 
/*     */   public String getEjbJndiName(String ejbLinkClass businessIntf)
/*     */   {
/* 320 */     return this..getEjbJndiName(ejbLinkbusinessIntf);
/*     */   }
/*     */ 
/*     */   public EJBContainer getEjbContainer(Ejb3Deployment deploymentClass businessIntfthrows NameNotFoundException
/*     */   {
/* 325 */     return this..getEjbContainer(deploymentbusinessIntf);
/*     */   }
/*     */ 
/*     */   public EJBContainer getEjbContainer(Class businessIntfthrows NameNotFoundException
/*     */   {
/* 330 */     return this..getEjbContainer(businessIntf);
/*     */   }
/*     */ 
/*     */   public String getEjbJndiName(Class businessIntfthrows NameNotFoundException
/*     */   {
/* 335 */     return this..getEjbJndiName(businessIntf);
/*     */   }
/*     */ 
/*     */   protected void processEJBContainerMetadata(Container containerthrows Exception
/*     */   {
/* 340 */     .trace("Process EJB container metadata " + container);
/* 341 */     ObjectName on = container.getObjectName();
/* 342 */     this..put(oncontainer);
/* 343 */     container.processMetadata();
/*     */   }
/*     */ 
/*     */   protected void registerEJBContainer(Container containerthrows Exception
/*     */   {
/* 348 */     ObjectName on = container.getObjectName();
/* 349 */     String name = on.getCanonicalName();
/* 350 */     this..install(namecontainer.getDependencyPolicy(), container);
/* 351 */     this..registerMBean(container.getMBean(), on);
/* 352 */     .debug("Bound ejb3 container " + name);
/*     */   }
/*     */ 
/*     */   protected abstract PolicyConfiguration createPolicyConfiguration()
/*     */     throws Exception;
/*     */ 
/*     */   protected abstract void putJaccInService(PolicyConfiguration paramPolicyConfigurationDeploymentUnit paramDeploymentUnit);
/*     */ 
/*     */   public void create()
/*     */     throws Exception
/*     */   {
/*     */     try
/*     */     {
/* 372 */       long start = System.currentTimeMillis();
/*     */ 
/* 374 */       this. = createPolicyConfiguration();
/*     */ 
/* 376 */       deploy();
/*     */ 
/* 378 */       initializePersistenceUnits();
/*     */ 
/* 380 */       .debug("EJB3 deployment time took: " + (System.currentTimeMillis() - start));
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/*     */       try
/*     */       {
/* 386 */         destroy();
/*     */       }
/*     */       catch (Exception ignored)
/*     */       {
/*     */       }
/*     */ 
/* 392 */       throw e;
/*     */     }
/*     */   }
/*     */ 
/*     */   public void start() throws Exception
/*     */   {
/*     */     try
/*     */     {
/* 400 */       startPersistenceUnits();
/*     */ 
/* 402 */       for (Object o : this..values())
/*     */       {
/* 404 */         Container con = (Container)o;
/* 405 */         processEJBContainerMetadata(con);
/*     */       }
/*     */ 
/* 408 */       for (Object o : this..values())
/*     */       {
/* 410 */         Container con = (Container)o;
/* 411 */         registerEJBContainer(con);
/*     */       }
/*     */ 
/* 414 */       putJaccInService(this.this.);
/*     */     }
/*     */     catch (Exception ex)
/*     */     {
/*     */       try
/*     */       {
/* 420 */         stop();
/* 421 */         destroy();
/*     */       }
/*     */       catch (Exception ignored)
/*     */       {
/*     */       }
/* 426 */       throw ex;
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void deploy() throws Exception
/*     */   {
/* 432 */     Ejb3HandlerFactory factory = Ejb3HandlerFactory.getInstance(this);
/* 433 */     if (this..getUrl() != null) {
/* 434 */       deployUrl(factory);
/*     */     }
/* 436 */     if (this..getClasses() != null)
/*     */     {
/* 438 */       for (Class explicit : this..getClasses())
/*     */       {
/* 440 */         if (explicit.isAnnotationPresent(Entity.class))
/*     */         {
/*     */           continue;
/*     */         }
/* 444 */         String name = explicit.getName().replace('.''/') + ".class";
/* 445 */         InputStream stream = explicit.getClassLoader().getResourceAsStream(name);
/* 446 */         deployElement(streamfactorythis.);
/*     */       }
/*     */     }
/*     */ 
/* 450 */     deployBeansFromLib(this.);
/*     */   }
/*     */ 
/*     */   protected void deployUrl(Ejb3HandlerFactory factory)
/*     */     throws Exception
/*     */   {
/* 456 */     List clientDescriptors = this..getResources(new ClientDescriptorFileFilter());
/*     */ 
/* 458 */     if (clientDescriptors.size() > 0) {
/* 459 */       return;
/*     */     }
/* 461 */     InitialContext ctx = this.;
/*     */ 
/* 464 */     List classes = this..getResources(new ClassFileFilter());
/* 465 */     for (VirtualFile classFile : classes)
/*     */     {
/* 467 */       InputStream stream = classFile.openStream();
/* 468 */       deployElement(streamfactoryctx);
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void deployElement(InputStream streamEjb3HandlerFactory factoryInitialContext ctxthrows Exception
/*     */   {
/* 474 */     DataInputStream dstream = new DataInputStream(new BufferedInputStream(stream));
/* 475 */     ClassFile cf = null;
/*     */     try
/*     */     {
/* 478 */       cf = new ClassFile(dstream);
/*     */     }
/*     */     finally
/*     */     {
/* 482 */       dstream.close();
/* 483 */       stream.close();
/*     */     }
/*     */ 
/* 486 */     deployElement(factorycfctx);
/*     */   }
/*     */ 
/*     */   protected void deployBeansFromLib(InitialContext ctx)
/*     */     throws Exception
/*     */   {
/* 492 */     JBossMetaData dd = getMetaData();
/* 493 */     if (dd != null)
/*     */     {
/* 495 */       Ejb3DescriptorHandler handler = new Ejb3DescriptorHandler(thisdd);
/* 496 */       handler.setCtxProperties(this..getJndiProperties());
/*     */ 
/* 498 */       Map localContainers = new HashMap();
/* 499 */       Iterator containerIterator = this..values().iterator();
/* 500 */       while (containerIterator.hasNext())
/*     */       {
/* 502 */         Container container = (Container)containerIterator.next();
/* 503 */         localContainers.put(container.getEjbName(), container);
/*     */       }
/*     */ 
/* 506 */       List containers = handler.getContainers(thislocalContainers);
/* 507 */       for (Container con : containers)
/*     */       {
/* 512 */         ((EJBContainer)con).instantiated();
/* 513 */         this..put(con.getObjectName(), con);
/* 514 */         Ejb3Registry.register(con);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void deployElement(Ejb3HandlerFactory factory, ClassFile cfInitialContext ctxthrows Exception
/*     */   {
/* 521 */     Ejb3Handler handler = factory.createHandler(cf);
/* 522 */     handler.setCtxProperties(this..getJndiProperties());
/*     */ 
/* 524 */     if ((handler.isEjb()) || (handler.isJBossBeanType()))
/*     */     {
/* 526 */       List containers = handler.getContainers(cfthis);
/* 527 */       for (Container con : containers)
/*     */       {
/*     */         try
/*     */         {
/* 534 */           ((EJBContainer)con).instantiated();
/* 535 */           this..put(con.getObjectName(), con);
/* 536 */           Ejb3Registry.register(con);
/*     */         }
/*     */         catch (Throwable t)
/*     */         {
/* 540 */           throw new DeploymentException("Error creating ejb container " + con.getEjbName() + ": " + t.getMessage(), t);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void initializePersistenceUnits()
/*     */     throws Exception
/*     */   {
/* 549 */     this. = (this. != null);
/*     */ 
/* 551 */     if (!this.) {
/* 552 */       return;
/*     */     }
/* 554 */     if (this..getClasses() != null)
/*     */     {
/* 556 */       for (Class explicit : this..getClasses())
/*     */       {
/* 558 */         if (explicit.isAnnotationPresent(Entity.class))
/*     */         {
/* 560 */           this..add(explicit.getName());
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 567 */     for (PersistenceUnitMetaData persistenceUnitMetaData : this.)
/*     */     {
/* 569 */       PersistenceMetadata metadata = persistenceUnitMetaData.getLegacyMetadata();
/*     */ 
/* 571 */       String earShortName = this. == null ? null : this..getShortName();
/* 572 */       boolean isScoped = this..size() > 0;
/*     */ 
/* 575 */       String cache_prefix = metadata.getProps().getProperty("hibernate.cache.region_prefix");
/* 576 */       if (cache_prefix == null)
/*     */       {
/* 580 */         String jarName = isScoped ? this..getShortName() : null;
/* 581 */         cache_prefix = SecondLevelCacheUtil.createCacheRegionPrefix(earShortNamejarNamemetadata.getName());
/* 582 */         metadata.getProps().setProperty("hibernate.cache.region_prefix"cache_prefix);
/*     */       }
/* 584 */       PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(this.thisthis.persistenceUnitMetaDataearShortNamethis..getShortName(), isScoped);
/*     */ 
/* 586 */       PersistenceUnitRegistry.register(deployment);
/* 587 */       this..add(deployment);
/*     */     }
/*     */   }
/*     */ 
/*     */   public abstract DependencyPolicy createDependencyPolicy(JavaEEComponent paramJavaEEComponent);
/*     */ 
/*     */   protected void startPersistenceUnits() {
/* 595 */     if (this. == null) {
/* 596 */       return;
/*     */     }
/* 598 */     for (PersistenceUnitDeployment entityDeployment : this.)
/*     */     {
/* 600 */       if (entityDeployment != null)
/*     */       {
/* 602 */         DependencyPolicy policy = createDependencyPolicy(entityDeployment);
/* 603 */         entityDeployment.addDependencies(policy);
/* 604 */         this..install(entityDeployment.getKernelName(), policyentityDeployment);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void stopPersistenceUnits()
/*     */   {
/* 611 */     if (this. == null) {
/* 612 */       return;
/*     */     }
/* 614 */     for (PersistenceUnitDeployment entityDeployment : this.)
/*     */     {
/*     */       try
/*     */       {
/* 618 */         PersistenceUnitRegistry.unregister(entityDeployment);
/* 619 */         if (entityDeployment != null)
/*     */         {
/* 621 */           this..uninstall(entityDeployment.getKernelName());
/*     */         }
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 626 */         .debug("error trying to shut down persistence unit"e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public void stop()
/*     */     throws Exception
/*     */   {
/* 634 */     for (ObjectName on : this..keySet())
/*     */     {
/*     */       try
/*     */       {
/* 638 */         this..unregisterMBean(on);
/* 639 */         this..uninstall(on.getCanonicalName());
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 643 */         .debug("error trying to shut down ejb container"e);
/*     */       }
/*     */     }
/* 646 */     stopPersistenceUnits();
/*     */   }
/*     */ 
/*     */   public void destroy() throws Exception
/*     */   {
/* 651 */     undeploy();
/*     */ 
/* 653 */     PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
/* 654 */     PolicyConfiguration pc = pcFactory.getPolicyConfiguration(getJaccContextId(), true);
/* 655 */     pc.delete();
/*     */   }
/*     */ 
/*     */   private void undeploy()
/*     */   {
/* 660 */     for (Container container : this..values())
/*     */     {
/* 662 */       Ejb3Registry.unregister(container);
/*     */     }
/*     */   }
/*     */ 
/*     */   public String resolveMessageDestination(String link)
/*     */   {
/* 724 */     return this..resolveMessageDestination(link);
/*     */   }
/*     */ 
/*     */   {
/* 729 */     return this.;
/*     */   }
/*     */ 
/*     */   public JBossMetaData getMetaData()
/*     */   {
/* 739 */     return this.;
/*     */   }
/*     */ 
/*     */   public String getName()
/*     */   {
/* 744 */     return this..getShortName();
/*     */   }
/*     */ 
/*     */   static
/*     */   {
/*  75 */      = Logger.getLogger(Ejb3Deployment.class);
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/jboss-embedded-all.jar
 * Qualified Name:     org.jboss.ejb3.Ejb3Deployment
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X