[jboss-cvs] JBossAS SVN: r75617 - in projects/ejb3/tags: jboss-ejb3-core-0.1.7 and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 10 07:46:35 EDT 2008


Author: wolfc
Date: 2008-07-10 07:46:34 -0400 (Thu, 10 Jul 2008)
New Revision: 75617

Added:
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/.settings/org.eclipse.jdt.core.prefs
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/pom.xml
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/EJBContainer.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/EJBRemoteHandler.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/InjectionContainer.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PcEncInjector.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PersistenceUnitHandler.java
Removed:
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/.settings/org.eclipse.jdt.core.prefs
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/pom.xml
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/EJBContainer.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/EJBRemoteHandler.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/InjectionContainer.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PcEncInjector.java
   projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PersistenceUnitHandler.java
Log:
[maven-release-plugin]  copy for tag jboss-ejb3-core-0.1.7

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7 (from rev 75587, projects/ejb3/trunk/core)

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/ejb3/trunk/core/.settings/org.eclipse.jdt.core.prefs	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/.settings/org.eclipse.jdt.core.prefs	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,5 +0,0 @@
-#Wed May 14 18:44:22 EDT 2008
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.source=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/.settings/org.eclipse.jdt.core.prefs (from rev 75612, projects/ejb3/trunk/core/.settings/org.eclipse.jdt.core.prefs)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/.settings/org.eclipse.jdt.core.prefs	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,5 @@
+#Mon Jun 16 11:22:19 CEST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/pom.xml	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,560 +0,0 @@
-<!--
-  vi:ts=2:sw=2:expandtab
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-  <!-- Parent -->
-  <parent>
-    <groupId>org.jboss.ejb3</groupId>
-    <artifactId>jboss-ejb3-build</artifactId>
-    <version>0.13.9</version>
-    <relativePath>../build/pom.xml</relativePath>
-  </parent>
-
-  <!-- POM Model Version -->
-  <modelVersion>4.0.0</modelVersion>
-
-  <!-- Artifact Information -->
-  <artifactId>jboss-ejb3-core</artifactId>
-  <packaging>jar</packaging>
-  <version>0.1.7-SNAPSHOT</version>
-  <name>JBoss EJB 3.0 Core</name>
-  <url>http://labs.jboss.com/jbossejb3</url>
-  <description>JBoss EJB 3.0 Core</description>
-
-  <repositories>
-    <!-- APIviz repository -->
-    <repository>
-      <id>apiviz.release</id>
-      <name>APIviz releases</name>
-      <url>http://apiviz.googlecode.com/svn/site/repo/mvn/release</url>
-      <releases>
-
-        <enabled>true</enabled>
-      </releases>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-    </repository>
-  </repositories>
-
-  <!-- Properties -->
-
-  <properties>
-    <version.org.jboss.jboss-as>5.0.0.Beta4</version.org.jboss.jboss-as>
-  </properties>
-
-  <!-- Build Information -->
-  <build>
-
-    <plugins>
-
-      <!-- Assembly Plugin -->
-      <plugin>
-        <artifactId>maven-assembly-plugin</artifactId>
-        <version>2.2-beta-1</version>
-        <executions>
-          <execution>
-            <id>make-assembly</id><!-- this is used for inheritance merges -->
-            <phase>package</phase>
-            <goals>
-              <goal>attached</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <!-- JBoss EJB3 Client JAR -->
-          <descriptors>
-            <descriptor>jboss-ejb3-client.xml</descriptor>
-          </descriptors>
-          <attach>true</attach>
-        </configuration>
-        <inherited>false</inherited>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-javadoc-plugin</artifactId>
-<!--
-        <executions>
-          <execution>
-            <id>attach-javadoc</id>
-            <phase>package</phase>
-            <goals>
-              <goal>jar</goal>
-            </goals>
-          </execution>
-        </executions>
--->
-        <configuration>
-          <doclet>net.gleamynode.apiviz.APIviz</doclet>
-          <docletArtifact>
-            <groupId>net.gleamynode.apiviz</groupId>
-            <artifactId>apiviz</artifactId>
-            <version>1.0.3</version>
-          </docletArtifact>
-<!--
-          <aggregate>true</aggregate>
-          <encoding>UTF-8</encoding>
-          <locale>en_US</locale>
--->
-        </configuration>
-      </plugin>
-
-    </plugins>
-
-  </build>
-
-  <!-- Dependencies -->
-
-  <dependencies>
-
-    <!-- Because AOP doesn't declare a proper dependency -->
-    <dependency>
-      <groupId>javassist</groupId>
-      <artifactId>javassist</artifactId>
-      <version>3.7.1.GA</version>
-    </dependency>
-
-    <dependency>
-      <groupId>javax.xml.soap</groupId>
-      <artifactId>saaj-api</artifactId>
-      <version>1.3</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>javax.mail</groupId>
-      <artifactId>mail</artifactId>
-      <version>1.4</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>jboss.jbossts</groupId>
-      <artifactId>jbossjta</artifactId>
-      <version>4.3.0.GA</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <!-- To actually run SimpleTransactionService -->
-    <dependency>
-      <groupId>jboss.jbossts</groupId>
-      <artifactId>jbossts-common</artifactId>
-      <version>4.3.0.GA</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate</artifactId>
-      <version>3.2.6.ga</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-annotations</artifactId>
-      <version>3.3.1.GA</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-entitymanager</artifactId>
-      <version>3.3.2.GA</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.metadata</groupId>
-      <artifactId>jboss-metadata</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss.javaee</groupId>
-          <artifactId>jboss-javaee</artifactId>
-        </exclusion>
-      </exclusions>      
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-spi</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.test</groupId>
-      <artifactId>jboss-test</artifactId>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>org.jboss.jbossas</groupId>
-      <artifactId>jboss-server-manager</artifactId>
-      <scope>test</scope>      
-    </dependency>  
-      
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-transaction-spi</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-vfs</artifactId>
-      <version>2.0.0.Beta13</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.naming</groupId>
-      <artifactId>jnpserver</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.aop</groupId>
-      <artifactId>jboss-aop</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>javassist</artifactId>
-        </exclusion>        
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-container</artifactId>
-        </exclusion>        
-      </exclusions>      
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.aop</groupId>
-      <artifactId>jboss-aop-aspects</artifactId>
-    </dependency>
-    
-    <!-- used in the basicbootstrap-beans.xml -->
-    <dependency>
-      <groupId>org.jboss.aop</groupId>
-      <artifactId>jboss-aop-deployer-jdk50</artifactId>
-      <version>2.0.0.CR10</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.cache</groupId>
-      <artifactId>jbosscache-core</artifactId>
-      <!-- not used anywhere else -->
-      <version>2.1.1.GA</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss.javaee</groupId>
-          <artifactId>jboss-javaee</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.aspects</groupId>
-      <artifactId>jboss-aspects-test</artifactId>
-      <version>1.0.0.Beta1</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.aspects</groupId>
-      <artifactId>jboss-remoting-aspects</artifactId>
-      <version>1.0.1.CR2</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.cluster</groupId>
-      <artifactId>jboss-ha-client</artifactId>
-      <version>1.1.0.CR1</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss.aspects</groupId>
-          <artifactId>jboss-remoting-aspects</artifactId>            
-        </exclusion>
-        <exclusion>
-          <groupId>jboss.remoting</groupId>
-          <artifactId>jboss-remoting</artifactId>            
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.aop</groupId>
-          <artifactId>jboss-aop</artifactId>            
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.cluster</groupId>
-      <artifactId>jboss-ha-server-api</artifactId>
-      <version>1.1.0.CR1</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>            
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.logging</groupId>
-          <artifactId>jboss-logging-spi</artifactId>            
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.cache</groupId>
-          <artifactId>jbosscache-core</artifactId>            
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.cache</groupId>
-          <artifactId>jbosscache-pojo</artifactId>            
-        </exclusion>
-        <exclusion>
-          <groupId>jgroups</groupId>
-          <artifactId>jgroups</artifactId>            
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-async</artifactId>
-      <version>0.1.1</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-cache</artifactId>
-      <version>0.13.0</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-common</artifactId>
-      <version>0.1.2</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-security</artifactId>
-      <version>0.13.0</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-ext-api</artifactId>
-      <version>0.4</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-ext-api-impl</artifactId>
-      <version>0.4</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-interceptors</artifactId>
-      <version>0.13.1</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-metadata</artifactId>
-      <version>0.12.1</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-test</artifactId>
-      <version>0.1.1</version>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>org.jboss.ejb3</groupId>
-      <artifactId>jboss-ejb3-transactions</artifactId>
-      <version>0.13.1</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.embedded</groupId>
-      <artifactId>jboss-embedded</artifactId>
-      <version>beta3</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.javaee</groupId>
-      <artifactId>jboss-ejb-api</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.javaee</groupId>
-      <artifactId>jboss-jacc-api</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.javaee</groupId>
-      <artifactId>jboss-jca-api</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.jboss.javaee</groupId>
-      <artifactId>jboss-jms-api</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.javaee</groupId>
-      <artifactId>jboss-servlet-api</artifactId>
-    </dependency>
-    
-    <!-- those needs to be removed - EJBTHREE-1340 -->
-    <dependency>
-      <groupId>org.jboss.jbossas</groupId>
-      <artifactId>jboss-as-main</artifactId>
-      <version>${version.org.jboss.jboss-as}</version>
-      <scope>provided</scope>
-    </dependency>     
-    <dependency>
-      <groupId>org.jboss.jbossas</groupId>
-      <artifactId>jboss-as-system</artifactId>
-      <version>${version.org.jboss.jboss-as}</version>
-      <scope>provided</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>javassist</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-aop-mc-int</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-container</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-deployers-impl</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-deployers-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.jbossas</groupId>
-      <artifactId>jboss-as-system-jmx</artifactId>
-      <version>${version.org.jboss.jboss-as}</version>
-      <scope>provided</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>javassist</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-aop-mc-int</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-container</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-deployers-impl</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-deployers-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.jbossas</groupId>
-      <artifactId>jboss-as-mbeans</artifactId>
-      <version>${version.org.jboss.jboss-as}</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-test</artifactId>
-        </exclusion>        
-      </exclusions>      
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.jbossas</groupId>
-      <artifactId>jboss-as-j2se</artifactId>
-      <version>${version.org.jboss.jboss-as}</version>
-      <scope>provided</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-container</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <!-- this needs to be removed - EJBTHREE-1343 -->
-    <dependency>
-      <groupId>org.jboss.jbossas</groupId>
-      <artifactId>jboss-as-server</artifactId>
-      <version>${version.org.jboss.jboss-as}</version>
-      <exclusions>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-remoting</artifactId>
-        </exclusion>        
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-metadata</artifactId>
-        </exclusion>        
-        <exclusion>
-          <groupId>org.jboss.jbossas</groupId>
-          <artifactId>jboss-as-security</artifactId>
-        </exclusion>        
-      </exclusions>      
-      <scope>provided</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.microcontainer</groupId>
-      <artifactId>jboss-deployers-core-spi</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.microcontainer</groupId>
-      <artifactId>jboss-kernel</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.security</groupId>
-      <artifactId>jboss-security-spi</artifactId>
-      <version>2.0.2.CR5</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.security</groupId>
-      <artifactId>jbosssx</artifactId>
-      <version>2.0.2.CR5</version>
-    </dependency>
-    
-     <dependency>
-      <groupId>org.jboss.ws</groupId>
-      <artifactId>jbossws-spi</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>quartz</groupId>
-      <artifactId>quartz</artifactId>
-      <version>1.6.0</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>trove</groupId>
-      <artifactId>trove</artifactId>
-    </dependency>
-    
-  </dependencies>
-</project>

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/pom.xml (from rev 75616, projects/ejb3/trunk/core/pom.xml)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/pom.xml	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/pom.xml	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,572 @@
+<!--
+  vi:ts=2:sw=2:expandtab
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <!-- Parent -->
+  <parent>
+    <groupId>org.jboss.ejb3</groupId>
+    <artifactId>jboss-ejb3-build</artifactId>
+    <version>0.13.9</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+
+  <!-- POM Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Information -->
+  <artifactId>jboss-ejb3-core</artifactId>
+  <packaging>jar</packaging>
+  <version>0.1.7</version>
+  <name>JBoss EJB 3.0 Core</name>
+  <url>http://labs.jboss.com/jbossejb3</url>
+  <description>JBoss EJB 3.0 Core</description>
+
+  <repositories>
+    <!-- APIviz repository -->
+    <repository>
+      <id>apiviz.release</id>
+      <name>APIviz releases</name>
+      <url>http://apiviz.googlecode.com/svn/site/repo/mvn/release</url>
+      <releases>
+
+        <enabled>true</enabled>
+      </releases>
+      <snapshots>
+        <enabled>false</enabled>
+      </snapshots>
+    </repository>
+  </repositories>
+
+  <!-- Properties -->
+
+  <properties>
+    <version.org.jboss.jboss-as>5.0.0.Beta4</version.org.jboss.jboss-as>
+  </properties>
+
+  <!-- Build Information -->
+  <build>
+
+    <plugins>
+
+      <!-- Assembly Plugin -->
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>2.2-beta-1</version>
+        <executions>
+          <execution>
+            <id>make-assembly</id><!-- this is used for inheritance merges -->
+            <phase>package</phase>
+            <goals>
+              <goal>attached</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <!-- JBoss EJB3 Client JAR -->
+          <descriptors>
+            <descriptor>jboss-ejb3-client.xml</descriptor>
+          </descriptors>
+          <attach>true</attach>
+        </configuration>
+        <inherited>false</inherited>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+<!--
+        <executions>
+          <execution>
+            <id>attach-javadoc</id>
+            <phase>package</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+-->
+        <configuration>
+          <doclet>net.gleamynode.apiviz.APIviz</doclet>
+          <docletArtifact>
+            <groupId>net.gleamynode.apiviz</groupId>
+            <artifactId>apiviz</artifactId>
+            <version>1.0.3</version>
+          </docletArtifact>
+<!--
+          <aggregate>true</aggregate>
+          <encoding>UTF-8</encoding>
+          <locale>en_US</locale>
+-->
+        </configuration>
+      </plugin>
+
+    </plugins>
+
+  </build>
+
+  <!-- Dependencies -->
+
+  <dependencies>
+
+    <!-- Because AOP doesn't declare a proper dependency -->
+    <dependency>
+      <groupId>javassist</groupId>
+      <artifactId>javassist</artifactId>
+      <version>3.7.1.GA</version>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.xml.soap</groupId>
+      <artifactId>saaj-api</artifactId>
+      <version>1.3</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+      <version>1.4</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>jboss.jbossts</groupId>
+      <artifactId>jbossjta</artifactId>
+      <version>4.3.0.GA</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <!-- To actually run SimpleTransactionService -->
+    <dependency>
+      <groupId>jboss.jbossts</groupId>
+      <artifactId>jbossts-common</artifactId>
+      <version>4.3.0.GA</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate</artifactId>
+      <version>3.2.6.ga</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-annotations</artifactId>
+      <version>3.3.1.GA</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-entitymanager</artifactId>
+      <version>3.3.2.GA</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.metadata</groupId>
+      <artifactId>jboss-metadata</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss.javaee</groupId>
+          <artifactId>jboss-javaee</artifactId>
+        </exclusion>
+      </exclusions>      
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.test</groupId>
+      <artifactId>jboss-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-server-manager</artifactId>
+      <scope>test</scope>      
+    </dependency>  
+      
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-transaction-spi</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-vfs</artifactId>
+      <version>2.0.0.Beta13</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.naming</groupId>
+      <artifactId>jnpserver</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.aop</groupId>
+      <artifactId>jboss-aop</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>javassist</artifactId>
+        </exclusion>        
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-container</artifactId>
+        </exclusion>        
+      </exclusions>      
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.aop</groupId>
+      <artifactId>jboss-aop-aspects</artifactId>
+    </dependency>
+    
+    <!-- used in the basicbootstrap-beans.xml -->
+    <dependency>
+      <groupId>org.jboss.aop</groupId>
+      <artifactId>jboss-aop-deployer-jdk50</artifactId>
+      <version>2.0.0.CR10</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.cache</groupId>
+      <artifactId>jbosscache-core</artifactId>
+      <!-- not used anywhere else -->
+      <version>2.1.1.GA</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss.javaee</groupId>
+          <artifactId>jboss-javaee</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.aspects</groupId>
+      <artifactId>jboss-aspects-test</artifactId>
+      <version>1.0.0.Beta1</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.aspects</groupId>
+      <artifactId>jboss-remoting-aspects</artifactId>
+      <version>1.0.1.CR2</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.cluster</groupId>
+      <artifactId>jboss-ha-client</artifactId>
+      <version>1.1.0.CR1</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss.aspects</groupId>
+          <artifactId>jboss-remoting-aspects</artifactId>            
+        </exclusion>
+        <exclusion>
+          <groupId>jboss.remoting</groupId>
+          <artifactId>jboss-remoting</artifactId>            
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.aop</groupId>
+          <artifactId>jboss-aop</artifactId>            
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.cluster</groupId>
+      <artifactId>jboss-ha-server-api</artifactId>
+      <version>1.1.0.CR1</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>            
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.logging</groupId>
+          <artifactId>jboss-logging-spi</artifactId>            
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.cache</groupId>
+          <artifactId>jbosscache-core</artifactId>            
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.cache</groupId>
+          <artifactId>jbosscache-pojo</artifactId>            
+        </exclusion>
+        <exclusion>
+          <groupId>jgroups</groupId>
+          <artifactId>jgroups</artifactId>            
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-async</artifactId>
+      <version>0.1.1</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-cache</artifactId>
+      <version>0.13.0</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-common</artifactId>
+      <version>0.1.2</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-security</artifactId>
+      <version>0.13.0</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-ext-api</artifactId>
+      <version>0.4</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-ext-api-impl</artifactId>
+      <version>0.4</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-interceptors</artifactId>
+      <version>0.13.1</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-metadata</artifactId>
+      <version>0.12.1</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-test</artifactId>
+      <version>0.1.1</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jboss.ejb3</groupId>
+      <artifactId>jboss-ejb3-transactions</artifactId>
+      <version>0.13.1</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.embedded</groupId>
+      <artifactId>jboss-embedded</artifactId>
+      <version>beta3</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.javaee</groupId>
+      <artifactId>jboss-ejb-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.javaee</groupId>
+      <artifactId>jboss-jacc-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.javaee</groupId>
+      <artifactId>jboss-jca-api</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jboss.javaee</groupId>
+      <artifactId>jboss-jms-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.javaee</groupId>
+      <artifactId>jboss-servlet-api</artifactId>
+    </dependency>
+    
+    <!-- those needs to be removed - EJBTHREE-1340 -->
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-main</artifactId>
+      <version>${version.org.jboss.jboss-as}</version>
+      <scope>provided</scope>
+    </dependency>     
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-system</artifactId>
+      <version>${version.org.jboss.jboss-as}</version>
+      <scope>provided</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>javassist</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-aop-mc-int</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-container</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-deployers-impl</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-deployers-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-system-jmx</artifactId>
+      <version>${version.org.jboss.jboss-as}</version>
+      <scope>provided</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>javassist</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-aop-mc-int</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-container</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-deployers-impl</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-deployers-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-mbeans</artifactId>
+      <version>${version.org.jboss.jboss-as}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-test</artifactId>
+        </exclusion>        
+      </exclusions>      
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-j2se</artifactId>
+      <version>${version.org.jboss.jboss-as}</version>
+      <scope>provided</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-container</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <!-- this needs to be removed - EJBTHREE-1343 -->
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-server</artifactId>
+      <version>${version.org.jboss.jboss-as}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-remoting</artifactId>
+        </exclusion>        
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-metadata</artifactId>
+        </exclusion>        
+        <exclusion>
+          <groupId>org.jboss.jbossas</groupId>
+          <artifactId>jboss-as-security</artifactId>
+        </exclusion>        
+      </exclusions>      
+      <scope>provided</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.jpa</groupId>
+      <artifactId>jboss-jpa-deployers</artifactId>
+      <version>0.1.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-deployers-core-spi</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.security</groupId>
+      <artifactId>jboss-security-spi</artifactId>
+      <version>2.0.2.CR5</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.security</groupId>
+      <artifactId>jbosssx</artifactId>
+      <version>2.0.2.CR5</version>
+    </dependency>
+    
+     <dependency>
+      <groupId>org.jboss.ws</groupId>
+      <artifactId>jbossws-spi</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>quartz</groupId>
+      <artifactId>quartz</artifactId>
+      <version>1.6.0</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>trove</groupId>
+      <artifactId>trove</artifactId>
+    </dependency>
+    
+  </dependencies>
+
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/tags/jboss-ejb3-core-0.1.7</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/ejb3/tags/jboss-ejb3-core-0.1.7</developerConnection>
+    <url>http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/tags/jboss-ejb3-core-0.1.7</url>
+  </scm>
+</project>

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/EJBContainer.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,1502 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.EJBContext;
-import javax.ejb.EJBException;
-import javax.ejb.Local;
-import javax.ejb.Remote;
-import javax.ejb.TimedObject;
-import javax.ejb.Timeout;
-import javax.ejb.Timer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.LinkRef;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.Domain;
-import org.jboss.aop.MethodInfo;
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.annotation.AnnotationRepository;
-import org.jboss.aop.joinpoint.ConstructionInvocation;
-import org.jboss.aop.util.MethodHashing;
-import org.jboss.ejb3.annotation.Clustered;
-import org.jboss.ejb3.annotation.SecurityDomain;
-import org.jboss.ejb3.annotation.defaults.PoolDefaults;
-import org.jboss.ejb3.aop.BeanContainer;
-import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
-import org.jboss.ejb3.interceptor.InterceptorInjector;
-import org.jboss.ejb3.interceptors.aop.LifecycleCallbacks;
-import org.jboss.ejb3.interceptors.container.ManagedObjectAdvisor;
-import org.jboss.ejb3.interceptors.direct.DirectContainer;
-import org.jboss.ejb3.interceptors.direct.IndirectContainer;
-import org.jboss.ejb3.javaee.JavaEEComponent;
-import org.jboss.ejb3.javaee.JavaEEComponentHelper;
-import org.jboss.ejb3.javaee.JavaEEModule;
-import org.jboss.ejb3.pool.Pool;
-import org.jboss.ejb3.pool.PoolFactory;
-import org.jboss.ejb3.pool.PoolFactoryRegistry;
-import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
-import org.jboss.ejb3.security.SecurityDomainManager;
-import org.jboss.ejb3.statistics.InvocationStatistics;
-import org.jboss.ejb3.tx.UserTransactionImpl;
-import org.jboss.injection.DependsHandler;
-import org.jboss.injection.EJBHandler;
-import org.jboss.injection.EncInjector;
-import org.jboss.injection.InjectionContainer;
-import org.jboss.injection.InjectionHandler;
-import org.jboss.injection.InjectionUtil;
-import org.jboss.injection.Injector;
-import org.jboss.injection.JndiInjectHandler;
-import org.jboss.injection.PersistenceContextHandler;
-import org.jboss.injection.PersistenceUnitHandler;
-import org.jboss.injection.ResourceHandler;
-import org.jboss.injection.WebServiceRefHandler;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorsMetaData;
-import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
-import org.jboss.metadata.javaee.spec.Environment;
-import org.jboss.metadata.javaee.spec.ServiceReferenceMetaData;
-import org.jboss.util.StringPropertyReplacer;
-import org.jboss.util.naming.Util;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public abstract class EJBContainer implements Container, IndirectContainer<EJBContainer, DirectContainer<EJBContainer>>, InjectionContainer, JavaEEComponent
-{
-   private static final Logger log = Logger.getLogger(EJBContainer.class);
-
-   private String name;
-   
-   private BeanContainer beanContainer;
-   
-   private DirectContainer<EJBContainer> directContainer;
-   
-   protected EjbEncFactory encFactory = new DefaultEjbEncFactory();
-
-   protected Pool pool;
-
-   protected String ejbName;
-
-   protected ObjectName objectName;
-
-   protected int defaultConstructorIndex;
-
-   protected String beanClassName;
-   
-   private Class<?> beanClass;
-
-   protected ClassLoader classloader;
-
-   // for performance there is an array.
-   protected List<Injector> injectors = new ArrayList<Injector>();
-
-   protected Context enc;
-
-//   protected LifecycleInterceptorHandler callbackHandler;
-
-   protected Hashtable initialContextProperties;
-
-   protected Map<String, EncInjector> encInjectors = new HashMap<String, EncInjector>();
-
-   protected JBossEnterpriseBeanMetaData xml;
-   protected JBossAssemblyDescriptorMetaData assembly;
-
-   protected Map<String, Map<AccessibleObject, Injector>> encInjections = new HashMap<String, Map<AccessibleObject, Injector>>();
-
-//   protected List<InterceptorInfo> classInterceptors = new ArrayList<InterceptorInfo>();
-//
-//   protected LinkedHashSet<InterceptorInfo> applicableInterceptors;
-
-   private HashMap<Class<?>, InterceptorInjector> interceptorInjectors = new HashMap<Class<?>, InterceptorInjector>();
-
-   private Ejb3Deployment deployment;
-
-   private DependencyPolicy dependencyPolicy;
-
-   private String jaccContextId;
-
-   protected HashMap invokedMethod = new HashMap();
-
-   protected InvocationStatistics invokeStats = new InvocationStatistics();
-   
-   private String partitionName;
-   
-   private List<Class<?>> businessInterfaces;
-   
-   private ThreadLocalStack<BeanContext<?>> currentBean = new ThreadLocalStack<BeanContext<?>>();
-   
-   protected boolean reinitialize = false;
-   
-   /**
-    * @param name                  Advisor name
-    * @param manager               Domain to get interceptor bindings from
-    * @param cl                    the EJB's classloader
-    * @param beanClassName
-    * @param ejbName
-    * @param ctxProperties
-    * @param interceptorRepository
-    * @param deployment
-    * @param beanMetaData           the meta data for this bean or null
-    */
-
-   public EJBContainer(String name, Domain domain, ClassLoader cl,
-                       String beanClassName, String ejbName, Hashtable ctxProperties,
-                       Ejb3Deployment deployment, JBossEnterpriseBeanMetaData beanMetaData) throws ClassNotFoundException
-   {
-      assert name != null : "name is null";
-      assert deployment != null : "deployment is null";
-      
-      this.name = name;
-      this.deployment = deployment;
-      this.beanClassName = beanClassName;
-      this.classloader = cl;
-      this.xml = beanMetaData;
-         
-      this.beanClass = classloader.loadClass(beanClassName);
-      
-      // We can't type cast the direct container, because we just loaded the beanClass
-      // so assuming we have an object is a safe bet.
-      this.beanContainer = new BeanContainer(this);
-      
-      this.ejbName = ejbName;
-      
-      // Because interceptors will query back the EJBContainer for annotations
-      // we must have set beanContainer first and then do the advisor. 
-      try
-      {
-         beanContainer.initialize(ejbName, domain, beanClass, beanMetaData, cl); 
-      }
-      catch(Exception e)
-      {
-         throw new RuntimeException("failed to initialize bean container ",e);
-      }
-      String on = createObjectName(ejbName);
-     
-      try
-      {
-         objectName = new ObjectName(on);
-      }
-      catch (MalformedObjectNameException e)
-      {
-         throw new RuntimeException("failed to create object name for: " + on, e);
-      }
-      
-      //annotations = new AnnotationRepositoryToMetaData(this);
-      
-      initialContextProperties = ctxProperties;
-      try
-      {
-         Util.createSubcontext(getEnc(), "env");
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-      bindORB();
-      bindEJBContext();
-      
-      this.dependencyPolicy = deployment.createDependencyPolicy(this);
-   }
-
-   private void bindEJBContext()
-   {
-      try 
-      {
-         Reference ref = new Reference(EJBContext.class.getName(), EJBContextFactory.class.getName(), null);
-         ref.add(new StringRefAddr("containerGuid", Ejb3Registry.guid(this)));
-         ref.add(new StringRefAddr("containerClusterUid", Ejb3Registry.clusterUid(this)));
-         ref.add(new StringRefAddr("isClustered", Boolean.toString(isClustered())));
-         Util.rebind(getEnc(), "EJBContext", ref);
-      }
-      catch (NamingException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   private void bindORB()
-   {
-      try
-      {
-         Util.rebind(getEnc(), "ORB", new LinkRef("java:/JBossCorbaORB"));
-      }
-      catch(NamingException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   public abstract BeanContext<?> createBeanContext();
-   
-   public String createObjectName(String ejbName)
-   {
-      return JavaEEComponentHelper.createObjectName(deployment, ejbName);
-   }
-   
-   /**
-    * Do not call, for BeanContainer.
-    * @throws IllegalAccessException 
-    * @throws InstantiationException 
-    */
-   public Object createInterceptor(Class<?> interceptorClass) throws InstantiationException, IllegalAccessException
-   {
-      Object instance = interceptorClass.newInstance();
-      InterceptorInjector interceptorInjector = interceptorInjectors.get(interceptorClass);
-      assert interceptorInjector != null : "interceptorInjector not found for " + interceptorClass;
-      interceptorInjector.inject(null, instance);
-      return instance;
-   }
-   
-   public String createObjectName(String unitName, String ejbName)
-   {
-      return JavaEEComponentHelper.createObjectName(deployment, unitName, ejbName);
-   }
-   
-   // TODO: re-evaluate this exposure
-   @Deprecated
-   public Advisor getAdvisor()
-   {
-      return beanContainer._getAdvisor();
-   }
-
-   /*
-    * TODO: re-evalute this exposure
-    */
-   @Deprecated
-   public AnnotationRepository getAnnotations()
-   {
-      return beanContainer.getAnnotationRepository();
-   }
-
-   protected BeanContainer getBeanContainer()
-   {
-      return beanContainer;
-   }
-   
-   /**
-    * 
-    * @return   the bean class of this container
-    * @deprecated   use getBeanClass
-    */
-   public Class<?> getClazz()
-   {
-      return getBeanClass();
-   }
-   
-   @SuppressWarnings("unchecked")
-   public static <C extends EJBContainer> C getEJBContainer(Advisor advisor)
-   {
-      try
-      {
-         return (C) ((ManagedObjectAdvisor<Object, BeanContainer>) advisor).getContainer().getEJBContainer();
-      }
-      catch(ClassCastException e)
-      {
-         throw new ClassCastException(e.getMessage() + " using " + advisor);
-      }
-   }
-   
-   public String getName()
-   {
-      return name;
-   }
-   
-   public void pushContext(BeanContext<?> beanContext)
-   {
-      currentBean.push(beanContext);
-   }
-   
-   /**
-    * Makes sure that EJB's ENC is available
-    * Delegates to whatever implementation is used to push the ENC of the EJB
-    * onto the stack
-    *
-    */
-   protected void pushEnc()
-   {
-      encFactory.pushEnc(this);
-   }
-
-   public BeanContext<?> peekContext()
-   {
-      BeanContext<?> ctx = currentBean.get();
-      assert ctx != null : "ctx is null";
-      return ctx;
-   }
-   
-   public BeanContext<?> popContext()
-   {
-      return currentBean.pop();
-   }
-   
-   /**
-    * Pops EJB's ENC from the stack.  Delegates to whatever implementation
-    * is used to pop the EJB's ENC from the stock
-    *
-    */
-   protected void popEnc()
-   {
-      encFactory.popEnc(this);
-   }
-   
-   public Environment getEnvironmentRefGroup()
-   {
-      return xml;
-   }
-
-   public List<Injector> getInjectors()
-   {
-      return injectors;
-   }
-
-
-   public String getJaccContextId()
-   {
-      return jaccContextId;
-   }
-
-   /**
-    * Do not call, used by BeanContainer.
-    * @return
-    */
-   public List<Method> getVirtualMethods()
-   {
-      return null;
-   }
-   
-   public void setJaccContextId(String jaccContextId)
-   {
-      this.jaccContextId = jaccContextId;
-   }
-   
-   public VirtualFile getRootFile()
-   {
-      return getDeploymentUnit().getRootFile();
-   }
-   
-   /**
-    * Return all the business interfaces implemented by this bean.
-    * 
-    * Available after the meta data has been processed.
-    * 
-    * @return   an array of business interfaces or empty if no interface is provided
-    */
-   public List<Class<?>> getBusinessInterfaces()
-   {
-      if(businessInterfaces == null) throw new IllegalStateException("businessInterfaces not yet initialized");
-      return businessInterfaces;
-   }
-      
-   public String getDeploymentQualifiedName()
-   {
-      return objectName.getCanonicalName();
-   }
-   
-   /**
-    * Returns a String identifier for this bean that is qualified by the
-    * deployment, and hence should be unique across deployments. Name is of the 
-    * form "ear=foo.ear,jar=foo.jar,name=Bar", where "Bar" is the value 
-    * returned by {@link #getEjbName()}. The "ear=foo.ear" portion is ommitted 
-    * if the bean is not packaged in an ear.
-    */
-   public String getDeploymentPropertyListString()
-   {
-      return objectName.getCanonicalKeyPropertyListString();
-   }
-   
-   public DeploymentUnit getDeploymentUnit()
-   {
-      return deployment.getDeploymentUnit();
-   }
-
-   public Ejb3Deployment getDeployment()
-   {
-      return deployment;
-   }
-
-   public DependencyPolicy getDependencyPolicy()
-   {
-      return dependencyPolicy;
-   }
-
-   public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
-   {
-      return beanContainer.isAnnotationPresent(annotationType);
-   }
-   
-   /**
-    * Is the method a business method of this container.
-    * 
-    * @param businessMethod     the method in question
-    * @return   true if so, otherwise false
-    */
-   public boolean isBusinessMethod(Method businessMethod)
-   {
-      for(Class<?> businessInterface : getBusinessInterfaces())
-      {
-         for(Method method : businessInterface.getMethods())
-         {
-            if(isCallable(method, businessMethod))
-               return true;
-         }
-      }
-      return false;
-   }
-   
-   /**
-    * Can method definition method be used to call method other.
-    * For example if the method is defined in an interface it can be used to call a method
-    * in a class.
-    * 
-    * @param method
-    * @param other
-    * @return
-    */
-   private static boolean isCallable(Method method, Method other)
-   {
-      if ((method.getDeclaringClass().isAssignableFrom(other.getDeclaringClass())) && (method.getName().equals(other.getName())))
-      {
-         if (!method.getReturnType().equals(other.getReturnType()))
-            return false;
-         Class<?>[] params1 = method.getParameterTypes();
-         Class<?>[] params2 = other.getParameterTypes();
-         if (params1.length == params2.length)
-         {
-            for (int i = 0; i < params1.length; i++)
-            {
-               if (params1[i] != params2[i])
-                  return false;
-            }
-            return true;
-         }
-      }
-      return false;
-   }   
-   
-   /**
-    * introspects EJB container to find all dependencies
-    * and initialize any extra metadata.
-    * <p/>
-    * This must be called before container is registered with any microcontainer
-    *
-    * @param dependencyPolicy
-    */
-   public void processMetadata()
-   {
-      // XML must be done first so that any annotation overrides are initialized
-      
-      // todo injection handlers should be pluggable from XML
-      Collection<InjectionHandler<Environment>> handlers = this.deployment.getHandlers();
-      if(handlers == null)
-      {
-         handlers = new ArrayList<InjectionHandler<Environment>>();
-         handlers.add(new EJBHandler<Environment>());
-         handlers.add(new DependsHandler<Environment>());
-         handlers.add(new JndiInjectHandler<Environment>());
-         handlers.add(new PersistenceContextHandler<Environment>());
-         handlers.add(new PersistenceUnitHandler<Environment>());
-         handlers.add(new ResourceHandler<Environment>());
-         handlers.add(new WebServiceRefHandler<Environment>());
-      }
-
-      ClassLoader old = Thread.currentThread().getContextClassLoader();
-      Thread.currentThread().setContextClassLoader(classloader);
-      try
-      {
-         // EJB container's XML must be processed before interceptor's as it may override interceptor's references
-         for (InjectionHandler<Environment> handler : handlers) handler.loadXml(xml, this);
-
-         Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(this, handlers, getBeanClass());
-         injectors.addAll(tmp.values());
-
-         /*
-         initialiseInterceptors();
-         */
-         for (Class<?> interceptorClass : beanContainer.getInterceptorClasses())
-         {
-            InterceptorMetaData interceptorMetaData = findInterceptor(interceptorClass);
-            if(interceptorMetaData == null)
-               continue;
-            
-            for (InjectionHandler<Environment> handler : handlers)
-            {
-               handler.loadXml(interceptorMetaData, this);
-            }
-         }
-         for (Class<?> interceptorClass : beanContainer.getInterceptorClasses())
-         {
-            Map<AccessibleObject, Injector> injections = InjectionUtil.processAnnotations(this, handlers, interceptorClass);
-            InterceptorInjector injector = new InterceptorInjector(injections);
-            interceptorInjectors.put(interceptorClass, injector);
-         }
-
-         // When @WebServiceRef is not used service-ref won't be processed
-         // In this case we process them late
-         if(xml != null && xml.getServiceReferences() != null)
-         {
-            for(ServiceReferenceMetaData sref : xml.getServiceReferences())
-            {
-               // FIXME: fix WS metadata
-               /*
-               if(!sref.isProcessed())
-               {
-                  try
-                  {
-                     String name = sref.getServiceRefName();
-                     String encName = "env/" + name;
-                     Context encCtx = getEnc();
-
-                     UnifiedVirtualFile vfsRoot = new VirtualFileAdaptor(getRootFile());
-                     new ServiceRefDelegate().bindServiceRef(encCtx, encName, vfsRoot, getClassloader(), sref);
-
-                  }
-                  catch (Exception e)
-                  {
-                     log.error("Failed to bind service-ref", e);
-                  }
-               }
-               */
-            }
-         }
-         
-         // EJBTHREE-1025
-         this.checkForDuplicateLocalAndRemoteInterfaces();
-         
-         for(Class<?> businessInterface : getBusinessInterfaces())
-            ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(businessInterface);
-         
-         Class localHomeInterface = ProxyFactoryHelper.getLocalHomeInterface(this);
-         if(localHomeInterface != null)
-            ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(localHomeInterface);
-         
-         Class remoteHomeInterface = ProxyFactoryHelper.getRemoteHomeInterface(this);
-         if(remoteHomeInterface != null)
-            ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(remoteHomeInterface);
-      }
-      finally
-      {
-         Thread.currentThread().setContextClassLoader(old);
-      }
-   }
-   
-   /**
-    * Ensures that the bean does not implement any one interface as both @Local and @Remote
-    *
-    * @throws EJBException If the bean does implements any one interface as both @Local and @Remote
-    */
-   protected void checkForDuplicateLocalAndRemoteInterfaces() throws EJBException
-   {
-      // Initialize issue used in Error Message
-      String issue = "(EJBTHREE-1025)";
-
-      // Obtain annotations, if found
-      Local local = (Local) resolveAnnotation(Local.class);
-      Remote remote = (Remote) resolveAnnotation(Remote.class);
-
-      // If either local or remote is unspecified, return safely - there can be no overlap
-      if (local == null || remote == null)
-      {
-         return;
-      }
-
-      // Ensure "value" attribute of both local and remote are not blank
-      if (local.value().length < 1 && local.value().length < 1)
-      {
-         throw new EJBException("Cannot designate both " + Local.class.getName() + " and " + Remote.class.getName()
-               + " annotations without 'value' attribute on " + this.getEjbName() + ". " + issue);
-      }
-
-      // Iterate through local and remote interfaces, ensuring any one interface is not being used for both local and remote exposure
-      for (Class<?> localClass : local.value())
-      {
-         for (Class<?> remoteClass : remote.value())
-         {
-            if (localClass.equals(remoteClass))
-            {
-               throw new EJBException("Cannot designate " + localClass.getName() + " as both " + Local.class.getName()
-                     + " and " + Remote.class.getName() + " on " + this.getEjbName() + ". " + issue);
-            }
-         }
-      }
-   }
-
-   public JBossEnterpriseBeanMetaData getXml()
-   {
-      return xml;
-   }
-
-   public JBossAssemblyDescriptorMetaData getAssemblyDescriptor()
-   {
-      return assembly;
-   }
-
-   // FIXME: remove
-   @Deprecated
-   public void setAssemblyDescriptor(JBossAssemblyDescriptorMetaData assembly)
-   {
-      this.assembly = assembly;
-   }
-
-   protected abstract List<Class<?>> resolveBusinessInterfaces();
-   
-   public InterceptorInfoRepository getInterceptorRepository()
-   {
-      throw new RuntimeException("invalid");
-   }
-   
-   public Map<String, EncInjector> getEncInjectors()
-   {
-      return encInjectors;
-   }
-
-   public ClassLoader getClassloader()
-   {
-      return classloader;
-   }
-
-   public InitialContext getInitialContext()
-   {
-      try
-      {
-         return InitialContextFactory.getInitialContext(initialContextProperties);
-      }
-      catch (NamingException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
-   public Map<String, Map<AccessibleObject, Injector>> getEncInjections()
-   {
-      return encInjections;
-   }
-
-   public Context getEnc()
-   {
-      if (enc == null)
-      {
-         enc = encFactory.getEnc(this);
-      }
-      return enc;
-   }
-
-   public Hashtable getInitialContextProperties()
-   {
-      return initialContextProperties;
-   }
-
-   public ObjectName getObjectName()
-   {
-      return objectName;
-   }
-
-   public String getEjbName()
-   {
-      return ejbName;
-   }
-
-   public String getBeanClassName()
-   {
-      return beanClassName;
-   }
-
-   public Class<?> getBeanClass()
-   {
-      return beanClass;
-   }
-
-   public Pool getPool()
-   {
-      return pool;
-   }
-   
-   /**
-    * Gets the name of the cluster partition with which this container is
-    * associated. Not available until <code>EJBContainer.start()</code>
-    * is completed.
-    * 
-    * @return the name of the cluster partition with which this container is
-    *         associated, or <code>null</code> if the container is not clustered
-    */
-   public String getPartitionName()
-   {
-      if (partitionName == null)
-         this.findPartitionName();
-      return partitionName;
-   }
-
-   protected Object construct()
-   {
-      /*
-      try
-      {
-         return beanContainer.construct();
-      }
-      catch (SecurityException e)
-      {
-         throw new RuntimeException(e);
-      }
-      catch (NoSuchMethodException e)
-      {
-         throw new RuntimeException(e);
-      }
-      */
-      try
-      {
-         return beanClass.newInstance();
-      }
-      catch (InstantiationException e)
-      {
-         throw new RuntimeException(e);
-      }
-      catch (IllegalAccessException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   protected void reinitialize()
-   {
-      // FIXME: is this correct?
-      beanContainer.reinitializeAdvisor();
-      
-      /*
-      initClassMetaDataBindingsList();
-      adviceBindings.clear();
-      doesHaveAspects = false;
-      constructorInfos = null;
-      rebuildInterceptors();
-      */
-      
-      bindEJBContext();
-      
-      reinitialize = false;
-   }
-
-   public void create() throws Exception
-   {
-      /*
-      initializeClassContainer();
-      for (int i = 0; i < constructors.length; i++)
-      {
-         if (constructors[i].getParameterTypes().length == 0)
-         {
-            defaultConstructorIndex = i;
-            break;
-         }
-      }
-      */
-   }
-
-   // Everything must be done in start to make sure all dependencies have been satisfied
-   public void start() throws Exception
-   {
-      if (reinitialize)
-         reinitialize();
-       
-      initializePool();
-
-      for (EncInjector injector : encInjectors.values())
-      {
-         injector.inject(this);   
-      }
-      
-      // creating of injector array should come after injection into ENC as an ENC injector
-      // may add additional injectors into the injector list.  An example is an extended persistence
-      // context which mush be created and added to the SFSB bean context.
-
-      Injector[] injectors2 = injectors.toArray(new Injector[injectors.size()]);
-      if (pool != null) pool.setInjectors(injectors2);
-
-//      createCallbackHandler();
-      
-      // If we're clustered, find our partition name
-      findPartitionName();
-      
-      log.info("STARTED EJB: " + beanClass.getName() + " ejbName: " + ejbName);
-   }
-
-   public void stop() throws Exception
-   {
-      reinitialize = true;
-      
-      //encFactory.cleanupEnc(this);
-      
-      if (pool != null)
-      {
-         pool.destroy();
-         pool = null;
-      }
-      
-      injectors = new ArrayList<Injector>();
-      encInjectors = new HashMap<String, EncInjector>();
-      
-      InitialContextFactory.close(enc, this.initialContextProperties);
-      enc = null; 
-      
-      log.info("STOPPED EJB: " + beanClass.getName() + " ejbName: " + ejbName);
-   }
-
-   public void destroy() throws Exception
-   {
-      encFactory.cleanupEnc(this);
-      
-      // TODO: clean up BeanContainer?
-      //super.cleanup();
-   }
-
-   @SuppressWarnings("unchecked")
-   public <T> T getSecurityManager(Class<T> type)
-   {
-      try
-      {
-         InitialContext ctx = getInitialContext();
-         SecurityDomain securityAnnotation = (SecurityDomain) resolveAnnotation(SecurityDomain.class);
-         if (securityAnnotation != null && securityAnnotation.value().length() > 0)
-         {
-            return (T) SecurityDomainManager.getSecurityManager(securityAnnotation.value(),ctx);
-         }
-         return null;
-      }
-      catch (NamingException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   protected Method getTimeoutCallback(NamedMethodMetaData timeoutMethodMetaData, Class<?> beanClass)
-   {
-      JBossEnterpriseBeanMetaData metaData = xml;
-      if(metaData != null)
-      {
-         if(timeoutMethodMetaData != null)
-         {
-            String methodName = timeoutMethodMetaData.getMethodName();
-            try
-            {
-               return beanClass.getMethod(methodName, Timer.class);
-            }
-            catch (SecurityException e)
-            {
-               throw new RuntimeException(e);
-            }
-            catch (NoSuchMethodException e)
-            {
-               throw new RuntimeException("No method " + methodName + "(javax.ejb.Timer timer) found on bean " + ejbName, e);
-            }
-         }
-      }
-      
-      if(TimedObject.class.isAssignableFrom(beanClass))
-      {
-         try
-         {
-            return TimedObject.class.getMethod("ejbTimeout", Timer.class);
-         }
-         catch (SecurityException e)
-         {
-            throw new RuntimeException(e);
-         }
-         catch (NoSuchMethodException e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
-      
-      if(metaData != null)
-      {  
-         // TODO: cross cutting concern
-         if(metaData.getEjbJarMetaData().isMetadataComplete())
-            return null;
-      }
-      
-      for (Method method : beanClass.getMethods())
-      {
-         if (getAnnotation(Timeout.class, method) != null)
-         {
-            if (Modifier.isPublic(method.getModifiers()) &&
-                  method.getReturnType().equals(Void.TYPE) &&
-                  method.getParameterTypes().length == 1 &&
-                  method.getParameterTypes()[0].equals(Timer.class))
-            {
-               // TODO: check for multiples
-               return method;
-            }
-            else
-            {
-               throw new RuntimeException("@Timeout method " + method + " must have signature: void <METHOD>(javax.ejb.Timer timer) (EJB3 18.2.2)");
-            }
-         }
-      }
-      
-      return null;
-   }
-   
-   protected void initializePool() throws Exception
-   {
-      org.jboss.ejb3.annotation.Pool poolAnnotation = getAnnotation(org.jboss.ejb3.annotation.Pool.class);
-      if (poolAnnotation == null)
-         throw new IllegalStateException("No pool annotation");
-      String registeredPoolName = poolAnnotation.value();
-      // EJBTHREE-1119
-      if(registeredPoolName==null||registeredPoolName.trim().equals(""))
-      {
-         // Default the Pool Implementation
-         registeredPoolName = PoolDefaults.POOL_IMPLEMENTATION_THREADLOCAL;
-      }
-      int maxSize = poolAnnotation.maxSize();
-      long timeout = poolAnnotation.timeout();
-      PoolFactoryRegistry registry = deployment.getPoolFactoryRegistry();
-      PoolFactory factory = registry.getPoolFactory(registeredPoolName);
-      pool = factory.createPool();
-      pool.initialize(this, maxSize, timeout);
-
-      resolveInjectors();
-      pool.setInjectors(injectors.toArray(new Injector[injectors.size()]));
-   }
-
-   /**
-    * Note that this method is a WIP.
-    * 
-    * @param beanContext
-    * @param callbackAnnotationClass    on of PostConstruct, PreDestroy, PostActivate or PrePassivate
-    */
-   protected void invokeCallback(BeanContext<?> beanContext, Class<? extends Annotation> callbackAnnotationClass)
-   {
-      try
-      {
-         // Do lifecycle callbacks
-         List<Class<?>> lifecycleInterceptorClasses = beanContainer.getInterceptorRegistry().getLifecycleInterceptorClasses();
-         Advisor advisor = getAdvisor();
-         Interceptor interceptors[] = LifecycleCallbacks.createLifecycleCallbackInterceptors(advisor, lifecycleInterceptorClasses, beanContext, callbackAnnotationClass);
-         
-         Constructor<?> constructor = beanClass.getConstructor();
-         Object initargs[] = null;
-         ConstructionInvocation invocation = new ConstructionInvocation(interceptors, constructor, initargs);
-         invocation.setAdvisor(advisor);
-         invocation.setTargetObject(beanContext.getInstance());
-         invocation.invokeNext();
-      }
-      catch(Throwable t)
-      {
-         throw new RuntimeException(t);
-      }
-   }
-   
-   public void invokePostConstruct(BeanContext<?> beanContext)
-   {
-      invokeCallback(beanContext, PostConstruct.class);
-   }
-
-   @Deprecated
-   public void invokePostConstruct(BeanContext beanContext, Object[] params)
-   {
-      invokePostConstruct(beanContext);
-   }
-
-   public void invokePreDestroy(BeanContext beanContext)
-   {
-      // This is the correct way to destroy an instance, do
-      // not call invokeCallback here.
-      beanContainer.destroy(beanContext);
-   }
-
-   public void invokePostActivate(BeanContext beanContext)
-   {
-      throw new RuntimeException("PostActivate not implemented for container");
-   }
-
-   public void invokePrePassivate(BeanContext beanContext)
-   {
-      throw new RuntimeException("PrePassivate not implemented for container");
-   }
-
-   public void invokeInit(Object bean, Class[] initParameterTypes,
-                          Object[] initParameterValues)
-   {
-      // do nothing, only useful on a stateful session bean
-   }
-
-   public static final String MANAGED_ENTITY_MANAGER_FACTORY = "ManagedEntityManagerFactory";
-
-   public static final String ENTITY_MANAGER_FACTORY = "EntityManagerFactory";
-
-   protected void resolveInjectors() throws Exception
-   {
-      pushEnc();
-      try
-      {
-         Thread.currentThread().setContextClassLoader(classloader);
-         try
-         {
-            Util.rebind(getEnc(), "UserTransaction", new UserTransactionImpl());
-         }
-         catch (NamingException e)
-         {
-            NamingException namingException = new NamingException("Could not bind user transaction for ejb name " + ejbName + " into JNDI under jndiName: " + getEnc().getNameInNamespace() + "/" + "UserTransaction");
-            namingException.setRootCause(e);
-            throw namingException;
-         }
-         try
-         {
-            Util.rebind(getEnc(), "TransactionSynchronizationRegistry", new LinkRef("java:TransactionSynchronizationRegistry"));
-            log.debug("Linked java:comp/TransactionSynchronizationRegistry to JNDI name: java:TransactionSynchronizationRegistry");
-         }
-         catch (NamingException e)
-         {
-            NamingException namingException = new NamingException("Could not bind TransactionSynchronizationRegistry for ejb name " + ejbName + " into JNDI under jndiName: " + getEnc().getNameInNamespace() + "/" + "TransactionSynchronizationRegistry");
-            namingException.setRootCause(e);
-            throw namingException;
-         }
-      }
-      finally
-      {
-         popEnc();
-      }
-   }
-
-   /*
-   protected void createCallbackHandler()
-   {
-      try
-      {
-         callbackHandler = new LifecycleInterceptorHandler(this,
-                 getHandledCallbacks());
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException("Error creating callback handler for bean "
-                 + beanClassName, e);
-      }
-   }
-   */
-
-   protected Class[] getHandledCallbacks()
-   {
-      return new Class[]
-              {PostConstruct.class, PreDestroy.class, Timeout.class};
-   }
-
-   // TODO: once injection is finalized this method will disappear
-   private InterceptorMetaData findInterceptor(Class<?> interceptorClass)
-   {
-      if(xml == null)
-         return null;
-      JBossMetaData ejbJarMetaData = xml.getEjbJarMetaData();
-      if(ejbJarMetaData == null)
-         return null;
-      InterceptorsMetaData interceptors = ejbJarMetaData.getInterceptors();
-      if(interceptors == null)
-         return null;
-      for(InterceptorMetaData interceptorMetaData : interceptors)
-      {
-         if(interceptorMetaData.getInterceptorClass().equals(interceptorClass.getName()))
-            return interceptorMetaData;
-      }
-      return null;
-   }
-   
-   protected void findPartitionName()
-   {
-      Clustered clustered = (Clustered) getAnnotation(Clustered.class);
-      if (clustered == null)
-      {
-         partitionName = null;
-         return;
-      }
-      
-      String value = clustered.partition();
-      try
-      {
-         String replacedValue = StringPropertyReplacer.replaceProperties(value);
-         if (value != replacedValue)
-         {            
-            log.debug("Replacing @Clustered partition attribute " + value + " with " + replacedValue);
-            value = replacedValue;
-         }
-      }
-      catch (Exception e)
-      {
-         log.warn("Unable to replace @Clustered partition attribute " + value + 
-                  ". Caused by " + e.getClass() + " " + e.getMessage());         
-      }
-      
-      partitionName = value;
-   }
-
-   public <T> T getBusinessObject(BeanContext<?> beanContext, Class<T> businessInterface) throws IllegalStateException
-   {
-      throw new IllegalStateException("Not implemented");
-   }
-
-   public Object getInvokedBusinessInterface(BeanContext beanContext) throws IllegalStateException
-   {
-      throw new IllegalStateException("Not implemented");
-   }
-
-   protected Object getInvokedInterface(Method method)
-   {
-      Remote remoteAnnotation = (Remote) resolveAnnotation(Remote.class);
-      if (remoteAnnotation != null)
-      {
-         Class[] remotes = remoteAnnotation.value();
-         for (int i = 0; i < remotes.length; ++i)
-         {
-            try
-            {
-               remotes[i].getMethod(method.getName(), method.getParameterTypes());
-               return remotes[i];
-            }
-            catch (NoSuchMethodException e)
-            {
-            }
-         }
-      }
-
-      Local localAnnotation = (Local) resolveAnnotation(Local.class);
-      if (localAnnotation != null)
-      {
-         Class[] locals = localAnnotation.value();
-         for (int i = 0; i < locals.length; ++i)
-         {
-            Method[] interfaceMethods = locals[i].getMethods();
-            for (int j = 0; j < interfaceMethods.length; ++j)
-            {
-               if (interfaceMethods[j].equals(method))
-                  return locals[i];
-            }
-         }
-      }
-
-      return null;
-   }
-
-   // todo these method overrides for aop are for performance reasons
-   private Class loadPublicAnnotation(String annotation)
-   {
-      try
-      {
-         Class ann = classloader.loadClass(annotation);
-         if (!ann.isAnnotation()) return null;
-         Retention retention = (Retention) ann.getAnnotation(Retention.class);
-         if (retention != null && retention.value() == RetentionPolicy.RUNTIME) return ann;
-
-      }
-      catch (ClassNotFoundException ignored)
-      {
-      }
-      return null;
-   }
-
-   /*
-   @Override
-   public boolean hasAnnotation(Class tgt, String annotation)
-   {
-      if (annotations.hasClassAnnotation(annotation)) return true;
-      if (tgt == null) return false;
-      try
-      {
-         Class ann = loadPublicAnnotation(annotation);
-         // it is metadata or CLASS annotation
-         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(tgt, annotation);
-         return tgt.isAnnotationPresent(ann);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
-      }
-   }
-
-
-   @Override
-   public boolean hasAnnotation(Method m, String annotation)
-   {
-      if (annotations.hasAnnotation(m, annotation)) return true;
-      try
-      {
-         Class ann = loadPublicAnnotation(annotation);
-         // it is metadata or CLASS annotation
-         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(m, annotation);
-         return m.isAnnotationPresent(ann);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
-      }
-   }
-
-   @Override
-   public boolean hasAnnotation(Field m, String annotation)
-   {
-      if (annotations.hasAnnotation(m, annotation)) return true;
-      try
-      {
-         Class ann = loadPublicAnnotation(annotation);
-         // it is metadata or CLASS annotation
-         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(m, annotation);
-         return m.isAnnotationPresent(ann);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
-      }
-   }
-
-   @Override
-   public boolean hasAnnotation(Constructor m, String annotation)
-   {
-      if (annotations.hasAnnotation(m, annotation)) return true;
-      try
-      {
-         Class ann = loadPublicAnnotation(annotation);
-         // it is metadata or CLASS annotation
-         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(m, annotation);
-         return m.isAnnotationPresent(ann);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
-      }
-   }
-   */
-   
-   public Container resolveEjbContainer(String link, Class businessIntf)
-   {
-      return deployment.getEjbContainer(link, businessIntf);
-   }
-
-   public Container resolveEjbContainer(Class businessIntf) throws NameNotFoundException
-   {
-      return deployment.getEjbContainer(businessIntf);
-   }
-
-   public String resolveMessageDestination(String link)
-   {
-      return deployment.resolveMessageDestination(link);
-   }
-   
-   public <T extends Annotation> T getAnnotation(Class<T> annotationType)
-   {
-      if (this.getAnnotations().isDisabled(annotationType))
-         return null;
-      
-      return beanContainer.getAnnotation(annotationType);
-   }
-   
-   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz)
-   {
-      return beanContainer.getAnnotation(clazz, annotationType);
-   }
-
-   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Method method)
-   {
-      return beanContainer.getAnnotation(annotationType, clazz, method);
-   }
-   
-   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Method method)
-   {
-      if (this.getAnnotations().isDisabled(method, annotationType))
-         return null;
-      
-      return beanContainer.getAnnotation(annotationType, method);
-   }
-
-   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Field field)
-   {
-      return beanContainer.getAnnotation(annotationType, clazz, field);
-   }
-   
-   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Field field)
-   {
-      return beanContainer.getAnnotation(annotationType, field);
-   }
-   
-   /**
-    * @deprecated use getAnnotation
-    */
-   @SuppressWarnings("unchecked")
-   public Object resolveAnnotation(Class annotationType)
-   {
-      return getAnnotation(annotationType);
-   }
-   
-   /**
-    * @deprecated use getAnnotation
-    */
-   @SuppressWarnings("unchecked")
-   public Object resolveAnnotation(Field field, Class annotationType)
-   {
-      return getAnnotation(annotationType, field);
-   }
-   
-   /**
-    * @deprecated use getAnnotation
-    */
-   @SuppressWarnings("unchecked")
-   public Object resolveAnnotation(Method method, Class annotationType)
-   {
-      return getAnnotation(annotationType, method);
-   }
-   
-   /**
-    * @deprecated this is going to be gone soon
-    */
-   @SuppressWarnings("unchecked")
-   public Object resolveAnnotation(Method m, Class[] annotationChoices)
-   {
-      Object value = null;
-      int i = 0;
-      while (value == null && i < annotationChoices.length){
-         value = resolveAnnotation(m, annotationChoices[i++]);
-      }
-      
-      return value;
-   }
-
-   public String getIdentifier()
-   {
-      return getEjbName();
-   }
-
-   public String getDeploymentDescriptorType()
-   {
-      return "ejb-jar.xml";
-   }
-
-   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
-   {
-      return deployment.getPersistenceUnitDeployment(unitName);
-   }
-
-   public String getEjbJndiName(Class businessInterface) throws NameNotFoundException
-   {
-      return deployment.getEjbJndiName(businessInterface);
-   }
-
-   public String getEjbJndiName(String link, Class businessInterface)
-   {
-      return deployment.getEjbJndiName(link, businessInterface);
-   }
-   
-   public InvocationStatistics getInvokeStats()
-   {
-      return invokeStats;
-   }
-
-   @Deprecated
-   protected MethodInfo getMethodInfo(Method method)
-   {
-      long hash = MethodHashing.calculateHash(method);
-      MethodInfo info = getAdvisor().getMethodInfo(hash);
-      if (info == null)
-      {
-         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
-      }
-      return info;
-   }
-   
-   public boolean isClustered()
-   {
-      return false;
-   }
-   
-   public JavaEEModule getModule()
-   {
-      return deployment;
-   }
-   
-   public abstract boolean hasJNDIBinding(String jndiName);
-   
-   /**
-    * After XML processing has been done this allows the container
-    * to further initialize the meta data.
-    */
-   public void instantiated()
-   {
-      this.businessInterfaces = resolveBusinessInterfaces();
-      
-      // Before we start to process annotations, make sure we also have the ones from interceptors-aop.
-      // FIXME: because of the flaked life cycle of an EJBContainer (we add annotations after it's been
-      // constructed), we must reinitialize the whole thing. 
-      beanContainer.reinitializeAdvisor();
-   }
-   
-   public void setDirectContainer(DirectContainer<EJBContainer> container)
-   {
-      this.directContainer = container;
-   }
-   
-   protected Method getNonBridgeMethod(Method bridgeMethod)
-   {
-      Class clazz = bridgeMethod.getDeclaringClass();
-      Method[] methods = clazz.getMethods();
-      for (Method method : methods)
-      {
-         if (!method.isBridge() && method.getParameterTypes().length == bridgeMethod.getParameterTypes().length)
-         {
-            return method;
-         }
-      }
-      
-      return bridgeMethod;
-   }
-   
-   public String toString()
-   {
-      return getObjectName().getCanonicalName();
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/EJBContainer.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/EJBContainer.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/EJBContainer.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,1507 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.EJBContext;
+import javax.ejb.EJBException;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.TimedObject;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.LinkRef;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.Domain;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.annotation.AnnotationRepository;
+import org.jboss.aop.joinpoint.ConstructionInvocation;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.annotation.Clustered;
+import org.jboss.ejb3.annotation.SecurityDomain;
+import org.jboss.ejb3.annotation.defaults.PoolDefaults;
+import org.jboss.ejb3.aop.BeanContainer;
+import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
+import org.jboss.ejb3.interceptor.InterceptorInjector;
+import org.jboss.ejb3.interceptors.aop.LifecycleCallbacks;
+import org.jboss.ejb3.interceptors.container.ManagedObjectAdvisor;
+import org.jboss.ejb3.interceptors.direct.DirectContainer;
+import org.jboss.ejb3.interceptors.direct.IndirectContainer;
+import org.jboss.ejb3.javaee.JavaEEComponent;
+import org.jboss.ejb3.javaee.JavaEEComponentHelper;
+import org.jboss.ejb3.javaee.JavaEEModule;
+import org.jboss.ejb3.pool.Pool;
+import org.jboss.ejb3.pool.PoolFactory;
+import org.jboss.ejb3.pool.PoolFactoryRegistry;
+import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
+import org.jboss.ejb3.security.SecurityDomainManager;
+import org.jboss.ejb3.statistics.InvocationStatistics;
+import org.jboss.ejb3.tx.UserTransactionImpl;
+import org.jboss.injection.DependsHandler;
+import org.jboss.injection.EJBHandler;
+import org.jboss.injection.EncInjector;
+import org.jboss.injection.ExtendedInjectionContainer;
+import org.jboss.injection.InjectionHandler;
+import org.jboss.injection.InjectionUtil;
+import org.jboss.injection.Injector;
+import org.jboss.injection.JndiInjectHandler;
+import org.jboss.injection.PersistenceContextHandler;
+import org.jboss.injection.PersistenceUnitHandler;
+import org.jboss.injection.ResourceHandler;
+import org.jboss.injection.WebServiceRefHandler;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorsMetaData;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+import org.jboss.metadata.javaee.spec.Environment;
+import org.jboss.metadata.javaee.spec.ServiceReferenceMetaData;
+import org.jboss.util.StringPropertyReplacer;
+import org.jboss.util.naming.Util;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public abstract class EJBContainer implements Container, IndirectContainer<EJBContainer, DirectContainer<EJBContainer>>, ExtendedInjectionContainer, JavaEEComponent
+{
+   private static final Logger log = Logger.getLogger(EJBContainer.class);
+
+   private String name;
+   
+   private BeanContainer beanContainer;
+   
+   private DirectContainer<EJBContainer> directContainer;
+   
+   protected EjbEncFactory encFactory = new DefaultEjbEncFactory();
+
+   protected Pool pool;
+
+   protected String ejbName;
+
+   protected ObjectName objectName;
+
+   protected int defaultConstructorIndex;
+
+   protected String beanClassName;
+   
+   private Class<?> beanClass;
+
+   protected ClassLoader classloader;
+
+   // for performance there is an array.
+   protected List<Injector> injectors = new ArrayList<Injector>();
+
+   protected Context enc;
+
+//   protected LifecycleInterceptorHandler callbackHandler;
+
+   protected Hashtable initialContextProperties;
+
+   protected Map<String, EncInjector> encInjectors = new HashMap<String, EncInjector>();
+
+   protected JBossEnterpriseBeanMetaData xml;
+   protected JBossAssemblyDescriptorMetaData assembly;
+
+   protected Map<String, Map<AccessibleObject, Injector>> encInjections = new HashMap<String, Map<AccessibleObject, Injector>>();
+
+//   protected List<InterceptorInfo> classInterceptors = new ArrayList<InterceptorInfo>();
+//
+//   protected LinkedHashSet<InterceptorInfo> applicableInterceptors;
+
+   private HashMap<Class<?>, InterceptorInjector> interceptorInjectors = new HashMap<Class<?>, InterceptorInjector>();
+
+   private Ejb3Deployment deployment;
+
+   private DependencyPolicy dependencyPolicy;
+
+   private String jaccContextId;
+
+   protected HashMap invokedMethod = new HashMap();
+
+   protected InvocationStatistics invokeStats = new InvocationStatistics();
+   
+   private String partitionName;
+   
+   private List<Class<?>> businessInterfaces;
+   
+   private ThreadLocalStack<BeanContext<?>> currentBean = new ThreadLocalStack<BeanContext<?>>();
+   
+   protected boolean reinitialize = false;
+   
+   /**
+    * @param name                  Advisor name
+    * @param manager               Domain to get interceptor bindings from
+    * @param cl                    the EJB's classloader
+    * @param beanClassName
+    * @param ejbName
+    * @param ctxProperties
+    * @param interceptorRepository
+    * @param deployment
+    * @param beanMetaData           the meta data for this bean or null
+    */
+
+   public EJBContainer(String name, Domain domain, ClassLoader cl,
+                       String beanClassName, String ejbName, Hashtable ctxProperties,
+                       Ejb3Deployment deployment, JBossEnterpriseBeanMetaData beanMetaData) throws ClassNotFoundException
+   {
+      assert name != null : "name is null";
+      assert deployment != null : "deployment is null";
+      
+      this.name = name;
+      this.deployment = deployment;
+      this.beanClassName = beanClassName;
+      this.classloader = cl;
+      this.xml = beanMetaData;
+         
+      this.beanClass = classloader.loadClass(beanClassName);
+      
+      // We can't type cast the direct container, because we just loaded the beanClass
+      // so assuming we have an object is a safe bet.
+      this.beanContainer = new BeanContainer(this);
+      
+      this.ejbName = ejbName;
+      
+      // Because interceptors will query back the EJBContainer for annotations
+      // we must have set beanContainer first and then do the advisor. 
+      try
+      {
+         beanContainer.initialize(ejbName, domain, beanClass, beanMetaData, cl); 
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException("failed to initialize bean container ",e);
+      }
+      String on = createObjectName(ejbName);
+     
+      try
+      {
+         objectName = new ObjectName(on);
+      }
+      catch (MalformedObjectNameException e)
+      {
+         throw new RuntimeException("failed to create object name for: " + on, e);
+      }
+      
+      //annotations = new AnnotationRepositoryToMetaData(this);
+      
+      initialContextProperties = ctxProperties;
+      try
+      {
+         Util.createSubcontext(getEnc(), "env");
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+      bindORB();
+      bindEJBContext();
+      
+      this.dependencyPolicy = deployment.createDependencyPolicy(this);
+   }
+
+   private void bindEJBContext()
+   {
+      try 
+      {
+         Reference ref = new Reference(EJBContext.class.getName(), EJBContextFactory.class.getName(), null);
+         ref.add(new StringRefAddr("containerGuid", Ejb3Registry.guid(this)));
+         ref.add(new StringRefAddr("containerClusterUid", Ejb3Registry.clusterUid(this)));
+         ref.add(new StringRefAddr("isClustered", Boolean.toString(isClustered())));
+         Util.rebind(getEnc(), "EJBContext", ref);
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   private void bindORB()
+   {
+      try
+      {
+         Util.rebind(getEnc(), "ORB", new LinkRef("java:/JBossCorbaORB"));
+      }
+      catch(NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public abstract BeanContext<?> createBeanContext();
+   
+   public String createObjectName(String ejbName)
+   {
+      return JavaEEComponentHelper.createObjectName(deployment, ejbName);
+   }
+   
+   /**
+    * Do not call, for BeanContainer.
+    * @throws IllegalAccessException 
+    * @throws InstantiationException 
+    */
+   public Object createInterceptor(Class<?> interceptorClass) throws InstantiationException, IllegalAccessException
+   {
+      Object instance = interceptorClass.newInstance();
+      InterceptorInjector interceptorInjector = interceptorInjectors.get(interceptorClass);
+      assert interceptorInjector != null : "interceptorInjector not found for " + interceptorClass;
+      interceptorInjector.inject(null, instance);
+      return instance;
+   }
+   
+   public String createObjectName(String unitName, String ejbName)
+   {
+      return JavaEEComponentHelper.createObjectName(deployment, unitName, ejbName);
+   }
+   
+   // TODO: re-evaluate this exposure
+   @Deprecated
+   public Advisor getAdvisor()
+   {
+      return beanContainer._getAdvisor();
+   }
+
+   /*
+    * TODO: re-evalute this exposure
+    */
+   @Deprecated
+   public AnnotationRepository getAnnotations()
+   {
+      return beanContainer.getAnnotationRepository();
+   }
+
+   protected BeanContainer getBeanContainer()
+   {
+      return beanContainer;
+   }
+   
+   /**
+    * 
+    * @return   the bean class of this container
+    * @deprecated   use getBeanClass
+    */
+   public Class<?> getClazz()
+   {
+      return getBeanClass();
+   }
+   
+   @SuppressWarnings("unchecked")
+   public static <C extends EJBContainer> C getEJBContainer(Advisor advisor)
+   {
+      try
+      {
+         return (C) ((ManagedObjectAdvisor<Object, BeanContainer>) advisor).getContainer().getEJBContainer();
+      }
+      catch(ClassCastException e)
+      {
+         throw new ClassCastException(e.getMessage() + " using " + advisor);
+      }
+   }
+   
+   public String getName()
+   {
+      return name;
+   }
+   
+   public void pushContext(BeanContext<?> beanContext)
+   {
+      currentBean.push(beanContext);
+   }
+   
+   /**
+    * Makes sure that EJB's ENC is available
+    * Delegates to whatever implementation is used to push the ENC of the EJB
+    * onto the stack
+    *
+    */
+   protected void pushEnc()
+   {
+      encFactory.pushEnc(this);
+   }
+
+   public BeanContext<?> peekContext()
+   {
+      BeanContext<?> ctx = currentBean.get();
+      assert ctx != null : "ctx is null";
+      return ctx;
+   }
+   
+   public BeanContext<?> popContext()
+   {
+      return currentBean.pop();
+   }
+   
+   /**
+    * Pops EJB's ENC from the stack.  Delegates to whatever implementation
+    * is used to pop the EJB's ENC from the stock
+    *
+    */
+   protected void popEnc()
+   {
+      encFactory.popEnc(this);
+   }
+   
+   public Environment getEnvironmentRefGroup()
+   {
+      return xml;
+   }
+
+   public List<Injector> getInjectors()
+   {
+      return injectors;
+   }
+
+
+   public String getJaccContextId()
+   {
+      return jaccContextId;
+   }
+
+   /**
+    * Do not call, used by BeanContainer.
+    * @return
+    */
+   public List<Method> getVirtualMethods()
+   {
+      return null;
+   }
+   
+   public void setJaccContextId(String jaccContextId)
+   {
+      this.jaccContextId = jaccContextId;
+   }
+   
+   public VirtualFile getRootFile()
+   {
+      return getDeploymentUnit().getRootFile();
+   }
+   
+   /**
+    * Return all the business interfaces implemented by this bean.
+    * 
+    * Available after the meta data has been processed.
+    * 
+    * @return   an array of business interfaces or empty if no interface is provided
+    */
+   public List<Class<?>> getBusinessInterfaces()
+   {
+      if(businessInterfaces == null) throw new IllegalStateException("businessInterfaces not yet initialized");
+      return businessInterfaces;
+   }
+      
+   public String getDeploymentQualifiedName()
+   {
+      return objectName.getCanonicalName();
+   }
+   
+   /**
+    * Returns a String identifier for this bean that is qualified by the
+    * deployment, and hence should be unique across deployments. Name is of the 
+    * form "ear=foo.ear,jar=foo.jar,name=Bar", where "Bar" is the value 
+    * returned by {@link #getEjbName()}. The "ear=foo.ear" portion is ommitted 
+    * if the bean is not packaged in an ear.
+    */
+   public String getDeploymentPropertyListString()
+   {
+      return objectName.getCanonicalKeyPropertyListString();
+   }
+   
+   public DeploymentUnit getDeploymentUnit()
+   {
+      return deployment.getDeploymentUnit();
+   }
+
+   public Ejb3Deployment getDeployment()
+   {
+      return deployment;
+   }
+
+   public DependencyPolicy getDependencyPolicy()
+   {
+      return dependencyPolicy;
+   }
+
+   public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+   {
+      return beanContainer.isAnnotationPresent(annotationType);
+   }
+   
+   /**
+    * Is the method a business method of this container.
+    * 
+    * @param businessMethod     the method in question
+    * @return   true if so, otherwise false
+    */
+   public boolean isBusinessMethod(Method businessMethod)
+   {
+      for(Class<?> businessInterface : getBusinessInterfaces())
+      {
+         for(Method method : businessInterface.getMethods())
+         {
+            if(isCallable(method, businessMethod))
+               return true;
+         }
+      }
+      return false;
+   }
+   
+   /**
+    * Can method definition method be used to call method other.
+    * For example if the method is defined in an interface it can be used to call a method
+    * in a class.
+    * 
+    * @param method
+    * @param other
+    * @return
+    */
+   private static boolean isCallable(Method method, Method other)
+   {
+      if ((method.getDeclaringClass().isAssignableFrom(other.getDeclaringClass())) && (method.getName().equals(other.getName())))
+      {
+         if (!method.getReturnType().equals(other.getReturnType()))
+            return false;
+         Class<?>[] params1 = method.getParameterTypes();
+         Class<?>[] params2 = other.getParameterTypes();
+         if (params1.length == params2.length)
+         {
+            for (int i = 0; i < params1.length; i++)
+            {
+               if (params1[i] != params2[i])
+                  return false;
+            }
+            return true;
+         }
+      }
+      return false;
+   }   
+   
+   /**
+    * introspects EJB container to find all dependencies
+    * and initialize any extra metadata.
+    * <p/>
+    * This must be called before container is registered with any microcontainer
+    *
+    * @param dependencyPolicy
+    */
+   public void processMetadata()
+   {
+      // XML must be done first so that any annotation overrides are initialized
+      
+      // todo injection handlers should be pluggable from XML
+      Collection<InjectionHandler<Environment>> handlers = this.deployment.getHandlers();
+      if(handlers == null)
+      {
+         handlers = new ArrayList<InjectionHandler<Environment>>();
+         handlers.add(new EJBHandler<Environment>());
+         handlers.add(new DependsHandler<Environment>());
+         handlers.add(new JndiInjectHandler<Environment>());
+         handlers.add(new PersistenceContextHandler<Environment>());
+         handlers.add(new PersistenceUnitHandler<Environment>());
+         handlers.add(new ResourceHandler<Environment>());
+         handlers.add(new WebServiceRefHandler<Environment>());
+      }
+
+      ClassLoader old = Thread.currentThread().getContextClassLoader();
+      Thread.currentThread().setContextClassLoader(classloader);
+      try
+      {
+         // EJB container's XML must be processed before interceptor's as it may override interceptor's references
+         for (InjectionHandler<Environment> handler : handlers) handler.loadXml(xml, this);
+
+         Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(this, handlers, getBeanClass());
+         injectors.addAll(tmp.values());
+
+         /*
+         initialiseInterceptors();
+         */
+         for (Class<?> interceptorClass : beanContainer.getInterceptorClasses())
+         {
+            InterceptorMetaData interceptorMetaData = findInterceptor(interceptorClass);
+            if(interceptorMetaData == null)
+               continue;
+            
+            for (InjectionHandler<Environment> handler : handlers)
+            {
+               handler.loadXml(interceptorMetaData, this);
+            }
+         }
+         for (Class<?> interceptorClass : beanContainer.getInterceptorClasses())
+         {
+            Map<AccessibleObject, Injector> injections = InjectionUtil.processAnnotations(this, handlers, interceptorClass);
+            InterceptorInjector injector = new InterceptorInjector(injections);
+            interceptorInjectors.put(interceptorClass, injector);
+         }
+
+         // When @WebServiceRef is not used service-ref won't be processed
+         // In this case we process them late
+         if(xml != null && xml.getServiceReferences() != null)
+         {
+            for(ServiceReferenceMetaData sref : xml.getServiceReferences())
+            {
+               // FIXME: fix WS metadata
+               /*
+               if(!sref.isProcessed())
+               {
+                  try
+                  {
+                     String name = sref.getServiceRefName();
+                     String encName = "env/" + name;
+                     Context encCtx = getEnc();
+
+                     UnifiedVirtualFile vfsRoot = new VirtualFileAdaptor(getRootFile());
+                     new ServiceRefDelegate().bindServiceRef(encCtx, encName, vfsRoot, getClassloader(), sref);
+
+                  }
+                  catch (Exception e)
+                  {
+                     log.error("Failed to bind service-ref", e);
+                  }
+               }
+               */
+            }
+         }
+         
+         // EJBTHREE-1025
+         this.checkForDuplicateLocalAndRemoteInterfaces();
+         
+         for(Class<?> businessInterface : getBusinessInterfaces())
+            ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(businessInterface);
+         
+         Class localHomeInterface = ProxyFactoryHelper.getLocalHomeInterface(this);
+         if(localHomeInterface != null)
+            ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(localHomeInterface);
+         
+         Class remoteHomeInterface = ProxyFactoryHelper.getRemoteHomeInterface(this);
+         if(remoteHomeInterface != null)
+            ((JBoss5DependencyPolicy) getDependencyPolicy()).addSupply(remoteHomeInterface);
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(old);
+      }
+   }
+   
+   /**
+    * Ensures that the bean does not implement any one interface as both @Local and @Remote
+    *
+    * @throws EJBException If the bean does implements any one interface as both @Local and @Remote
+    */
+   protected void checkForDuplicateLocalAndRemoteInterfaces() throws EJBException
+   {
+      // Initialize issue used in Error Message
+      String issue = "(EJBTHREE-1025)";
+
+      // Obtain annotations, if found
+      Local local = (Local) resolveAnnotation(Local.class);
+      Remote remote = (Remote) resolveAnnotation(Remote.class);
+
+      // If either local or remote is unspecified, return safely - there can be no overlap
+      if (local == null || remote == null)
+      {
+         return;
+      }
+
+      // Ensure "value" attribute of both local and remote are not blank
+      if (local.value().length < 1 && local.value().length < 1)
+      {
+         throw new EJBException("Cannot designate both " + Local.class.getName() + " and " + Remote.class.getName()
+               + " annotations without 'value' attribute on " + this.getEjbName() + ". " + issue);
+      }
+
+      // Iterate through local and remote interfaces, ensuring any one interface is not being used for both local and remote exposure
+      for (Class<?> localClass : local.value())
+      {
+         for (Class<?> remoteClass : remote.value())
+         {
+            if (localClass.equals(remoteClass))
+            {
+               throw new EJBException("Cannot designate " + localClass.getName() + " as both " + Local.class.getName()
+                     + " and " + Remote.class.getName() + " on " + this.getEjbName() + ". " + issue);
+            }
+         }
+      }
+   }
+
+   public JBossEnterpriseBeanMetaData getXml()
+   {
+      return xml;
+   }
+
+   public JBossAssemblyDescriptorMetaData getAssemblyDescriptor()
+   {
+      return assembly;
+   }
+
+   // FIXME: remove
+   @Deprecated
+   public void setAssemblyDescriptor(JBossAssemblyDescriptorMetaData assembly)
+   {
+      this.assembly = assembly;
+   }
+
+   protected abstract List<Class<?>> resolveBusinessInterfaces();
+   
+   public InterceptorInfoRepository getInterceptorRepository()
+   {
+      throw new RuntimeException("invalid");
+   }
+   
+   public Map<String, EncInjector> getEncInjectors()
+   {
+      return encInjectors;
+   }
+
+   public ClassLoader getClassloader()
+   {
+      return classloader;
+   }
+
+   public InitialContext getInitialContext()
+   {
+      try
+      {
+         return InitialContextFactory.getInitialContext(initialContextProperties);
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public Map<String, Map<AccessibleObject, Injector>> getEncInjections()
+   {
+      return encInjections;
+   }
+
+   public Context getEnc()
+   {
+      if (enc == null)
+      {
+         enc = encFactory.getEnc(this);
+      }
+      return enc;
+   }
+
+   public Hashtable getInitialContextProperties()
+   {
+      return initialContextProperties;
+   }
+
+   public ObjectName getObjectName()
+   {
+      return objectName;
+   }
+
+   public String getEjbName()
+   {
+      return ejbName;
+   }
+
+   public String getBeanClassName()
+   {
+      return beanClassName;
+   }
+
+   public Class<?> getBeanClass()
+   {
+      return beanClass;
+   }
+
+   public Pool getPool()
+   {
+      return pool;
+   }
+   
+   /**
+    * Gets the name of the cluster partition with which this container is
+    * associated. Not available until <code>EJBContainer.start()</code>
+    * is completed.
+    * 
+    * @return the name of the cluster partition with which this container is
+    *         associated, or <code>null</code> if the container is not clustered
+    */
+   public String getPartitionName()
+   {
+      if (partitionName == null)
+         this.findPartitionName();
+      return partitionName;
+   }
+
+   protected Object construct()
+   {
+      /*
+      try
+      {
+         return beanContainer.construct();
+      }
+      catch (SecurityException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RuntimeException(e);
+      }
+      */
+      try
+      {
+         return beanClass.newInstance();
+      }
+      catch (InstantiationException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   protected void reinitialize()
+   {
+      // FIXME: is this correct?
+      beanContainer.reinitializeAdvisor();
+      
+      /*
+      initClassMetaDataBindingsList();
+      adviceBindings.clear();
+      doesHaveAspects = false;
+      constructorInfos = null;
+      rebuildInterceptors();
+      */
+      
+      bindEJBContext();
+      
+      reinitialize = false;
+   }
+
+   public void create() throws Exception
+   {
+      /*
+      initializeClassContainer();
+      for (int i = 0; i < constructors.length; i++)
+      {
+         if (constructors[i].getParameterTypes().length == 0)
+         {
+            defaultConstructorIndex = i;
+            break;
+         }
+      }
+      */
+   }
+
+   // Everything must be done in start to make sure all dependencies have been satisfied
+   public void start() throws Exception
+   {
+      if (reinitialize)
+         reinitialize();
+       
+      initializePool();
+
+      for (EncInjector injector : encInjectors.values())
+      {
+         injector.inject(this);   
+      }
+      
+      // creating of injector array should come after injection into ENC as an ENC injector
+      // may add additional injectors into the injector list.  An example is an extended persistence
+      // context which mush be created and added to the SFSB bean context.
+
+      Injector[] injectors2 = injectors.toArray(new Injector[injectors.size()]);
+      if (pool != null) pool.setInjectors(injectors2);
+
+//      createCallbackHandler();
+      
+      // If we're clustered, find our partition name
+      findPartitionName();
+      
+      log.info("STARTED EJB: " + beanClass.getName() + " ejbName: " + ejbName);
+   }
+
+   public void stop() throws Exception
+   {
+      reinitialize = true;
+      
+      //encFactory.cleanupEnc(this);
+      
+      if (pool != null)
+      {
+         pool.destroy();
+         pool = null;
+      }
+      
+      injectors = new ArrayList<Injector>();
+      encInjectors = new HashMap<String, EncInjector>();
+      
+      InitialContextFactory.close(enc, this.initialContextProperties);
+      enc = null; 
+      
+      log.info("STOPPED EJB: " + beanClass.getName() + " ejbName: " + ejbName);
+   }
+
+   public void destroy() throws Exception
+   {
+      encFactory.cleanupEnc(this);
+      
+      // TODO: clean up BeanContainer?
+      //super.cleanup();
+   }
+
+   @SuppressWarnings("unchecked")
+   public <T> T getSecurityManager(Class<T> type)
+   {
+      try
+      {
+         InitialContext ctx = getInitialContext();
+         SecurityDomain securityAnnotation = (SecurityDomain) resolveAnnotation(SecurityDomain.class);
+         if (securityAnnotation != null && securityAnnotation.value().length() > 0)
+         {
+            return (T) SecurityDomainManager.getSecurityManager(securityAnnotation.value(),ctx);
+         }
+         return null;
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   protected Method getTimeoutCallback(NamedMethodMetaData timeoutMethodMetaData, Class<?> beanClass)
+   {
+      JBossEnterpriseBeanMetaData metaData = xml;
+      if(metaData != null)
+      {
+         if(timeoutMethodMetaData != null)
+         {
+            String methodName = timeoutMethodMetaData.getMethodName();
+            try
+            {
+               return beanClass.getMethod(methodName, Timer.class);
+            }
+            catch (SecurityException e)
+            {
+               throw new RuntimeException(e);
+            }
+            catch (NoSuchMethodException e)
+            {
+               throw new RuntimeException("No method " + methodName + "(javax.ejb.Timer timer) found on bean " + ejbName, e);
+            }
+         }
+      }
+      
+      if(TimedObject.class.isAssignableFrom(beanClass))
+      {
+         try
+         {
+            return TimedObject.class.getMethod("ejbTimeout", Timer.class);
+         }
+         catch (SecurityException e)
+         {
+            throw new RuntimeException(e);
+         }
+         catch (NoSuchMethodException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      
+      if(metaData != null)
+      {  
+         // TODO: cross cutting concern
+         if(metaData.getEjbJarMetaData().isMetadataComplete())
+            return null;
+      }
+      
+      for (Method method : beanClass.getMethods())
+      {
+         if (getAnnotation(Timeout.class, method) != null)
+         {
+            if (Modifier.isPublic(method.getModifiers()) &&
+                  method.getReturnType().equals(Void.TYPE) &&
+                  method.getParameterTypes().length == 1 &&
+                  method.getParameterTypes()[0].equals(Timer.class))
+            {
+               // TODO: check for multiples
+               return method;
+            }
+            else
+            {
+               throw new RuntimeException("@Timeout method " + method + " must have signature: void <METHOD>(javax.ejb.Timer timer) (EJB3 18.2.2)");
+            }
+         }
+      }
+      
+      return null;
+   }
+   
+   protected void initializePool() throws Exception
+   {
+      org.jboss.ejb3.annotation.Pool poolAnnotation = getAnnotation(org.jboss.ejb3.annotation.Pool.class);
+      if (poolAnnotation == null)
+         throw new IllegalStateException("No pool annotation");
+      String registeredPoolName = poolAnnotation.value();
+      // EJBTHREE-1119
+      if(registeredPoolName==null||registeredPoolName.trim().equals(""))
+      {
+         // Default the Pool Implementation
+         registeredPoolName = PoolDefaults.POOL_IMPLEMENTATION_THREADLOCAL;
+      }
+      int maxSize = poolAnnotation.maxSize();
+      long timeout = poolAnnotation.timeout();
+      PoolFactoryRegistry registry = deployment.getPoolFactoryRegistry();
+      PoolFactory factory = registry.getPoolFactory(registeredPoolName);
+      pool = factory.createPool();
+      pool.initialize(this, maxSize, timeout);
+
+      resolveInjectors();
+      pool.setInjectors(injectors.toArray(new Injector[injectors.size()]));
+   }
+
+   /**
+    * Note that this method is a WIP.
+    * 
+    * @param beanContext
+    * @param callbackAnnotationClass    on of PostConstruct, PreDestroy, PostActivate or PrePassivate
+    */
+   protected void invokeCallback(BeanContext<?> beanContext, Class<? extends Annotation> callbackAnnotationClass)
+   {
+      try
+      {
+         // Do lifecycle callbacks
+         List<Class<?>> lifecycleInterceptorClasses = beanContainer.getInterceptorRegistry().getLifecycleInterceptorClasses();
+         Advisor advisor = getAdvisor();
+         Interceptor interceptors[] = LifecycleCallbacks.createLifecycleCallbackInterceptors(advisor, lifecycleInterceptorClasses, beanContext, callbackAnnotationClass);
+         
+         Constructor<?> constructor = beanClass.getConstructor();
+         Object initargs[] = null;
+         ConstructionInvocation invocation = new ConstructionInvocation(interceptors, constructor, initargs);
+         invocation.setAdvisor(advisor);
+         invocation.setTargetObject(beanContext.getInstance());
+         invocation.invokeNext();
+      }
+      catch(Throwable t)
+      {
+         throw new RuntimeException(t);
+      }
+   }
+   
+   public void invokePostConstruct(BeanContext<?> beanContext)
+   {
+      invokeCallback(beanContext, PostConstruct.class);
+   }
+
+   @Deprecated
+   public void invokePostConstruct(BeanContext beanContext, Object[] params)
+   {
+      invokePostConstruct(beanContext);
+   }
+
+   public void invokePreDestroy(BeanContext beanContext)
+   {
+      // This is the correct way to destroy an instance, do
+      // not call invokeCallback here.
+      beanContainer.destroy(beanContext);
+   }
+
+   public void invokePostActivate(BeanContext beanContext)
+   {
+      throw new RuntimeException("PostActivate not implemented for container");
+   }
+
+   public void invokePrePassivate(BeanContext beanContext)
+   {
+      throw new RuntimeException("PrePassivate not implemented for container");
+   }
+
+   public void invokeInit(Object bean, Class[] initParameterTypes,
+                          Object[] initParameterValues)
+   {
+      // do nothing, only useful on a stateful session bean
+   }
+
+   public static final String MANAGED_ENTITY_MANAGER_FACTORY = "ManagedEntityManagerFactory";
+
+   public static final String ENTITY_MANAGER_FACTORY = "EntityManagerFactory";
+
+   protected void resolveInjectors() throws Exception
+   {
+      pushEnc();
+      try
+      {
+         Thread.currentThread().setContextClassLoader(classloader);
+         try
+         {
+            Util.rebind(getEnc(), "UserTransaction", new UserTransactionImpl());
+         }
+         catch (NamingException e)
+         {
+            NamingException namingException = new NamingException("Could not bind user transaction for ejb name " + ejbName + " into JNDI under jndiName: " + getEnc().getNameInNamespace() + "/" + "UserTransaction");
+            namingException.setRootCause(e);
+            throw namingException;
+         }
+         try
+         {
+            Util.rebind(getEnc(), "TransactionSynchronizationRegistry", new LinkRef("java:TransactionSynchronizationRegistry"));
+            log.debug("Linked java:comp/TransactionSynchronizationRegistry to JNDI name: java:TransactionSynchronizationRegistry");
+         }
+         catch (NamingException e)
+         {
+            NamingException namingException = new NamingException("Could not bind TransactionSynchronizationRegistry for ejb name " + ejbName + " into JNDI under jndiName: " + getEnc().getNameInNamespace() + "/" + "TransactionSynchronizationRegistry");
+            namingException.setRootCause(e);
+            throw namingException;
+         }
+      }
+      finally
+      {
+         popEnc();
+      }
+   }
+
+   /*
+   protected void createCallbackHandler()
+   {
+      try
+      {
+         callbackHandler = new LifecycleInterceptorHandler(this,
+                 getHandledCallbacks());
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error creating callback handler for bean "
+                 + beanClassName, e);
+      }
+   }
+   */
+
+   protected Class[] getHandledCallbacks()
+   {
+      return new Class[]
+              {PostConstruct.class, PreDestroy.class, Timeout.class};
+   }
+
+   // TODO: once injection is finalized this method will disappear
+   private InterceptorMetaData findInterceptor(Class<?> interceptorClass)
+   {
+      if(xml == null)
+         return null;
+      JBossMetaData ejbJarMetaData = xml.getEjbJarMetaData();
+      if(ejbJarMetaData == null)
+         return null;
+      InterceptorsMetaData interceptors = ejbJarMetaData.getInterceptors();
+      if(interceptors == null)
+         return null;
+      for(InterceptorMetaData interceptorMetaData : interceptors)
+      {
+         if(interceptorMetaData.getInterceptorClass().equals(interceptorClass.getName()))
+            return interceptorMetaData;
+      }
+      return null;
+   }
+   
+   protected void findPartitionName()
+   {
+      Clustered clustered = (Clustered) getAnnotation(Clustered.class);
+      if (clustered == null)
+      {
+         partitionName = null;
+         return;
+      }
+      
+      String value = clustered.partition();
+      try
+      {
+         String replacedValue = StringPropertyReplacer.replaceProperties(value);
+         if (value != replacedValue)
+         {            
+            log.debug("Replacing @Clustered partition attribute " + value + " with " + replacedValue);
+            value = replacedValue;
+         }
+      }
+      catch (Exception e)
+      {
+         log.warn("Unable to replace @Clustered partition attribute " + value + 
+                  ". Caused by " + e.getClass() + " " + e.getMessage());         
+      }
+      
+      partitionName = value;
+   }
+
+   public <T> T getBusinessObject(BeanContext<?> beanContext, Class<T> businessInterface) throws IllegalStateException
+   {
+      throw new IllegalStateException("Not implemented");
+   }
+
+   public Object getInvokedBusinessInterface(BeanContext beanContext) throws IllegalStateException
+   {
+      throw new IllegalStateException("Not implemented");
+   }
+
+   protected Object getInvokedInterface(Method method)
+   {
+      Remote remoteAnnotation = (Remote) resolveAnnotation(Remote.class);
+      if (remoteAnnotation != null)
+      {
+         Class[] remotes = remoteAnnotation.value();
+         for (int i = 0; i < remotes.length; ++i)
+         {
+            try
+            {
+               remotes[i].getMethod(method.getName(), method.getParameterTypes());
+               return remotes[i];
+            }
+            catch (NoSuchMethodException e)
+            {
+            }
+         }
+      }
+
+      Local localAnnotation = (Local) resolveAnnotation(Local.class);
+      if (localAnnotation != null)
+      {
+         Class[] locals = localAnnotation.value();
+         for (int i = 0; i < locals.length; ++i)
+         {
+            Method[] interfaceMethods = locals[i].getMethods();
+            for (int j = 0; j < interfaceMethods.length; ++j)
+            {
+               if (interfaceMethods[j].equals(method))
+                  return locals[i];
+            }
+         }
+      }
+
+      return null;
+   }
+
+   // todo these method overrides for aop are for performance reasons
+   private Class loadPublicAnnotation(String annotation)
+   {
+      try
+      {
+         Class ann = classloader.loadClass(annotation);
+         if (!ann.isAnnotation()) return null;
+         Retention retention = (Retention) ann.getAnnotation(Retention.class);
+         if (retention != null && retention.value() == RetentionPolicy.RUNTIME) return ann;
+
+      }
+      catch (ClassNotFoundException ignored)
+      {
+      }
+      return null;
+   }
+
+   /*
+   @Override
+   public boolean hasAnnotation(Class tgt, String annotation)
+   {
+      if (annotations.hasClassAnnotation(annotation)) return true;
+      if (tgt == null) return false;
+      try
+      {
+         Class ann = loadPublicAnnotation(annotation);
+         // it is metadata or CLASS annotation
+         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(tgt, annotation);
+         return tgt.isAnnotationPresent(ann);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+   }
+
+
+   @Override
+   public boolean hasAnnotation(Method m, String annotation)
+   {
+      if (annotations.hasAnnotation(m, annotation)) return true;
+      try
+      {
+         Class ann = loadPublicAnnotation(annotation);
+         // it is metadata or CLASS annotation
+         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         return m.isAnnotationPresent(ann);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+   }
+
+   @Override
+   public boolean hasAnnotation(Field m, String annotation)
+   {
+      if (annotations.hasAnnotation(m, annotation)) return true;
+      try
+      {
+         Class ann = loadPublicAnnotation(annotation);
+         // it is metadata or CLASS annotation
+         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         return m.isAnnotationPresent(ann);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+   }
+
+   @Override
+   public boolean hasAnnotation(Constructor m, String annotation)
+   {
+      if (annotations.hasAnnotation(m, annotation)) return true;
+      try
+      {
+         Class ann = loadPublicAnnotation(annotation);
+         // it is metadata or CLASS annotation
+         if (ann == null) return AnnotationElement.isAnyAnnotationPresent(m, annotation);
+         return m.isAnnotationPresent(ann);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
+      }
+   }
+   */
+   
+   public Container resolveEjbContainer(String link, Class businessIntf)
+   {
+      return deployment.getEjbContainer(link, businessIntf);
+   }
+
+   public Container resolveEjbContainer(Class businessIntf) throws NameNotFoundException
+   {
+      return deployment.getEjbContainer(businessIntf);
+   }
+
+   public String resolveMessageDestination(String link)
+   {
+      return deployment.resolveMessageDestination(link);
+   }
+   
+   public String resolvePersistenceUnitSupplier(String unitName)
+   {
+      return getDeployment().resolvePersistenceUnitSupplier(unitName);
+   }
+   
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+   {
+      if (this.getAnnotations().isDisabled(annotationType))
+         return null;
+      
+      return beanContainer.getAnnotation(annotationType);
+   }
+   
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz)
+   {
+      return beanContainer.getAnnotation(clazz, annotationType);
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Method method)
+   {
+      return beanContainer.getAnnotation(annotationType, clazz, method);
+   }
+   
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Method method)
+   {
+      if (this.getAnnotations().isDisabled(method, annotationType))
+         return null;
+      
+      return beanContainer.getAnnotation(annotationType, method);
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Field field)
+   {
+      return beanContainer.getAnnotation(annotationType, clazz, field);
+   }
+   
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Field field)
+   {
+      return beanContainer.getAnnotation(annotationType, field);
+   }
+   
+   /**
+    * @deprecated use getAnnotation
+    */
+   @SuppressWarnings("unchecked")
+   public Object resolveAnnotation(Class annotationType)
+   {
+      return getAnnotation(annotationType);
+   }
+   
+   /**
+    * @deprecated use getAnnotation
+    */
+   @SuppressWarnings("unchecked")
+   public Object resolveAnnotation(Field field, Class annotationType)
+   {
+      return getAnnotation(annotationType, field);
+   }
+   
+   /**
+    * @deprecated use getAnnotation
+    */
+   @SuppressWarnings("unchecked")
+   public Object resolveAnnotation(Method method, Class annotationType)
+   {
+      return getAnnotation(annotationType, method);
+   }
+   
+   /**
+    * @deprecated this is going to be gone soon
+    */
+   @SuppressWarnings("unchecked")
+   public Object resolveAnnotation(Method m, Class[] annotationChoices)
+   {
+      Object value = null;
+      int i = 0;
+      while (value == null && i < annotationChoices.length){
+         value = resolveAnnotation(m, annotationChoices[i++]);
+      }
+      
+      return value;
+   }
+
+   public String getIdentifier()
+   {
+      return getEjbName();
+   }
+
+   public String getDeploymentDescriptorType()
+   {
+      return "ejb-jar.xml";
+   }
+
+   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
+   {
+      return deployment.getPersistenceUnitDeployment(unitName);
+   }
+
+   public String getEjbJndiName(Class businessInterface) throws NameNotFoundException
+   {
+      return deployment.getEjbJndiName(businessInterface);
+   }
+
+   public String getEjbJndiName(String link, Class businessInterface)
+   {
+      return deployment.getEjbJndiName(link, businessInterface);
+   }
+   
+   public InvocationStatistics getInvokeStats()
+   {
+      return invokeStats;
+   }
+
+   @Deprecated
+   protected MethodInfo getMethodInfo(Method method)
+   {
+      long hash = MethodHashing.calculateHash(method);
+      MethodInfo info = getAdvisor().getMethodInfo(hash);
+      if (info == null)
+      {
+         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
+      }
+      return info;
+   }
+   
+   public boolean isClustered()
+   {
+      return false;
+   }
+   
+   public JavaEEModule getModule()
+   {
+      return deployment;
+   }
+   
+   public abstract boolean hasJNDIBinding(String jndiName);
+   
+   /**
+    * After XML processing has been done this allows the container
+    * to further initialize the meta data.
+    */
+   public void instantiated()
+   {
+      this.businessInterfaces = resolveBusinessInterfaces();
+      
+      // Before we start to process annotations, make sure we also have the ones from interceptors-aop.
+      // FIXME: because of the flaked life cycle of an EJBContainer (we add annotations after it's been
+      // constructed), we must reinitialize the whole thing. 
+      beanContainer.reinitializeAdvisor();
+   }
+   
+   public void setDirectContainer(DirectContainer<EJBContainer> container)
+   {
+      this.directContainer = container;
+   }
+   
+   protected Method getNonBridgeMethod(Method bridgeMethod)
+   {
+      Class clazz = bridgeMethod.getDeclaringClass();
+      Method[] methods = clazz.getMethods();
+      for (Method method : methods)
+      {
+         if (!method.isBridge() && method.getParameterTypes().length == bridgeMethod.getParameterTypes().length)
+         {
+            return method;
+         }
+      }
+      
+      return bridgeMethod;
+   }
+   
+   public String toString()
+   {
+      return getObjectName().getCanonicalName();
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/Ejb3Deployment.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,898 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-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 javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.persistence.Entity;
-import javax.security.jacc.PolicyConfiguration;
-
-import javassist.bytecode.ClassFile;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.ejb3.cache.CacheFactoryRegistry;
-import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
-import org.jboss.ejb3.common.lang.ClassHelper;
-import org.jboss.ejb3.enc.EjbModulePersistenceUnitResolver;
-import org.jboss.ejb3.enc.MessageDestinationResolver;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.ejb3.entity.SecondLevelCacheUtil;
-import org.jboss.ejb3.javaee.JavaEEApplication;
-import org.jboss.ejb3.javaee.JavaEEComponent;
-import org.jboss.ejb3.javaee.JavaEEComponentHelper;
-import org.jboss.ejb3.javaee.JavaEEModule;
-import org.jboss.ejb3.metadata.JBossSessionGenericWrapper;
-import org.jboss.ejb3.pool.PoolFactoryRegistry;
-import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
-import org.jboss.ejb3.proxy.factory.RemoteProxyFactoryRegistry;
-import org.jboss.injection.InjectionHandler;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossGenericBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanGenericWrapper;
-import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
-import org.jboss.metadata.javaee.spec.Environment;
-import org.jboss.metadata.javaee.spec.MessageDestinationsMetaData;
-import org.jboss.metadata.jpa.spec.PersistenceMetaData;
-import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
-import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * An EjbModule represents a collection of beans that are deployed as a unit.
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @author adrian at jboss.org
- * @version $Revision$
- */
-public abstract class Ejb3Deployment extends ServiceMBeanSupport
-  implements JavaEEModule, Ejb3DeploymentMBean
-{
-   private static final Logger log = Logger.getLogger(Ejb3Deployment.class);
-
-   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 PersistenceMetaData persistenceUnitsMetaData;
-
-   protected DeploymentUnit unit;
-
-   protected LinkedHashMap<ObjectName, Container> ejbContainers = new LinkedHashMap<ObjectName, Container>();
-
-   protected boolean hasEntities;
-
-   protected List<String> explicitEntityClasses = new ArrayList<String>();
-
-   protected List<PersistenceUnitDeployment> persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
-
-   protected String defaultSLSBDomain = "Stateless Bean";
-
-   protected String defaultSFSBDomain = "Stateful Bean";
-
-   protected String defaultMDBDomain = "Message Driven Bean";
-
-   protected String defaultConsumerDomain = "Consumer Bean";
-
-   protected String defaultServiceDomain = "Service Bean";
-
-   protected InitialContext initialContext;
-
-   protected KernelAbstraction kernelAbstraction;
-
-   // used for @Management interfaces
-   protected MBeanServer mbeanServer;
-
-   protected DeploymentScope deploymentScope;
-
-   protected EjbModulePersistenceUnitResolver persistenceUnitResolver;
-
-   protected MessageDestinationResolver messageDestinationResolver;
-   protected CacheFactoryRegistry cacheFactoryRegistry;
-   protected RemoteProxyFactoryRegistry remoteProxyFactoryRegistry;
-   protected PersistenceManagerFactoryRegistry persistenceManagerFactoryRegistry;
-   protected PoolFactoryRegistry poolFactoryRegistry;
-   
-   protected ObjectName objectName;
-   
-   protected boolean reinitialize = false;
-
-   public Ejb3Deployment(DeploymentUnit unit, DeploymentScope deploymentScope, JBossMetaData metaData, PersistenceMetaData persistenceUnitsMetaData)
-   {
-      assert unit != null : "unit is null";
-      
-      this.unit = unit;
-      this.deploymentScope = deploymentScope;
-      this.metaData = metaData;
-      this.persistenceUnitsMetaData = persistenceUnitsMetaData;
-      try
-      {
-         initialContext = InitialContextFactory.getInitialContext(unit.getJndiProperties());
-      }
-      catch (NamingException e)
-      {
-         throw new RuntimeException(e);
-      }
-      persistenceUnitResolver = new EjbModulePersistenceUnitResolver(persistenceUnitDeployments, deploymentScope, ejbContainers);
-      MessageDestinationsMetaData destinations = null;
-      if (metaData != null && metaData.getAssemblyDescriptor() != null)
-         destinations = metaData.getAssemblyDescriptor().getMessageDestinations();
-      messageDestinationResolver = new MessageDestinationResolver(deploymentScope, destinations);
-   }
-
-   public JavaEEApplication getApplication()
-   {
-      return deploymentScope;
-   }
-
-   public DeploymentScope getEar()
-   {
-      return deploymentScope;
-   }
-
-   public KernelAbstraction getKernelAbstraction()
-   {
-      return kernelAbstraction;
-   }
-
-   public MBeanServer getMbeanServer()
-   {
-      return mbeanServer;
-   }
-
-   public void setMbeanServer(MBeanServer mbeanServer)
-   {
-      this.mbeanServer = mbeanServer;
-   }
-
-   public DeploymentUnit getDeploymentUnit()
-   {
-      return unit;
-   }
-
-   public String getDefaultSLSBDomain()
-   {
-      return defaultSLSBDomain;
-   }
-
-   public CacheFactoryRegistry getCacheFactoryRegistry()
-   {
-      return cacheFactoryRegistry;
-   }
-   public void setCacheFactoryRegistry(CacheFactoryRegistry registry)
-   {
-      this.cacheFactoryRegistry = registry;
-   }
-
-   public RemoteProxyFactoryRegistry getRemoteProxyFactoryRegistry()
-   {
-      return remoteProxyFactoryRegistry;
-   }
-   public void setRemoteProxyFactoryRegistry(RemoteProxyFactoryRegistry registry)
-   {
-      this.remoteProxyFactoryRegistry = registry;
-   }
-
-   public PersistenceManagerFactoryRegistry getPersistenceManagerFactoryRegistry()
-   {
-      return persistenceManagerFactoryRegistry;
-   }
-   public void setPersistenceManagerFactoryRegistry(PersistenceManagerFactoryRegistry registry)
-   {
-      this.persistenceManagerFactoryRegistry = registry;
-   }
-   
-   public PoolFactoryRegistry getPoolFactoryRegistry()
-   {
-      return poolFactoryRegistry;
-   }
-   public void setPoolFactoryRegistry(PoolFactoryRegistry poolFactoryRegistry)
-   {
-      this.poolFactoryRegistry = poolFactoryRegistry;
-   }
-
-   /**
-    * Returns a partial MBean attribute name of the form
-    * ",ear=foo.ear,jar=foo.jar"
-    *
-    * @return
-    */
-   public String getScopeKernelName()
-   {
-      String scopedKernelName = "";
-      if (deploymentScope != null)
-         scopedKernelName += ",ear=" + deploymentScope.getShortName();
-      scopedKernelName += ",jar=" + unit.getShortName();
-      return scopedKernelName;
-   }
-
-   /**
-    * The default AOP domain for stateless session beans
-    *
-    * @param defaultSLSBDomain
-    */
-   public void setDefaultSLSBDomain(String defaultSLSBDomain)
-   {
-      this.defaultSLSBDomain = defaultSLSBDomain;
-   }
-
-   public String getDefaultSFSBDomain()
-   {
-      return defaultSFSBDomain;
-   }
-
-   public String getDefaultConsumerDomain()
-   {
-      return defaultConsumerDomain;
-   }
-
-   /**
-    * The default stateful session bean aspect domain
-    *
-    * @param defaultSFSBDomain
-    */
-   public void setDefaultSFSBDomain(String defaultSFSBDomain)
-   {
-      this.defaultSFSBDomain = defaultSFSBDomain;
-   }
-
-   public String getDefaultMDBDomain()
-   {
-      return defaultMDBDomain;
-   }
-
-   /**
-    * The default AOP domain for message driven beans.
-    *
-    * @param defaultMDBDomain
-    */
-   public void setDefaultMDBDomain(String defaultMDBDomain)
-   {
-      this.defaultMDBDomain = defaultMDBDomain;
-   }
-
-   public String getDefaultServiceDomain()
-   {
-      return defaultServiceDomain;
-   }
-
-   /**
-    * default AOP domain for service beans.
-    *
-    * @param defaultServiceDomain
-    */
-   public void setDefaultServiceDomain(String defaultServiceDomain)
-   {
-      this.defaultServiceDomain = defaultServiceDomain;
-   }
-
-   protected String getJaccContextId()
-   {
-      return unit.getShortName();
-   }
-
-   /**
-    * Get the deployment ejb container for the given ejb name.
-    * 
-    * @param ejbName the deployment unique ejb name
-    * @return the ejb container if found, null otherwise
-    * @throws IllegalStateException if the ejbName cannot be used to
-    *    for the container name.
-    */
-   public EJBContainer getEjbContainerForEjbName(String ejbName)
-   {
-      String ejbObjectName = JavaEEComponentHelper.createObjectName(this, ejbName);
-      EJBContainer container = null;
-      ObjectName ejbON;
-      try
-      {
-         ejbON = new ObjectName(ejbObjectName);
-      }
-      catch (Exception e)
-      {
-         throw new IllegalStateException("Failed to ", e);
-      }
-      container = (EJBContainer) ejbContainers.get(ejbON);
-      return container;
-   }
-
-   public Container getContainer(ObjectName name)
-   {
-      return (Container) ejbContainers.get(name);
-   }
-
-   public java.util.Map getEjbContainers()
-   {
-      return ejbContainers;
-   }
-
-   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
-   {
-      return persistenceUnitResolver.getPersistenceUnitDeployment(unitName);
-   }
-
-   public PersistenceUnitDeployment getPersistenceUnitDeploymentInternal(String unitName)
-   {
-      return persistenceUnitResolver.getPersistenceUnitDeploymentInternal(unitName);
-   }
-
-   public List<PersistenceUnitDeployment> getPersistenceUnitDeployments()
-   {
-      return persistenceUnitDeployments;
-   }
-
-
-   public EJBContainer getEjbContainer(String ejbLink, Class businessIntf)
-   {
-      String relativePath = unit.getRelativePath();
-      EJBContainer container = deploymentScope.getEjbContainer(ejbLink, businessIntf, relativePath);
-      return container;
-   }
-
-   public String getEjbJndiName(String ejbLink, Class businessIntf)
-   {
-      EJBContainer container = getEjbContainer(ejbLink, businessIntf);
-      String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
-      return jndiName;
-   }
-   public String getEjbJndiName(Class businessIntf)
-      throws NameNotFoundException
-   {
-      EJBContainer container = getEjbContainer(businessIntf);
-      String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
-      return jndiName;
-   }
-
-   public EJBContainer getEjbContainer(Class businessIntf) throws NameNotFoundException
-   {
-      String relativePath = unit.getRelativePath();
-      return deploymentScope.getEjbContainer(businessIntf, relativePath);
-   }
-
-   protected void processEJBContainerMetadata(Container container) throws Exception
-   {
-      log.trace("Process EJB container metadata " + container);
-      ObjectName on = container.getObjectName();
-      ejbContainers.put(on, container);
-      container.processMetadata();
-   }
-   
-   protected void registerDeployment() throws Exception
-   {
-      String on = "jboss.j2ee:jar=" + this.getName() + ",service=EJB3";
-      if (metaData != null && metaData.getEnterpriseBeans() != null && metaData.getEnterpriseBeans().getEjbJarMetaData() != null)
-      {
-         String jmxName = metaData.getEnterpriseBeans().getEjbJarMetaData().getJmxName();
-         if (jmxName != null && jmxName.trim().length() > 0)
-            on = jmxName;
-      } 
-     
-      objectName = new ObjectName(on);
-      
-      mbeanServer.registerMBean(this, objectName);
-   }
-   
-   protected void unregisterDeployment()
-   {
-      try
-      {
-         mbeanServer.unregisterMBean(objectName);
-      }
-      catch (Exception e)
-      {
-         log.debug("error trying to stop ejb deployment", e);
-      }
-   }
-
-   protected void registerEJBContainer(Container container) throws Exception
-   {
-      ObjectName on = container.getObjectName();
-      String name = on.getCanonicalName();
-      DependencyPolicy dependsPolicy = container.getDependencyPolicy();
-      dependsPolicy.addDependency("jboss.ejb:service=EJBTimerService");
-      kernelAbstraction.install(name, dependsPolicy, unit, container);
-      mbeanServer.registerMBean(container.getMBean(), on);
-      log.debug("Bound ejb3 container " + name);
-   }
-
-   protected abstract PolicyConfiguration createPolicyConfiguration() throws Exception;
-
-   protected abstract void putJaccInService(PolicyConfiguration pc, DeploymentUnit unit);
-
-   /**
-    * Return the container injection handler collection. If not specified(null)
-    * a default handler collection will be created.
-    * @return the injection handler collection to use, null if the container
-    *    should use a default setup.
-    */
-   protected Collection<InjectionHandler<Environment>> getHandlers()
-   {
-      return null;
-   }
-
-   /**
-    * Create all EJB containers and Persistence Units
-    * The only things that should be initialized is metadata that does not need access to any
-    * other deployment.  This is because we want the entire EAR to be initialized so that we do not
-    * have to guess on dependencies MBean names.  This is because of the silly scoping rules for persistence units
-    * and EJBs.
-    *
-    * @throws Exception
-    */
-   public void create() throws Exception
-   {
-      try
-      {
-         long start = System.currentTimeMillis();
-
-         //pc = createPolicyConfiguration();
-
-         deploy();
-
-         initializePersistenceUnits();
-         
-         registerDeployment();
-
-         log.debug("EJB3 deployment time took: " + (System.currentTimeMillis() - start));
-      }
-      catch (Exception e)
-      {
-         try
-         {
-            destroy();
-         }
-         catch (Exception ignored)
-         {
-            // ignore
-         }
-         throw e;
-      }
-   }
-   
-   protected void reinitialize() throws Exception
-   {
-      initializePersistenceUnits();
-      reinitialize = false;
-   }
-
-   public void start() throws Exception
-   {
-      try
-      {
-         if (reinitialize)
-            reinitialize();
-         
-         startPersistenceUnits();
-
-         for (Object o : ejbContainers.values())
-         {
-            Container con = (Container) o;
-            processEJBContainerMetadata(con);
-         }
-
-         for (Object o : ejbContainers.values())
-         {
-            Container con = (Container) o;
-            registerEJBContainer(con);
-         }
-
-         //putJaccInService(pc, unit);
-      }
-      catch (Exception ex)
-      {
-         try
-         {
-            stop();
-            destroy();
-         }
-         catch (Exception ignored)
-         {
-         }
-         throw ex;
-      }
-   }
-   
-   public void stop() //throws Exception
-   {
-      for (ObjectName on : ejbContainers.keySet())
-      {
-         try
-         {
-            mbeanServer.unregisterMBean(on);
-            kernelAbstraction.uninstall(on.getCanonicalName());
-         }
-         catch (Exception e)
-         {
-            log.debug("error trying to stop ejb container", e);
-         }
-      }
-      stopPersistenceUnits();
-      
-      reinitialize = true;
-   }
-
-   protected void deploy() throws Exception
-   {
-      Ejb3HandlerFactory factory = Ejb3HandlerFactory.getInstance(this);
-      if (unit.getUrl() != null)
-         deployUrl(factory);
-
-      if (unit.getClasses() != null)
-      {
-         for (Class explicit : unit.getClasses())
-         {
-            if (explicit.isAnnotationPresent(Entity.class))
-            {
-               continue;
-            }
-            String name = explicit.getName().replace('.', '/') + ".class";
-            InputStream stream = explicit.getClassLoader().getResourceAsStream(name);
-            deployElement(stream, factory, initialContext);
-         }
-      }
-
-      deployBeansFromLib(initialContext);
-   }
-
-   protected void deployUrl(Ejb3HandlerFactory factory) throws Exception
-   {
-      // make sure we are not deploying ejbs from client jar
-      List<VirtualFile> clientDescriptors = unit.getResources(new org.jboss.ejb3.ClientDescriptorFileFilter());
-
-      if (clientDescriptors.size() > 0)
-         return;
-
-      InitialContext ctx = initialContext;
-      // need to look into every entry in the archive to see if anybody has tags
-      // defined.
-      List<VirtualFile> classes = unit.getResources(new org.jboss.ejb3.ClassFileFilter());
-      for (VirtualFile classFile : classes)
-      {
-         InputStream stream = classFile.openStream();
-         deployElement(stream, factory, ctx);
-      }
-   }
-
-   protected void deployElement(InputStream stream, Ejb3HandlerFactory factory, InitialContext ctx) throws Exception
-   {
-      DataInputStream dstream = new DataInputStream(new BufferedInputStream(stream));
-      ClassFile cf = null;
-      try
-      {
-         cf = new ClassFile(dstream);
-      }
-      finally
-      {
-         dstream.close();
-         stream.close();
-      }
-
-      deployElement(factory, cf, ctx);
-
-   }
-
-   protected void deployBeansFromLib(InitialContext ctx) throws Exception
-   {
-      JBossMetaData dd = getMetaData();
-      if (dd != null)
-      {
-         Ejb3DescriptorHandler handler = new Ejb3DescriptorHandler(this, dd);
-         handler.setCtxProperties(unit.getJndiProperties());
-
-         Map<String, Container> localContainers = new HashMap<String, Container>();
-         Iterator<Container> containerIterator = ejbContainers.values().iterator();
-         while (containerIterator.hasNext())
-         {
-            Container container = containerIterator.next();
-            localContainers.put(container.getEjbName(), container);
-         }
-
-         List<Container> containers = handler.getContainers(this, localContainers);
-         for (Container con : containers)
-         {
-            // EJBContainer has finished with all metadata initialization from XML files and such.
-            // this is really a hook to do some processing after XML has been set up and before
-            // and processing of dependencies and such.
-            ((EJBContainer) con).instantiated();
-            this.ejbContainers.put(con.getObjectName(), con);
-            Ejb3Registry.register(con);
-         }
-      }
-   }
-
-   protected void deployElement(Ejb3HandlerFactory factory, ClassFile cf, InitialContext ctx) throws Exception
-   {
-      Ejb3Handler handler = factory.createHandler(cf);
-      handler.setCtxProperties(unit.getJndiProperties());
-
-      if (handler.isEjb() || handler.isJBossBeanType())
-      {
-         List<Container> containers = handler.getContainers(cf, this);
-         for (Container con : containers)
-         {
-            // EJBContainer has finished with all metadata initialization from XML files and such.
-            // this is really a hook to do some processing after XML has been set up and before
-            // and processing of dependencies and such.
-            try
-            {
-               ((EJBContainer) con).instantiated();
-               this.ejbContainers.put(con.getObjectName(), con);
-               Ejb3Registry.register(con);
-            }
-            catch (Throwable t)
-            {
-               throw new DeploymentException(
-                     "Error creating ejb container " + con.getEjbName() + ": " + t.getMessage(), t);
-            }
-         }
-      }
-   }
-
-   protected void initializePersistenceUnits() throws Exception
-   {
-      hasEntities = persistenceUnitsMetaData != null;
-
-      if (!hasEntities)
-         return;
-
-      if (unit.getClasses() != null)
-      {
-         for (Class<?> explicit : unit.getClasses())
-         {
-            if (explicit.isAnnotationPresent(Entity.class))
-            {
-               explicitEntityClasses.add(explicit.getName());
-            }
-         }
-      }
-
-      // scope the unitName if this is an ejb archive
-      // todo revert to this: List<PersistenceMetadata> persistenceMetadata = PersistenceXmlLoader.deploy(persistenceXmlUrl, new HashMap(), new EJB3DTDEntityResolver());
-      List<PersistenceUnitMetaData> pumds = persistenceUnitsMetaData.getPersistenceUnits();
-      for (PersistenceUnitMetaData metaData : pumds)
-      {
-         String earShortName = deploymentScope == null ? null : deploymentScope.getShortName();
-         boolean isScoped = ejbContainers.size() > 0;
-
-         Map<String, String> properties = metaData.getProperties();
-         if (properties == null)
-         {
-            properties = new HashMap<String, String>();
-            metaData.setProperties(properties);
-         }
-         // Ensure 2nd level cache entries are segregated from other deployments
-         String cache_prefix = properties.get(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX);
-         if (cache_prefix == null)
-         {
-            // Create a region_prefix for the 2nd level cache to ensure
-            // deployments are segregated
-            String jarName = isScoped ? unit.getShortName() : null;
-            cache_prefix = SecondLevelCacheUtil.createCacheRegionPrefix(earShortName, jarName, metaData.getName());
-            properties.put(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX, cache_prefix);
-         }
-         PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(initialContext, this, explicitEntityClasses, metaData, earShortName, unit.getShortName(), isScoped);
-         PersistenceUnitRegistry.register(deployment);
-         persistenceUnitDeployments.add(deployment);
-      }
-   }
-
-   public abstract DependencyPolicy createDependencyPolicy(JavaEEComponent component);
-
-   protected void startPersistenceUnits()
-   {
-      if (persistenceUnitDeployments == null)
-         return;
-
-      for (PersistenceUnitDeployment entityDeployment : persistenceUnitDeployments)
-      {
-         if (entityDeployment != null)
-         {
-            DependencyPolicy policy = createDependencyPolicy(entityDeployment);
-            entityDeployment.addDependencies(policy);
-            kernelAbstraction.install(entityDeployment.getKernelName(), policy, unit, entityDeployment);
-         }
-      }
-   }
-
-   protected void stopPersistenceUnits()
-   {
-      if (persistenceUnitDeployments == null)
-         return;
-
-      for (PersistenceUnitDeployment entityDeployment : persistenceUnitDeployments)
-      {
-         try
-         {
-            PersistenceUnitRegistry.unregister(entityDeployment);
-            if (entityDeployment != null)
-            {
-               kernelAbstraction.uninstall(entityDeployment.getKernelName());
-            }
-         }
-         catch (Exception e)
-         {
-            log.debug("error trying to shut down persistence unit", e);
-         }
-      }
-      
-      persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
-
-   }
-
-   
-
-   public void destroy() //throws Exception
-   {
-      try
-      {
-         undeploy();
-         
-         unregisterDeployment();
-      } 
-      catch (Exception e)
-      {
-         log.debug("error trying to destroy ejb deployment", e);
-      }
-   }
-
-   private void undeploy()
-   {
-      for (Container container : ejbContainers.values())
-      {
-         Ejb3Registry.unregister(container);
-      }
-   }
-
-   //   /**
-   //    * Get the jndi name of a message destination.
-   //    * 
-   //    * @param name   the name of the message destination
-   //    * @return       the jndi name
-   //    */
-   //   private String getMessageDestination(String name)
-   //   {
-   //      EjbJarDD dd;
-   //      // FIXME: Why isn't dd stored somewhere?
-   //      try
-   //      {
-   //         dd = EjbJarDDObjectFactory.parse(getDeploymentUnit().getEjbJarXml());
-   //         dd = JBossDDObjectFactory.parse(getDeploymentUnit().getJbossXml(), dd);
-   //      }
-   //      catch(IOException e)
-   //      {
-   //         throw new RuntimeException(e);
-   //      }
-   //      catch(JBossXBException e)
-   //      {
-   //         throw new RuntimeException(e);
-   //      }
-   //
-   //      AssemblyDescriptor ad = dd.getAssemblyDescriptor();
-   //      if(ad == null)
-   //         throw new IllegalStateException("No assembly descriptor found in '" + getName() + "'");
-   //      MessageDestination md = ad.findMessageDestination(name);
-   //      if(md == null)
-   //         throw new IllegalStateException("No message destination '" + name + "' found in '" + getName() + "'");
-   //      String jndiName = md.getJndiName();
-   //      if(jndiName == null)
-   //         throw new IllegalStateException("No jndi name specified for message destination '" + name + "' in '" + getName() + "'");
-   //      return jndiName;
-   //   }
-
-   public String resolveMessageDestination(String link)
-   {
-      //      // FIXME: this is a copy of DeploymentEjbResolver
-      //      int hashIndex = link.indexOf('#');
-      //      if (hashIndex != -1)
-      //      {
-      //         if (deploymentScope == null)
-      //         {
-      //            log.warn("ejb link '" + link + "' is relative, but no deployment scope found");
-      //            return null;
-      //         }
-      //         String relativePath = link.substring(0, hashIndex);
-      //         Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
-      //         if (dep == null)
-      //         {
-      //            log.warn("can't find a deployment for path '" + relativePath + "' of ejb link '" + link + "'");
-      //            return null;
-      //         }
-      //         String name = link.substring(hashIndex + 1);
-      //         return dep.getMessageDestination(name);
-      //      }
-      //      return getMessageDestination(link);
-      return messageDestinationResolver.resolveMessageDestination(link);
-   }
-
-   public MessageDestinationResolver getMessageDestinationResolver()
-   {
-      return messageDestinationResolver;
-   }
-
-   /**
-    * Do not call, for use in Ejb3Handler.
-    * 
-    * @param <B>
-    * @param ejbName
-    * @param enterpriseBeanMetaDataClass
-    * @return
-    */
-   protected <B extends JBossEnterpriseBeanMetaData> B getEnterpriseBeanMetaData(String ejbName, Class<B> enterpriseBeanMetaDataClass)
-   {
-      if(metaData == null)
-         return null;
-      
-      JBossEnterpriseBeanMetaData result = metaData.getEnterpriseBean(ejbName);
-      
-      // FIXME: EJBTHREE-1227: temporary workaround for JBCTS-756
-      // see also org.jboss.ejb3.metadata.JBossSessionGenericWrapper
-      if(result instanceof JBossGenericBeanMetaData)
-      {
-         log.warn("FIXME: EJBTHREE-1227: JBossGenericBeanMetaData found for '" + ejbName + "' instead of " + enterpriseBeanMetaDataClass);
-         if(enterpriseBeanMetaDataClass.equals(JBossSessionBeanMetaData.class))
-         {
-            result = new JBossSessionGenericWrapper((JBossGenericBeanMetaData) result);
-         }
-         else if(enterpriseBeanMetaDataClass.equals(JBossMessageDrivenBeanMetaData.class))
-         {
-            result = new JBossMessageDrivenBeanGenericWrapper((JBossGenericBeanMetaData) result);
-         }
-         else
-         {
-            throw new IllegalStateException("Can't find a generic bean meta data wrapper for " + enterpriseBeanMetaDataClass);
-         }
-      }
-      
-      return ClassHelper.cast(enterpriseBeanMetaDataClass, result);
-   }
-   
-   /**
-    * Get the meta data associated with this deployment or null if none.
-    * 
-    * @return   meta data or null
-    */
-   public JBossMetaData getMetaData()
-   {
-      return metaData;
-   }
-
-   public String getName()
-   {
-      return unit.getShortName();
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/Ejb3Deployment.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/Ejb3Deployment.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/Ejb3Deployment.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,941 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+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 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 javax.security.jacc.PolicyConfiguration;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.ejb3.cache.CacheFactoryRegistry;
+import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
+import org.jboss.ejb3.common.lang.ClassHelper;
+import org.jboss.ejb3.enc.EjbModulePersistenceUnitResolver;
+import org.jboss.ejb3.enc.MessageDestinationResolver;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.ejb3.entity.SecondLevelCacheUtil;
+import org.jboss.ejb3.javaee.JavaEEApplication;
+import org.jboss.ejb3.javaee.JavaEEComponent;
+import org.jboss.ejb3.javaee.JavaEEComponentHelper;
+import org.jboss.ejb3.javaee.JavaEEModule;
+import org.jboss.ejb3.metadata.JBossSessionGenericWrapper;
+import org.jboss.ejb3.pool.PoolFactoryRegistry;
+import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
+import org.jboss.ejb3.proxy.factory.RemoteProxyFactoryRegistry;
+import org.jboss.injection.InjectionHandler;
+import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossGenericBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanGenericWrapper;
+import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.javaee.spec.Environment;
+import org.jboss.metadata.javaee.spec.MessageDestinationsMetaData;
+import org.jboss.metadata.jpa.spec.PersistenceMetaData;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * An EjbModule represents a collection of beans that are deployed as a unit.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision$
+ */
+public abstract class Ejb3Deployment extends ServiceMBeanSupport
+  implements JavaEEModule, Ejb3DeploymentMBean
+{
+   private static final Logger log = Logger.getLogger(Ejb3Deployment.class);
+
+   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 PersistenceMetaData persistenceUnitsMetaData;
+
+   protected DeploymentUnit unit;
+
+   protected LinkedHashMap<ObjectName, Container> ejbContainers = new LinkedHashMap<ObjectName, Container>();
+
+   private boolean processPersistenceUnits = true;
+   protected boolean hasEntities;
+
+   protected List<String> explicitEntityClasses = new ArrayList<String>();
+
+   protected List<PersistenceUnitDeployment> persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
+
+   protected String defaultSLSBDomain = "Stateless Bean";
+
+   protected String defaultSFSBDomain = "Stateful Bean";
+
+   protected String defaultMDBDomain = "Message Driven Bean";
+
+   protected String defaultConsumerDomain = "Consumer Bean";
+
+   protected String defaultServiceDomain = "Service Bean";
+
+   protected InitialContext initialContext;
+
+   protected KernelAbstraction kernelAbstraction;
+
+   // used for @Management interfaces
+   protected MBeanServer mbeanServer;
+
+   protected DeploymentScope deploymentScope;
+
+   protected EjbModulePersistenceUnitResolver persistenceUnitResolver;
+
+   protected MessageDestinationResolver messageDestinationResolver;
+   protected CacheFactoryRegistry cacheFactoryRegistry;
+   protected RemoteProxyFactoryRegistry remoteProxyFactoryRegistry;
+   protected PersistenceManagerFactoryRegistry persistenceManagerFactoryRegistry;
+   protected PoolFactoryRegistry poolFactoryRegistry;
+   
+   protected ObjectName objectName;
+   
+   protected boolean reinitialize = false;
+
+   private org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit;
+   
+   private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
+
+   @Deprecated
+   public Ejb3Deployment(DeploymentUnit unit, DeploymentScope deploymentScope, JBossMetaData metaData, PersistenceMetaData persistenceUnitsMetaData)
+   {
+      assert unit != null : "unit is null";
+      
+      this.unit = unit;
+      this.deploymentScope = deploymentScope;
+      this.metaData = metaData;
+      this.persistenceUnitsMetaData = persistenceUnitsMetaData;
+      try
+      {
+         initialContext = InitialContextFactory.getInitialContext(unit.getJndiProperties());
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+      persistenceUnitResolver = new EjbModulePersistenceUnitResolver(persistenceUnitDeployments, deploymentScope, ejbContainers);
+      MessageDestinationsMetaData destinations = null;
+      if (metaData != null && metaData.getAssemblyDescriptor() != null)
+         destinations = metaData.getAssemblyDescriptor().getMessageDestinations();
+      messageDestinationResolver = new MessageDestinationResolver(deploymentScope, destinations);
+   }
+   
+   /**
+    * Do not deploy persistence unit anymore.
+    * 
+    * @param deploymentUnit
+    * @param unit
+    * @param deploymentScope
+    * @param metaData
+    */
+   public Ejb3Deployment(org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit, DeploymentUnit unit, DeploymentScope deploymentScope, JBossMetaData metaData)
+   {
+      this(unit, deploymentScope, metaData, null);
+      
+      assert deploymentUnit != null : "deploymentUnit is null";
+      
+      this.deploymentUnit = deploymentUnit;
+   }
+
+   public JavaEEApplication getApplication()
+   {
+      return deploymentScope;
+   }
+
+   public DeploymentScope getEar()
+   {
+      return deploymentScope;
+   }
+
+   public KernelAbstraction getKernelAbstraction()
+   {
+      return kernelAbstraction;
+   }
+
+   public MBeanServer getMbeanServer()
+   {
+      return mbeanServer;
+   }
+
+   public void setMbeanServer(MBeanServer mbeanServer)
+   {
+      this.mbeanServer = mbeanServer;
+   }
+
+   public DeploymentUnit getDeploymentUnit()
+   {
+      return unit;
+   }
+
+   public String getDefaultSLSBDomain()
+   {
+      return defaultSLSBDomain;
+   }
+
+   public CacheFactoryRegistry getCacheFactoryRegistry()
+   {
+      return cacheFactoryRegistry;
+   }
+   public void setCacheFactoryRegistry(CacheFactoryRegistry registry)
+   {
+      this.cacheFactoryRegistry = registry;
+   }
+
+   public RemoteProxyFactoryRegistry getRemoteProxyFactoryRegistry()
+   {
+      return remoteProxyFactoryRegistry;
+   }
+   public void setRemoteProxyFactoryRegistry(RemoteProxyFactoryRegistry registry)
+   {
+      this.remoteProxyFactoryRegistry = registry;
+   }
+
+   public PersistenceManagerFactoryRegistry getPersistenceManagerFactoryRegistry()
+   {
+      return persistenceManagerFactoryRegistry;
+   }
+   public void setPersistenceManagerFactoryRegistry(PersistenceManagerFactoryRegistry registry)
+   {
+      this.persistenceManagerFactoryRegistry = registry;
+   }
+   
+   @Inject
+   public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
+   {
+      this.persistenceUnitDependencyResolver = resolver;
+   }
+   
+   public PoolFactoryRegistry getPoolFactoryRegistry()
+   {
+      return poolFactoryRegistry;
+   }
+   public void setPoolFactoryRegistry(PoolFactoryRegistry poolFactoryRegistry)
+   {
+      this.poolFactoryRegistry = poolFactoryRegistry;
+   }
+
+   public void setProcessPersistenceUnits(boolean b)
+   {
+      this.processPersistenceUnits = b;
+   }
+   
+   /**
+    * Returns a partial MBean attribute name of the form
+    * ",ear=foo.ear,jar=foo.jar"
+    *
+    * @return
+    */
+   public String getScopeKernelName()
+   {
+      String scopedKernelName = "";
+      if (deploymentScope != null)
+         scopedKernelName += ",ear=" + deploymentScope.getShortName();
+      scopedKernelName += ",jar=" + unit.getShortName();
+      return scopedKernelName;
+   }
+
+   /**
+    * The default AOP domain for stateless session beans
+    *
+    * @param defaultSLSBDomain
+    */
+   public void setDefaultSLSBDomain(String defaultSLSBDomain)
+   {
+      this.defaultSLSBDomain = defaultSLSBDomain;
+   }
+
+   public String getDefaultSFSBDomain()
+   {
+      return defaultSFSBDomain;
+   }
+
+   public String getDefaultConsumerDomain()
+   {
+      return defaultConsumerDomain;
+   }
+
+   /**
+    * The default stateful session bean aspect domain
+    *
+    * @param defaultSFSBDomain
+    */
+   public void setDefaultSFSBDomain(String defaultSFSBDomain)
+   {
+      this.defaultSFSBDomain = defaultSFSBDomain;
+   }
+
+   public String getDefaultMDBDomain()
+   {
+      return defaultMDBDomain;
+   }
+
+   /**
+    * The default AOP domain for message driven beans.
+    *
+    * @param defaultMDBDomain
+    */
+   public void setDefaultMDBDomain(String defaultMDBDomain)
+   {
+      this.defaultMDBDomain = defaultMDBDomain;
+   }
+
+   public String getDefaultServiceDomain()
+   {
+      return defaultServiceDomain;
+   }
+
+   /**
+    * default AOP domain for service beans.
+    *
+    * @param defaultServiceDomain
+    */
+   public void setDefaultServiceDomain(String defaultServiceDomain)
+   {
+      this.defaultServiceDomain = defaultServiceDomain;
+   }
+
+   protected String getJaccContextId()
+   {
+      return unit.getShortName();
+   }
+
+   /**
+    * Get the deployment ejb container for the given ejb name.
+    * 
+    * @param ejbName the deployment unique ejb name
+    * @return the ejb container if found, null otherwise
+    * @throws IllegalStateException if the ejbName cannot be used to
+    *    for the container name.
+    */
+   public EJBContainer getEjbContainerForEjbName(String ejbName)
+   {
+      String ejbObjectName = JavaEEComponentHelper.createObjectName(this, ejbName);
+      EJBContainer container = null;
+      ObjectName ejbON;
+      try
+      {
+         ejbON = new ObjectName(ejbObjectName);
+      }
+      catch (Exception e)
+      {
+         throw new IllegalStateException("Failed to ", e);
+      }
+      container = (EJBContainer) ejbContainers.get(ejbON);
+      return container;
+   }
+
+   public Container getContainer(ObjectName name)
+   {
+      return (Container) ejbContainers.get(name);
+   }
+
+   public java.util.Map getEjbContainers()
+   {
+      return ejbContainers;
+   }
+
+   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
+   {
+      return persistenceUnitResolver.getPersistenceUnitDeployment(unitName);
+   }
+
+   public PersistenceUnitDeployment getPersistenceUnitDeploymentInternal(String unitName)
+   {
+      return persistenceUnitResolver.getPersistenceUnitDeploymentInternal(unitName);
+   }
+
+   public List<PersistenceUnitDeployment> getPersistenceUnitDeployments()
+   {
+      return persistenceUnitDeployments;
+   }
+
+
+   public EJBContainer getEjbContainer(String ejbLink, Class businessIntf)
+   {
+      String relativePath = unit.getRelativePath();
+      EJBContainer container = deploymentScope.getEjbContainer(ejbLink, businessIntf, relativePath);
+      return container;
+   }
+
+   public String getEjbJndiName(String ejbLink, Class businessIntf)
+   {
+      EJBContainer container = getEjbContainer(ejbLink, businessIntf);
+      String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
+      return jndiName;
+   }
+   public String getEjbJndiName(Class businessIntf)
+      throws NameNotFoundException
+   {
+      EJBContainer container = getEjbContainer(businessIntf);
+      String jndiName = ProxyFactoryHelper.getJndiName(container, businessIntf);
+      return jndiName;
+   }
+
+   public EJBContainer getEjbContainer(Class businessIntf) throws NameNotFoundException
+   {
+      String relativePath = unit.getRelativePath();
+      return deploymentScope.getEjbContainer(businessIntf, relativePath);
+   }
+
+   protected void processEJBContainerMetadata(Container container) throws Exception
+   {
+      log.trace("Process EJB container metadata " + container);
+      ObjectName on = container.getObjectName();
+      ejbContainers.put(on, container);
+      container.processMetadata();
+   }
+   
+   protected void registerDeployment() throws Exception
+   {
+      String on = "jboss.j2ee:jar=" + this.getName() + ",service=EJB3";
+      if (metaData != null && metaData.getEnterpriseBeans() != null && metaData.getEnterpriseBeans().getEjbJarMetaData() != null)
+      {
+         String jmxName = metaData.getEnterpriseBeans().getEjbJarMetaData().getJmxName();
+         if (jmxName != null && jmxName.trim().length() > 0)
+            on = jmxName;
+      } 
+     
+      objectName = new ObjectName(on);
+      
+      mbeanServer.registerMBean(this, objectName);
+   }
+   
+   protected void unregisterDeployment()
+   {
+      try
+      {
+         mbeanServer.unregisterMBean(objectName);
+      }
+      catch (Exception e)
+      {
+         log.debug("error trying to stop ejb deployment", e);
+      }
+   }
+
+   protected void registerEJBContainer(Container container) throws Exception
+   {
+      ObjectName on = container.getObjectName();
+      String name = on.getCanonicalName();
+      DependencyPolicy dependsPolicy = container.getDependencyPolicy();
+      dependsPolicy.addDependency("jboss.ejb:service=EJBTimerService");
+      kernelAbstraction.install(name, dependsPolicy, unit, container);
+      mbeanServer.registerMBean(container.getMBean(), on);
+      log.debug("Bound ejb3 container " + name);
+   }
+
+   protected abstract PolicyConfiguration createPolicyConfiguration() throws Exception;
+
+   protected abstract void putJaccInService(PolicyConfiguration pc, DeploymentUnit unit);
+
+   /**
+    * Return the container injection handler collection. If not specified(null)
+    * a default handler collection will be created.
+    * @return the injection handler collection to use, null if the container
+    *    should use a default setup.
+    */
+   protected Collection<InjectionHandler<Environment>> getHandlers()
+   {
+      return null;
+   }
+
+   /**
+    * Create all EJB containers and Persistence Units
+    * The only things that should be initialized is metadata that does not need access to any
+    * other deployment.  This is because we want the entire EAR to be initialized so that we do not
+    * have to guess on dependencies MBean names.  This is because of the silly scoping rules for persistence units
+    * and EJBs.
+    *
+    * @throws Exception
+    */
+   public void create() throws Exception
+   {
+      try
+      {
+         long start = System.currentTimeMillis();
+
+         //pc = createPolicyConfiguration();
+
+         deploy();
+
+         initializePersistenceUnits();
+         
+         registerDeployment();
+
+         log.debug("EJB3 deployment time took: " + (System.currentTimeMillis() - start));
+      }
+      catch (Exception e)
+      {
+         try
+         {
+            destroy();
+         }
+         catch (Exception ignored)
+         {
+            // ignore
+         }
+         throw e;
+      }
+   }
+   
+   protected void reinitialize() throws Exception
+   {
+      initializePersistenceUnits();
+      reinitialize = false;
+   }
+
+   public void start() throws Exception
+   {
+      try
+      {
+         if (reinitialize)
+            reinitialize();
+         
+         startPersistenceUnits();
+
+         for (Object o : ejbContainers.values())
+         {
+            Container con = (Container) o;
+            processEJBContainerMetadata(con);
+         }
+
+         for (Object o : ejbContainers.values())
+         {
+            Container con = (Container) o;
+            registerEJBContainer(con);
+         }
+
+         //putJaccInService(pc, unit);
+      }
+      catch (Exception ex)
+      {
+         try
+         {
+            stop();
+            destroy();
+         }
+         catch (Exception ignored)
+         {
+         }
+         throw ex;
+      }
+   }
+   
+   public void stop() //throws Exception
+   {
+      for (ObjectName on : ejbContainers.keySet())
+      {
+         try
+         {
+            mbeanServer.unregisterMBean(on);
+            kernelAbstraction.uninstall(on.getCanonicalName());
+         }
+         catch (Exception e)
+         {
+            log.debug("error trying to stop ejb container", e);
+         }
+      }
+      stopPersistenceUnits();
+      
+      reinitialize = true;
+   }
+
+   protected void deploy() throws Exception
+   {
+      Ejb3HandlerFactory factory = Ejb3HandlerFactory.getInstance(this);
+      if (unit.getUrl() != null)
+         deployUrl(factory);
+
+      if (unit.getClasses() != null)
+      {
+         for (Class explicit : unit.getClasses())
+         {
+            if (explicit.isAnnotationPresent(Entity.class))
+            {
+               continue;
+            }
+            String name = explicit.getName().replace('.', '/') + ".class";
+            InputStream stream = explicit.getClassLoader().getResourceAsStream(name);
+            deployElement(stream, factory, initialContext);
+         }
+      }
+
+      deployBeansFromLib(initialContext);
+   }
+
+   protected void deployUrl(Ejb3HandlerFactory factory) throws Exception
+   {
+      // make sure we are not deploying ejbs from client jar
+      List<VirtualFile> clientDescriptors = unit.getResources(new org.jboss.ejb3.ClientDescriptorFileFilter());
+
+      if (clientDescriptors.size() > 0)
+         return;
+
+      InitialContext ctx = initialContext;
+      // need to look into every entry in the archive to see if anybody has tags
+      // defined.
+      List<VirtualFile> classes = unit.getResources(new org.jboss.ejb3.ClassFileFilter());
+      for (VirtualFile classFile : classes)
+      {
+         InputStream stream = classFile.openStream();
+         deployElement(stream, factory, ctx);
+      }
+   }
+
+   protected void deployElement(InputStream stream, Ejb3HandlerFactory factory, InitialContext ctx) throws Exception
+   {
+      DataInputStream dstream = new DataInputStream(new BufferedInputStream(stream));
+      ClassFile cf = null;
+      try
+      {
+         cf = new ClassFile(dstream);
+      }
+      finally
+      {
+         dstream.close();
+         stream.close();
+      }
+
+      deployElement(factory, cf, ctx);
+
+   }
+
+   protected void deployBeansFromLib(InitialContext ctx) throws Exception
+   {
+      JBossMetaData dd = getMetaData();
+      if (dd != null)
+      {
+         Ejb3DescriptorHandler handler = new Ejb3DescriptorHandler(this, dd);
+         handler.setCtxProperties(unit.getJndiProperties());
+
+         Map<String, Container> localContainers = new HashMap<String, Container>();
+         Iterator<Container> containerIterator = ejbContainers.values().iterator();
+         while (containerIterator.hasNext())
+         {
+            Container container = containerIterator.next();
+            localContainers.put(container.getEjbName(), container);
+         }
+
+         List<Container> containers = handler.getContainers(this, localContainers);
+         for (Container con : containers)
+         {
+            // EJBContainer has finished with all metadata initialization from XML files and such.
+            // this is really a hook to do some processing after XML has been set up and before
+            // and processing of dependencies and such.
+            ((EJBContainer) con).instantiated();
+            this.ejbContainers.put(con.getObjectName(), con);
+            Ejb3Registry.register(con);
+         }
+      }
+   }
+
+   protected void deployElement(Ejb3HandlerFactory factory, ClassFile cf, InitialContext ctx) throws Exception
+   {
+      Ejb3Handler handler = factory.createHandler(cf);
+      handler.setCtxProperties(unit.getJndiProperties());
+
+      if (handler.isEjb() || handler.isJBossBeanType())
+      {
+         List<Container> containers = handler.getContainers(cf, this);
+         for (Container con : containers)
+         {
+            // EJBContainer has finished with all metadata initialization from XML files and such.
+            // this is really a hook to do some processing after XML has been set up and before
+            // and processing of dependencies and such.
+            try
+            {
+               ((EJBContainer) con).instantiated();
+               this.ejbContainers.put(con.getObjectName(), con);
+               Ejb3Registry.register(con);
+            }
+            catch (Throwable t)
+            {
+               throw new DeploymentException(
+                     "Error creating ejb container " + con.getEjbName() + ": " + t.getMessage(), t);
+            }
+         }
+      }
+   }
+
+   protected void initializePersistenceUnits() throws Exception
+   {
+      hasEntities = persistenceUnitsMetaData != null && processPersistenceUnits;
+
+      if (!hasEntities)
+         return;
+
+      if (unit.getClasses() != null)
+      {
+         for (Class<?> explicit : unit.getClasses())
+         {
+            if (explicit.isAnnotationPresent(Entity.class))
+            {
+               explicitEntityClasses.add(explicit.getName());
+            }
+         }
+      }
+
+      // scope the unitName if this is an ejb archive
+      // todo revert to this: List<PersistenceMetadata> persistenceMetadata = PersistenceXmlLoader.deploy(persistenceXmlUrl, new HashMap(), new EJB3DTDEntityResolver());
+      List<PersistenceUnitMetaData> pumds = persistenceUnitsMetaData.getPersistenceUnits();
+      for (PersistenceUnitMetaData metaData : pumds)
+      {
+         String earShortName = deploymentScope == null ? null : deploymentScope.getShortName();
+         boolean isScoped = ejbContainers.size() > 0;
+
+         Map<String, String> properties = metaData.getProperties();
+         if (properties == null)
+         {
+            properties = new HashMap<String, String>();
+            metaData.setProperties(properties);
+         }
+         // Ensure 2nd level cache entries are segregated from other deployments
+         String cache_prefix = properties.get(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX);
+         if (cache_prefix == null)
+         {
+            // Create a region_prefix for the 2nd level cache to ensure
+            // deployments are segregated
+            String jarName = isScoped ? unit.getShortName() : null;
+            cache_prefix = SecondLevelCacheUtil.createCacheRegionPrefix(earShortName, jarName, metaData.getName());
+            properties.put(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX, cache_prefix);
+         }
+         PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(initialContext, this, explicitEntityClasses, metaData, earShortName, unit.getShortName(), isScoped);
+         PersistenceUnitRegistry.register(deployment);
+         persistenceUnitDeployments.add(deployment);
+      }
+   }
+
+   public abstract DependencyPolicy createDependencyPolicy(JavaEEComponent component);
+
+   protected void startPersistenceUnits()
+   {
+      if (persistenceUnitDeployments == null)
+         return;
+
+      for (PersistenceUnitDeployment entityDeployment : persistenceUnitDeployments)
+      {
+         if (entityDeployment != null)
+         {
+            DependencyPolicy policy = createDependencyPolicy(entityDeployment);
+            entityDeployment.addDependencies(policy);
+            kernelAbstraction.install(entityDeployment.getKernelName(), policy, unit, entityDeployment);
+         }
+      }
+   }
+
+   protected void stopPersistenceUnits()
+   {
+      if (persistenceUnitDeployments == null)
+         return;
+
+      for (PersistenceUnitDeployment entityDeployment : persistenceUnitDeployments)
+      {
+         try
+         {
+            PersistenceUnitRegistry.unregister(entityDeployment);
+            if (entityDeployment != null)
+            {
+               kernelAbstraction.uninstall(entityDeployment.getKernelName());
+            }
+         }
+         catch (Exception e)
+         {
+            log.debug("error trying to shut down persistence unit", e);
+         }
+      }
+      
+      persistenceUnitDeployments = new ArrayList<PersistenceUnitDeployment>();
+
+   }
+
+   
+
+   public void destroy() //throws Exception
+   {
+      try
+      {
+         undeploy();
+         
+         unregisterDeployment();
+      } 
+      catch (Exception e)
+      {
+         log.debug("error trying to destroy ejb deployment", e);
+      }
+   }
+
+   private void undeploy()
+   {
+      for (Container container : ejbContainers.values())
+      {
+         Ejb3Registry.unregister(container);
+      }
+   }
+
+   //   /**
+   //    * Get the jndi name of a message destination.
+   //    * 
+   //    * @param name   the name of the message destination
+   //    * @return       the jndi name
+   //    */
+   //   private String getMessageDestination(String name)
+   //   {
+   //      EjbJarDD dd;
+   //      // FIXME: Why isn't dd stored somewhere?
+   //      try
+   //      {
+   //         dd = EjbJarDDObjectFactory.parse(getDeploymentUnit().getEjbJarXml());
+   //         dd = JBossDDObjectFactory.parse(getDeploymentUnit().getJbossXml(), dd);
+   //      }
+   //      catch(IOException e)
+   //      {
+   //         throw new RuntimeException(e);
+   //      }
+   //      catch(JBossXBException e)
+   //      {
+   //         throw new RuntimeException(e);
+   //      }
+   //
+   //      AssemblyDescriptor ad = dd.getAssemblyDescriptor();
+   //      if(ad == null)
+   //         throw new IllegalStateException("No assembly descriptor found in '" + getName() + "'");
+   //      MessageDestination md = ad.findMessageDestination(name);
+   //      if(md == null)
+   //         throw new IllegalStateException("No message destination '" + name + "' found in '" + getName() + "'");
+   //      String jndiName = md.getJndiName();
+   //      if(jndiName == null)
+   //         throw new IllegalStateException("No jndi name specified for message destination '" + name + "' in '" + getName() + "'");
+   //      return jndiName;
+   //   }
+
+   public String resolveMessageDestination(String link)
+   {
+      //      // FIXME: this is a copy of DeploymentEjbResolver
+      //      int hashIndex = link.indexOf('#');
+      //      if (hashIndex != -1)
+      //      {
+      //         if (deploymentScope == null)
+      //         {
+      //            log.warn("ejb link '" + link + "' is relative, but no deployment scope found");
+      //            return null;
+      //         }
+      //         String relativePath = link.substring(0, hashIndex);
+      //         Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
+      //         if (dep == null)
+      //         {
+      //            log.warn("can't find a deployment for path '" + relativePath + "' of ejb link '" + link + "'");
+      //            return null;
+      //         }
+      //         String name = link.substring(hashIndex + 1);
+      //         return dep.getMessageDestination(name);
+      //      }
+      //      return getMessageDestination(link);
+      return messageDestinationResolver.resolveMessageDestination(link);
+   }
+
+   protected String resolvePersistenceUnitSupplier(String persistenceUnitName)
+   {
+      return persistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
+   }
+   
+   public MessageDestinationResolver getMessageDestinationResolver()
+   {
+      return messageDestinationResolver;
+   }
+
+   /**
+    * Do not call, for use in Ejb3Handler.
+    * 
+    * @param <B>
+    * @param ejbName
+    * @param enterpriseBeanMetaDataClass
+    * @return
+    */
+   protected <B extends JBossEnterpriseBeanMetaData> B getEnterpriseBeanMetaData(String ejbName, Class<B> enterpriseBeanMetaDataClass)
+   {
+      if(metaData == null)
+         return null;
+      
+      JBossEnterpriseBeanMetaData result = metaData.getEnterpriseBean(ejbName);
+      
+      // FIXME: EJBTHREE-1227: temporary workaround for JBCTS-756
+      // see also org.jboss.ejb3.metadata.JBossSessionGenericWrapper
+      if(result instanceof JBossGenericBeanMetaData)
+      {
+         log.warn("FIXME: EJBTHREE-1227: JBossGenericBeanMetaData found for '" + ejbName + "' instead of " + enterpriseBeanMetaDataClass);
+         if(enterpriseBeanMetaDataClass.equals(JBossSessionBeanMetaData.class))
+         {
+            result = new JBossSessionGenericWrapper((JBossGenericBeanMetaData) result);
+         }
+         else if(enterpriseBeanMetaDataClass.equals(JBossMessageDrivenBeanMetaData.class))
+         {
+            result = new JBossMessageDrivenBeanGenericWrapper((JBossGenericBeanMetaData) result);
+         }
+         else
+         {
+            throw new IllegalStateException("Can't find a generic bean meta data wrapper for " + enterpriseBeanMetaDataClass);
+         }
+      }
+      
+      return ClassHelper.cast(enterpriseBeanMetaDataClass, result);
+   }
+   
+   /**
+    * Get the meta data associated with this deployment or null if none.
+    * 
+    * @return   meta data or null
+    */
+   public JBossMetaData getMetaData()
+   {
+      return metaData;
+   }
+
+   public String getName()
+   {
+      return unit.getShortName();
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3;
-
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.Collection;
-import org.jboss.logging.Logger;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-
-/**
- * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
- * @version <tt>$Revision$</tt>
- */
-public class PersistenceUnitRegistry
-{
-   private static final Logger log = Logger.getLogger(PersistenceUnitRegistry.class);
-
-   private static ConcurrentHashMap<String, PersistenceUnitDeployment> persistenceUnits = new ConcurrentHashMap<String, PersistenceUnitDeployment>();
-
-   public static void register(PersistenceUnitDeployment container)
-   {
-      if (persistenceUnits.contains(container.getKernelName())) throw new RuntimeException("Persistence Unit is already registered: " + container.getKernelName());
-      persistenceUnits.put(container.getKernelName(), container);
-   }
-
-   public static void unregister(PersistenceUnitDeployment container)
-   {
-      persistenceUnits.remove(container.getKernelName());
-   }
-
-   public static PersistenceUnitDeployment getPersistenceUnit(String kernelName)
-   {
-      return persistenceUnits.get(kernelName);
-   }
-
-   public static Collection<PersistenceUnitDeployment> getPersistenceUnits()
-   {
-      return persistenceUnits.values();
-   }
-
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3;
+
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ * @version <tt>$Revision$</tt>
+ */
+ at Deprecated
+public class PersistenceUnitRegistry
+{
+   private static final Logger log = Logger.getLogger(PersistenceUnitRegistry.class);
+
+   private static ConcurrentHashMap<String, PersistenceUnitDeployment> persistenceUnits = new ConcurrentHashMap<String, PersistenceUnitDeployment>();
+
+   public static void register(PersistenceUnitDeployment container)
+   {
+      if (persistenceUnits.contains(container.getKernelName())) throw new RuntimeException("Persistence Unit is already registered: " + container.getKernelName());
+      persistenceUnits.put(container.getKernelName(), container);
+   }
+
+   public static void unregister(PersistenceUnitDeployment container)
+   {
+      persistenceUnits.remove(container.getKernelName());
+   }
+
+   public static PersistenceUnitDeployment getPersistenceUnit(String kernelName)
+   {
+      return persistenceUnits.get(kernelName);
+   }
+
+   public static Collection<PersistenceUnitDeployment> getPersistenceUnits()
+   {
+      return persistenceUnits.values();
+   }
+
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,73 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity;
-
-import java.util.Map;
-import javax.persistence.EntityManager;
-import javax.transaction.TransactionManager;
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.ejb3.PersistenceUnitRegistry;
-import org.jboss.ejb3.stateful.StatefulBeanContext;
-import org.jboss.ejb3.stateful.StatefulContainerInvocation;
-import org.jboss.ejb3.tx.TxUtil;
-import org.jboss.logging.Logger;
-
-/**
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class ExtendedPersistenceContextPropagationInterceptor implements Interceptor
-{
-   private static final Logger log = Logger.getLogger(ExtendedPersistenceContextPropagationInterceptor.class);
-
-   public String getName()
-   {
-      return this.getClass().getName();
-   }
-
-   public Object invoke(Invocation invocation) throws Throwable
-   {
-      log.debug("++++ LongLivedSessionPropagationInterceptor");
-      StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
-      StatefulBeanContext ctx = (StatefulBeanContext) ejb.getBeanContext();
-
-      Map<String, EntityManager> extendedPCs = ctx.getExtendedPersistenceContexts();
-      if (extendedPCs == null || extendedPCs.size() == 0)
-      {
-         return invocation.invokeNext();
-      }
-
-      TransactionManager tm = TxUtil.getTransactionManager();
-      if (tm.getTransaction() != null)
-      {
-         for (String kernelname : extendedPCs.keySet())
-         {
-            EntityManager manager = extendedPCs.get(kernelname);
-            ManagedEntityManagerFactory factory = PersistenceUnitRegistry.getPersistenceUnit(kernelname).getManagedFactory();
-            factory.registerExtendedWithTransaction(manager);
-         }
-      }
-
-      return invocation.invokeNext();
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity;
+
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.transaction.TransactionManager;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.ejb3.stateful.StatefulContainerInvocation;
+import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class ExtendedPersistenceContextPropagationInterceptor implements Interceptor
+{
+   private static final Logger log = Logger.getLogger(ExtendedPersistenceContextPropagationInterceptor.class);
+
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      log.debug("++++ LongLivedSessionPropagationInterceptor");
+      StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
+      StatefulBeanContext ctx = (StatefulBeanContext) ejb.getBeanContext();
+
+      Map<String, EntityManager> extendedPCs = ctx.getExtendedPersistenceContexts();
+      if (extendedPCs == null || extendedPCs.size() == 0)
+      {
+         return invocation.invokeNext();
+      }
+
+      TransactionManager tm = TxUtil.getTransactionManager();
+      if (tm.getTransaction() != null)
+      {
+         for (String kernelname : extendedPCs.keySet())
+         {
+            EntityManager manager = extendedPCs.get(kernelname);
+            ManagedEntityManagerFactory factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelname);
+            factory.registerExtendedWithTransaction(manager);
+         }
+      }
+
+      return invocation.invokeNext();
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,101 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Map;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import org.jboss.ejb3.PersistenceUnitRegistry;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class InjectedEntityManagerFactory implements EntityManagerFactory, Externalizable
-{
-   private static final long serialVersionUID = -3734435119658196788L;
-   
-   private transient EntityManagerFactory delegate;
-   private transient ManagedEntityManagerFactory managedFactory;
-   
-   public InjectedEntityManagerFactory() {}
-
-   public InjectedEntityManagerFactory(ManagedEntityManagerFactory managedFactory)
-   {
-      assert managedFactory != null : "managedFactory is null";
-      
-      this.delegate = managedFactory.getEntityManagerFactory();
-      this.managedFactory = managedFactory;
-   }
-
-
-   public EntityManagerFactory getDelegate()
-   {
-      return delegate;
-   }
-
-   public void writeExternal(ObjectOutput out) throws IOException
-   {
-      out.writeUTF(managedFactory.getKernelName());
-   }
-
-   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
-   {
-      String kernelName = in.readUTF();
-      PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
-      if (deployment == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
-      managedFactory = deployment.getManagedFactory();
-      delegate = managedFactory.getEntityManagerFactory();
-   }
-
-   public EntityManager createEntityManager()
-   {
-      return getDelegate().createEntityManager();
-   }
-
-   public EntityManager createEntityManager(Map map)
-   {
-      return delegate.createEntityManager(map);
-   }
-
-
-   public EntityManager getEntityManager()
-   {
-      return new TransactionScopedEntityManager(managedFactory);
-   }
-
-   public void close()
-   {
-      throw new IllegalStateException("It is illegal to close an injected EntityManagerFactory");
-   }
-
-   public boolean isOpen()
-   {
-      return getDelegate().isOpen();
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class InjectedEntityManagerFactory implements EntityManagerFactory, Externalizable
+{
+   private static final long serialVersionUID = -3734435119658196788L;
+   
+   private transient EntityManagerFactory delegate;
+   private transient ManagedEntityManagerFactory managedFactory;
+   
+   public InjectedEntityManagerFactory() {}
+
+   public InjectedEntityManagerFactory(ManagedEntityManagerFactory managedFactory)
+   {
+      assert managedFactory != null : "managedFactory is null";
+      
+      this.delegate = managedFactory.getEntityManagerFactory();
+      this.managedFactory = managedFactory;
+   }
+
+
+   public EntityManagerFactory getDelegate()
+   {
+      return delegate;
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeUTF(managedFactory.getKernelName());
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      String kernelName = in.readUTF();
+      managedFactory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+      if(managedFactory == null)
+         throw new IOException("Unable to find persistence unit in registry: " + kernelName);
+      delegate = managedFactory.getEntityManagerFactory();
+   }
+
+   public EntityManager createEntityManager()
+   {
+      return getDelegate().createEntityManager();
+   }
+
+   public EntityManager createEntityManager(Map map)
+   {
+      return delegate.createEntityManager(map);
+   }
+
+
+   public EntityManager getEntityManager()
+   {
+      return new TransactionScopedEntityManager(managedFactory);
+   }
+
+   public void close()
+   {
+      throw new IllegalStateException("It is illegal to close an injected EntityManagerFactory");
+   }
+
+   public boolean isOpen()
+   {
+      return getDelegate().isOpen();
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,240 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Serializable;
-import java.sql.Connection;
-import java.util.Map;
-import java.util.Set;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.persistence.EntityManagerFactory;
-import org.hibernate.HibernateException;
-import org.hibernate.Interceptor;
-import org.hibernate.SessionFactory;
-import org.hibernate.StatelessSession;
-import org.hibernate.classic.Session;
-import org.hibernate.ejb.HibernateEntityManagerFactory;
-import org.hibernate.engine.FilterDefinition;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.metadata.CollectionMetadata;
-import org.hibernate.stat.Statistics;
-import org.jboss.ejb3.PersistenceUnitRegistry;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class InjectedSessionFactory implements SessionFactory, Externalizable
-{
-   private static final long serialVersionUID = 7866450655332120010L;
-   
-   private transient EntityManagerFactory delegate;
-   private transient ManagedEntityManagerFactory managedFactory;
-
-   public InjectedSessionFactory(ManagedEntityManagerFactory factory)
-   {
-      this.managedFactory = factory;
-      this.delegate = factory.getEntityManagerFactory();
-   }
-
-   public InjectedSessionFactory() {}
-
-   public void writeExternal(ObjectOutput out) throws IOException
-   {
-      out.writeUTF(managedFactory.getKernelName());
-   }
-
-   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
-   {
-      String kernelName = in.readUTF();
-      PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
-      if (deployment == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
-      managedFactory = deployment.getManagedFactory();
-      delegate = managedFactory.getEntityManagerFactory();
-   }
-
-   private EntityManagerFactory getDelegate()
-   {
-      return delegate;
-   }
-
-   private SessionFactory getSessionFactory()
-   {
-      return ((HibernateEntityManagerFactory)getDelegate()).getSessionFactory();
-   }
-
-   public Set getDefinedFilterNames()
-   {
-      return getSessionFactory().getDefinedFilterNames();
-   }
-
-   public FilterDefinition getFilterDefinition(String filterName) throws HibernateException
-   {
-      return getSessionFactory().getFilterDefinition(filterName);
-   }
-
-   public Session openSession(Connection connection)
-   {
-      return getSessionFactory().openSession(connection);
-   }
-
-   public Session openSession(Interceptor interceptor)
-   throws HibernateException
-   {
-      return getSessionFactory().openSession(interceptor);
-   }
-
-   public Session openSession(Connection connection, Interceptor interceptor)
-   {
-      return getSessionFactory().openSession(connection, interceptor);
-   }
-
-   public Session openSession()
-   throws HibernateException
-   {
-      return getSessionFactory().openSession();
-   }
-
-   public Session getCurrentSession()
-   throws HibernateException
-   {
-      return getSessionFactory().getCurrentSession();
-   }
-
-   public ClassMetadata getClassMetadata(Class persistentClass)
-   throws HibernateException
-   {
-      return getSessionFactory().getClassMetadata(persistentClass);
-   }
-
-   public ClassMetadata getClassMetadata(String entityName)
-   throws HibernateException
-   {
-      return getSessionFactory().getClassMetadata(entityName);
-   }
-
-   public CollectionMetadata getCollectionMetadata(String roleName)
-   throws HibernateException
-   {
-      return getSessionFactory().getCollectionMetadata(roleName);
-   }
-
-   public Map getAllClassMetadata()
-   throws HibernateException
-   {
-      return getSessionFactory().getAllClassMetadata();
-   }
-
-   public Map getAllCollectionMetadata()
-   throws HibernateException
-   {
-      return getSessionFactory().getAllCollectionMetadata();
-   }
-
-   public Statistics getStatistics()
-   {
-      return getSessionFactory().getStatistics();
-   }
-
-   public void close()
-   throws HibernateException
-   {
-      throw new IllegalStateException("It is illegal to close an injected SessionFactory");
-   }
-
-   public boolean isClosed()
-   {
-      return getSessionFactory().isClosed();
-   }
-
-   public void evict(Class persistentClass)
-   throws HibernateException
-   {
-      getSessionFactory().evict(persistentClass);
-   }
-
-   public void evict(Class persistentClass, Serializable id)
-   throws HibernateException
-   {
-      getSessionFactory().evict(persistentClass, id);
-   }
-
-   public void evictEntity(String entityName)
-   throws HibernateException
-   {
-      getSessionFactory().evictEntity(entityName);
-   }
-
-   public void evictEntity(String entityName, Serializable id)
-   throws HibernateException
-   {
-      getSessionFactory().evictEntity(entityName, id);
-   }
-
-   public void evictCollection(String roleName)
-   throws HibernateException
-   {
-      getSessionFactory().evictCollection(roleName);
-   }
-
-   public void evictCollection(String roleName, Serializable id)
-   throws HibernateException
-   {
-      getSessionFactory().evictCollection(roleName, id);
-   }
-
-   public void evictQueries()
-   throws HibernateException
-   {
-      getSessionFactory().evictQueries();
-   }
-
-   public void evictQueries(String cacheRegion)
-   throws HibernateException
-   {
-      getSessionFactory().evictQueries(cacheRegion);
-   }
-
-   public StatelessSession openStatelessSession()
-   {
-      return getSessionFactory().openStatelessSession();
-   }
-
-   public StatelessSession openStatelessSession(Connection connection)
-   {
-      return getSessionFactory().openStatelessSession(connection);
-   }
-
-   public Reference getReference()
-   throws NamingException
-   {
-      return getSessionFactory().getReference();
-   }
-
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,241 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.sql.Connection;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.persistence.EntityManagerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Interceptor;
+import org.hibernate.SessionFactory;
+import org.hibernate.StatelessSession;
+import org.hibernate.classic.Session;
+import org.hibernate.ejb.HibernateEntityManagerFactory;
+import org.hibernate.engine.FilterDefinition;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.metadata.CollectionMetadata;
+import org.hibernate.stat.Statistics;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class InjectedSessionFactory implements SessionFactory, Externalizable
+{
+   private static final long serialVersionUID = 7866450655332120010L;
+   
+   private transient EntityManagerFactory delegate;
+   private transient ManagedEntityManagerFactory managedFactory;
+
+   public InjectedSessionFactory(ManagedEntityManagerFactory factory)
+   {
+      this.managedFactory = factory;
+      this.delegate = factory.getEntityManagerFactory();
+   }
+
+   public InjectedSessionFactory() {}
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeUTF(managedFactory.getKernelName());
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      String kernelName = in.readUTF();
+      managedFactory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+      if (managedFactory == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
+      delegate = managedFactory.getEntityManagerFactory();
+   }
+
+   private EntityManagerFactory getDelegate()
+   {
+      return delegate;
+   }
+
+   private SessionFactory getSessionFactory()
+   {
+      return ((HibernateEntityManagerFactory)getDelegate()).getSessionFactory();
+   }
+
+   public Set getDefinedFilterNames()
+   {
+      return getSessionFactory().getDefinedFilterNames();
+   }
+
+   public FilterDefinition getFilterDefinition(String filterName) throws HibernateException
+   {
+      return getSessionFactory().getFilterDefinition(filterName);
+   }
+
+   public Session openSession(Connection connection)
+   {
+      return getSessionFactory().openSession(connection);
+   }
+
+   public Session openSession(Interceptor interceptor)
+   throws HibernateException
+   {
+      return getSessionFactory().openSession(interceptor);
+   }
+
+   public Session openSession(Connection connection, Interceptor interceptor)
+   {
+      return getSessionFactory().openSession(connection, interceptor);
+   }
+
+   public Session openSession()
+   throws HibernateException
+   {
+      return getSessionFactory().openSession();
+   }
+
+   public Session getCurrentSession()
+   throws HibernateException
+   {
+      return getSessionFactory().getCurrentSession();
+   }
+
+   public ClassMetadata getClassMetadata(Class persistentClass)
+   throws HibernateException
+   {
+      return getSessionFactory().getClassMetadata(persistentClass);
+   }
+
+   public ClassMetadata getClassMetadata(String entityName)
+   throws HibernateException
+   {
+      return getSessionFactory().getClassMetadata(entityName);
+   }
+
+   public CollectionMetadata getCollectionMetadata(String roleName)
+   throws HibernateException
+   {
+      return getSessionFactory().getCollectionMetadata(roleName);
+   }
+
+   public Map getAllClassMetadata()
+   throws HibernateException
+   {
+      return getSessionFactory().getAllClassMetadata();
+   }
+
+   public Map getAllCollectionMetadata()
+   throws HibernateException
+   {
+      return getSessionFactory().getAllCollectionMetadata();
+   }
+
+   public Statistics getStatistics()
+   {
+      return getSessionFactory().getStatistics();
+   }
+
+   public void close()
+   throws HibernateException
+   {
+      throw new IllegalStateException("It is illegal to close an injected SessionFactory");
+   }
+
+   public boolean isClosed()
+   {
+      return getSessionFactory().isClosed();
+   }
+
+   public void evict(Class persistentClass)
+   throws HibernateException
+   {
+      getSessionFactory().evict(persistentClass);
+   }
+
+   public void evict(Class persistentClass, Serializable id)
+   throws HibernateException
+   {
+      getSessionFactory().evict(persistentClass, id);
+   }
+
+   public void evictEntity(String entityName)
+   throws HibernateException
+   {
+      getSessionFactory().evictEntity(entityName);
+   }
+
+   public void evictEntity(String entityName, Serializable id)
+   throws HibernateException
+   {
+      getSessionFactory().evictEntity(entityName, id);
+   }
+
+   public void evictCollection(String roleName)
+   throws HibernateException
+   {
+      getSessionFactory().evictCollection(roleName);
+   }
+
+   public void evictCollection(String roleName, Serializable id)
+   throws HibernateException
+   {
+      getSessionFactory().evictCollection(roleName, id);
+   }
+
+   public void evictQueries()
+   throws HibernateException
+   {
+      getSessionFactory().evictQueries();
+   }
+
+   public void evictQueries(String cacheRegion)
+   throws HibernateException
+   {
+      getSessionFactory().evictQueries(cacheRegion);
+   }
+
+   public StatelessSession openStatelessSession()
+   {
+      return getSessionFactory().openStatelessSession();
+   }
+
+   public StatelessSession openStatelessSession(Connection connection)
+   {
+      return getSessionFactory().openStatelessSession(connection);
+   }
+
+   public Reference getReference()
+   throws NamingException
+   {
+      return getSessionFactory().getReference();
+   }
+
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,203 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceContextType;
-import javax.persistence.TransactionRequiredException;
-import javax.transaction.RollbackException;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionLocal;
-import org.jboss.tm.TxUtils;
-import org.jboss.ejb3.ThreadLocalStack;
-import org.jboss.ejb3.tx.TxUtil;
-
-import java.util.IdentityHashMap;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:gavine at hibernate.org">Gavin King</a>
- * @version $Revision$
- */
-public class ManagedEntityManagerFactory
-{
-   private static final Logger log = Logger.getLogger(ManagedEntityManagerFactory.class);
-
-   protected EntityManagerFactory entityManagerFactory;
-   protected TransactionLocal session = new TransactionLocal(TxUtil.getTransactionManager());
-   protected String kernelName;
-
-   public static ThreadLocalStack<Map> nonTxStack = new ThreadLocalStack<Map>();
-
-   public EntityManager getNonTxEntityManager()
-   {
-      Map map = nonTxStack.get();
-      
-      EntityManager em = null;
-      if (map != null)
-         em = (EntityManager)map.get(this);
-      else
-      {
-         map = new HashMap();
-         nonTxStack.push(map);
-      }
-      
-      if (em == null)
-      {
-         em = entityManagerFactory.createEntityManager();
-         map.put(this, em);
-      }
-      return em;
-   }
-
-   public ManagedEntityManagerFactory(EntityManagerFactory sf, String kernelName)
-   {
-      this.entityManagerFactory = sf;
-      this.kernelName = kernelName;
-   }
-
-   public EntityManagerFactory getEntityManagerFactory()
-   {
-      return entityManagerFactory;
-   }
-
-   public String getKernelName()
-   {
-      return kernelName;
-   }
-
-   public void destroy()
-   {
-      entityManagerFactory.close();
-   }
-
-   private static class SessionSynchronization implements Synchronization
-   {
-      private EntityManager manager;
-      private Transaction tx;
-      private boolean closeAtTxCompletion;
-
-      public SessionSynchronization(EntityManager session, Transaction tx, boolean close)
-      {
-         this.manager = session;
-         this.tx = tx;
-         closeAtTxCompletion = close;
-      }
-
-      public void beforeCompletion()
-      {
-         /*  IF THIS GETS REACTIVATED THEN YOU MUST remove the if(closeAtTxCompletion) block in getSession()
-         try
-         {
-            int status = tx.getStatus();
-            if (status != Status.STATUS_ROLLEDBACK && status != Status.STATUS_ROLLING_BACK && status != Status.STATUS_MARKED_ROLLBACK)
-            {
-               if (FlushModeInterceptor.getTxFlushMode() != FlushModeType.NEVER)
-               {
-                  log.debug("************** flushing.....");
-                  manager.flush();
-               }
-            }
-         }
-         catch (SystemException e)
-         {
-            throw new RuntimeException(e);
-         }
-         */
-      }
-
-      public void afterCompletion(int status)
-      {
-         if (closeAtTxCompletion)
-         {
-            log.debug("************** closing entity managersession **************");
-            manager.close();
-         }
-      }
-   }
-
-   public static ThreadLocal longLivedSession = new ThreadLocal();
-
-   public TransactionLocal getTransactionSession()
-   {
-      return session;
-   }
-
-   public void registerExtendedWithTransaction(EntityManager pc)
-   {
-      pc.joinTransaction();
-      session.set(pc);
-   }
-
-   public void verifyInTx()
-   {
-      Transaction tx = session.getTransaction();
-      if (tx == null || !TxUtils.isActive(tx)) throw new TransactionRequiredException("EntityManager must be access within a transaction");
-      if (!TxUtils.isActive(tx))
-         throw new TransactionRequiredException("Transaction must be active to access EntityManager");
-   }
-   public boolean isInTx()
-   {
-      Transaction tx = session.getTransaction();
-      if (tx == null || !TxUtils.isActive(tx)) return false;
-      return true;
-   }
-
-   public EntityManager getTransactionScopedEntityManager()
-   {
-      Transaction tx = session.getTransaction();
-      if (tx == null || !TxUtils.isActive(tx)) return getNonTxEntityManager();
-
-      EntityManager rtnSession = (EntityManager) session.get();
-      if (rtnSession == null)
-      {
-         rtnSession = createEntityManager();
-         try
-         {
-            tx.registerSynchronization(new SessionSynchronization(rtnSession, tx, true));
-         }
-         catch (RollbackException e)
-         {
-            throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
-         }
-         catch (SystemException e)
-         {
-            throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
-         }
-         session.set(rtnSession);
-         rtnSession.joinTransaction(); // force registration with TX
-      }
-      return rtnSession;
-   }
-
-   public EntityManager createEntityManager()
-   {
-      return entityManagerFactory.createEntityManager();
-   }
-
-
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity;
+
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.deployment.PersistenceUnitDeployment;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ManagedEntityManagerFactoryHelper
+{
+   public static ManagedEntityManagerFactory getManagedEntityManagerFactory(String kernelName)
+   {
+      PersistenceUnitDeployment pu = (PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(kernelName);
+      if(pu != null)
+         return pu.getManagedFactory();
+      // Legacy
+      org.jboss.ejb3.entity.PersistenceUnitDeployment oldPu = org.jboss.ejb3.PersistenceUnitRegistry.getPersistenceUnit(kernelName);
+      if(oldPu != null)
+         return oldPu.getManagedFactory();
+      return null;
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,330 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import javax.naming.InitialContext;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceProvider;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-
-import org.hibernate.ejb.HibernatePersistence;
-import org.jboss.ejb3.DependencyPolicy;
-import org.jboss.ejb3.DeploymentUnit;
-import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.NonSerializableFactory;
-import org.jboss.ejb3.javaee.AbstractJavaEEComponent;
-import org.jboss.ejb3.javaee.SimpleJavaEEModule;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
-import org.jboss.metadata.jpa.spec.TransactionType;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VFSUtils;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class PersistenceUnitDeployment extends AbstractJavaEEComponent
-{
-   private static final Logger log = Logger.getLogger(PersistenceUnitDeployment.class);
-
-   protected InitialContext initialContext;
-   protected DeploymentUnit di;
-   protected List<String> explicitEntityClasses = new ArrayList<String>();
-   protected ManagedEntityManagerFactory managedFactory;
-   protected EntityManagerFactory actualFactory;
-   protected PersistenceUnitMetaData metaData;
-   protected String kernelName;
-   protected Ejb3Deployment deployment;
-   protected boolean scoped;
-
-   public PersistenceUnitDeployment(InitialContext initialContext, Ejb3Deployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String ear, String jar, boolean isScoped)
-   {
-      super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
-      
-      this.scoped = isScoped;
-      this.deployment = deployment;
-      this.initialContext = initialContext;
-      this.di = deployment.getDeploymentUnit();
-      this.explicitEntityClasses = explicitEntityClasses;
-      this.metaData = metadata;
-      kernelName = "persistence.units:";
-      String name = getEntityManagerName();
-      if (name == null || name.length() == 0)
-         throw new RuntimeException("Null string is not allowed for a persistence unit name.  Fix your persistence.xml file");
-      
-      if (ear != null)
-      {
-         kernelName += "ear=" + ear;
-         if (!ear.endsWith(".ear")) kernelName += ".ear";
-         kernelName += ",";
-      }
-      if (isScoped)
-      {
-         kernelName += "jar=" + jar;
-         if (!jar.endsWith(".jar")) kernelName += ".jar";
-         kernelName += ",";
-      }
-      kernelName += "unitName=" + name;
-   }
-
-   public static String getDefaultKernelName(String unitName)
-   {
-      int hashIndex = unitName.indexOf('#');
-      if (hashIndex != -1)
-      {
-         String relativePath = unitName.substring(3, hashIndex);
-         String name = unitName.substring(hashIndex + 1);
-         return "persistence.units:jar=" + relativePath + "," + "unitName=" + name;
-      }
-      return "persistence.units:unitName=" + unitName;
-   }
-
-   public boolean isScoped()
-   {
-      return scoped;
-   }
-
-   public Ejb3Deployment getDeployment()
-   {
-      return deployment;
-   }
-
-   protected String getJaccContextId()
-   {
-      return di.getShortName();
-   }
-
-   public EntityManagerFactory getActualFactory()
-   {
-      return actualFactory;
-   }
-
-   public PersistenceUnitMetaData getXml()
-   {
-      return metaData;
-   }
-
-   public String getKernelName()
-   {
-      return kernelName;
-   }
-
-   public String getEntityManagerName()
-   {
-      return metaData.getName();
-   }
-
-   public ManagedEntityManagerFactory getManagedFactory()
-   {
-      if(managedFactory == null)
-         log.warn("managed factory is null, persistence unit " + kernelName + " has not yet been started");
-      return managedFactory;
-   }
-
-   protected Map<String, String> getProperties()
-   {
-      Map<String, String> properties = metaData.getProperties();
-      return (properties != null) ? properties : Collections.<String, String>emptyMap();
-   }
-
-   public void addDependencies(DependencyPolicy policy)
-   {
-      Map<String, String> props = getProperties();
-      if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
-      {
-         if (metaData.getJtaDataSource() != null)
-         {
-            String ds = metaData.getJtaDataSource();
-            policy.addDatasource(ds);
-         }
-         if (metaData.getNonJtaDataSource() != null)
-         {
-            String ds = metaData.getNonJtaDataSource();
-            policy.addDatasource(ds);
-         }
-      }
-      for (Object prop : props.keySet())
-      {
-         String property = (String)prop;
-         if (property.startsWith("jboss.depends"))
-         {
-            policy.addDependency(props.get(property));
-         }
-      }
-
-   }
-
-   protected PersistenceUnitTransactionType getJPATransactionType()
-   {
-      TransactionType type = metaData.getTransactionType();
-      if (type == TransactionType.RESOURCE_LOCAL)
-         return PersistenceUnitTransactionType.RESOURCE_LOCAL;
-      else // default or actually being JTA
-         return PersistenceUnitTransactionType.JTA;
-   }
-
-   private List<String> safeList(Set<String> set)
-   {
-      return (set == null || set.isEmpty()) ? Collections.<String>emptyList() : new ArrayList<String>(set);
-   }
-
-   public void start() throws Exception
-   {
-      log.info("Starting persistence unit " + kernelName);
-      
-      Properties props = new Properties();
-      props.putAll(di.getDefaultPersistenceProperties());
-      props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
-
-      PersistenceUnitInfoImpl pi = new PersistenceUnitInfoImpl();
-      log.debug("Using class loader " + di.getClassLoader());
-      pi.setClassLoader(di.getClassLoader());
-
-      ArrayList<URL> jarFiles = new ArrayList<URL>();
-      pi.setJarFiles(jarFiles);
-      pi.setPersistenceProviderClassName(HibernatePersistence.class.getName());
-      log.debug("Found persistence.xml file in EJB3 jar");
-      props.putAll(getProperties());
-      pi.setManagedClassnames(safeList(metaData.getClasses()));
-      pi.setPersistenceUnitName(metaData.getName());
-      pi.setMappingFileNames(safeList(metaData.getMappingFiles()));
-      pi.setExcludeUnlistedClasses(metaData.isExcludeUnlistedClasses());
-      VirtualFile root = di.getRootFile();
-      log.debug("Persistence root: " + root);
-      // TODO - update this with VFSUtils helper method
-      // hack the JPA url
-      URL url = root.toURL();
-      // is not nested, so direct VFS URL is not an option
-      if (VFSUtils.isNestedFile(root) == false)
-      {
-         String urlString = url.toExternalForm();
-         if (urlString.startsWith("vfs"))
-         {
-            // treat vfszip as file
-            if (urlString.startsWith("vfszip"))
-               url = new URL("file" + urlString.substring(6));
-            else
-               url = new URL(urlString.substring(3)); // (vfs)file and (vfs)jar are ok
-         }
-      }
-      pi.setPersistenceUnitRootUrl(url);
-      PersistenceUnitTransactionType transactionType = getJPATransactionType();
-      pi.setTransactionType(transactionType);
-
-      Set<String> files = metaData.getJarFiles();
-      if (files != null)
-      {
-         for (String jar : files)
-         {
-            jarFiles.add(deployment.getDeploymentUnit().getRelativeURL(jar));
-         }
-      }
-
-      if (metaData.getProvider() != null) pi.setPersistenceProviderClassName(metaData.getProvider());
-      if (explicitEntityClasses.size() > 0)
-      {
-         List<String> classes = pi.getManagedClassNames();
-         if (classes == null) classes = explicitEntityClasses;
-         else classes.addAll(explicitEntityClasses);
-         pi.setManagedClassnames(classes);
-      }
-      if (metaData.getJtaDataSource() != null)
-      {
-         pi.setJtaDataSource((javax.sql.DataSource) initialContext.lookup(metaData.getJtaDataSource()));
-      }
-      else if (transactionType == PersistenceUnitTransactionType.JTA)
-      {
-         throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
-               + "You have not defined a jta-data-source for a JTA enabled persistence context named: " + metaData.getName());
-      }
-      if (metaData.getNonJtaDataSource() != null)
-      {
-         pi.setNonJtaDataSource((javax.sql.DataSource) initialContext.lookup(metaData.getNonJtaDataSource()));
-      }
-      else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
-      {
-         throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
-               + "You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: "
-               + metaData.getName());
-      }
-      pi.setProperties(props);
-
-      if (pi.getPersistenceUnitName() == null)
-      {
-         throw new RuntimeException("you must specify a name in persistence.xml");
-      }
-
-      Class providerClass = Thread.currentThread().getContextClassLoader().loadClass(pi.getPersistenceProviderClassName());
-
-      // EJBTHREE-893
-      if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
-      {
-         pi.getProperties().put("hibernate.session_factory_name", kernelName);
-      }
-      
-      PersistenceProvider pp = (PersistenceProvider) providerClass.newInstance();
-      actualFactory = pp.createContainerEntityManagerFactory(pi, null);
-
-      managedFactory = new ManagedEntityManagerFactory(actualFactory, kernelName);
-
-      String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
-      if (entityManagerJndiName != null)
-      {
-         EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
-         NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
-      }
-      String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
-      if (entityManagerFactoryJndiName != null)
-      {
-         EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
-         NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
-      }
-   }
-
-   public void stop() throws Exception
-   {
-      log.info("Stopping persistence unit " + kernelName);
-      
-      String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
-      if (entityManagerJndiName != null)
-      {
-         NonSerializableFactory.unbind(initialContext, entityManagerJndiName);
-      }
-      String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
-      if (entityManagerFactoryJndiName != null)
-      {
-         NonSerializableFactory.unbind(initialContext, entityManagerFactoryJndiName);
-      }
-      managedFactory.destroy();
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,333 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+
+import org.hibernate.ejb.HibernatePersistence;
+import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.DeploymentUnit;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.NonSerializableFactory;
+import org.jboss.ejb3.javaee.AbstractJavaEEComponent;
+import org.jboss.ejb3.javaee.SimpleJavaEEModule;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.metadata.jpa.spec.TransactionType;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+ at Deprecated
+public class PersistenceUnitDeployment extends AbstractJavaEEComponent
+{
+   private static final Logger log = Logger.getLogger(PersistenceUnitDeployment.class);
+
+   protected InitialContext initialContext;
+   protected DeploymentUnit di;
+   protected List<String> explicitEntityClasses = new ArrayList<String>();
+   protected ManagedEntityManagerFactory managedFactory;
+   protected EntityManagerFactory actualFactory;
+   protected PersistenceUnitMetaData metaData;
+   protected String kernelName;
+   protected Ejb3Deployment deployment;
+   protected boolean scoped;
+
+   public PersistenceUnitDeployment(InitialContext initialContext, Ejb3Deployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String ear, String jar, boolean isScoped)
+   {
+      super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
+      
+      this.scoped = isScoped;
+      this.deployment = deployment;
+      this.initialContext = initialContext;
+      this.di = deployment.getDeploymentUnit();
+      this.explicitEntityClasses = explicitEntityClasses;
+      this.metaData = metadata;
+      kernelName = "persistence.units:";
+      String name = getEntityManagerName();
+      if (name == null || name.length() == 0)
+         throw new RuntimeException("Null string is not allowed for a persistence unit name.  Fix your persistence.xml file");
+      
+      if (ear != null)
+      {
+         kernelName += "ear=" + ear;
+         if (!ear.endsWith(".ear")) kernelName += ".ear";
+         kernelName += ",";
+      }
+      if (isScoped)
+      {
+         kernelName += "jar=" + jar;
+         if (!jar.endsWith(".jar")) kernelName += ".jar";
+         kernelName += ",";
+      }
+      kernelName += "unitName=" + name;
+   }
+
+   public static String getDefaultKernelName(String unitName)
+   {
+      int hashIndex = unitName.indexOf('#');
+      if (hashIndex != -1)
+      {
+         String relativePath = unitName.substring(3, hashIndex);
+         String name = unitName.substring(hashIndex + 1);
+         return "persistence.units:jar=" + relativePath + "," + "unitName=" + name;
+      }
+      return "persistence.units:unitName=" + unitName;
+   }
+
+   public boolean isScoped()
+   {
+      return scoped;
+   }
+
+   public Ejb3Deployment getDeployment()
+   {
+      return deployment;
+   }
+
+   protected String getJaccContextId()
+   {
+      return di.getShortName();
+   }
+
+   public EntityManagerFactory getActualFactory()
+   {
+      return actualFactory;
+   }
+
+   public PersistenceUnitMetaData getXml()
+   {
+      return metaData;
+   }
+
+   public String getKernelName()
+   {
+      return kernelName;
+   }
+
+   public String getEntityManagerName()
+   {
+      return metaData.getName();
+   }
+
+   public ManagedEntityManagerFactory getManagedFactory()
+   {
+      if(managedFactory == null)
+         log.warn("managed factory is null, persistence unit " + kernelName + " has not yet been started");
+      return managedFactory;
+   }
+
+   protected Map<String, String> getProperties()
+   {
+      Map<String, String> properties = metaData.getProperties();
+      return (properties != null) ? properties : Collections.<String, String>emptyMap();
+   }
+
+   public void addDependencies(DependencyPolicy policy)
+   {
+      Map<String, String> props = getProperties();
+      if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
+      {
+         if (metaData.getJtaDataSource() != null)
+         {
+            String ds = metaData.getJtaDataSource();
+            policy.addDatasource(ds);
+         }
+         if (metaData.getNonJtaDataSource() != null)
+         {
+            String ds = metaData.getNonJtaDataSource();
+            policy.addDatasource(ds);
+         }
+      }
+      for (Object prop : props.keySet())
+      {
+         String property = (String)prop;
+         if (property.startsWith("jboss.depends"))
+         {
+            policy.addDependency(props.get(property));
+         }
+      }
+
+   }
+
+   protected PersistenceUnitTransactionType getJPATransactionType()
+   {
+      TransactionType type = metaData.getTransactionType();
+      if (type == TransactionType.RESOURCE_LOCAL)
+         return PersistenceUnitTransactionType.RESOURCE_LOCAL;
+      else // default or actually being JTA
+         return PersistenceUnitTransactionType.JTA;
+   }
+
+   private List<String> safeList(Set<String> set)
+   {
+      return (set == null || set.isEmpty()) ? Collections.<String>emptyList() : new ArrayList<String>(set);
+   }
+
+   public void start() throws Exception
+   {
+      log.info("Starting persistence unit " + kernelName);
+      
+      Properties props = new Properties();
+      props.putAll(di.getDefaultPersistenceProperties());
+      props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
+
+      PersistenceUnitInfoImpl pi = new PersistenceUnitInfoImpl();
+      log.debug("Using class loader " + di.getClassLoader());
+      pi.setClassLoader(di.getClassLoader());
+
+      ArrayList<URL> jarFiles = new ArrayList<URL>();
+      pi.setJarFiles(jarFiles);
+      pi.setPersistenceProviderClassName(HibernatePersistence.class.getName());
+      log.debug("Found persistence.xml file in EJB3 jar");
+      props.putAll(getProperties());
+      pi.setManagedClassnames(safeList(metaData.getClasses()));
+      pi.setPersistenceUnitName(metaData.getName());
+      pi.setMappingFileNames(safeList(metaData.getMappingFiles()));
+      pi.setExcludeUnlistedClasses(metaData.isExcludeUnlistedClasses());
+      VirtualFile root = di.getRootFile();
+      log.debug("Persistence root: " + root);
+      // TODO - update this with VFSUtils helper method
+      // hack the JPA url
+      URL url = root.toURL();
+      // is not nested, so direct VFS URL is not an option
+      if (VFSUtils.isNestedFile(root) == false)
+      {
+         String urlString = url.toExternalForm();
+         if (urlString.startsWith("vfs"))
+         {
+            // treat vfszip as file
+            if (urlString.startsWith("vfszip"))
+               url = new URL("file" + urlString.substring(6));
+            else
+               url = new URL(urlString.substring(3)); // (vfs)file and (vfs)jar are ok
+         }
+      }
+      pi.setPersistenceUnitRootUrl(url);
+      PersistenceUnitTransactionType transactionType = getJPATransactionType();
+      pi.setTransactionType(transactionType);
+
+      Set<String> files = metaData.getJarFiles();
+      if (files != null)
+      {
+         for (String jar : files)
+         {
+            jarFiles.add(deployment.getDeploymentUnit().getRelativeURL(jar));
+         }
+      }
+
+      if (metaData.getProvider() != null) pi.setPersistenceProviderClassName(metaData.getProvider());
+      if (explicitEntityClasses.size() > 0)
+      {
+         List<String> classes = pi.getManagedClassNames();
+         if (classes == null) classes = explicitEntityClasses;
+         else classes.addAll(explicitEntityClasses);
+         pi.setManagedClassnames(classes);
+      }
+      if (metaData.getJtaDataSource() != null)
+      {
+         pi.setJtaDataSource((javax.sql.DataSource) initialContext.lookup(metaData.getJtaDataSource()));
+      }
+      else if (transactionType == PersistenceUnitTransactionType.JTA)
+      {
+         throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
+               + "You have not defined a jta-data-source for a JTA enabled persistence context named: " + metaData.getName());
+      }
+      if (metaData.getNonJtaDataSource() != null)
+      {
+         pi.setNonJtaDataSource((javax.sql.DataSource) initialContext.lookup(metaData.getNonJtaDataSource()));
+      }
+      else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
+      {
+         throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
+               + "You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: "
+               + metaData.getName());
+      }
+      pi.setProperties(props);
+
+      if (pi.getPersistenceUnitName() == null)
+      {
+         throw new RuntimeException("you must specify a name in persistence.xml");
+      }
+
+      Class providerClass = Thread.currentThread().getContextClassLoader().loadClass(pi.getPersistenceProviderClassName());
+
+      // EJBTHREE-893
+      if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
+      {
+         pi.getProperties().put("hibernate.session_factory_name", kernelName);
+      }
+      
+      PersistenceProvider pp = (PersistenceProvider) providerClass.newInstance();
+      actualFactory = pp.createContainerEntityManagerFactory(pi, null);
+
+      managedFactory = new ManagedEntityManagerFactory(actualFactory, kernelName);
+
+      String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
+      if (entityManagerJndiName != null)
+      {
+         EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
+         NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
+      }
+      String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
+      if (entityManagerFactoryJndiName != null)
+      {
+         EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
+         NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
+      }
+   }
+
+   public void stop() throws Exception
+   {
+      log.info("Stopping persistence unit " + kernelName);
+      
+      String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
+      if (entityManagerJndiName != null)
+      {
+         NonSerializableFactory.unbind(initialContext, entityManagerJndiName);
+      }
+      String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
+      if (entityManagerFactoryJndiName != null)
+      {
+         NonSerializableFactory.unbind(initialContext, entityManagerFactoryJndiName);
+      }
+      managedFactory.destroy();
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,248 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity;
-
-import org.hibernate.Session;
-import org.hibernate.ejb.HibernateEntityManager;
-import org.jboss.ejb3.PersistenceUnitRegistry;
-import org.jboss.ejb3.stateful.StatefulBeanContext;
-import org.jboss.logging.Logger;
-
-import javax.persistence.*;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class TransactionScopedEntityManager implements EntityManager, HibernateSession, Externalizable
-{
-   private static final long serialVersionUID = 4260828563883650376L;
-   
-   private static final Logger log = Logger.getLogger(TransactionScopedEntityManager.class);
-   
-   private transient ManagedEntityManagerFactory factory;
-
-   public Session getHibernateSession()
-   {
-      EntityManager em = factory.getTransactionScopedEntityManager();
-      if (em instanceof HibernateEntityManager)
-      {
-         return ((HibernateEntityManager) em).getSession();
-      }
-      throw new RuntimeException("ILLEGAL ACTION:  Not a Hibernate pe" +
-              "rsistence provider");
-   }
-
-   public TransactionScopedEntityManager(ManagedEntityManagerFactory factory)
-   {
-      if (factory == null) throw new NullPointerException("factory must not be null");
-      this.factory = factory;
-   }
-
-   public TransactionScopedEntityManager()
-   {
-   }
-
-   public void writeExternal(ObjectOutput out) throws IOException
-   {
-      out.writeUTF(factory.getKernelName());
-   }
-
-   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
-   {
-      String kernelName = in.readUTF();
-      PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
-      if (deployment == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
-      factory = deployment.getManagedFactory();
-   }
-
-   public Object getDelegate()
-   {
-      return getEntityManager().getDelegate();
-   }
-
-   public void joinTransaction()
-   {
-      factory.verifyInTx();
-      getEntityManager().joinTransaction();
-   }
-
-   public void clear()
-   {
-      getEntityManager().clear();
-   }
-
-   public FlushModeType getFlushMode()
-   {
-      return getEntityManager().getFlushMode();
-   }
-
-   public void lock(Object entity, LockModeType lockMode)
-   {
-      factory.verifyInTx();
-      getEntityManager().lock(entity, lockMode);
-   }
-
-   public <T> T getReference(Class<T> entityClass, Object primaryKey)
-   {
-      EntityManager em = getEntityManager();
-      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      try
-      {
-         return em.getReference(entityClass, primaryKey);
-      }
-      finally
-      {
-         if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      }
-   }
-
-   public void setFlushMode(FlushModeType flushMode)
-   {
-      getEntityManager().setFlushMode(flushMode);
-   }
-
-   public Query createQuery(String ejbqlString)
-   {
-      EntityManager em = getEntityManager();
-      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      return em.createQuery(ejbqlString);
-   }
-
-   public Query createNamedQuery(String name)
-   {
-      EntityManager em = getEntityManager();
-      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      return em.createNamedQuery(name);
-   }
-
-   public Query createNativeQuery(String sqlString)
-   {
-      EntityManager em = getEntityManager();
-      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      return em.createNativeQuery(sqlString);
-   }
-
-   public Query createNativeQuery(String sqlString, Class resultClass)
-   {
-      EntityManager em = getEntityManager();
-      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      return em.createNativeQuery(sqlString, resultClass);
-   }
-
-   public Query createNativeQuery(String sqlString, String resultSetMapping)
-   {
-      EntityManager em = getEntityManager();
-      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      return em.createNativeQuery(sqlString, resultSetMapping);
-   }
-
-   public <A> A find(Class<A> entityClass, Object primaryKey)
-   {
-      EntityManager em = getEntityManager();
-      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      try
-      {
-         return em.find(entityClass, primaryKey);
-      }
-      finally
-      {
-         if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
-      }
-   }
-
-   public void persist(Object entity)
-   {
-      factory.verifyInTx();
-      getEntityManager().persist(entity);
-   }
-
-   public <A> A merge(A entity)
-   {
-      factory.verifyInTx();
-      return (A) getEntityManager().merge(entity);
-   }
-
-   public void remove(Object entity)
-   {
-      factory.verifyInTx();
-      getEntityManager().remove(entity);
-   }
-
-   public void refresh(Object entity)
-   {
-      factory.verifyInTx();
-      getEntityManager().refresh(entity);
-   }
-
-   public boolean contains(Object entity)
-   {
-      return getEntityManager().contains(entity);
-   }
-
-   public void flush()
-   {
-      factory.verifyInTx();
-      getEntityManager().flush();
-   }
-
-   public void close()
-   {
-      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
-   }
-
-   public boolean isOpen()
-   {
-      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
-   }
-
-   public EntityTransaction getTransaction()
-   {
-      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
-   }
-   
-   protected EntityManager getEntityManager()
-   {
-      StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
-     
-      EntityManager em;
-      if (beanContext != null)
-      {
-         List<StatefulBeanContext> beanContexts = StatefulBeanContext.currentBean.getList();
-         for( StatefulBeanContext bc : beanContexts)
-         {
-            em = bc.getExtendedPersistenceContext(factory.getKernelName());
-            if (em != null)
-               return em;
-         }
-      }
-     
-      return factory.getTransactionScopedEntityManager();
-   }
-
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+
+import org.hibernate.Session;
+import org.hibernate.ejb.HibernateEntityManager;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class TransactionScopedEntityManager implements EntityManager, HibernateSession, Externalizable
+{
+   private static final long serialVersionUID = 4260828563883650376L;
+   
+   private static final Logger log = Logger.getLogger(TransactionScopedEntityManager.class);
+   
+   private transient ManagedEntityManagerFactory factory;
+
+   public Session getHibernateSession()
+   {
+      EntityManager em = factory.getTransactionScopedEntityManager();
+      if (em instanceof HibernateEntityManager)
+      {
+         return ((HibernateEntityManager) em).getSession();
+      }
+      throw new RuntimeException("ILLEGAL ACTION:  Not a Hibernate pe" +
+              "rsistence provider");
+   }
+
+   public TransactionScopedEntityManager(ManagedEntityManagerFactory factory)
+   {
+      if (factory == null) throw new NullPointerException("factory must not be null");
+      this.factory = factory;
+   }
+
+   public TransactionScopedEntityManager()
+   {
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeUTF(factory.getKernelName());
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      String kernelName = in.readUTF();
+      factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+      if ( factory == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
+   }
+
+   public Object getDelegate()
+   {
+      return getEntityManager().getDelegate();
+   }
+
+   public void joinTransaction()
+   {
+      factory.verifyInTx();
+      getEntityManager().joinTransaction();
+   }
+
+   public void clear()
+   {
+      getEntityManager().clear();
+   }
+
+   public FlushModeType getFlushMode()
+   {
+      return getEntityManager().getFlushMode();
+   }
+
+   public void lock(Object entity, LockModeType lockMode)
+   {
+      factory.verifyInTx();
+      getEntityManager().lock(entity, lockMode);
+   }
+
+   public <T> T getReference(Class<T> entityClass, Object primaryKey)
+   {
+      EntityManager em = getEntityManager();
+      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      try
+      {
+         return em.getReference(entityClass, primaryKey);
+      }
+      finally
+      {
+         if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      }
+   }
+
+   public void setFlushMode(FlushModeType flushMode)
+   {
+      getEntityManager().setFlushMode(flushMode);
+   }
+
+   public Query createQuery(String ejbqlString)
+   {
+      EntityManager em = getEntityManager();
+      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      return em.createQuery(ejbqlString);
+   }
+
+   public Query createNamedQuery(String name)
+   {
+      EntityManager em = getEntityManager();
+      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      return em.createNamedQuery(name);
+   }
+
+   public Query createNativeQuery(String sqlString)
+   {
+      EntityManager em = getEntityManager();
+      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      return em.createNativeQuery(sqlString);
+   }
+
+   public Query createNativeQuery(String sqlString, Class resultClass)
+   {
+      EntityManager em = getEntityManager();
+      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      return em.createNativeQuery(sqlString, resultClass);
+   }
+
+   public Query createNativeQuery(String sqlString, String resultSetMapping)
+   {
+      EntityManager em = getEntityManager();
+      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      return em.createNativeQuery(sqlString, resultSetMapping);
+   }
+
+   public <A> A find(Class<A> entityClass, Object primaryKey)
+   {
+      EntityManager em = getEntityManager();
+      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      try
+      {
+         return em.find(entityClass, primaryKey);
+      }
+      finally
+      {
+         if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
+      }
+   }
+
+   public void persist(Object entity)
+   {
+      factory.verifyInTx();
+      getEntityManager().persist(entity);
+   }
+
+   public <A> A merge(A entity)
+   {
+      factory.verifyInTx();
+      return (A) getEntityManager().merge(entity);
+   }
+
+   public void remove(Object entity)
+   {
+      factory.verifyInTx();
+      getEntityManager().remove(entity);
+   }
+
+   public void refresh(Object entity)
+   {
+      factory.verifyInTx();
+      getEntityManager().refresh(entity);
+   }
+
+   public boolean contains(Object entity)
+   {
+      return getEntityManager().contains(entity);
+   }
+
+   public void flush()
+   {
+      factory.verifyInTx();
+      getEntityManager().flush();
+   }
+
+   public void close()
+   {
+      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
+   }
+
+   public boolean isOpen()
+   {
+      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
+   }
+
+   public EntityTransaction getTransaction()
+   {
+      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
+   }
+   
+   protected EntityManager getEntityManager()
+   {
+      StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
+     
+      EntityManager em;
+      if (beanContext != null)
+      {
+         List<StatefulBeanContext> beanContexts = StatefulBeanContext.currentBean.getList();
+         for( StatefulBeanContext bc : beanContexts)
+         {
+            em = bc.getExtendedPersistenceContext(factory.getKernelName());
+            if (em != null)
+               return em;
+         }
+      }
+     
+      return factory.getTransactionScopedEntityManager();
+   }
+
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity;
-
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.logging.Logger;
-
-import javax.persistence.EntityManager;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
-/**
- * If a transaction-scoped entitymanager is accessed outside of a transaction
- * an entitymanager is created for the duration of the current EJB method call
- * this entitymanager must be closed at the end of the method invocation.
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class TransactionScopedEntityManagerInterceptor implements Interceptor
-{
-   private static final Logger log = Logger.getLogger(TransactionScopedEntityManagerInterceptor.class);
-
-   public String getName()
-   {
-      return this.getClass().getName();
-   }
-
-   public Object invoke(Invocation invocation) throws Throwable
-   {
-      try
-      {
-         ManagedEntityManagerFactory.nonTxStack.push(new IdentityHashMap());
-         return invocation.invokeNext();
-      }
-      finally
-      {
-         Map map = ManagedEntityManagerFactory.nonTxStack.pop();
-         for (Object obj : map.values())
-         {
-            try
-            {
-               ((EntityManager)obj).close();
-               log.debug("********************* CLOSING tx scoped nontx entity manager");
-            }
-            catch (Exception ignored)
-            {
-            }
-         }
-      }
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.logging.Logger;
+
+/**
+ * If a transaction-scoped entitymanager is accessed outside of a transaction
+ * an entitymanager is created for the duration of the current EJB method call
+ * this entitymanager must be closed at the end of the method invocation.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class TransactionScopedEntityManagerInterceptor implements Interceptor
+{
+   private static final Logger log = Logger.getLogger(TransactionScopedEntityManagerInterceptor.class);
+
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      try
+      {
+         ManagedEntityManagerFactory.nonTxStack.push(new IdentityHashMap());
+         return invocation.invokeNext();
+      }
+      finally
+      {
+         Map map = ManagedEntityManagerFactory.nonTxStack.pop();
+         for (Object obj : map.values())
+         {
+            try
+            {
+               ((EntityManager)obj).close();
+               log.debug("********************* CLOSING tx scoped nontx entity manager");
+            }
+            catch (Exception ignored)
+            {
+            }
+         }
+      }
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,110 +0,0 @@
-//$Id: $
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.entity.hibernate;
-
-import java.io.ObjectOutput;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.Externalizable;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import javax.persistence.EntityManager;
-
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.ejb3.PersistenceUnitRegistry;
-import org.hibernate.Session;
-import org.hibernate.ejb.HibernateEntityManager;
-
-/**
- * Handle method execution delegation to an Hibernate session following the transaction scoped persistence context rules
- *
- * @author Emmanuel Bernard
- */
-public class TransactionScopedSessionInvocationHandler implements InvocationHandler, Externalizable
-{
-   private static final long serialVersionUID = -5788395417446868080L;
-   
-   private transient ManagedEntityManagerFactory factory;
-
-   public TransactionScopedSessionInvocationHandler(ManagedEntityManagerFactory factory)
-   {
-      if ( factory == null ) throw new NullPointerException( "factory must not be null" );
-      this.factory = factory;
-   }
-
-   //is it useful?
-   public TransactionScopedSessionInvocationHandler()
-   {
-   }
-
-   protected Session getHibernateSession()
-   {
-      if ( getSession() instanceof HibernateEntityManager )
-      {
-         return ( (HibernateEntityManager) getSession() ).getSession();
-      }
-      throw new RuntimeException( "ILLEGAL ACTION: Not a Hibernate persistence provider" );
-   }
-
-   protected EntityManager getSession()
-   {
-      return factory.getTransactionScopedEntityManager();
-   }
-
-
-   public void writeExternal(ObjectOutput out) throws IOException
-   {
-      out.writeUTF( factory.getKernelName() );
-   }
-
-   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
-   {
-      String kernelName = in.readUTF();
-      PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit( kernelName );
-      if ( deployment == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
-      factory = deployment.getManagedFactory();
-   }
-
-   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
-   {
-      if ( "close".equals( method.getName() ) ) {
-         throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
-      }
-      else {
-         //catch all
-         try {
-            return method.invoke( getHibernateSession(), args );
-         }
-         catch ( InvocationTargetException e ) {
-				if ( e.getTargetException() instanceof RuntimeException ) {
-					throw ( RuntimeException ) e.getTargetException();
-				}
-				else {
-					throw e;
-				}
-			}
-      }
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,109 @@
+//$Id: $
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.entity.hibernate;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.Session;
+import org.hibernate.ejb.HibernateEntityManager;
+import org.jboss.ejb3.entity.ManagedEntityManagerFactoryHelper;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+
+/**
+ * Handle method execution delegation to an Hibernate session following the transaction scoped persistence context rules
+ *
+ * @author Emmanuel Bernard
+ */
+public class TransactionScopedSessionInvocationHandler implements InvocationHandler, Externalizable
+{
+   private static final long serialVersionUID = -5788395417446868080L;
+   
+   private transient ManagedEntityManagerFactory factory;
+
+   public TransactionScopedSessionInvocationHandler(ManagedEntityManagerFactory factory)
+   {
+      if ( factory == null ) throw new NullPointerException( "factory must not be null" );
+      this.factory = factory;
+   }
+
+   //is it useful?
+   public TransactionScopedSessionInvocationHandler()
+   {
+   }
+
+   protected Session getHibernateSession()
+   {
+      if ( getSession() instanceof HibernateEntityManager )
+      {
+         return ( (HibernateEntityManager) getSession() ).getSession();
+      }
+      throw new RuntimeException( "ILLEGAL ACTION: Not a Hibernate persistence provider" );
+   }
+
+   protected EntityManager getSession()
+   {
+      return factory.getTransactionScopedEntityManager();
+   }
+
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeUTF( factory.getKernelName() );
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      String kernelName = in.readUTF();
+      factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+      if ( factory == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      if ( "close".equals( method.getName() ) ) {
+         throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
+      }
+      else {
+         //catch all
+         try {
+            return method.invoke( getHibernateSession(), args );
+         }
+         catch ( InvocationTargetException e ) {
+				if ( e.getTargetException() instanceof RuntimeException ) {
+					throw ( RuntimeException ) e.getTargetException();
+				}
+				else {
+					throw e;
+				}
+			}
+      }
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/EJBRemoteHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBRemoteHandler.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/EJBRemoteHandler.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,399 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.injection;
-
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Map;
-
-import javax.ejb.EJB;
-import javax.ejb.EJBs;
-import javax.naming.NameNotFoundException;
-
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.annotation.IgnoreDependency;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.javaee.spec.AbstractEJBReferenceMetaData;
-import org.jboss.metadata.javaee.spec.AnnotatedEJBReferenceMetaData;
-import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
-import org.jboss.metadata.javaee.spec.EJBReferenceMetaData;
-import org.jboss.metadata.javaee.spec.RemoteEnvironment;
-
-/**
- * Searches bean class for all @Inject and create Injectors
- * for a remote environment.
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class EJBRemoteHandler<X extends RemoteEnvironment> extends EJBInjectionHandler<X>
-{
-   private static final Logger log = Logger.getLogger(EJBRemoteHandler.class);
-
-   public void loadXml(X xml, InjectionContainer container)
-   {
-      if (xml != null)
-      {
-         log.trace("ejbRefs = " + xml.getEjbReferences());
-         if (xml.getEjbReferences() != null) loadEjbRefXml(xml.getEjbReferences(), container);
-      }
-   }
-
-   protected void loadEjbRefXml(Collection<EJBReferenceMetaData> refs, InjectionContainer container)
-   {
-      for (EJBReferenceMetaData ref : refs)
-      {
-         String interfaceName = ref.getRemote();
-         String errorType = "<ejb-ref>";
-
-         ejbRefXml(ref, interfaceName, container, errorType);
-      }
-   }
-
-   protected void ejbRefXml(AbstractEJBReferenceMetaData ref, String interfaceName, InjectionContainer container, String errorType)
-   {
-      String encName = "env/" + ref.getEjbRefName();
-      InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
-      if (container.getEncInjectors().containsKey(encName))
-         return;
-
-      String mappedName = ref.getMappedName();
-      if (mappedName != null && mappedName.equals(""))
-         mappedName = null;
-      if(mappedName == null && ref.getResolvedJndiName() != null)
-         mappedName = ref.getResolvedJndiName();
-
-      String link = ref.getLink();
-      if (link != null && link.trim().equals("")) link = null;
-
-      Class<?> refClass = null;
-
-      if (interfaceName != null)
-      {
-         try
-         {
-            refClass = container.getClassloader().loadClass(interfaceName);
-         }
-         catch (ClassNotFoundException e)
-         {
-            throw new RuntimeException("could not find " + errorType + "'s local interface " + interfaceName + " in " + container.getDeploymentDescriptorType() + " of " + container.getIdentifier());
-         }
-      }
-      
-      //----- injectors
-
-      if (mappedName == null && refClass == null && link == null)
-      {
-         // must be jboss.xml only with @EJB used to define reference.  jboss.xml used to tag for ignore dependency
-         // i think it is ok to assume this because the ejb-jar.xml schema should handle any missing elements
-      }
-      else
-      {
-         ejbRefEncInjector(mappedName, encName, null, refClass, link, errorType, container);
-         if (ref.getIgnoreDependency() != null)
-         {
-            log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
-            return;
-         }
-
-         ejbRefDependency(mappedName, link, container, refClass, errorType, encName);
-      }
-   }
-
-   protected void ejbRefDependency(String mappedName, String link, InjectionContainer container, Class<?> refClass, String errorType, String encName)
-   {
-      if(mappedName != null && mappedName.length() == 0) mappedName = null;
-      if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
-      
-      if(mappedName != null)
-      {
-         addJNDIDependency(container, mappedName);
-         return;
-      }
-      
-      if (refClass != null)
-      {
-         if (link != null && !link.trim().equals(""))
-         {
-            addDependency(container, link, refClass);
-         }
-         else
-         {
-            addDependency(container, refClass);
-         }
-      }
-      
-      else
-      {
-         String msg = "IGNORING DEPENDENCY: unable to resolve dependency of EJB, there is too little information";
-         log.warn(msg);
-      }
-   }
-
-   protected void ejbRefEncInjector(String mappedName, String encName, String fieldName, Class refClass, String link, String errorType, InjectionContainer container)
-   {
-      if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class)))
-         refClass = null;
-      if (mappedName != null && mappedName.trim().equals(""))
-         mappedName = null;
-      
-      // Initialize the lookupName to the encName
-      String lookupName = encName;
-      
-      // EJBTHREE-1289: this code should be enabled, but MappedDeploymentEndpointResolver is broken
-//      assert lookupName.startsWith("env/") : "encName used to start with 'env/'";
-//      lookupName = lookupName.substring(4);
-      
-      // mappedName can be null, because an annotation has not been augmented with resolvedJndiName
-      if (mappedName == null)
-      {
-         //
-         AnnotatedEJBReferencesMetaData amds = container.getEnvironmentRefGroup().getAnnotatedEjbReferences();
-         if(amds != null)
-         {
-            AnnotatedEJBReferenceMetaData amd = amds.get(lookupName);
-            if (amd == null && fieldName != null)
-            {
-               lookupName = fieldName;
-               amd = amds.get(lookupName);
-            }
-            if (amd != null)
-            {
-               mappedName = amd.getMappedName();
-               if (mappedName == null)
-                  mappedName = amd.getResolvedJndiName();
-            }
-         }
-      }
-
-      // The MappedDeploymentEndpointResolver should have put resolvedJndiName everywhere.
-      // If no mappedName is known by now, we have a bug.
-      assert mappedName != null : "mappedName for enc \"" + encName + "\", field \"" + fieldName
-            + "\" is null (container.environmentRefGroup.annotatedEjbReferences = "
-            + container.getEnvironmentRefGroup().getAnnotatedEjbReferences() + ")";
-      
-      EncInjector injector = null;
-      
-      if (mappedName == null)
-      {
-         // TODO: remove this block, see previous comments
-         log.warn("EJBTHREE-1289: Using legacy EjbEncInjector, because mappedName for enc \"" + encName + "\", field \"" + fieldName
-            + "\" is null (container.environmentRefGroup.annotatedEjbReferences = "
-            + container.getEnvironmentRefGroup().getAnnotatedEjbReferences() + ")");
-         // legacy
-         injector = new EjbEncInjector(encName, refClass, link, errorType);
-      }
-      else
-      {
-         injector = new EjbEncInjector(encName, mappedName, errorType);
-      }
-
-      container.getEncInjectors().put(encName, injector);
-   }
-
-   public static EJBContainer getEjbContainer(EJB ref, InjectionContainer container, Class<?> memberType)
-   {
-      EJBContainer rtn = null;
-
-      if (ref.mappedName() != null && !"".equals(ref.mappedName()))
-      {
-         return null;
-      }
-
-      if (ref.beanName().equals("") && memberType == null)
-         throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB.  Please fill out the beanName and/or businessInterface attributes");
-
-      Class<?> businessInterface = memberType;
-      if (!ref.beanInterface().getName().equals(Object.class.getName()))
-      {
-         businessInterface = ref.beanInterface();
-      }
-
-      if (ref.beanName().equals(""))
-      {
-         try
-         {
-            rtn = (EJBContainer) container.resolveEjbContainer(businessInterface);
-         }
-         catch (NameNotFoundException e)
-         {
-            log.warn("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
-         }
-      }
-      else
-      {
-         rtn = (EJBContainer) container.resolveEjbContainer(ref.beanName(), businessInterface);
-      }
-
-      return rtn;
-   }
-
-   public static String getJndiName(EJB ref, InjectionContainer container, Class<?> memberType)
-   {
-      String jndiName;
-
-      if (ref.mappedName() != null && !"".equals(ref.mappedName()))
-      {
-         return ref.mappedName();
-      }
-
-      if (ref.beanName().equals("") && memberType == null)
-         throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB.  Please fill out the beanName and/or businessInterface attributes");
-
-      Class<?> businessInterface = memberType;
-      if (!ref.beanInterface().getName().equals(Object.class.getName()))
-      {
-         businessInterface = ref.beanInterface();
-      }
-
-      if (ref.beanName().equals(""))
-      {
-         try
-         {
-            jndiName = container.getEjbJndiName(businessInterface);
-         }
-         catch (NameNotFoundException e)
-         {
-            throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
-         }
-         if (jndiName == null)
-         {
-            throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ")");
-         }
-      }
-      else
-      {
-         jndiName = container.getEjbJndiName(ref.beanName(), businessInterface);
-         if (jndiName == null)
-         {
-            throw new RuntimeException("For EJB " + container.getIdentifier() + "could not find jndi binding based on beanName and business interface for @EJB(" + ref.beanName() + ", " + businessInterface.getName() + ")");
-         }
-      }
-
-      return jndiName;
-   }
-
-   public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
-   {
-      EJBs ref = container.getAnnotation(EJBs.class, clazz);
-      if (ref != null)
-      {
-         EJB[] ejbs = ref.value();
-
-         for (EJB ejb : ejbs)
-         {
-            handleClassAnnotation(ejb, clazz, container);
-         }
-      }
-      EJB ejbref = container.getAnnotation(EJB.class, clazz);
-      if (ejbref != null) handleClassAnnotation(ejbref, clazz, container);
-   }
-
-   protected void handleClassAnnotation(EJB ejb, Class<?> clazz, InjectionContainer container)
-   {
-      String encName = ejb.name();
-      if (encName == null || encName.equals(""))
-      {
-         throw new RuntimeException("JBoss requires the name of the @EJB in the @EJBs: " + clazz);
-      }
-      encName = "env/" + encName;
-
-      if (container.getEncInjectors().containsKey(encName)) return;
-      ejbRefEncInjector(ejb.mappedName(), encName, null, ejb.beanInterface(), ejb.beanName(), "@EJB", container);
-
-      // handle dependencies
-
-      if (isIgnoreDependency(container, ejb))
-         log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
-      else
-         ejbRefDependency(ejb.mappedName(), ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName);
-   }
-
-   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
-   {
-      EJB ref = container.getAnnotation(EJB.class, method);
-      if (ref != null)
-      {
-         if (!method.getName().startsWith("set"))
-            throw new RuntimeException("@EJB can only be used with a set method: " + method);
-         String encName = getEncName(ref, method);
-         if (!container.getEncInjectors().containsKey(encName))
-         {
-            ejbRefEncInjector(ref.mappedName(), encName, method.getName().substring(0), method.getParameterTypes()[0], ref.beanName(), "@EJB", container);
-            
-            if (container.getAnnotation(IgnoreDependency.class, method) == null)
-            {
-               if (isIgnoreDependency(container, ref))
-                  log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
-               else
-                  ejbRefDependency(ref.mappedName(), ref.beanName(), container, method.getParameterTypes()[0], "@EJB", encName);
-            }
-         }
-
-         super.handleMethodAnnotations(method, container, injectors);
-      }
-   }
-
-   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
-   {
-      EJB ref = container.getAnnotation(EJB.class, field);
-      if (ref != null)
-      {
-         String encName = getEncName(ref, field);
-         if (!container.getEncInjectors().containsKey(encName))
-         {
-            if (container.getAnnotation(IgnoreDependency.class, field) == null)
-            {
-               if (isIgnoreDependency(container, ref))
-                  log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
-               else
-                  ejbRefDependency(ref.mappedName(), ref.beanName(), container, field.getType(), "@EJB", encName);
-            }
-            ejbRefEncInjector(ref.mappedName(), encName, field.getName(), field.getType(), ref.beanName(), "@EJB", container);
-         }
-         super.handleFieldAnnotations(field, container, injectors);
-      }
-   }
-
-   protected boolean isIgnoreDependency(InjectionContainer container, EJB ref)
-   {
-      RemoteEnvironment refGroup =  container.getEnvironmentRefGroup();
-      
-      if (refGroup != null)
-      {
-         if(refGroup.getEjbReferences() != null)
-         for(EJBReferenceMetaData ejbRef : refGroup.getEjbReferences())
-         {
-            if (ejbRef.getEjbRefName().equals(ref.name()))
-            {
-               return ejbRef.getIgnoreDependency() != null;
-            }
-         }
-      }
-      
-      // TODO: shouldn't we scan local ejb refs as well?
-      
-      return false;
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/EJBRemoteHandler.java (from rev 75611, projects/ejb3/trunk/core/src/main/java/org/jboss/injection/EJBRemoteHandler.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/EJBRemoteHandler.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/EJBRemoteHandler.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,399 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+
+import javax.ejb.EJB;
+import javax.ejb.EJBs;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.annotation.IgnoreDependency;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.javaee.spec.AbstractEJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
+import org.jboss.metadata.javaee.spec.EJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+
+/**
+ * Searches bean class for all @Inject and create Injectors
+ * for a remote environment.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class EJBRemoteHandler<X extends RemoteEnvironment> extends EJBInjectionHandler<X>
+{
+   private static final Logger log = Logger.getLogger(EJBRemoteHandler.class);
+
+   public void loadXml(X xml, InjectionContainer container)
+   {
+      if (xml != null)
+      {
+         log.trace("ejbRefs = " + xml.getEjbReferences());
+         if (xml.getEjbReferences() != null) loadEjbRefXml(xml.getEjbReferences(), container);
+      }
+   }
+
+   protected void loadEjbRefXml(Collection<EJBReferenceMetaData> refs, InjectionContainer container)
+   {
+      for (EJBReferenceMetaData ref : refs)
+      {
+         String interfaceName = ref.getRemote();
+         String errorType = "<ejb-ref>";
+
+         ejbRefXml(ref, interfaceName, container, errorType);
+      }
+   }
+
+   protected void ejbRefXml(AbstractEJBReferenceMetaData ref, String interfaceName, InjectionContainer container, String errorType)
+   {
+      String encName = "env/" + ref.getEjbRefName();
+      InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
+      if (container.getEncInjectors().containsKey(encName))
+         return;
+
+      String mappedName = ref.getMappedName();
+      if (mappedName != null && mappedName.equals(""))
+         mappedName = null;
+      if(mappedName == null && ref.getResolvedJndiName() != null)
+         mappedName = ref.getResolvedJndiName();
+
+      String link = ref.getLink();
+      if (link != null && link.trim().equals("")) link = null;
+
+      Class<?> refClass = null;
+
+      if (interfaceName != null)
+      {
+         try
+         {
+            refClass = container.getClassloader().loadClass(interfaceName);
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new RuntimeException("could not find " + errorType + "'s local interface " + interfaceName + " in " + container.getDeploymentDescriptorType() + " of " + container.getIdentifier());
+         }
+      }
+      
+      //----- injectors
+
+      if (mappedName == null && refClass == null && link == null)
+      {
+         // must be jboss.xml only with @EJB used to define reference.  jboss.xml used to tag for ignore dependency
+         // i think it is ok to assume this because the ejb-jar.xml schema should handle any missing elements
+      }
+      else
+      {
+         ejbRefEncInjector(mappedName, encName, null, refClass, link, errorType, container);
+         if (ref.getIgnoreDependency() != null)
+         {
+            log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+            return;
+         }
+
+         ejbRefDependency(mappedName, link, container, refClass, errorType, encName);
+      }
+   }
+
+   protected void ejbRefDependency(String mappedName, String link, InjectionContainer container, Class<?> refClass, String errorType, String encName)
+   {
+      if(mappedName != null && mappedName.length() == 0) mappedName = null;
+      if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
+      
+      if(mappedName != null)
+      {
+         addJNDIDependency(container, mappedName);
+         return;
+      }
+      
+      if (refClass != null)
+      {
+         if (link != null && !link.trim().equals(""))
+         {
+            addDependency(container, link, refClass);
+         }
+         else
+         {
+            addDependency(container, refClass);
+         }
+      }
+      
+      else
+      {
+         String msg = "IGNORING DEPENDENCY: unable to resolve dependency of EJB, there is too little information";
+         log.warn(msg);
+      }
+   }
+
+   protected void ejbRefEncInjector(String mappedName, String encName, String fieldName, Class refClass, String link, String errorType, InjectionContainer container)
+   {
+      if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class)))
+         refClass = null;
+      if (mappedName != null && mappedName.trim().equals(""))
+         mappedName = null;
+      
+      // Initialize the lookupName to the encName
+      String lookupName = encName;
+      
+      // EJBTHREE-1289: this code should be enabled, but MappedDeploymentEndpointResolver is broken
+//      assert lookupName.startsWith("env/") : "encName used to start with 'env/'";
+//      lookupName = lookupName.substring(4);
+      
+      // mappedName can be null, because an annotation has not been augmented with resolvedJndiName
+      if (mappedName == null)
+      {
+         //
+         AnnotatedEJBReferencesMetaData amds = container.getEnvironmentRefGroup().getAnnotatedEjbReferences();
+         if(amds != null)
+         {
+            AnnotatedEJBReferenceMetaData amd = amds.get(lookupName);
+            if (amd == null && fieldName != null)
+            {
+               lookupName = fieldName;
+               amd = amds.get(lookupName);
+            }
+            if (amd != null)
+            {
+               mappedName = amd.getMappedName();
+               if (mappedName == null)
+                  mappedName = amd.getResolvedJndiName();
+            }
+         }
+      }
+
+      // The MappedDeploymentEndpointResolver should have put resolvedJndiName everywhere.
+      // If no mappedName is known by now, we have a bug.
+//      assert mappedName != null : "mappedName for enc \"" + encName + "\", field \"" + fieldName
+//            + "\" is null (container.environmentRefGroup.annotatedEjbReferences = "
+//            + container.getEnvironmentRefGroup().getAnnotatedEjbReferences() + ")";
+      
+      EncInjector injector = null;
+      
+      if (mappedName == null)
+      {
+         // TODO: remove this block, see previous comments
+         log.warn("EJBTHREE-1289: Using legacy EjbEncInjector, because mappedName for enc \"" + encName + "\", field \"" + fieldName
+            + "\" is null (container.environmentRefGroup.annotatedEjbReferences = "
+            + container.getEnvironmentRefGroup().getAnnotatedEjbReferences() + ")");
+         // legacy
+         injector = new EjbEncInjector(encName, refClass, link, errorType);
+      }
+      else
+      {
+         injector = new EjbEncInjector(encName, mappedName, errorType);
+      }
+
+      container.getEncInjectors().put(encName, injector);
+   }
+
+   public static EJBContainer getEjbContainer(EJB ref, InjectionContainer container, Class<?> memberType)
+   {
+      EJBContainer rtn = null;
+
+      if (ref.mappedName() != null && !"".equals(ref.mappedName()))
+      {
+         return null;
+      }
+
+      if (ref.beanName().equals("") && memberType == null)
+         throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB.  Please fill out the beanName and/or businessInterface attributes");
+
+      Class<?> businessInterface = memberType;
+      if (!ref.beanInterface().getName().equals(Object.class.getName()))
+      {
+         businessInterface = ref.beanInterface();
+      }
+
+      if (ref.beanName().equals(""))
+      {
+         try
+         {
+            rtn = (EJBContainer) container.resolveEjbContainer(businessInterface);
+         }
+         catch (NameNotFoundException e)
+         {
+            log.warn("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
+         }
+      }
+      else
+      {
+         rtn = (EJBContainer) container.resolveEjbContainer(ref.beanName(), businessInterface);
+      }
+
+      return rtn;
+   }
+
+   public static String getJndiName(EJB ref, InjectionContainer container, Class<?> memberType)
+   {
+      String jndiName;
+
+      if (ref.mappedName() != null && !"".equals(ref.mappedName()))
+      {
+         return ref.mappedName();
+      }
+
+      if (ref.beanName().equals("") && memberType == null)
+         throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB.  Please fill out the beanName and/or businessInterface attributes");
+
+      Class<?> businessInterface = memberType;
+      if (!ref.beanInterface().getName().equals(Object.class.getName()))
+      {
+         businessInterface = ref.beanInterface();
+      }
+
+      if (ref.beanName().equals(""))
+      {
+         try
+         {
+            jndiName = container.getEjbJndiName(businessInterface);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ") " + e.getMessage());
+         }
+         if (jndiName == null)
+         {
+            throw new RuntimeException("For deployment " + container.getIdentifier() + " could not find jndi binding based on interface only for @EJB(" + businessInterface.getName() + ")");
+         }
+      }
+      else
+      {
+         jndiName = container.getEjbJndiName(ref.beanName(), businessInterface);
+         if (jndiName == null)
+         {
+            throw new RuntimeException("For EJB " + container.getIdentifier() + "could not find jndi binding based on beanName and business interface for @EJB(" + ref.beanName() + ", " + businessInterface.getName() + ")");
+         }
+      }
+
+      return jndiName;
+   }
+
+   public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
+   {
+      EJBs ref = container.getAnnotation(EJBs.class, clazz);
+      if (ref != null)
+      {
+         EJB[] ejbs = ref.value();
+
+         for (EJB ejb : ejbs)
+         {
+            handleClassAnnotation(ejb, clazz, container);
+         }
+      }
+      EJB ejbref = container.getAnnotation(EJB.class, clazz);
+      if (ejbref != null) handleClassAnnotation(ejbref, clazz, container);
+   }
+
+   protected void handleClassAnnotation(EJB ejb, Class<?> clazz, InjectionContainer container)
+   {
+      String encName = ejb.name();
+      if (encName == null || encName.equals(""))
+      {
+         throw new RuntimeException("JBoss requires the name of the @EJB in the @EJBs: " + clazz);
+      }
+      encName = "env/" + encName;
+
+      if (container.getEncInjectors().containsKey(encName)) return;
+      ejbRefEncInjector(ejb.mappedName(), encName, null, ejb.beanInterface(), ejb.beanName(), "@EJB", container);
+
+      // handle dependencies
+
+      if (isIgnoreDependency(container, ejb))
+         log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+      else
+         ejbRefDependency(ejb.mappedName(), ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName);
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      EJB ref = container.getAnnotation(EJB.class, method);
+      if (ref != null)
+      {
+         if (!method.getName().startsWith("set"))
+            throw new RuntimeException("@EJB can only be used with a set method: " + method);
+         String encName = getEncName(ref, method);
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            ejbRefEncInjector(ref.mappedName(), encName, method.getName().substring(0), method.getParameterTypes()[0], ref.beanName(), "@EJB", container);
+            
+            if (container.getAnnotation(IgnoreDependency.class, method) == null)
+            {
+               if (isIgnoreDependency(container, ref))
+                  log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+               else
+                  ejbRefDependency(ref.mappedName(), ref.beanName(), container, method.getParameterTypes()[0], "@EJB", encName);
+            }
+         }
+
+         super.handleMethodAnnotations(method, container, injectors);
+      }
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      EJB ref = container.getAnnotation(EJB.class, field);
+      if (ref != null)
+      {
+         String encName = getEncName(ref, field);
+         if (!container.getEncInjectors().containsKey(encName))
+         {
+            if (container.getAnnotation(IgnoreDependency.class, field) == null)
+            {
+               if (isIgnoreDependency(container, ref))
+                  log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
+               else
+                  ejbRefDependency(ref.mappedName(), ref.beanName(), container, field.getType(), "@EJB", encName);
+            }
+            ejbRefEncInjector(ref.mappedName(), encName, field.getName(), field.getType(), ref.beanName(), "@EJB", container);
+         }
+         super.handleFieldAnnotations(field, container, injectors);
+      }
+   }
+
+   protected boolean isIgnoreDependency(InjectionContainer container, EJB ref)
+   {
+      RemoteEnvironment refGroup =  container.getEnvironmentRefGroup();
+      
+      if (refGroup != null)
+      {
+         if(refGroup.getEjbReferences() != null)
+         for(EJBReferenceMetaData ejbRef : refGroup.getEjbReferences())
+         {
+            if (ejbRef.getEjbRefName().equals(ref.name()))
+            {
+               return ejbRef.getIgnoreDependency() != null;
+            }
+         }
+      }
+      
+      // TODO: shouldn't we scan local ejb refs as well?
+      
+      return false;
+   }
+}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface ExtendedInjectionContainer extends InjectionContainer
+{
+   String resolvePersistenceUnitSupplier(String unitName);
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.injection;
-
-import javax.persistence.EntityManager;
-import org.jboss.ejb3.BeanContext;
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
-import org.jboss.ejb3.stateful.StatefulBeanContext;
-import org.jboss.logging.Logger;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class ExtendedPersistenceContextInjector implements Injector, PojoInjector
-{
-   protected static final Logger log = Logger.getLogger(ExtendedPersistenceContextInjector.class);
-   protected ManagedEntityManagerFactory factory;
-
-   protected ExtendedPersistenceContextInjector(ManagedEntityManagerFactory factory)
-   {
-      this.factory = factory;
-   }
-
-   public void inject(BeanContext ctx)
-   {
-      inject(ctx, ctx.getInstance());
-   }
-
-   public void inject(BeanContext beanContext, Object instance)
-   {
-      StatefulBeanContext ctx = (StatefulBeanContext)beanContext;
-      EntityManager pc = ctx.getExtendedPersistenceContext(factory.getKernelName());
-      if (pc == null)
-      {
-         pc = factory.createEntityManager();
-         ctx.addExtendedPersistenceContext(factory.getKernelName(), pc);
-      }
-   }
-
-   public void inject(Object instance)
-   {
-      throw new RuntimeException("Illegal operation");
-   }
-
-   public Class getInjectionClass()
-   {
-      return null;
-   }
-
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class ExtendedPersistenceContextInjector implements Injector, PojoInjector
+{
+   protected static final Logger log = Logger.getLogger(ExtendedPersistenceContextInjector.class);
+   protected ManagedEntityManagerFactory factory;
+
+   protected ExtendedPersistenceContextInjector(ManagedEntityManagerFactory factory)
+   {
+      this.factory = factory;
+   }
+
+   public void inject(BeanContext ctx)
+   {
+      inject(ctx, ctx.getInstance());
+   }
+
+   public void inject(BeanContext beanContext, Object instance)
+   {
+      StatefulBeanContext ctx = (StatefulBeanContext)beanContext;
+      EntityManager pc = ctx.getExtendedPersistenceContext(factory.getKernelName());
+      if (pc == null)
+      {
+         pc = factory.createEntityManager();
+         ctx.addExtendedPersistenceContext(factory.getKernelName(), pc);
+      }
+   }
+
+   public void inject(Object instance)
+   {
+      throw new RuntimeException("Illegal operation");
+   }
+
+   public Class getInjectionClass()
+   {
+      return null;
+   }
+
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/InjectionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/InjectionContainer.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,113 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.injection;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.NameNotFoundException;
-
-import org.jboss.ejb3.Container;
-import org.jboss.ejb3.DependencyPolicy;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.metadata.javaee.spec.Environment;
-import org.jboss.metadata.javaee.spec.RemoteEnvironment;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * This is the container that manages all injections.  Could be an EJB Container
- * or a WAR.
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public interface InjectionContainer
-{
-   /** Some identifier that can be used in error messages */
-   String getIdentifier();
-
-   /** 
-    * For error messages
-    * @return  ejb-jar.xml, web.xml, etc..
-    */
-   String getDeploymentDescriptorType();
-
-   ClassLoader getClassloader();
-
-   Map<String, EncInjector> getEncInjectors();
-   Map<String, Map<AccessibleObject, Injector>> getEncInjections();
-
-   // EncInjectors/Handlers may need to add extra instance injectors
-   List<Injector> getInjectors();
-   
-   VirtualFile getRootFile();
-
-   Context getEnc();
-
-   PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException;
-
-   Container resolveEjbContainer(String link, Class<?> businessIntf);
-   Container resolveEjbContainer(Class<?> businessIntf) throws NameNotFoundException;
-   String getEjbJndiName(Class<?> businessInterface) throws NameNotFoundException;
-   String getEjbJndiName(String link, Class<?> businessInterface);
-   
-   /**
-    * Find a message destination in a deployment.
-    * 
-    * @param link   the message destination name
-    * @return       the jndi name of the message destination
-    */
-   String resolveMessageDestination(String link);
-
-   /**
-    * If class has container overridable annotations, this method will
-    * discover those overriden annotations.
-    */
-   <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz);
-   
-   /**
-    * If class has container overridable annotations, this method will
-    * discover those overriden annotations.
-    */
-   <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Method method);
-   
-   <T extends Annotation> T getAnnotation(Class<T> annotationType, Method method);
-
-   /**
-    * If class has container overridable annotations, this method will
-    * discover those overriden annotations.
-    */
-   <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Field field);
-   
-   <T extends Annotation> T getAnnotation(Class<T> annotationType, Field field);
-
-   DependencyPolicy getDependencyPolicy();
-   
-   RemoteEnvironment getEnvironmentRefGroup();
-   
-   boolean hasJNDIBinding(String jndiName);
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/InjectionContainer.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/InjectionContainer.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/InjectionContainer.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * This is the container that manages all injections.  Could be an EJB Container
+ * or a WAR.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public interface InjectionContainer
+{
+   /** Some identifier that can be used in error messages */
+   String getIdentifier();
+
+   /** 
+    * For error messages
+    * @return  ejb-jar.xml, web.xml, etc..
+    */
+   String getDeploymentDescriptorType();
+
+   ClassLoader getClassloader();
+
+   Map<String, EncInjector> getEncInjectors();
+   Map<String, Map<AccessibleObject, Injector>> getEncInjections();
+
+   // EncInjectors/Handlers may need to add extra instance injectors
+   List<Injector> getInjectors();
+   
+   VirtualFile getRootFile();
+
+   Context getEnc();
+
+   @Deprecated
+   PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException;
+
+   Container resolveEjbContainer(String link, Class<?> businessIntf);
+   Container resolveEjbContainer(Class<?> businessIntf) throws NameNotFoundException;
+   String getEjbJndiName(Class<?> businessInterface) throws NameNotFoundException;
+   String getEjbJndiName(String link, Class<?> businessInterface);
+   
+   /**
+    * Find a message destination in a deployment.
+    * 
+    * @param link   the message destination name
+    * @return       the jndi name of the message destination
+    */
+   String resolveMessageDestination(String link);
+
+   /**
+    * If class has container overridable annotations, this method will
+    * discover those overriden annotations.
+    */
+   <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz);
+   
+   /**
+    * If class has container overridable annotations, this method will
+    * discover those overriden annotations.
+    */
+   <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Method method);
+   
+   <T extends Annotation> T getAnnotation(Class<T> annotationType, Method method);
+
+   /**
+    * If class has container overridable annotations, this method will
+    * discover those overriden annotations.
+    */
+   <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Field field);
+   
+   <T extends Annotation> T getAnnotation(Class<T> annotationType, Field field);
+
+   DependencyPolicy getDependencyPolicy();
+   
+   RemoteEnvironment getEnvironmentRefGroup();
+   
+   boolean hasJNDIBinding(String jndiName);
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PcEncInjector.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PcEncInjector.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PcEncInjector.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,143 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.injection;
-
-import java.lang.reflect.Proxy;
-
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
-import org.jboss.ejb3.entity.ExtendedEntityManager;
-import org.jboss.ejb3.entity.TransactionScopedEntityManager;
-import org.jboss.ejb3.entity.hibernate.ExtendedSessionInvocationHandler;
-import org.jboss.ejb3.entity.hibernate.TransactionScopedSessionInvocationHandler;
-import org.jboss.ejb3.stateful.StatefulContainer;
-import org.jboss.util.naming.Util;
-import org.hibernate.Session;
-
-import javax.persistence.PersistenceContextType;
-import javax.persistence.EntityManager;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class PcEncInjector implements EncInjector
-{
-   private static final Class[] SESS_PROXY_INTERFACES = new Class[] {
-         org.hibernate.classic.Session.class,
-         org.hibernate.engine.SessionImplementor.class,
-         org.hibernate.jdbc.JDBCContext.Context.class,
-         org.hibernate.event.EventSource.class
-   };
-
-   private String encName;
-   private String unitName;
-   private PersistenceContextType type;
-   private Class injectionType;
-   private String error;
-
-   public PcEncInjector(String encName, String unitName, PersistenceContextType type, Class injectionType, String error)
-   {
-      this.encName = encName;
-      this.unitName = unitName;
-      this.type = type;
-      this.injectionType = injectionType;
-      this.error = error;
-   }
-
-   public void inject(InjectionContainer container)
-   {
-      String error1 = error;
-      ManagedEntityManagerFactory factory = null;
-      try
-      {
-         factory = PersistenceUnitHandler.getManagedEntityManagerFactory(
-                 container, unitName);
-      }
-      catch (NameNotFoundException e)
-      {
-         error1 += " " + e.getMessage();
-      }
-      if (factory == null)
-      {
-         throw new RuntimeException(error1);
-      }
-      if (type == PersistenceContextType.EXTENDED)
-      {
-         if (!(container instanceof StatefulContainer))
-            throw new RuntimeException("It is illegal to inject an EXTENDED PC into something other than a SFSB");
-         container.getInjectors().add(0, new ExtendedPersistenceContextInjector(factory));
-         Object extendedPc;
-         if (injectionType == null
-                 || injectionType.getName().equals(EntityManager.class.getName()))
-         {
-            extendedPc = new ExtendedEntityManager(factory.getKernelName());
-         }
-         else
-         {
-            ExtendedSessionInvocationHandler handler = new ExtendedSessionInvocationHandler(factory.getKernelName());
-            extendedPc = Proxy.newProxyInstance(
-                  Session.class.getClassLoader(), //use the Hibernate classloader so the proxy has the same scope as Hibernate
-                  SESS_PROXY_INTERFACES,
-                  handler
-            );
-         }
-         try
-         {
-            Util.rebind(container.getEnc(), encName, extendedPc);
-         }
-         catch (NamingException e)
-         {
-            throw new RuntimeException(error1, e);
-         }
-      }
-      else
-      {
-         Object entityManager;
-         if (injectionType == null
-                 || injectionType.getName().equals(EntityManager.class.getName()))
-         {
-            entityManager = new TransactionScopedEntityManager(factory);
-         }
-         else
-         {
-            TransactionScopedSessionInvocationHandler handler = new TransactionScopedSessionInvocationHandler(factory);
-            entityManager = Proxy.newProxyInstance(
-                  Session.class.getClassLoader(), //use the Hibernate classloader so the proxy has the same scope as Hibernate
-                  SESS_PROXY_INTERFACES,
-                  handler
-            );
-         }
-         try
-         {
-            Util.rebind(container.getEnc(), encName, entityManager);
-         }
-         catch (NamingException e)
-         {
-            throw new RuntimeException(error1, e);
-         }
-      }
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PcEncInjector.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PcEncInjector.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PcEncInjector.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PcEncInjector.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+import java.lang.reflect.Proxy;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContextType;
+
+import org.hibernate.Session;
+import org.jboss.ejb3.entity.ExtendedEntityManager;
+import org.jboss.ejb3.entity.TransactionScopedEntityManager;
+import org.jboss.ejb3.entity.hibernate.ExtendedSessionInvocationHandler;
+import org.jboss.ejb3.entity.hibernate.TransactionScopedSessionInvocationHandler;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.util.naming.Util;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class PcEncInjector implements EncInjector
+{
+   private static final Class[] SESS_PROXY_INTERFACES = new Class[] {
+         org.hibernate.classic.Session.class,
+         org.hibernate.engine.SessionImplementor.class,
+         org.hibernate.jdbc.JDBCContext.Context.class,
+         org.hibernate.event.EventSource.class
+   };
+
+   private String encName;
+   private String unitName;
+   private PersistenceContextType type;
+   private Class injectionType;
+   private String error;
+
+   public PcEncInjector(String encName, String unitName, PersistenceContextType type, Class injectionType, String error)
+   {
+      this.encName = encName;
+      this.unitName = unitName;
+      this.type = type;
+      this.injectionType = injectionType;
+      this.error = error;
+   }
+
+   public void inject(InjectionContainer container)
+   {
+      String error1 = error;
+      ManagedEntityManagerFactory factory = null;
+      try
+      {
+         factory = PersistenceUnitHandler.getManagedEntityManagerFactory(
+                 container, unitName);
+      }
+      catch (NameNotFoundException e)
+      {
+         error1 += " " + e.getMessage();
+      }
+      if (factory == null)
+      {
+         throw new RuntimeException(error1);
+      }
+      if (type == PersistenceContextType.EXTENDED)
+      {
+         if (!(container instanceof StatefulContainer))
+            throw new RuntimeException("It is illegal to inject an EXTENDED PC into something other than a SFSB");
+         container.getInjectors().add(0, new ExtendedPersistenceContextInjector(factory));
+         Object extendedPc;
+         if (injectionType == null
+                 || injectionType.getName().equals(EntityManager.class.getName()))
+         {
+            extendedPc = new ExtendedEntityManager(factory.getKernelName());
+         }
+         else
+         {
+            ExtendedSessionInvocationHandler handler = new ExtendedSessionInvocationHandler(factory.getKernelName());
+            extendedPc = Proxy.newProxyInstance(
+                  Session.class.getClassLoader(), //use the Hibernate classloader so the proxy has the same scope as Hibernate
+                  SESS_PROXY_INTERFACES,
+                  handler
+            );
+         }
+         try
+         {
+            Util.rebind(container.getEnc(), encName, extendedPc);
+         }
+         catch (NamingException e)
+         {
+            throw new RuntimeException(error1, e);
+         }
+      }
+      else
+      {
+         Object entityManager;
+         if (injectionType == null
+                 || injectionType.getName().equals(EntityManager.class.getName()))
+         {
+            entityManager = new TransactionScopedEntityManager(factory);
+         }
+         else
+         {
+            TransactionScopedSessionInvocationHandler handler = new TransactionScopedSessionInvocationHandler(factory);
+            entityManager = Proxy.newProxyInstance(
+                  Session.class.getClassLoader(), //use the Hibernate classloader so the proxy has the same scope as Hibernate
+                  SESS_PROXY_INTERFACES,
+                  handler
+            );
+         }
+         try
+         {
+            Util.rebind(container.getEnc(), encName, entityManager);
+         }
+         catch (NamingException e)
+         {
+            throw new RuntimeException(error1, e);
+         }
+      }
+   }
+}

Deleted: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PersistenceUnitHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PersistenceUnitHandler.java	2008-07-10 06:24:42 UTC (rev 75587)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PersistenceUnitHandler.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -1,254 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.injection;
-
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Map;
-
-import javax.naming.NameNotFoundException;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnit;
-import javax.persistence.PersistenceUnits;
-
-import org.hibernate.SessionFactory;
-import org.jboss.ejb3.annotation.IgnoreDependency;
-import org.jboss.ejb3.entity.InjectedEntityManagerFactory;
-import org.jboss.ejb3.entity.InjectedSessionFactory;
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData;
-import org.jboss.metadata.javaee.spec.RemoteEnvironment;
-
-/**
- * Searches bean class for all @Inject and create Injectors
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class PersistenceUnitHandler<X extends RemoteEnvironment> implements InjectionHandler<X>
-{
-   private static final Logger log = Logger.getLogger(PersistenceUnitHandler.class);
-
-   public void loadXml(X xml, InjectionContainer container)
-   {
-      if (xml == null) return;
-      if (xml.getPersistenceUnitRefs() == null) return;
-
-      for (PersistenceUnitReferenceMetaData ref : xml.getPersistenceUnitRefs())
-      {
-         String encName = "env/" + ref.getPersistenceUnitRefName();
-         // we add injection target no matter what.  enc injection might be overridden but
-         // XML injection cannot be overriden
-         Class<?> injectionType = InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
-         if (container.getEncInjectors().containsKey(encName))
-            return;
-         container.getEncInjectors().put(encName, new PuEncInjector(encName, injectionType, ref.getPersistenceUnitName(), "<persistence-unit-ref>"));
-         try
-         {
-            addPUDependency(ref.getPersistenceUnitName(), container);
-         }
-         catch (NameNotFoundException e)
-         {
-            throw new RuntimeException("Illegal <persistence-unit-ref> of " + ref.getPersistenceUnitRefName() + " :" + e.getMessage());
-         }
-      }
-   }
-
-
-   public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
-   {
-      PersistenceUnits resources = container.getAnnotation(
-              PersistenceUnits.class, clazz);
-      if (resources != null)
-      {
-         for (PersistenceUnit ref : resources.value())
-         {
-            handleClassAnnotation(ref, container, clazz);
-         }
-      }
-      PersistenceUnit pu = container.getAnnotation(PersistenceUnit.class, clazz);
-      if (pu != null)
-      {
-         handleClassAnnotation(pu, container, clazz);
-      }
-   }
-
-   private static void handleClassAnnotation(PersistenceUnit ref, InjectionContainer container, Class<?> clazz)
-   {
-      String encName = ref.name();
-      if (encName == null || encName.equals(""))
-      {
-         throw new RuntimeException("JBoss requires name() for class level @PersistenceUnit");
-      }
-      encName = "env/" + encName;
-      if (container.getEncInjectors().containsKey(encName)) return;
-      container.getEncInjectors().put(encName, new PuEncInjector(encName, null, ref.unitName(), "@PersistenceUnit"));
-      try
-      {
-         addPUDependency(ref.unitName(), container);
-      }
-      catch (NameNotFoundException e)
-      {
-         throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage());
-      }
-   }
-
-   public static void addPUDependency(String unitName, InjectionContainer container) throws NameNotFoundException
-   {
-      PersistenceUnitDeployment deployment = null;
-      // look in EAR first
-      deployment = container.getPersistenceUnitDeployment(unitName);
-      if (deployment != null)
-      {
-         container.getDependencyPolicy().addDependency(deployment.getKernelName());
-         log.debug("***** adding PU dependency from located persistence unit: " + deployment.getKernelName());
-         return;
-      }
-      // probably not deployed yet.
-      // todo not sure if we should do this in JBoss 5
-      log.warn("Could not find PU dependency for " + PersistenceUnitDeployment.getDefaultKernelName(unitName) + ". Waiting for dependency to resolve");
-      container.getDependencyPolicy().addDependency(PersistenceUnitDeployment.getDefaultKernelName(unitName));
-   }
-
-   public static ManagedEntityManagerFactory getManagedEntityManagerFactory(InjectionContainer container, String unitName)
-           throws NameNotFoundException
-   {
-      ManagedEntityManagerFactory factory;
-      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
-      if (deployment != null)
-      {
-         factory = deployment.getManagedFactory();
-      }
-      else
-      {
-         throw new NameNotFoundException("Unable to find persistence unit: " + unitName + " for deployment: " + container.getIdentifier());
-      }
-      return factory;
-   }
-
-
-   public static EntityManagerFactory getEntityManagerFactory(PersistenceUnit ref, InjectionContainer container) throws NameNotFoundException
-   {
-      return getEntityManagerFactory(ref.unitName(), container);
-   }
-
-   public static Object getFactory(Class<?> type, String unitName, InjectionContainer container) throws NameNotFoundException
-   {
-      if (type != null && type.getName().equals(SessionFactory.class.getName()))
-         return getSessionFactory(unitName, container);
-      return getEntityManagerFactory(unitName, container);
-   }
-
-   public static EntityManagerFactory getEntityManagerFactory(String unitName, InjectionContainer container) throws NameNotFoundException
-   {
-      ManagedEntityManagerFactory managedFactory;
-      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
-      if (deployment != null)
-      {
-         managedFactory = deployment.getManagedFactory();
-      }
-      else
-      {
-         return null;
-      }
-      return new InjectedEntityManagerFactory(managedFactory);
-   }
-
-
-   private static SessionFactory getSessionFactory(String ref, InjectionContainer container) throws NameNotFoundException
-   {
-      ManagedEntityManagerFactory managedFactory;
-      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(ref);
-      if (deployment != null)
-      {
-         managedFactory = deployment.getManagedFactory();
-      }
-      else
-      {
-         return null;
-      }
-      return new InjectedSessionFactory(managedFactory);
-   }
-
-   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
-   {
-      PersistenceUnit ref = method.getAnnotation(PersistenceUnit.class);
-      if (ref == null) return;
-      if (!method.getName().startsWith("set"))
-         throw new RuntimeException("@PersistenceUnit can only be used with a set method: " + method);
-      String encName = ref.name();
-      if (encName == null || encName.equals(""))
-      {
-         encName = InjectionUtil.getEncName(method);
-      }
-      else
-      {
-         encName = "env/" + encName;
-      }
-      if (!container.getEncInjectors().containsKey(encName))
-      {
-         container.getEncInjectors().put(encName, new PuEncInjector(encName, method.getParameterTypes()[0], ref.unitName(), "@PersistenceUnit"));
-         try
-         {
-            if (!method.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
-         }
-         catch (NameNotFoundException e)
-         {
-            throw new RuntimeException("Illegal @PersistenceUnit on " + method + " :" + e.getMessage());
-         }
-      }
-
-      injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
-   }
-
-   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
-   {
-      PersistenceUnit ref = field.getAnnotation(PersistenceUnit.class);
-      if (ref == null) return;
-      String encName = ref.name();
-      if (encName == null || encName.equals(""))
-      {
-         encName = InjectionUtil.getEncName(field);
-      }
-      else
-      {
-         encName = "env/" + encName;
-      }
-      if (!container.getEncInjectors().containsKey(encName))
-      {
-         container.getEncInjectors().put(encName, new PuEncInjector(encName, field.getType(), ref.unitName(), "@PersistenceUnit"));
-         try
-         {
-            if (!field.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
-         }
-         catch (NameNotFoundException e)
-         {
-            throw new RuntimeException("Illegal @PersistenceUnit on " + field + " :" + e.getMessage());
-         }
-      }
-
-      injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
-   }
-}

Copied: projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PersistenceUnitHandler.java (from rev 75613, projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PersistenceUnitHandler.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PersistenceUnitHandler.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-core-0.1.7/src/main/java/org/jboss/injection/PersistenceUnitHandler.java	2008-07-10 11:46:34 UTC (rev 75617)
@@ -0,0 +1,282 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.naming.NameNotFoundException;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+import javax.persistence.PersistenceUnits;
+
+import org.hibernate.SessionFactory;
+import org.jboss.ejb3.annotation.IgnoreDependency;
+import org.jboss.ejb3.entity.InjectedEntityManagerFactory;
+import org.jboss.ejb3.entity.InjectedSessionFactory;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+
+/**
+ * Searches bean class for all @Inject and create Injectors
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class PersistenceUnitHandler<X extends RemoteEnvironment> implements InjectionHandler<X>
+{
+   private static final Logger log = Logger.getLogger(PersistenceUnitHandler.class);
+
+   public void loadXml(X xml, InjectionContainer container)
+   {
+      if (xml == null) return;
+      if (xml.getPersistenceUnitRefs() == null) return;
+
+      for (PersistenceUnitReferenceMetaData ref : xml.getPersistenceUnitRefs())
+      {
+         String encName = "env/" + ref.getPersistenceUnitRefName();
+         // we add injection target no matter what.  enc injection might be overridden but
+         // XML injection cannot be overriden
+         Class<?> injectionType = InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections());
+         if (container.getEncInjectors().containsKey(encName))
+            return;
+         container.getEncInjectors().put(encName, new PuEncInjector(encName, injectionType, ref.getPersistenceUnitName(), "<persistence-unit-ref>"));
+         try
+         {
+            addPUDependency(ref.getPersistenceUnitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal <persistence-unit-ref> of " + ref.getPersistenceUnitRefName() + " :" + e.getMessage());
+         }
+      }
+   }
+
+
+   public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
+   {
+      PersistenceUnits resources = container.getAnnotation(
+              PersistenceUnits.class, clazz);
+      if (resources != null)
+      {
+         for (PersistenceUnit ref : resources.value())
+         {
+            handleClassAnnotation(ref, container, clazz);
+         }
+      }
+      PersistenceUnit pu = container.getAnnotation(PersistenceUnit.class, clazz);
+      if (pu != null)
+      {
+         handleClassAnnotation(pu, container, clazz);
+      }
+   }
+
+   private static void handleClassAnnotation(PersistenceUnit ref, InjectionContainer container, Class<?> clazz)
+   {
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         throw new RuntimeException("JBoss requires name() for class level @PersistenceUnit");
+      }
+      encName = "env/" + encName;
+      if (container.getEncInjectors().containsKey(encName)) return;
+      container.getEncInjectors().put(encName, new PuEncInjector(encName, null, ref.unitName(), "@PersistenceUnit"));
+      try
+      {
+         addPUDependency(ref.unitName(), container);
+      }
+      catch (NameNotFoundException e)
+      {
+         throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage());
+      }
+   }
+
+   public static void addPUDependency(String unitName, InjectionContainer container) throws NameNotFoundException
+   {
+      if(container instanceof ExtendedInjectionContainer)
+      {
+         ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+         String dependency = eic.resolvePersistenceUnitSupplier(unitName);
+         container.getDependencyPolicy().addDependency(dependency);
+         return;
+      }
+      log.warn("Container " + container + " does not implement ExtendedInjectionContainer, doing old style PersistenceUnit resolving");
+      PersistenceUnitDeployment deployment = null;
+      // look in EAR first
+      deployment = container.getPersistenceUnitDeployment(unitName);
+      if (deployment != null)
+      {
+         container.getDependencyPolicy().addDependency(deployment.getKernelName());
+         log.debug("***** adding PU dependency from located persistence unit: " + deployment.getKernelName());
+         return;
+      }
+      // probably not deployed yet.
+      // todo not sure if we should do this in JBoss 5
+      log.warn("Could not find PU dependency for " + PersistenceUnitDeployment.getDefaultKernelName(unitName) + ". Waiting for dependency to resolve");
+      container.getDependencyPolicy().addDependency(PersistenceUnitDeployment.getDefaultKernelName(unitName));
+   }
+
+   public static ManagedEntityManagerFactory getManagedEntityManagerFactory(InjectionContainer container, String unitName)
+           throws NameNotFoundException
+   {
+      if(container instanceof ExtendedInjectionContainer)
+      {
+         ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+         String beanName = eic.resolvePersistenceUnitSupplier(unitName);
+         return ((org.jboss.jpa.deployment.PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(beanName)).getManagedFactory();
+      }
+      log.warn("Container " + container + " does not implement ExtendedInjectionContainer");
+      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
+      if (deployment != null)
+      {
+         return deployment.getManagedFactory();
+      }
+      else
+      {
+         throw new NameNotFoundException("Unable to find persistence unit: " + unitName + " for deployment: " + container.getIdentifier());
+      }
+   }
+
+
+   public static EntityManagerFactory getEntityManagerFactory(PersistenceUnit ref, InjectionContainer container) throws NameNotFoundException
+   {
+      return getEntityManagerFactory(ref.unitName(), container);
+   }
+
+   public static Object getFactory(Class<?> type, String unitName, InjectionContainer container) throws NameNotFoundException
+   {
+      if (type != null && type.getName().equals(SessionFactory.class.getName()))
+         return getSessionFactory(unitName, container);
+      return getEntityManagerFactory(unitName, container);
+   }
+
+   public static EntityManagerFactory getEntityManagerFactory(String unitName, InjectionContainer container) throws NameNotFoundException
+   {
+      if(container instanceof ExtendedInjectionContainer)
+      {
+         ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+         String beanName = eic.resolvePersistenceUnitSupplier(unitName);
+         ManagedEntityManagerFactory managedFactory = ((org.jboss.jpa.deployment.PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(beanName)).getManagedFactory();
+         return new InjectedEntityManagerFactory(managedFactory);
+      }
+      log.warn("Container " + container + " does not implement ExtendedInjectionContainer");
+      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
+      if (deployment != null)
+      {
+         ManagedEntityManagerFactory managedFactory = deployment.getManagedFactory();
+         return new InjectedEntityManagerFactory(managedFactory);
+      }
+      else
+      {
+         return null;
+      }
+   }
+
+
+   private static SessionFactory getSessionFactory(String ref, InjectionContainer container) throws NameNotFoundException
+   {
+      if(container instanceof ExtendedInjectionContainer)
+      {
+         ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+         String beanName = eic.resolvePersistenceUnitSupplier(ref);
+         ManagedEntityManagerFactory managedFactory = ((org.jboss.jpa.deployment.PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(beanName)).getManagedFactory();
+         return new InjectedSessionFactory(managedFactory);
+      }
+      log.warn("Container " + container + " does not implement ExtendedInjectionContainer");
+      PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(ref);
+      if (deployment != null)
+      {
+         ManagedEntityManagerFactory managedFactory = deployment.getManagedFactory();
+         return new InjectedSessionFactory(managedFactory);
+      }
+      else
+      {
+         return null;
+      }
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      PersistenceUnit ref = method.getAnnotation(PersistenceUnit.class);
+      if (ref == null) return;
+      if (!method.getName().startsWith("set"))
+         throw new RuntimeException("@PersistenceUnit can only be used with a set method: " + method);
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(method);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         container.getEncInjectors().put(encName, new PuEncInjector(encName, method.getParameterTypes()[0], ref.unitName(), "@PersistenceUnit"));
+         try
+         {
+            if (!method.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal @PersistenceUnit on " + method + " :" + e.getMessage());
+         }
+      }
+
+      injectors.put(method, new JndiMethodInjector(method, encName, container.getEnc()));
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
+   {
+      PersistenceUnit ref = field.getAnnotation(PersistenceUnit.class);
+      if (ref == null) return;
+      String encName = ref.name();
+      if (encName == null || encName.equals(""))
+      {
+         encName = InjectionUtil.getEncName(field);
+      }
+      else
+      {
+         encName = "env/" + encName;
+      }
+      if (!container.getEncInjectors().containsKey(encName))
+      {
+         container.getEncInjectors().put(encName, new PuEncInjector(encName, field.getType(), ref.unitName(), "@PersistenceUnit"));
+         try
+         {
+            if (!field.isAnnotationPresent(IgnoreDependency.class)) addPUDependency(ref.unitName(), container);
+         }
+         catch (NameNotFoundException e)
+         {
+            throw new RuntimeException("Illegal @PersistenceUnit on " + field + " :" + e.getMessage());
+         }
+      }
+
+      injectors.put(field, new JndiFieldInjector(field, encName, container.getEnc()));
+   }
+}




More information about the jboss-cvs-commits mailing list