[jboss-cvs] JBossAS SVN: r101289 - in projects/jpa/tags: 1.0.2-alpha-1 and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 22 18:29:48 EST 2010


Author: johnbailey
Date: 2010-02-22 18:29:47 -0500 (Mon, 22 Feb 2010)
New Revision: 101289

Added:
   projects/jpa/tags/1.0.2-alpha-1/
   projects/jpa/tags/1.0.2-alpha-1/pom.xml
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeploymentFactory.java
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/util/ServiceLoader.java
   projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeployment.java
   projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeploymentFactory.java
   projects/jpa/tags/1.0.2-alpha-1/src/test/resources/META-INF/services/
Removed:
   projects/jpa/tags/1.0.2-alpha-1/pom.xml
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java
   projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
Log:
[maven-release-plugin]  copy for tag 1.0.2-alpha-1

Copied: projects/jpa/tags/1.0.2-alpha-1 (from rev 101081, projects/jpa/trunk/deployers)

Deleted: projects/jpa/tags/1.0.2-alpha-1/pom.xml
===================================================================
--- projects/jpa/trunk/deployers/pom.xml	2010-02-17 16:23:52 UTC (rev 101081)
+++ projects/jpa/tags/1.0.2-alpha-1/pom.xml	2010-02-22 23:29:47 UTC (rev 101289)
@@ -1,151 +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>
-    <groupId>org.jboss.jpa</groupId>
-    <artifactId>jboss-jpa-build</artifactId>
-    <relativePath>../build/pom.xml</relativePath>
-    <version>1.0.1</version>
-  </parent>
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <artifactId>jboss-jpa-deployers</artifactId>
-  <version>1.0.2-SNAPSHOT</version>
-  <packaging>jar</packaging>
-  <name>JBoss Container Managed JPA Deployers</name>
-  <description>
-    The JBoss Container Managed JPA Deployers for deploying persistence units.
-    See EJB 3 JPA chapter 6 and 7.
-  </description>
-  
-  <properties>
-    <version.org.jboss.deployers>2.0.5.GA</version.org.jboss.deployers>
-  </properties>
-
-  <dependencies>
-    <!-- For 'mocking' a TransactionManager we use JBossTS -->
-    <dependency>
-      <groupId>jboss.jbossts</groupId>
-      <artifactId>jbossjta</artifactId>
-      <version>4.4.0.GA</version>
-      <scope>test</scope>
-    </dependency>
-  	<dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.4</version>
-      <scope>test</scope>
-    </dependency>
-    <!-- For 'mocking' a DataSource we use Derby -->
-    <dependency>
-      <groupId>org.apache.derby</groupId>
-      <artifactId>derby</artifactId>
-      <version>10.4.1.3</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-entitymanager</artifactId>
-      <version>${version.org.hibernate.hibernate-entitymanager}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.integration</groupId>
-      <artifactId>jboss-transaction-spi</artifactId>
-      <version>5.0.3.GA</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-test</artifactId>
-      <version>1.0.5.GA</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.deployers</groupId>
-      <artifactId>jboss-deployers-vfs</artifactId>
-      <version>${version.org.jboss.deployers}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.deployers</groupId>
-      <artifactId>jboss-deployers-vfs-spi</artifactId>
-      <version>${version.org.jboss.deployers}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.jpa</groupId>
-      <artifactId>jboss-jpa-impl</artifactId>
-      <version>1.0.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.jpa</groupId>
-      <artifactId>jboss-jpa-spi</artifactId>
-      <version>1.0.0</version>
-      <!-- TODO: we should really use the right jpa-spi -->
-      <exclusions>
-        <exclusion>
-          <groupId>org.hibernate</groupId>
-          <artifactId>ejb3-persistence</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.metadata</groupId>
-      <artifactId>jboss-metadata</artifactId>
-      <version>1.0.0.CR17</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.hibernate</groupId>
-          <artifactId>ejb3-persistence</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <!-- For @JMX -->
-    <dependency>
-      <groupId>org.jboss.microcontainer</groupId>
-      <artifactId>jboss-aop-mc-int</artifactId>
-      <version>2.0.4.GA</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.naming</groupId>
-      <artifactId>jnpserver</artifactId>
-      <version>5.0.1.GA</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <!-- For Arjuna / JBoss Transaction -->
-    <dependency>
-      <groupId>apache-logging</groupId>
-      <artifactId>commons-logging</artifactId>
-      <version>1.1.0.jboss</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>oswego-concurrent</groupId>
-      <artifactId>concurrent</artifactId>
-      <version>1.3.4-jboss-update1</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>jboss.jbossts</groupId>
-      <artifactId>jbossts-common</artifactId>
-      <version>4.4.0.GA</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <!-- Hibernate core logging -->
-    <dependency>
-      <groupId>org.jboss.slf4j</groupId>
-      <artifactId>slf4j-jboss-logging</artifactId>
-      <version>1.0.0.GA</version>
-      <scope>test</scope>
-    </dependency>
-    
-    <!-- jboss-common-core (For JNDI Utils) -->
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-common-core</artifactId>
-      <version>2.2.11.GA</version>
-    </dependency>
-    
-  </dependencies>
-</project>

Copied: projects/jpa/tags/1.0.2-alpha-1/pom.xml (from rev 101288, projects/jpa/trunk/deployers/pom.xml)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/pom.xml	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/pom.xml	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,157 @@
+<!--
+  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>
+    <groupId>org.jboss.jpa</groupId>
+    <artifactId>jboss-jpa-build</artifactId>
+    <relativePath>../build/pom.xml</relativePath>
+    <version>1.0.1</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>jboss-jpa-deployers</artifactId>
+  <version>1.0.2-alpha-1</version>
+  <packaging>jar</packaging>
+  <name>JBoss Container Managed JPA Deployers</name>
+  <description>
+    The JBoss Container Managed JPA Deployers for deploying persistence units.
+    See EJB 3 JPA chapter 6 and 7.
+  </description>
+  
+  <properties>
+    <version.org.jboss.deployers>2.0.5.GA</version.org.jboss.deployers>
+  </properties>
+
+  <dependencies>
+    <!-- For 'mocking' a TransactionManager we use JBossTS -->
+    <dependency>
+      <groupId>jboss.jbossts</groupId>
+      <artifactId>jbossjta</artifactId>
+      <version>4.4.0.GA</version>
+      <scope>test</scope>
+    </dependency>
+  	<dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.4</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- For 'mocking' a DataSource we use Derby -->
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+      <version>10.4.1.3</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-entitymanager</artifactId>
+      <version>${version.org.hibernate.hibernate-entitymanager}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.integration</groupId>
+      <artifactId>jboss-transaction-spi</artifactId>
+      <version>5.0.3.GA</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-test</artifactId>
+      <version>1.0.5.GA</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-vfs</artifactId>
+      <version>${version.org.jboss.deployers}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-vfs-spi</artifactId>
+      <version>${version.org.jboss.deployers}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.jpa</groupId>
+      <artifactId>jboss-jpa-impl</artifactId>
+      <version>1.0.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.jpa</groupId>
+      <artifactId>jboss-jpa-spi</artifactId>
+      <version>1.0.0</version>
+      <!-- TODO: we should really use the right jpa-spi -->
+      <exclusions>
+        <exclusion>
+          <groupId>org.hibernate</groupId>
+          <artifactId>ejb3-persistence</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.metadata</groupId>
+      <artifactId>jboss-metadata</artifactId>
+      <version>1.0.0.CR17</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.hibernate</groupId>
+          <artifactId>ejb3-persistence</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <!-- For @JMX -->
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-aop-mc-int</artifactId>
+      <version>2.0.4.GA</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.naming</groupId>
+      <artifactId>jnpserver</artifactId>
+      <version>5.0.1.GA</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <!-- For Arjuna / JBoss Transaction -->
+    <dependency>
+      <groupId>apache-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.1.0.jboss</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>oswego-concurrent</groupId>
+      <artifactId>concurrent</artifactId>
+      <version>1.3.4-jboss-update1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>jboss.jbossts</groupId>
+      <artifactId>jbossts-common</artifactId>
+      <version>4.4.0.GA</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <!-- Hibernate core logging -->
+    <dependency>
+      <groupId>org.jboss.slf4j</groupId>
+      <artifactId>slf4j-jboss-logging</artifactId>
+      <version>1.0.0.GA</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <!-- jboss-common-core (For JNDI Utils) -->
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+      <version>2.2.11.GA</version>
+    </dependency>
+    
+  </dependencies>
+
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jpa/tags/1.0.2-alpha-1</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jpa/tags/1.0.2-alpha-1</developerConnection>
+    <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/jpa/tags/1.0.2-alpha-1</url>
+  </scm>
+</project>

Deleted: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java	2010-02-17 16:23:52 UTC (rev 101081)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -1,148 +0,0 @@
-/*
- * 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.jpa.deployers;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.jboss.beans.metadata.api.annotations.Inject;
-import org.jboss.beans.metadata.api.annotations.MapValue;
-import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.jpa.deployment.PersistenceUnitDeployment;
-import org.jboss.jpa.resolvers.DataSourceDependencyResolver;
-import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
-import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- * @version $Revision: $
- */
-public class PersistenceUnitDeployer extends AbstractSimpleRealDeployer<PersistenceUnitMetaData>
-{
-   private Properties defaultPersistenceProperties;
-   private DataSourceDependencyResolver dataSourceDependencyResolver;
-   private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
-   
-   public PersistenceUnitDeployer()
-   {
-      super(PersistenceUnitMetaData.class);
-      // We want to process the components created by PersistenceDeployer, this seems to be the only way to get there.
-      setComponentsOnly(true);
-      addOutput(BeanMetaData.class);
-   }
-
-   private void addDependencies(BeanMetaDataBuilder builder, PersistenceUnitMetaData metaData)
-   {
-      // Initialize properties to default
-      Properties props = new Properties();
-      props.putAll(defaultPersistenceProperties);
-      
-      // Add properties from metadata
-      Map<String, String> metadataProps = metaData.getProperties() != null
-            ? metaData.getProperties()
-            : new HashMap<String, String>();
-      props.putAll(metadataProps);
-      
-      if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
-      {
-         if (metaData.getJtaDataSource() != null)
-         {
-            String ds = metaData.getJtaDataSource();
-            builder.addDependency(dataSourceDependencyResolver.resolveDataSourceSupplier(ds));
-         }
-         if (metaData.getNonJtaDataSource() != null)
-         {
-            String ds = metaData.getNonJtaDataSource();
-            builder.addDependency(dataSourceDependencyResolver.resolveDataSourceSupplier(ds));
-         }
-      }
-      for (Object prop : props.keySet())
-      {
-         String property = (String) prop;
-         if (property.startsWith("jboss.depends"))
-         {
-            builder.addDependency(props.get(property));
-         }
-      }
-   }
-
-   @Override
-   public void deploy(DeploymentUnit unit, PersistenceUnitMetaData metaData) throws DeploymentException
-   {
-      log.debug("deploy " + metaData);
-      
-      try
-      {
-         String name = persistenceUnitDependencyResolver.createBeanName(unit, metaData.getName());
-         
-         InitialContext initialContext = new InitialContext();
-         List<String> explicitEntityClasses = new ArrayList<String>();
-         VFSDeploymentUnit deploymentUnit = (VFSDeploymentUnit) unit.getParent();
-         PersistenceUnitDeployment pu = new PersistenceUnitDeployment(initialContext, null, explicitEntityClasses, metaData, name, deploymentUnit, defaultPersistenceProperties);
-         
-         AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(name, PersistenceUnitDeployment.class.getName());
-         BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanMetaData);
-         builder.setConstructorValue(pu);
-         addDependencies(builder, metaData);
-
-         DeploymentUnit parent = unit.getParent();
-         if (parent == null)
-            throw new IllegalArgumentException("Parent unit should not be null as this unit should be component: " + unit);
-
-         parent.addAttachment(BeanMetaData.class.getName() + "." + name, builder.getBeanMetaData(), BeanMetaData.class);
-      }
-      catch(NamingException e)
-      {
-         throw new DeploymentException(e);
-      }
-   }
-   
-   @Inject
-   public void setDataSourceDependencyResolver(DataSourceDependencyResolver resolver)
-   {
-      this.dataSourceDependencyResolver = resolver;
-   }
-   
-   @MapValue(keyClass=String.class, value={}, valueClass=String.class)
-   public void setDefaultPersistenceProperties(Properties p)
-   {
-      this.defaultPersistenceProperties = p;
-   }
-   
-   @Inject
-   public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
-   {
-      this.persistenceUnitDependencyResolver = resolver;
-   }
-}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java (from rev 101088, projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,149 @@
+/*
+ * 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.jpa.deployers;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.beans.metadata.api.annotations.MapValue;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.deployment.PersistenceUnitDeployment;
+import org.jboss.jpa.deployment.PersistenceUnitDeploymentFactory;
+import org.jboss.jpa.resolvers.DataSourceDependencyResolver;
+import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @version $Revision: $
+ */
+public class PersistenceUnitDeployer extends AbstractSimpleRealDeployer<PersistenceUnitMetaData>
+{
+   private Properties defaultPersistenceProperties;
+   private DataSourceDependencyResolver dataSourceDependencyResolver;
+   private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
+   
+   public PersistenceUnitDeployer()
+   {
+      super(PersistenceUnitMetaData.class);
+      // We want to process the components created by PersistenceDeployer, this seems to be the only way to get there.
+      setComponentsOnly(true);
+      addOutput(BeanMetaData.class);
+   }
+
+   private void addDependencies(BeanMetaDataBuilder builder, PersistenceUnitMetaData metaData)
+   {
+      // Initialize properties to default
+      Properties props = new Properties();
+      props.putAll(defaultPersistenceProperties);
+      
+      // Add properties from metadata
+      Map<String, String> metadataProps = metaData.getProperties() != null
+            ? metaData.getProperties()
+            : new HashMap<String, String>();
+      props.putAll(metadataProps);
+      
+      if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
+      {
+         if (metaData.getJtaDataSource() != null)
+         {
+            String ds = metaData.getJtaDataSource();
+            builder.addDependency(dataSourceDependencyResolver.resolveDataSourceSupplier(ds));
+         }
+         if (metaData.getNonJtaDataSource() != null)
+         {
+            String ds = metaData.getNonJtaDataSource();
+            builder.addDependency(dataSourceDependencyResolver.resolveDataSourceSupplier(ds));
+         }
+      }
+      for (Object prop : props.keySet())
+      {
+         String property = (String) prop;
+         if (property.startsWith("jboss.depends"))
+         {
+            builder.addDependency(props.get(property));
+         }
+      }
+   }
+
+   @Override
+   public void deploy(DeploymentUnit unit, PersistenceUnitMetaData metaData) throws DeploymentException
+   {
+      log.debug("deploy " + metaData);
+      
+      try
+      {
+         String name = persistenceUnitDependencyResolver.createBeanName(unit, metaData.getName());
+         
+         InitialContext initialContext = new InitialContext();
+         List<String> explicitEntityClasses = new ArrayList<String>();
+         VFSDeploymentUnit deploymentUnit = (VFSDeploymentUnit) unit.getParent();
+         PersistenceUnitDeployment pu = PersistenceUnitDeploymentFactory.getInstance().create(initialContext, null, explicitEntityClasses, metaData, name, deploymentUnit, defaultPersistenceProperties);
+         
+         AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(name, PersistenceUnitDeployment.class.getName());
+         BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanMetaData);
+         builder.setConstructorValue(pu);
+         addDependencies(builder, metaData);
+
+         DeploymentUnit parent = unit.getParent();
+         if (parent == null)
+            throw new IllegalArgumentException("Parent unit should not be null as this unit should be component: " + unit);
+
+         parent.addAttachment(BeanMetaData.class.getName() + "." + name, builder.getBeanMetaData(), BeanMetaData.class);
+      }
+      catch(NamingException e)
+      {
+         throw new DeploymentException(e);
+      }
+   }
+   
+   @Inject
+   public void setDataSourceDependencyResolver(DataSourceDependencyResolver resolver)
+   {
+      this.dataSourceDependencyResolver = resolver;
+   }
+   
+   @MapValue(keyClass=String.class, value={}, valueClass=String.class)
+   public void setDefaultPersistenceProperties(Properties p)
+   {
+      this.defaultPersistenceProperties = p;
+   }
+   
+   @Inject
+   public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
+   {
+      this.persistenceUnitDependencyResolver = resolver;
+   }
+}

Deleted: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java	2010-02-17 16:23:52 UTC (rev 101081)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -1,273 +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.jpa.deployment;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.InitialContext;
-
-import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.jpa.spi.PersistenceUnitRegistry;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.jpa.spec.PersistenceMetaData;
-import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
-
-/**
- * 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$
- */
- at Deprecated
-public class PersistenceDeployment //extends ServiceMBeanSupport
-//  implements JavaEEModule, Ejb3DeploymentMBean
-{
-   private static final Logger log = Logger.getLogger(PersistenceDeployment.class);
-
-//   public static final String ACTUAL_ENTITY_MANAGER_FACTORY_CONTEXT = "java:/ActualEntityManagerFactories";
-//
-//   public static final String MANAGED_ENTITY_FACTORY_CONTEXT = "java:/managedEntityFactories";
-
-   private PersistenceMetaData metaData;
-   
-   protected VFSDeploymentUnit 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 InitialContext initialContext;
-
-   private String earName;
-
-   public PersistenceDeployment(VFSDeploymentUnit unit, String earName, PersistenceMetaData metaData)
-   {
-      assert unit != null : "unit is null";
-      assert metaData != null : "metaData is null";
-      
-      this.unit = unit;
-      this.earName = earName;
-      this.metaData = metaData;
-   }
-
-//   public JavaEEApplication getApplication()
-//   {
-//      return deploymentScope;
-//   }
-
-   public VFSDeploymentUnit getDeploymentUnit()
-   {
-      return unit;
-   }
-
-   /**
-    * Returns a partial MBean attribute name of the form
-    * ",ear=foo.ear,jar=foo.jar"
-    *
-    * @return
-    */
-   public String getScopeKernelName()
-   {
-      String scopedKernelName = "";
-      if (earName != null)
-         scopedKernelName += ",ear=" + earName;
-      scopedKernelName += ",jar=" + unit.getSimpleName();
-      return scopedKernelName;
-   }
-
-   protected String getJaccContextId()
-   {
-      return unit.getSimpleName();
-   }
-
-   public List<PersistenceUnitDeployment> getPersistenceUnitDeployments()
-   {
-      return persistenceUnitDeployments;
-   }
-
-//   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
-   {
-      long start = System.currentTimeMillis();
-
-      //pc = createPolicyConfiguration();
-
-      initializePersistenceUnits();
-      
-      log.debug("Persistence deployment time took: " + (System.currentTimeMillis() - start));
-   }
-   
-   public void destroy()
-   {
-      persistenceUnitDeployments.clear();
-   }
-   
-   public void start() throws Exception
-   {
-      try
-      {
-         startPersistenceUnits();
-      }
-      catch (Exception ex)
-      {
-         try
-         {
-            stop();
-         }
-         catch (Exception ignored)
-         {
-         }
-         throw ex;
-      }
-   }
-   
-   public void stop() //throws Exception
-   {
-      stopPersistenceUnits();
-   }
-
-   protected void initializePersistenceUnits() throws Exception
-   {
-      // TODO: What is the meaning of this piece of code?
-//      if (unit.getClasses() != null)
-//      {
-//         for (Class<?> explicit : unit.getClasses())
-//         {
-//            if (explicit.isAnnotationPresent(Entity.class))
-//            {
-//               explicitEntityClasses.add(explicit.getName());
-//            }
-//         }
-//      }
-
-      List<PersistenceUnitMetaData> pumds = metaData.getPersistenceUnits();
-      for (PersistenceUnitMetaData metaData : pumds)
-      {
-         Map<String, String> properties = metaData.getProperties();
-         if (properties == null)
-         {
-            properties = new HashMap<String, String>();
-            metaData.setProperties(properties);
-         }         
-         
-         PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(initialContext, this, explicitEntityClasses, metaData, "wrong-kernel-name", getDeploymentUnit(), null);
-         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);
-            AbstractBeanMetaData bmd = new AbstractBeanMetaData("ToDo");
-            AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
-            constructor.setValueObject(entityDeployment);
-            bmd.setConstructor(constructor);
-            unit.addAttachment(BeanMetaData.class, bmd);
-//            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>();
-   }
-
-   /**
-    * Get the meta data associated with this deployment or null if none.
-    * 
-    * @return   meta data or null
-    */
-   public PersistenceMetaData getMetaData()
-   {
-      return metaData;
-   }
-
-   public String getName()
-   {
-      return unit.getSimpleName();
-   }
-}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java (from rev 101088, projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceDeployment.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,273 @@
+/*
+ * 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.jpa.deployment;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.InitialContext;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.jpa.spec.PersistenceMetaData;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+
+/**
+ * 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$
+ */
+ at Deprecated
+public class PersistenceDeployment //extends ServiceMBeanSupport
+//  implements JavaEEModule, Ejb3DeploymentMBean
+{
+   private static final Logger log = Logger.getLogger(PersistenceDeployment.class);
+
+//   public static final String ACTUAL_ENTITY_MANAGER_FACTORY_CONTEXT = "java:/ActualEntityManagerFactories";
+//
+//   public static final String MANAGED_ENTITY_FACTORY_CONTEXT = "java:/managedEntityFactories";
+
+   private PersistenceMetaData metaData;
+   
+   protected VFSDeploymentUnit 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 InitialContext initialContext;
+
+   private String earName;
+
+   public PersistenceDeployment(VFSDeploymentUnit unit, String earName, PersistenceMetaData metaData)
+   {
+      assert unit != null : "unit is null";
+      assert metaData != null : "metaData is null";
+      
+      this.unit = unit;
+      this.earName = earName;
+      this.metaData = metaData;
+   }
+
+//   public JavaEEApplication getApplication()
+//   {
+//      return deploymentScope;
+//   }
+
+   public VFSDeploymentUnit getDeploymentUnit()
+   {
+      return unit;
+   }
+
+   /**
+    * Returns a partial MBean attribute name of the form
+    * ",ear=foo.ear,jar=foo.jar"
+    *
+    * @return
+    */
+   public String getScopeKernelName()
+   {
+      String scopedKernelName = "";
+      if (earName != null)
+         scopedKernelName += ",ear=" + earName;
+      scopedKernelName += ",jar=" + unit.getSimpleName();
+      return scopedKernelName;
+   }
+
+   protected String getJaccContextId()
+   {
+      return unit.getSimpleName();
+   }
+
+   public List<PersistenceUnitDeployment> getPersistenceUnitDeployments()
+   {
+      return persistenceUnitDeployments;
+   }
+
+//   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
+   {
+      long start = System.currentTimeMillis();
+
+      //pc = createPolicyConfiguration();
+
+      initializePersistenceUnits();
+      
+      log.debug("Persistence deployment time took: " + (System.currentTimeMillis() - start));
+   }
+   
+   public void destroy()
+   {
+      persistenceUnitDeployments.clear();
+   }
+   
+   public void start() throws Exception
+   {
+      try
+      {
+         startPersistenceUnits();
+      }
+      catch (Exception ex)
+      {
+         try
+         {
+            stop();
+         }
+         catch (Exception ignored)
+         {
+         }
+         throw ex;
+      }
+   }
+   
+   public void stop() //throws Exception
+   {
+      stopPersistenceUnits();
+   }
+
+   protected void initializePersistenceUnits() throws Exception
+   {
+      // TODO: What is the meaning of this piece of code?
+//      if (unit.getClasses() != null)
+//      {
+//         for (Class<?> explicit : unit.getClasses())
+//         {
+//            if (explicit.isAnnotationPresent(Entity.class))
+//            {
+//               explicitEntityClasses.add(explicit.getName());
+//            }
+//         }
+//      }
+
+      List<PersistenceUnitMetaData> pumds = metaData.getPersistenceUnits();
+      for (PersistenceUnitMetaData metaData : pumds)
+      {
+         Map<String, String> properties = metaData.getProperties();
+         if (properties == null)
+         {
+            properties = new HashMap<String, String>();
+            metaData.setProperties(properties);
+         }         
+         
+         PersistenceUnitDeployment deployment = PersistenceUnitDeploymentFactory.getInstance().create(initialContext, this, explicitEntityClasses, metaData, "wrong-kernel-name", getDeploymentUnit(), null);
+         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);
+            AbstractBeanMetaData bmd = new AbstractBeanMetaData("ToDo");
+            AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
+            constructor.setValueObject(entityDeployment);
+            bmd.setConstructor(constructor);
+            unit.addAttachment(BeanMetaData.class, bmd);
+//            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>();
+   }
+
+   /**
+    * Get the meta data associated with this deployment or null if none.
+    * 
+    * @return   meta data or null
+    */
+   public PersistenceMetaData getMetaData()
+   {
+      return metaData;
+   }
+
+   public String getName()
+   {
+      return unit.getSimpleName();
+   }
+}

Deleted: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	2010-02-17 16:23:52 UTC (rev 101081)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -1,361 +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.jpa.deployment;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-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.naming.NamingException;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.hibernate.ejb.HibernatePersistence;
-import org.jboss.beans.metadata.api.annotations.Inject;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.jpa.builder.CEMFBuilder;
-import org.jboss.jpa.impl.deployment.PersistenceUnitInfoImpl;
-import org.jboss.jpa.injection.InjectedEntityManagerFactory;
-import org.jboss.jpa.spi.PersistenceUnit;
-import org.jboss.jpa.spi.PersistenceUnitRegistry;
-import org.jboss.jpa.spi.XPCResolver;
-import org.jboss.jpa.tx.TransactionScopedEntityManager;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
-import org.jboss.util.naming.NonSerializableFactory;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class PersistenceUnitDeployment //extends AbstractJavaEEComponent
-   implements PersistenceUnit
-{
-   private static final Logger log = Logger.getLogger(PersistenceUnitDeployment.class);
-
-   protected InitialContext initialContext;
-   protected VFSDeploymentUnit di;
-   protected List<String> explicitEntityClasses = new ArrayList<String>();
-   protected ManagedEntityManagerFactory managedFactory;
-   protected EntityManagerFactory actualFactory;
-   protected PersistenceUnitMetaData metaData;
-   protected String kernelName;
-   protected PersistenceDeployment deployment;
-   private Properties defaultPersistenceProperties;
-   private CEMFBuilder cemfBuilder;
-   private XPCResolver xpcResolver;
-
-   public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
-   {
-      //super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
-      
-      this.deployment = deployment;
-      this.initialContext = initialContext;
-      this.di = deploymentUnit;
-      this.explicitEntityClasses = explicitEntityClasses;
-      this.metaData = metadata;
-      this.defaultPersistenceProperties = defaultPersistenceProperties;
-      
-      this.kernelName = kernelName;
-   }
-
-   public void create()
-   {
-      assert xpcResolver != null : "xpcResolver wasn't set on " + this;
-      
-      // To allow for serializable objects to obtain a reference back
-      PersistenceUnitRegistry.register(this);
-   }
-   
-   public void destroy()
-   {
-      PersistenceUnitRegistry.unregister(this);
-   }
-   
-   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 PersistenceDeployment getDeployment()
-   {
-      return deployment;
-   }
-
-   protected String getJaccContextId()
-   {
-      return di.getSimpleName();
-   }
-
-   public EntityManagerFactory getActualFactory()
-   {
-      return actualFactory;
-   }
-
-   public PersistenceUnitMetaData getXml()
-   {
-      return metaData;
-   }
-
-   public String getKernelName()
-   {
-      return kernelName;
-   }
-
-   public String getName()
-   {
-      return getKernelName();
-   }
-
-   /**
-    * Find the persistence unit root, which can be the root of a jar
-    * or WEB-INF/classes of a war.
-    * @return the persistence unit root
-    */
-   protected VirtualFile getPersistenceUnitRoot()
-   {
-      // FIXME: What is the correct way to find the persistence unit root?
-      try
-      {
-         VirtualFile metaData = di.getMetaDataFile("persistence.xml");
-         assert metaData != null : "Can't find persistence.xml in " + di;
-         return metaData.getParent().getParent();
-      }
-      catch(IOException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   public EntityManagerFactory getContainerEntityManagerFactory()
-   {
-      return actualFactory;
-   }
-   
-   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();
-   }
-
-   private URL getRelativeURL(String jar)
-   {
-      try
-      {
-         return new URL(jar);
-      }
-      catch (MalformedURLException e)
-      {
-         try
-         {
-            VirtualFile deploymentUnitFile = di.getFile("");
-            VirtualFile parent = deploymentUnitFile.getParent();
-            VirtualFile baseDir = (parent != null ? parent : deploymentUnitFile);
-            VirtualFile jarFile = baseDir.getChild(jar);
-            if(jarFile == null)
-               throw new RuntimeException("could not find child '" + jar + "' on '" + baseDir + "'");
-            return jarFile.toURL();
-         }
-         catch (Exception e1)
-         {
-            throw new RuntimeException("could not find relative path: " + jar, e1);
-         }
-      }
-   }
-   
-   public EntityManager getTransactionScopedEntityManager()
-   {
-      return managedFactory.getTransactionScopedEntityManager();
-   }
-   
-   public XPCResolver getXPCResolver()
-   {
-      assert xpcResolver != null : "xpcResolver is null in " + this;  
-      return xpcResolver;
-   }
-   
-   public boolean isInTx()
-   {
-      return managedFactory.isInTx();
-   }
-   
-   @Inject
-   public void setCEMFBuilder(CEMFBuilder builder)
-   {
-      this.cemfBuilder = builder;
-   }
-   
-   @Inject
-   public void setXPCResolver(XPCResolver xpcResolver)
-   {
-      // Do not check for null, because MC does uninstall with null
-      this.xpcResolver = xpcResolver;
-   }
-   
-//   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));
-//         }
-//      }
-//
-//   }
-
-   public void start() throws Exception
-   {
-      log.info("Starting persistence unit " + kernelName);
-      
-      Properties props = new Properties();
-      props.putAll(defaultPersistenceProperties);
-      props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
-
-      List<URL> jarFiles = new ArrayList<URL>();
-      Set<String> files = metaData.getJarFiles();
-      if (files != null)
-      {
-         for (String jar : files)
-         {
-            jarFiles.add(getRelativeURL(jar));
-         }
-      }
-
-      VirtualFile root = getPersistenceUnitRoot();
-      log.debug("Persistence root: " + root);
-      // hack the JPA url
-      URL url = VFSUtils.getCompatibleURL(root);
-      PersistenceUnitInfoImpl pi = new PersistenceUnitInfoImpl(metaData, props, di.getClassLoader(), url, jarFiles, initialContext);
-
-      if (explicitEntityClasses.size() > 0)
-      {
-         List<String> classes = pi.getManagedClassNames();
-         if (classes == null) classes = explicitEntityClasses;
-         else classes.addAll(explicitEntityClasses);
-         pi.setManagedClassnames(classes);
-      }
-      
-      // EJBTHREE-893
-      if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
-      {
-         pi.getProperties().put("hibernate.session_factory_name", kernelName);
-      }
-      
-      // EJBTHREE-954/JBAS-6111
-      // Ensure 2nd level cache entries are segregated from other deployments
-      if (pi.getProperties().getProperty("hibernate.cache.region_prefix") == null)
-      {
-         pi.getProperties().setProperty("hibernate.cache.region_prefix", kernelName);
-      }
-      
-      actualFactory = cemfBuilder.build(di, pi);
-
-      managedFactory = new ManagedEntityManagerFactory(this);
-
-      String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
-      if (entityManagerJndiName != null)
-      {
-         EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
-         NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager, true);
-      }
-      String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
-      if (entityManagerFactoryJndiName != null)
-      {
-         EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
-         NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory, true);
-      }
-   }
-
-   public void stop() throws Exception
-   {
-      log.info("Stopping persistence unit " + kernelName);
-
-      String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
-      if (entityManagerJndiName != null)
-      {
-         unbind(entityManagerJndiName);
-      }
-      String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
-      if (entityManagerFactoryJndiName != null)
-      {
-         unbind(entityManagerFactoryJndiName);
-      }
-      actualFactory.close();
-   }
-   
-   private void unbind(String name) throws NamingException
-   {
-      NonSerializableFactory.unbind(name);
-      initialContext.unbind(name);
-   }
-   
-   public void verifyInTx()
-   {
-      managedFactory.verifyInTx();
-   }
-}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java (from rev 101088, projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,320 @@
+/*
+ * 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.jpa.deployment;
+
+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.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.hibernate.ejb.HibernatePersistence;
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.builder.CEMFBuilder;
+import org.jboss.jpa.impl.deployment.PersistenceUnitInfoImpl;
+import org.jboss.jpa.injection.InjectedEntityManagerFactory;
+import org.jboss.jpa.spi.PersistenceUnit;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.jboss.jpa.spi.XPCResolver;
+import org.jboss.jpa.tx.TransactionScopedEntityManager;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.util.naming.NonSerializableFactory;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public abstract class PersistenceUnitDeployment //extends AbstractJavaEEComponent
+   implements PersistenceUnit
+{
+   private static final Logger log = Logger.getLogger(PersistenceUnitDeployment.class);
+
+   protected InitialContext initialContext;
+   protected VFSDeploymentUnit di;
+   protected List<String> explicitEntityClasses = new ArrayList<String>();
+   protected ManagedEntityManagerFactory managedFactory;
+   protected EntityManagerFactory actualFactory;
+   protected PersistenceUnitMetaData metaData;
+   protected String kernelName;
+   protected PersistenceDeployment deployment;
+   private Properties defaultPersistenceProperties;
+   private CEMFBuilder cemfBuilder;
+   private XPCResolver xpcResolver;
+
+   public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
+   {
+      //super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
+      
+      this.deployment = deployment;
+      this.initialContext = initialContext;
+      this.di = deploymentUnit;
+      this.explicitEntityClasses = explicitEntityClasses;
+      this.metaData = metadata;
+      this.defaultPersistenceProperties = defaultPersistenceProperties;
+      
+      this.kernelName = kernelName;
+   }
+
+   public void create()
+   {
+      assert xpcResolver != null : "xpcResolver wasn't set on " + this;
+      
+      // To allow for serializable objects to obtain a reference back
+      PersistenceUnitRegistry.register(this);
+   }
+   
+   public void destroy()
+   {
+      PersistenceUnitRegistry.unregister(this);
+   }
+   
+   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 PersistenceDeployment getDeployment()
+   {
+      return deployment;
+   }
+
+   protected String getJaccContextId()
+   {
+      return di.getSimpleName();
+   }
+
+   public EntityManagerFactory getActualFactory()
+   {
+      return actualFactory;
+   }
+
+   public PersistenceUnitMetaData getXml()
+   {
+      return metaData;
+   }
+
+   public String getKernelName()
+   {
+      return kernelName;
+   }
+
+   public String getName()
+   {
+      return getKernelName();
+   }
+
+   /**
+    * Find the persistence unit URL, which can be the root of a jar
+    * or WEB-INF/classes of a war.
+    * @return the persistence unit ULR
+    */
+   protected abstract URL getPersistenceUnitURL();
+   
+   public EntityManagerFactory getContainerEntityManagerFactory()
+   {
+      return actualFactory;
+   }
+   
+   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();
+   }
+
+   protected abstract URL getRelativeURL(String jar);
+
+   
+   public EntityManager getTransactionScopedEntityManager()
+   {
+      return managedFactory.getTransactionScopedEntityManager();
+   }
+   
+   public XPCResolver getXPCResolver()
+   {
+      assert xpcResolver != null : "xpcResolver is null in " + this;  
+      return xpcResolver;
+   }
+   
+   public boolean isInTx()
+   {
+      return managedFactory.isInTx();
+   }
+   
+   @Inject
+   public void setCEMFBuilder(CEMFBuilder builder)
+   {
+      this.cemfBuilder = builder;
+   }
+   
+   @Inject
+   public void setXPCResolver(XPCResolver xpcResolver)
+   {
+      // Do not check for null, because MC does uninstall with null
+      this.xpcResolver = xpcResolver;
+   }
+   
+//   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));
+//         }
+//      }
+//
+//   }
+
+   public void start() throws Exception
+   {
+      log.info("Starting persistence unit " + kernelName);
+      
+      Properties props = new Properties();
+      props.putAll(defaultPersistenceProperties);
+      props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
+
+      List<URL> jarFiles = new ArrayList<URL>();
+      Set<String> files = metaData.getJarFiles();
+      if (files != null)
+      {
+         for (String jar : files)
+         {
+            jarFiles.add(getRelativeURL(jar));
+         }
+      }
+
+      URL url = getPersistenceUnitURL();
+      log.debug("Persistence url: " + url);
+      PersistenceUnitInfoImpl pi = new PersistenceUnitInfoImpl(metaData, props, di.getClassLoader(), url, jarFiles, initialContext);
+
+      if (explicitEntityClasses.size() > 0)
+      {
+         List<String> classes = pi.getManagedClassNames();
+         if (classes == null) classes = explicitEntityClasses;
+         else classes.addAll(explicitEntityClasses);
+         pi.setManagedClassnames(classes);
+      }
+      
+      // EJBTHREE-893
+      if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
+      {
+         pi.getProperties().put("hibernate.session_factory_name", kernelName);
+      }
+      
+      // EJBTHREE-954/JBAS-6111
+      // Ensure 2nd level cache entries are segregated from other deployments
+      if (pi.getProperties().getProperty("hibernate.cache.region_prefix") == null)
+      {
+         pi.getProperties().setProperty("hibernate.cache.region_prefix", kernelName);
+      }
+      
+      actualFactory = cemfBuilder.build(di, pi);
+
+      managedFactory = new ManagedEntityManagerFactory(this);
+
+      String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
+      if (entityManagerJndiName != null)
+      {
+         EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
+         NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager, true);
+      }
+      String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
+      if (entityManagerFactoryJndiName != null)
+      {
+         EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
+         NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory, true);
+      }
+   }
+
+   public void stop() throws Exception
+   {
+      log.info("Stopping persistence unit " + kernelName);
+
+      String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
+      if (entityManagerJndiName != null)
+      {
+         unbind(entityManagerJndiName);
+      }
+      String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
+      if (entityManagerFactoryJndiName != null)
+      {
+         unbind(entityManagerFactoryJndiName);
+      }
+      actualFactory.close();
+   }
+   
+   private void unbind(String name) throws NamingException
+   {
+      NonSerializableFactory.unbind(name);
+      initialContext.unbind(name);
+   }
+   
+   public void verifyInTx()
+   {
+      managedFactory.verifyInTx();
+   }
+}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeploymentFactory.java (from rev 101287, projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeploymentFactory.java)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeploymentFactory.java	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeploymentFactory.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jpa.deployment;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.util.ServiceLoader;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+
+/**
+ * Factory used to create {@link PersistenceUnitDeployment} instances.
+ * 
+ * @author John Bailey
+ */
+public abstract class PersistenceUnitDeploymentFactory
+{
+   /**
+    * Get a factory instance.  
+    * 
+    * @return factory instance
+    */
+   public static PersistenceUnitDeploymentFactory getInstance() {
+      ServiceLoader<PersistenceUnitDeploymentFactory> factoryLoader = ServiceLoader.load(PersistenceUnitDeploymentFactory.class);
+      
+      Iterator<PersistenceUnitDeploymentFactory> factoryIterator = factoryLoader.iterator();
+      
+      PersistenceUnitDeploymentFactory factory = null;
+      if(factoryIterator.hasNext())
+      {
+         factory = factoryIterator.next();
+         if(factoryIterator.hasNext())
+         {
+            throw new RuntimeException("More the one service found found for " + PersistenceUnitDeploymentFactory.class + ", please ensure only one factory implementation is found on the classpath.  (JBJPA-21)");
+         }
+      }
+      else 
+      {
+         throw new RuntimeException("No service found for " + PersistenceUnitDeploymentFactory.class + " (JBJPA-21)");
+      }
+      
+      return factory;
+   }
+   
+   /**
+    * Template method for factory implementations to create {@link PersistenceUnitDeployment} instances. 
+    *  
+    * @param initialContext
+    * @param deployment
+    * @param explicitEntityClasses
+    * @param metadata
+    * @param kernelName
+    * @param deploymentUnit
+    * @param defaultPersistenceProperties
+    * @return a {@link PersistenceUnitDeployment} instance
+    */
+   public abstract PersistenceUnitDeployment create(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties);
+}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/util/ServiceLoader.java (from rev 101088, projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/util/ServiceLoader.java)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/util/ServiceLoader.java	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/src/main/java/org/jboss/jpa/util/ServiceLoader.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jpa.util;
+
+import java.util.Iterator;
+
+import javax.imageio.spi.ServiceRegistry;
+
+
+/**
+ * Service loader following the API from http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html which is compatible with JDK 5.
+ * 
+ * @author John Bailey
+ * @param <S> the service 
+ */
+public class ServiceLoader<S> implements Iterable<S>
+{
+
+   /**
+    * @See <a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html#load%28java.lang.Class%29">ServiceLoader.load(Class)</a> 
+    */
+   public static <S> ServiceLoader<S> load(Class<S> serviceClass)
+   {
+      return load(serviceClass, Thread.currentThread().getContextClassLoader());
+   }
+
+   /**
+    * @See <a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html#load%28java.lang.Class,%20java.lang.ClassLoader%29">ServiceLoader.load(Class, ClassL oader)</a> 
+    */
+   public static <S> ServiceLoader<S> load(Class<S> service, ClassLoader loader)
+   {
+      return new ServiceLoader<S>(service, loader);
+   }
+   
+   private final Class<S> serviceClass;
+   private final ClassLoader loader;
+   private Iterator<S> serviceIterator;
+   
+   
+   /**
+    * ServiceLoader constructor
+    * @param serviceClass the service class
+    * @param loader classloader to load service from
+    */
+   private ServiceLoader(Class<S> serviceClass, ClassLoader loader) 
+   {
+      this.serviceClass = serviceClass;
+      this.loader = loader;
+      reload();
+   }
+
+   /**
+    * @See <a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html#iterator%28%29">ServiceLoader.iterator</a> 
+    */
+   public Iterator<S> iterator()
+   {
+      return serviceIterator;
+   }
+   
+   /**
+    * @See <a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html#reload%29">ServiceLoader.reload</a>
+    */
+   public void reload() 
+   {
+      serviceIterator = ServiceRegistry.lookupProviders(serviceClass, loader);  
+   }
+}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeployment.java (from rev 101088, projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeployment.java)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeployment.java	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeployment.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jpa.deployers.test.common;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.deployment.PersistenceDeployment;
+import org.jboss.jpa.deployment.PersistenceUnitDeployment;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Instance of PersistenceUnitDeployment that uses VFS2 roots 
+ * 
+ * @author John Bailey
+ */
+public class MockPersistenceUnitDeployment extends PersistenceUnitDeployment
+{
+
+   /**
+    * Constructs a new PersistenceUnitDeploymentImpl
+    * 
+    * @param initialContext
+    * @param deployment
+    * @param explicitEntityClasses
+    * @param metadata
+    * @param kernelName
+    * @param deploymentUnit
+    * @param defaultPersistenceProperties
+    */
+   public MockPersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment,
+         List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName,
+         VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
+   {
+      super(initialContext, deployment, explicitEntityClasses, metadata, kernelName, deploymentUnit, defaultPersistenceProperties);
+   }
+
+   /** {@inheritdoc} */
+   @Override
+   protected URL getPersistenceUnitURL()
+   {
+      try {
+         VirtualFile metaData = di.getMetaDataFile("persistence.xml");
+         assert metaData != null : "Can't find persistence.xml in " + di;
+         return metaData.getParent().getParent().toURL();
+      }
+      catch (Exception e) {
+         throw new RuntimeException(e);
+      }
+   }
+
+   /** {@inheritdoc} */
+   @Override
+   protected URL getRelativeURL(String jar)
+   {
+      try {
+         return new URL(jar);
+      }
+      catch (MalformedURLException e) {
+         try {
+            VirtualFile deploymentUnitFile = di.getFile("");
+            VirtualFile parent = deploymentUnitFile.getParent();
+            VirtualFile baseDir = (parent != null ? parent : deploymentUnitFile);
+            VirtualFile jarFile = baseDir.getChild(jar);
+            if (jarFile == null)
+               throw new RuntimeException("could not find child '" + jar + "' on '" + baseDir + "'");
+            return jarFile.toURL();
+         }
+         catch (Exception e1) {
+            throw new RuntimeException("could not find relative path: " + jar, e1);
+         }
+      }
+   }
+
+}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeploymentFactory.java (from rev 101088, projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeploymentFactory.java)
===================================================================
--- projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeploymentFactory.java	                        (rev 0)
+++ projects/jpa/tags/1.0.2-alpha-1/src/test/java/org/jboss/jpa/deployers/test/common/MockPersistenceUnitDeploymentFactory.java	2010-02-22 23:29:47 UTC (rev 101289)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jpa.deployers.test.common;
+
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.jpa.deployment.PersistenceDeployment;
+import org.jboss.jpa.deployment.PersistenceUnitDeployment;
+import org.jboss.jpa.deployment.PersistenceUnitDeploymentFactory;
+import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
+
+/**
+ * Implementation of {@link PersistenceUnitDeploymentFactory} that creates {@link PersistenceUnitDeployment} backed with VFS2 roots.
+ *  
+ * @author John Bailey
+ */
+public class MockPersistenceUnitDeploymentFactory extends PersistenceUnitDeploymentFactory 
+{
+
+   /** {@inheritdoc} */
+   @Override
+   public PersistenceUnitDeployment create(InitialContext initialContext, PersistenceDeployment deployment,
+         List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName,
+         VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
+   {
+      return new MockPersistenceUnitDeployment(initialContext, deployment, explicitEntityClasses, metadata, kernelName, deploymentUnit, defaultPersistenceProperties);
+   }
+   
+}

Copied: projects/jpa/tags/1.0.2-alpha-1/src/test/resources/META-INF/services (from rev 101088, projects/jpa/trunk/deployers/src/test/resources/META-INF/services)




More information about the jboss-cvs-commits mailing list