KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > util > ZipFileRegistry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.util;
26
27 import java.util.Hashtable JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.zip.ZipFile JavaDoc;
30 import java.io.*;
31
32 /**
33  * ZipFileRegistry provides a central point for lookup of zip files
34  * within the filter tool. It needs to be public because it's
35  * accessed from outside the filter.util package.
36  */

37
38 public
39 class ZipFileRegistry {
40   /* A mapping of file name to ZipFile */
41   private static Hashtable JavaDoc zipFileMap = new Hashtable JavaDoc(11);
42
43   /**
44    * Return a zip file which may already be open
45    */

46   public static ZipFile JavaDoc openZipFile(File JavaDoc f)
47     throws FileNotFoundException, IOException {
48     ZipFile JavaDoc zf = (ZipFile JavaDoc) zipFileMap.get(f.getPath());
49     if (zf == null) {
50       zf = new ZipFile JavaDoc(f);
51       zipFileMap.put(zf.getName(), zf);
52     }
53     return zf;
54   }
55
56   /**
57    * Return a zip file which must already be open
58    */

59   public static ZipFile JavaDoc getZipFile(String JavaDoc path) {
60     return (ZipFile JavaDoc) zipFileMap.get(path);
61   }
62
63   /**
64    * Returns an enumeration of the zip files in the registry
65    * Each element is a ZipFile.
66    */

67   public static Enumeration JavaDoc zipFiles() {
68     return zipFileMap.elements();
69   }
70   
71 }
72
Popular Tags