1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 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.internal.jsp;
20
21 import java.net.URL;
22 import java.net.URLClassLoader;
23
24 /**
25 * Tricky url classloader. In fact we don't want a real URLClassLoader: we want
26 * OSGi to provide its classloader and let it does. But to let
27 * {@link org.apache.jasper.compiler.TldLocationsCache} find the core tlds
28 * inside the jars we must be a URLClassLoader that returns an array of jars
29 * where tlds are stored when the method getURLs is called.
30 */
31 public class TldLocatableURLClassloader extends URLClassLoader
32 {
33
34 private URL[] _jarsWithTldsInside;
35
36 public TldLocatableURLClassloader(ClassLoader osgiClassLoader, URL[] jarsWithTldsInside)
37 {
38 super(new URL[] {},osgiClassLoader);
39 _jarsWithTldsInside = jarsWithTldsInside;
40 }
41
42 /**
43 * @return the jars that contains tlds so that TldLocationsCache or
44 * TldScanner can find them.
45 */
46 @Override
47 public URL[] getURLs()
48 {
49 return _jarsWithTldsInside;
50 }
51
52 public String toString()
53 {
54 StringBuilder builder = new StringBuilder();
55
56 if (_jarsWithTldsInside != null)
57 {
58 for (URL u:_jarsWithTldsInside)
59 builder.append(" "+u.toString());
60 return builder.toString();
61 }
62 else
63 return super.toString();
64 }
65 }