01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * Initial developer(s): Guillaume SAUTHIER
22: * --------------------------------------------------------------------------
23: * $Id: JarURLFactory.java 4622 2004-04-19 13:49:54Z sauthieg $
24: * --------------------------------------------------------------------------
25: */package org.objectweb.jonas_lib.loader.factory;
26:
27: import java.net.URL;
28: import java.io.IOException;
29:
30: /**
31: * A <code>JarURLFactory</code> is used to create URLs
32: * from a JarURL (jar:XXX) and paths.
33: * Example : <br/>
34: * base : <code>file:lib.jar</code><br/>
35: * path : <code>META-INF/directory/</code><br/>
36: * results : <code>jar:file:lib.jar!/META-INF/directory/</code><br/>
37: *
38: * @author Guillaume Sauthier
39: */
40: public class JarURLFactory extends URLFactory {
41:
42: /** the base URL */
43: private URL base;
44:
45: /** Jar URl prefix */
46: private static final String JAR = "jar:";
47:
48: /**
49: * Jar URL separator
50: */
51: private static final String SEP = "!/";
52:
53: /**
54: * Create a new JarURLFactory using the specified base URL.
55: *
56: * @param url the base url. (must be a Jar archive)
57: */
58: public JarURLFactory(URL url) {
59: base = url;
60: }
61:
62: /**
63: * Returns a new URL basically adding path to the base URL.
64: * returns the base URL when "" is used as parameter.
65: *
66: * @param path the path to add to the URL. (must not start with "/")
67: *
68: * @return a new URL of the form jar:<base>!/<path>.
69: *
70: * @throws IOException when created URL is invalid.
71: */
72: public URL getURL(String path) throws IOException {
73: if (path.equals("")) {
74: return base;
75: } else {
76: return new URL(JAR + base + SEP + path);
77: }
78: }
79:
80: }
|