1 //
2 // ========================================================================
3 // Copyright (c) 1995-2014 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 *
26 * FakeURLClassLoader
27 *
28 * A URLClassloader that overrides the getURLs() method to return the list
29 * of urls passed in to the constructor, but otherwise acts as if it has no
30 * urls, which would cause it to delegate to the parent classloader (in this
31 * case an OSGi classloader).
32 *
33 * The main use of this class is with jars containing tlds. Jasper expects a
34 * URL classloader to inspect for jars with tlds.
35 *
36 */
37 public class FakeURLClassLoader extends URLClassLoader
38 {
39
40 private URL[] _jars;
41
42
43 /* ------------------------------------------------------------ */
44 /**
45 * @param osgiClassLoader
46 * @param jars
47 */
48 public FakeURLClassLoader(ClassLoader osgiClassLoader, URL[] jars)
49 {
50 super(new URL[] {},osgiClassLoader);
51 _jars = jars;
52 }
53
54 /* ------------------------------------------------------------ */
55 /**
56 * @return the jars that contains tlds so that TldLocationsCache or
57 * TldScanner can find them.
58 */
59 @Override
60 public URL[] getURLs()
61 {
62 return _jars;
63 }
64
65
66 /* ------------------------------------------------------------ */
67 /**
68 * @see java.lang.Object#toString()
69 */
70 public String toString()
71 {
72 StringBuilder builder = new StringBuilder();
73
74 if (_jars != null)
75 {
76 for (URL u:_jars)
77 builder.append(" "+u.toString());
78 return builder.toString();
79 }
80 else
81 return super.toString();
82 }
83 }