1 // ========================================================================
2 // Copyright (c) 2009 Intalio, Inc.
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // ========================================================================
13 package org.eclipse.jetty.osgi.boot.utils;
14
15 import java.io.File;
16 import java.net.URL;
17 import java.util.Enumeration;
18
19 import org.eclipse.jetty.osgi.boot.utils.internal.DefaultFileLocatorHelper;
20 import org.osgi.framework.Bundle;
21
22 /**
23 * From a bundle to its location on the filesystem. Assumes the bundle is not a
24 * jar.
25 *
26 * @author hmalphettes
27 */
28 public interface BundleFileLocatorHelper
29 {
30
31 /** The name of the custom implementation for this interface in a fragment. */
32 public static final String CLASS_NAME = "org.eclipse.jetty.osgi.boot.utils.FileLocatorHelperImpl";
33
34 /** The default instance supports felix and equinox */
35 public static BundleFileLocatorHelper DEFAULT = new DefaultFileLocatorHelper();
36
37
38 /**
39 * Works with equinox, felix, nuxeo and probably more. Not exactly in the
40 * spirit of OSGi but quite necessary to support self-contained webapps and
41 * other situations.
42 * <p>
43 * Currently only works with bundles that are not jar.
44 * </p>
45 *
46 * @param bundle
47 * The bundle
48 * @return Its installation location as a file.
49 * @throws Exception
50 */
51 public File getBundleInstallLocation(Bundle bundle) throws Exception;
52
53 /**
54 * Locate a file inside a bundle.
55 *
56 * @param bundle
57 * @param path
58 * @return file object
59 * @throws Exception
60 */
61 public File getFileInBundle(Bundle bundle, String path) throws Exception;
62
63 /**
64 * If the bundle is a jar, returns the jar. If the bundle is a folder, look
65 * inside it and search for jars that it returns.
66 * <p>
67 * Good enough for our purpose (TldLocationsCache when it scans for tld
68 * files inside jars alone. In fact we only support the second situation for
69 * development purpose where the bundle was imported in pde and the classes
70 * kept in a jar.
71 * </p>
72 *
73 * @param bundle
74 * @return The jar(s) file that is either the bundle itself, either the jars
75 * embedded inside it.
76 */
77 public File[] locateJarsInsideBundle(Bundle bundle) throws Exception;
78
79
80 /**
81 * Helper method equivalent to Bundle#getEntry(String entryPath) except that
82 * it searches for entries in the fragments by using the findEntries method.
83 *
84 * @param bundle
85 * @param entryPath
86 * @return null or all the entries found for that path.
87 */
88 public Enumeration<URL> findEntries(Bundle bundle, String entryPath);
89
90 }