View Javadoc

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  
17  import org.eclipse.jetty.osgi.boot.utils.internal.DefaultFileLocatorHelper;
18  import org.osgi.framework.Bundle;
19  
20  /**
21   * From a bundle to its location on the filesystem. Assumes the bundle is not a
22   * jar.
23   * 
24   * @author hmalphettes
25   */
26  public interface BundleFileLocatorHelper
27  {
28  
29      /** The name of the custom implementation for this interface in a fragment. */
30      public static final String CLASS_NAME = "org.eclipse.jetty.osgi.boot.utils.FileLocatorHelperImpl";
31  
32      /** The default instance supports felix and equinox */
33      public static BundleFileLocatorHelper DEFAULT = new DefaultFileLocatorHelper();
34  
35  
36      /**
37       * Works with equinox, felix, nuxeo and probably more. Not exactly in the
38       * spirit of OSGi but quite necessary to support self-contained webapps and
39       * other situations.
40       * <p>
41       * Currently only works with bundles that are not jar.
42       * </p>
43       * 
44       * @param bundle
45       *            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
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  }