KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > mobilitools > smi > lib > URLClassLoaderAdapter


1 /*
2 * MobiliTools: an implementation of the Object Management Group's
3 * Mobile Agent Facility specification.
4 * Copyright (C) 2003 France Telecom R&D
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 of the License, or (at your option) 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 USA
19 *
20 * MobiliTools $Name: $
21 *
22 * Contact: mobilitools-smi@lists.debian-sf.objectweb.org
23 *
24 * Authors: Bruno Dillenseger
25 */

26
27
28 package org.objectweb.mobilitools.smi.lib;
29
30
31 import org.omg.CfMAF.AgentProfile;
32 import org.omg.CfMAF.MAFAgentSystem;
33 import java.net.MalformedURLException JavaDoc;
34 import java.net.URLClassLoader JavaDoc;
35 import java.net.URL JavaDoc;
36 import java.util.Hashtable JavaDoc;
37 import org.objectweb.mobilitools.smi.Misc;
38
39
40 /**
41  * MobiliTools $Name: $, $Id: URLClassLoaderAdapter.java,v 1.1.1.1 2003/03/28 14:48:06 dillense Exp $
42  * <P>
43  * Classloader factory providing URL classloaders.
44  */

45 abstract public class URLClassLoaderAdapter
46 {
47     static Hashtable JavaDoc loaders = new Hashtable JavaDoc();
48
49
50     /**
51      * Creates and a new URLClassLoader instance for the given codebase,
52      * if and and only if it does not already exist. Otherwise, the existing
53      * instance for the given codebase is re-used.
54      * @param parent parent classloader
55      * @param codebase codebase represented by URL strings separated with blanks
56      * @param profile ignored
57      * @param provider ignored
58      * @return the URLClassLoader for the given codebase
59      */

60     static public ClassLoader JavaDoc getClassLoader(
61         ClassLoader JavaDoc parent,
62         String JavaDoc codebase,
63         AgentProfile profile,
64         MAFAgentSystem provider)
65     throws MalformedURLException JavaDoc
66     {
67         Object JavaDoc loader = loaders.get(codebase);
68         if (loader == null)
69         {
70             loader = URLClassLoader.newInstance(
71                 Misc.codebase2URLs(codebase),
72                 parent);
73             loaders.put(codebase, loader);
74         }
75         return (ClassLoader JavaDoc)loader;
76     }
77 }
78
Popular Tags