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 * Works with equinox, felix, nuxeo and probably more. Not exactly in the
39 * spirit of OSGi but quite necessary to support self-contained webapps and
40 * other situations.
41 * <p>
42 * Currently only works with bundles that are not jar.
43 * </p>
44 *
45 * @param bundle The bundle
46 * @return Its installation location as a file.
47 * @throws Exception
48 */
49 public File getBundleInstallLocation(Bundle bundle) throws Exception;
50
51 /**
52 * Locate a file inside a bundle.
53 *
54 * @param bundle
55 * @param path
56 * @return file object
57 * @throws Exception
58 */
59 public File getFileInBundle(Bundle bundle, String path) throws Exception;
60
61 /**
62 * If the bundle is a jar, returns the jar. If the bundle is a folder, look
63 * inside it and search for jars that it returns.
64 * <p>
65 * Good enough for our purpose (TldLocationsCache when it scans for tld
66 * files inside jars alone. In fact we only support the second situation for
67 * development purpose where the bundle was imported in pde and the classes
68 * kept in a jar.
69 * </p>
70 *
71 * @param bundle
72 * @return The jar(s) file that is either the bundle itself, either the jars
73 * embedded inside it.
74 */
75 public File[] locateJarsInsideBundle(Bundle bundle) throws Exception;
76
77 /**
78 * Helper method equivalent to Bundle#getEntry(String entryPath) except that
79 * it searches for entries in the fragments by using the findEntries method.
80 *
81 * @param bundle
82 * @param entryPath
83 * @return null or all the entries found for that path.
84 */
85 public Enumeration<URL> findEntries(Bundle bundle, String entryPath);
86
87 }