KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > baseadaptor > bundlefile > NestedDirBundleFile


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.osgi.baseadaptor.bundlefile;
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.util.Enumeration JavaDoc;
17
18 /**
19  * A NestedDirBundleFile uses another BundleFile as its source but
20  * accesses all of its resources relative to a nested directory within
21  * the other BundleFile object. This is used to support zipped bundles
22  * that use a Bundle-ClassPath with an nested directory specified.
23  * <p>
24  * For Example:
25  * <pre>
26  * Bundle-ClassPath: nested.jar,nesteddir/
27  * </pre>
28  * @since 3.2
29  */

30 public class NestedDirBundleFile extends BundleFile {
31     BundleFile baseBundleFile;
32     String JavaDoc cp;
33
34     /**
35      * Constructs a NestedDirBundleFile
36      * @param baseBundlefile the base bundle file
37      * @param cp
38      */

39     public NestedDirBundleFile(BundleFile baseBundlefile, String JavaDoc cp) {
40         super(baseBundlefile.basefile);
41         this.baseBundleFile = baseBundlefile;
42         this.cp = cp;
43         if (cp.charAt(cp.length() - 1) != '/') {
44             this.cp = this.cp + '/';
45         }
46     }
47
48     public void close() {
49         // do nothing.
50
}
51
52     public BundleEntry getEntry(String JavaDoc path) {
53         if (path.length() > 0 && path.charAt(0) == '/')
54             path = path.substring(1);
55         String JavaDoc newpath = new StringBuffer JavaDoc(cp).append(path).toString();
56         return baseBundleFile.getEntry(newpath);
57     }
58
59     public boolean containsDir(String JavaDoc dir) {
60         if (dir == null)
61             return false;
62
63         if (dir.length() > 0 && dir.charAt(0) == '/')
64             dir = dir.substring(1);
65         String JavaDoc newdir = new StringBuffer JavaDoc(cp).append(dir).toString();
66         return baseBundleFile.containsDir(newdir);
67     }
68
69     public Enumeration JavaDoc getEntryPaths(String JavaDoc path) {
70         // getEntryPaths is only valid if this is a root bundle file.
71
return null;
72     }
73
74     public File JavaDoc getFile(String JavaDoc entry, boolean nativeCode) {
75         // getFile is only valid if this is a root bundle file.
76
return null;
77     }
78
79     public void open() throws IOException JavaDoc {
80         // do nothing
81
}
82 }
83
Popular Tags