KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > classloader > LoaderManagerImpl


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 Fossil E-Commerce, http://www.fossilec.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: LoaderManagerImpl.java 292 2006-05-02 07:30:43Z ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.classloader;
23
24 import java.io.IOException JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.net.URLClassLoader JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.objectweb.petals.PetalsException;
30
31 /**
32  * @version $Rev: 292 $ $Date: 2006-05-02 07:30:43Z $
33  * @since Petals 1.0
34  * @author <a HREF="mailto:rmarins@fossilec.com">Rafael Marins</a>, Adrien
35  * LOUIS
36  */

37 public class LoaderManagerImpl implements LoaderManager {
38
39     /**
40      * Default constructor.
41      */

42     public LoaderManagerImpl() {
43         super();
44     }
45
46     // ----------------------------------------------------------------------
47
// ClassLoadingService interface implementation
48
// ----------------------------------------------------------------------
49

50     /**
51      * Create a classLoader for a JBI Component. The parent classLoader will be
52      * the SharedLibrariesClassLoader.
53      *
54      * @see org.objectweb.petals.classloader.LoaderManager#createClassLoader(java.net.URL[],
55      * boolean)
56      */

57     public URLClassLoader JavaDoc createClassLoader(URL JavaDoc[] baseUrls, List JavaDoc<String JavaDoc> classpathLocations, boolean useParentFirst) throws PetalsException {
58
59         // create the class loader
60
PetalsClassLoader cl = null;
61
62         Loaders loaders = Loaders.getInstance();
63
64         try {
65             cl = new PetalsClassLoader(baseUrls, classpathLocations, loaders.getSharedLibrariesClassLoader());
66
67             cl.setParentFirst(useParentFirst);
68         }
69         catch (IOException JavaDoc e) {
70             throw new PetalsException("Error while creating a class loader", e);
71         }
72         return cl;
73     }
74
75     /**
76      * Remove classLoader from the list. If the classLoader is a ClassLoader for
77      * sharedLibraries, remove it from the SharedLibrariesClassLoader
78      *
79      * @see org.objectweb.petals.classloader.LoaderManager#deleteClassLoader(java.lang.String)
80      */

81     public void deleteClassLoader(String JavaDoc classLoaderId) {
82
83         Loaders loaders = Loaders.getInstance();
84
85         if (!containsClassLoader(classLoaderId)) {
86             return;
87         }
88
89         // delete class loader for further retrieve
90
loaders.remove(classLoaderId);
91         loaders.getSharedLibrariesClassLoader().removeSharedLibrariesClassLoader(classLoaderId);
92     }
93
94     /**
95      * @see org.objectweb.petals.classloader.LoaderManager#containsClassLoader(java.lang.String)
96      */

97     public boolean containsClassLoader(String JavaDoc classLoaderId) {
98
99         Loaders loaders = Loaders.getInstance();
100
101         return loaders.contains(classLoaderId);
102     }
103
104     /**
105      * @see org.objectweb.petals.classloader.LoaderManager#createClassLoader(java.lang.String,
106      * java.net.URL[], boolean)
107      */

108     public URLClassLoader JavaDoc createComponentClassLoader(String JavaDoc classLoaderId, URL JavaDoc[] baseUrls, List JavaDoc<String JavaDoc> classpathUrls, boolean useParentFirst, List JavaDoc<String JavaDoc> sharedLibrariesNameList)
109             throws PetalsException {
110
111         // create the class loader
112
PetalsClassLoader cl = null;
113
114         Loaders loaders = Loaders.getInstance();
115
116         try {
117             cl = new ComponentClassLoader(baseUrls, classpathUrls, loaders.getSharedLibrariesClassLoader(), sharedLibrariesNameList);
118
119             cl.setParentFirst(useParentFirst);
120         }
121         catch (IOException JavaDoc e) {
122             throw new PetalsException("Error while creating a class loader", e);
123         }
124
125         // save for further retrieve (overwrite existing class loader)
126
loaders.put(classLoaderId, cl);
127
128         return cl;
129     }
130
131     /**
132      * Create a classloader for a sharedLibrary. This classLoader will be added
133      * to the SharedLibrariesClassLoader.
134      *
135      * @see org.objectweb.petals.classloader.LoaderManager#createClassLoader(java.lang.String,
136      * java.net.URL[], boolean)
137      */

138     public URLClassLoader JavaDoc createSharedLibrariesClassLoader(String JavaDoc classLoaderId, URL JavaDoc[] baseUrls, List JavaDoc<String JavaDoc> classpathUrls, boolean useParentFirst) throws PetalsException {
139
140         // create the class loader
141
PetalsClassLoader cl = null;
142
143         try {
144             cl = new PetalsClassLoader(baseUrls, classpathUrls);
145             cl.setParentFirst(useParentFirst);
146         }
147         catch (IOException JavaDoc e) {
148             throw new PetalsException("Error while creating a class loader", e);
149         }
150
151         // save for further retrieve (overwrite existing class loader)
152
Loaders loaders = Loaders.getInstance();
153
154         loaders.put(classLoaderId, cl);
155         loaders.getSharedLibrariesClassLoader().addSharedLibrariesClassLoader(classLoaderId, cl);
156
157         return cl;
158     }
159
160 }
161
Popular Tags