Only in ./updated: com
Only in .: javadoc.css
diff -r -c -w ./org/stripesstuff/stripersist/Stripersist.java ./updated/org/stripesstuff/stripersist/Stripersist.java
*** ./org/stripesstuff/stripersist/Stripersist.java	2009-09-18 15:58:49.000000000 -0400
--- ./updated/org/stripesstuff/stripersist/Stripersist.java	2009-06-24 12:48:16.000000000 -0400
***************
*** 21,26 ****
--- 21,27 ----
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.net.URLDecoder;
+ import java.util.Enumeration;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
***************
*** 107,120 ****
  	{
  		try
  		{
  			URL url = Thread.currentThread().getContextClassLoader().getResource("/META-INF/persistence.xml");
  			
  			// url may be null if using ant/junit. if it is null we'll try a different classloader - thanks freddy!
  			if (url == null)
  			    url = getClass().getResource("/META-INF/persistence.xml");
  			    
! 			log.debug("Reading persistence.xml from ", url, ".");
  			init(url);
  			
  			requestInit();
  			for (Class<? extends StripersistInit> initClass :
--- 108,134 ----
      {
        try
          {
+ 
+           entityManagerFactories = new ConcurrentHashMap<String, EntityManagerFactory>();
+ 
+           // try to get all available resources.
+           Enumeration<URL> allResources = getClass().getClassLoader().getResources("META-INF/persistence.xml");
+           if (allResources != null && allResources.hasMoreElements()) {
+             while (allResources.hasMoreElements()) {
+               URL url = allResources.nextElement();
+               log.info("Reading persistence.xml from ", url, ".");
+               init(url);
+             }
+           } else {
              URL url = Thread.currentThread().getContextClassLoader().getResource("/META-INF/persistence.xml");
  
              // url may be null if using ant/junit. if it is null we'll try a different classloader - thanks freddy!
              if (url == null)
                url = getClass().getResource("/META-INF/persistence.xml");
  
!             log.info("Reading persistence.xml from ", url, ".");
              init(url);
+           }
  
            requestInit();
            for (Class<? extends StripersistInit> initClass :
***************
*** 149,160 ****
  	 */
  	public void init(URL xml)
  	{
! 		log.debug("Initializing Stripersist using JPA persistence file.");
  
  		try
  		{
- 			entityManagerFactories = new ConcurrentHashMap<String, EntityManagerFactory>();
- 			
  			Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xml.openStream());
  			NodeList nodeList = document.getElementsByTagName("persistence-unit");
  			for (int i = 0; i < nodeList.getLength(); i++)
--- 163,172 ----
       */
      public void init(URL xml)
      {
!       log.info("Initializing Stripersist using JPA persistence file.");
  
        try
          {
            Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xml.openStream());
            NodeList nodeList = document.getElementsByTagName("persistence-unit");
            for (int i = 0; i < nodeList.getLength(); i++)
***************
*** 162,172 ****
  				Node persistenceUnit = nodeList.item(i);
  				
  				String name = persistenceUnit.getAttributes().getNamedItem("name").getNodeValue();
! 				log.debug("Creating EntityManagerFactory for persistence unit \"", name, "\"");
  				
  				EntityManagerFactory factory = Persistence.createEntityManagerFactory(name);
  				
  				entityManagerFactories.put(name, factory);
  				
  				NodeList children = persistenceUnit.getChildNodes();
  				
--- 174,187 ----
                Node persistenceUnit = nodeList.item(i);
  
                String name = persistenceUnit.getAttributes().getNamedItem("name").getNodeValue();
!               log.info("t:  Creating EntityManagerFactory for persistence unit \"", name, "\"");
  
                EntityManagerFactory factory = Persistence.createEntityManagerFactory(name);
  
                entityManagerFactories.put(name, factory);
+               log.info("created factory " + factory + " for " + name);
+               log.info("emf.get(" + name + ") = " + entityManagerFactories.get(name));
+               log.info("emf = " + entityManagerFactories);
  
                NodeList children = persistenceUnit.getChildNodes();
  
***************
*** 206,221 ****
  						}
  					}
  				}
  			}
  			
  			if ((entityManagerFactories.size() == 1) && (entityManagerFactoryLookup.size() == 0))
  			{
  				EntityManagerFactory factory = entityManagerFactories.values().iterator().next();
  				String name = entityManagerFactories.keySet().iterator().next();
  				
  				for (Class<?> clazz : findEntities(null))
  				{
! 					log.debug("Associating ", clazz.getName(), " with persistence unit \"", name, "\"");
  					entityManagerFactoryLookup.put(clazz, factory);
  				}
  			}
--- 221,272 ----
                          }
                      }
                  }
+               // load up the Entities in the jar file that contained the
+               // persistence.xml file.
+               Set<Class<?>> classes = new HashSet<Class<?>>();
+ 
+               //log.debug("checking far file from url:  " + xml);
+               log.info("checking jar file from url:  " + xml);
+               String urlPath = xml.getFile();
+               log.info("urlPath = " + urlPath);
+               if ("vfszip".equals(xml.getProtocol())) {
+                 log.info("getting entitires from stream.");
+                 URL newUrl = new URL(xml.toString().substring(0, xml.toString().length() - 25));
+                 log.info("checking new url " + newUrl);
+                 classes.addAll(findEntitiesFromUrl(newUrl));
+               } else {
+                 urlPath = URLDecoder.decode(urlPath, "UTF-8");
+                 if (urlPath.startsWith("file:")) {
+                   urlPath = urlPath.substring(5);
+                 }
+                 if (urlPath.endsWith("!/META-INF/persistence.xml")) {
+                   urlPath = urlPath.substring(0, urlPath.length() - 26);
+                 }
+ 
+                 File file = new File(urlPath);
+                 if ( file.isDirectory() ) {
+                   classes.addAll(findEntitiesInDirectory("", file));
+                 }
+                 else {
+                   classes.addAll(findEntitiesInJar(file));
+                 }
+               }
+               for (Class<?> clazz : classes)
+                 {
+                   entityManagerFactoryLookup.put(clazz, factory);
+                 }
              }
  
+ 
            if ((entityManagerFactories.size() == 1) && (entityManagerFactoryLookup.size() == 0))
              {
+               log.debug("skipping lookup for null.");
                EntityManagerFactory factory = entityManagerFactories.values().iterator().next();
                String name = entityManagerFactories.keySet().iterator().next();
  
                for (Class<?> clazz : findEntities(null))
                  {
!                   log.debug("Default:  associating ", clazz.getName(), " with persistence unit \"", name, "\"");
                    entityManagerFactoryLookup.put(clazz, factory);
                  }
              }
***************
*** 256,269 ****
  
                  File file = new File(urlPath);
                  
!                 if (jarName == null && file.isFile())
!                 	continue;
                  
                  log.debug("Scanning for entities in [", urlPath, "]");
                  if ( file.isDirectory() ) {
                      classes.addAll(findEntitiesInDirectory("", file));
                  }
                  else {
                      classes.addAll(findEntitiesInJar(file));
                  }
  				
--- 307,322 ----
  
                File file = new File(urlPath);
  
!               //if (jarName == null && file.isFile())
!               //  continue;
  
                log.debug("Scanning for entities in [", urlPath, "]");
                if ( file.isDirectory() ) {
+                 log.debug("checking for directory.");
                  classes.addAll(findEntitiesInDirectory("", file));
                }
                else {
+                 log.debug("checking for jar.");
                  classes.addAll(findEntitiesInJar(file));
                }
  
***************
*** 307,312 ****
--- 360,395 ----
  
        return null;
      }
+     /**
+      * Returns a set of classes that are annotated with
+      * {@link Entity} or {@link MappedSuperclass} in the specified jar file.
+      *
+      * @param file
+      * @return a set of entity classes
+      */
+     private static Set<? extends Class<?>> findEntitiesFromUrl(URL url)
+     {
+       try {
+         JarEntry entry;
+         JarInputStream jarStream = new JarInputStream(url.openStream());
+ 
+         Set<Class<?>> classes = new HashSet<Class<?>>();
+ 
+         while ( (entry = jarStream.getNextJarEntry() ) != null) {
+           String name = entry.getName();
+           if (!entry.isDirectory() && name.endsWith(".class")) {
+             addIfEntity(classes, name);
+           }
+         }
+ 
+         return classes;
+       }
+       catch (IOException ioe) {
+         log.error("Could not search URL '", url, "' for entities due to an IOException: ", ioe.getMessage());
+       }
+ 
+       return new HashSet<Class<?>>();
+     }
  
      /**
       * Returns a set of classes that are annotated with
Only in ./org/stripesstuff/stripersist: .svn
Only in ./org/stripesstuff: .svn
Only in ./org: .svn
Only in .: overview.html
Only in .: .svn
