KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > loader > factory > JarURLFactory


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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,v 1.2 2004/04/19 13:49:09 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.loader.factory;
28
29 import java.net.URL JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 /**
33  * A <code>JarURLFactory</code> is used to create URLs
34  * from a JarURL (jar:XXX) and paths.
35  * Example : <br/>
36  * base : <code>file:lib.jar</code><br/>
37  * path : <code>META-INF/directory/</code><br/>
38  * results : <code>jar:file:lib.jar!/META-INF/directory/</code><br/>
39  *
40  * @author Guillaume Sauthier
41  */

42 public class JarURLFactory extends URLFactory {
43
44     /** the base URL */
45     private URL JavaDoc base;
46
47     /** Jar URl prefix */
48     private static final String JavaDoc JAR = "jar:";
49
50     /**
51      * Jar URL separator
52      */

53     private static final String JavaDoc SEP = "!/";
54
55     /**
56      * Create a new JarURLFactory using the specified base URL.
57      *
58      * @param url the base url. (must be a Jar archive)
59      */

60     public JarURLFactory(URL JavaDoc url) {
61         base = url;
62     }
63
64     /**
65      * Returns a new URL basically adding path to the base URL.
66      * returns the base URL when "" is used as parameter.
67      *
68      * @param path the path to add to the URL. (must not start with "/")
69      *
70      * @return a new URL of the form jar:<base>!/<path>.
71      *
72      * @throws IOException when created URL is invalid.
73      */

74     public URL JavaDoc getURL(String JavaDoc path) throws IOException JavaDoc {
75         if (path.equals("")) {
76             return base;
77         } else {
78             return new URL JavaDoc(JAR + base + SEP + path);
79         }
80     }
81
82 }
83
Popular Tags