01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ClasspathComponents.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: import com.uwyn.rife.tools.exceptions.*;
11:
12: import java.io.File;
13: import java.net.MalformedURLException;
14: import java.net.URL;
15: import java.util.ArrayList;
16:
17: class ClasspathComponents {
18: private ArrayList<URL> sClasspathComponents = null;
19:
20: ClasspathComponents() {
21: init();
22: }
23:
24: ArrayList<URL> getClasspathComponents() {
25: return sClasspathComponents;
26: }
27:
28: private void init() throws ClasspathUtilsErrorException {
29: String classpath = System.getProperty("java.class.path");
30: ArrayList<String> paths = StringUtils.split(classpath,
31: File.pathSeparator);
32:
33: ArrayList<URL> urls = new ArrayList<URL>();
34: File path_file = null;
35: URL path_url = null;
36: try {
37: for (String path : paths) {
38: path_file = new File(path);
39: path_url = path_file.toURL();
40: urls.add(path_url);
41: }
42: } catch (MalformedURLException e) {
43: throw new ClasspathUtilsErrorException(
44: "Unable to parse the class path '" + path_file
45: + "'.", e);
46: }
47:
48: sClasspathComponents = urls;
49: }
50: }
|