1 //
2 // ========================================================================
3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.osgi.boot.utils;
20
21 import java.net.URL;
22 import java.net.URLClassLoader;
23
24 /**
25 * FakeURLClassLoader
26 * <p>
27 * A URLClassloader that overrides the getURLs() method to return the list
28 * of urls passed in to the constructor, but otherwise acts as if it has no
29 * urls, which would cause it to delegate to the parent classloader (in this
30 * case an OSGi classloader).
31 * <p>
32 * The main use of this class is with jars containing tlds. Jasper expects a
33 * URL classloader to inspect for jars with tlds.
34 */
35 public class FakeURLClassLoader extends URLClassLoader
36 {
37 private URL[] _jars;
38
39 /* ------------------------------------------------------------ */
40 public FakeURLClassLoader(ClassLoader osgiClassLoader, URL[] jars)
41 {
42 super(new URL[] {},osgiClassLoader);
43 _jars = jars;
44 }
45
46 /* ------------------------------------------------------------ */
47 /**
48 * @return the jars that contains tlds so that TldLocationsCache or
49 * TldScanner can find them.
50 */
51 @Override
52 public URL[] getURLs()
53 {
54 return _jars;
55 }
56
57
58 /* ------------------------------------------------------------ */
59 /**
60 * @see java.lang.Object#toString()
61 */
62 public String toString()
63 {
64 StringBuilder builder = new StringBuilder();
65
66 if (_jars != null)
67 {
68 for (URL u:_jars)
69 builder.append(" "+u.toString());
70 return builder.toString();
71 }
72 else
73 return super.toString();
74 }
75 }