This repository has been archived by the owner on Nov 17, 2017. It is now read-only.
/
CdkClassLoader.java
85 lines (73 loc) · 2.32 KB
/
CdkClassLoader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* $Id$
*
* License Agreement.
*
* Rich Faces - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.richfaces.cdk;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* <p class="changed_added_4_0">
* </p>
*
* @author asmirnov@exadel.com
*/
public class CdkClassLoader extends URLClassLoader {
private static final URL[] EMPTY_URLS = {};
private Iterable<File> files;
public CdkClassLoader(Iterable<File> files) throws MalformedURLException {
super(EMPTY_URLS);
addFiles(files);
}
public CdkClassLoader(Iterable<File> files, ClassLoader parent) throws MalformedURLException {
super(EMPTY_URLS, parent);
addFiles(files);
}
public CdkClassLoader(ClassLoader classLoader) {
super(EMPTY_URLS, classLoader);
}
/**
* <p class="changed_added_4_0"></p>
*
* @return the files
*/
public Iterable<File> getFiles() {
return this.files;
}
private void addFileNames(Iterable<String> files) throws MalformedURLException {
Set<File> filesSet = Sets.newHashSet();
for (String name : files) {
File file = new File(name);
filesSet.add(file);
}
addFiles(filesSet);
}
private void addFiles(Iterable<File> filesSet) throws MalformedURLException {
this.files = ImmutableSet.copyOf(filesSet);
for (File file : filesSet) {
addURL(file.toURI().toURL());
}
}
}