KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ejb > packaging > ZippedJarVisitor


1 //$Id: ZippedJarVisitor.java,v 1.4 2005/08/04 00:46:04 epbernard Exp $
2
package org.hibernate.ejb.packaging;
3
4 import java.io.IOException JavaDoc;
5 import java.net.URL JavaDoc;
6 import java.util.Enumeration JavaDoc;
7 import java.util.jar.JarFile JavaDoc;
8 import java.util.zip.ZipEntry JavaDoc;
9
10 /**
11  * @author Emmanuel Bernard
12  */

13 public class ZippedJarVisitor extends JarVisitor {
14     public ZippedJarVisitor(String JavaDoc jarFileName, boolean detectClasses, boolean detectHbm) {
15         super( jarFileName, detectClasses, detectHbm );
16     }
17
18     public ZippedJarVisitor(URL JavaDoc url, boolean detectClasses, boolean detectHbm) {
19         this.detectClasses = detectClasses;
20         this.detectHbm = detectHbm;
21         String JavaDoc file = url.getFile();
22         jarFileName = file.substring( "file:/".length(), file.length() - "!/META-INF/persistence.xml".length() );
23         unqualify();
24     }
25
26     protected void doProcessElements() {
27         JarFile JavaDoc jarFile;
28         try {
29             jarFile = new JarFile JavaDoc( jarFileName );
30         }
31         catch (IOException JavaDoc ze) {
32             log.warn( "Unable to find file (ignored): " + jarFileName, ze );
33             return;
34         }
35         Enumeration JavaDoc<? extends ZipEntry JavaDoc> entries = jarFile.entries();
36         while ( entries.hasMoreElements() ) {
37             ZipEntry JavaDoc entry = entries.nextElement();
38             if ( !entry.isDirectory() ) {
39                 addElement( entry.getName() );
40             }
41         }
42     }
43 }
44
Popular Tags