01: /*
02: * @(#)getClassPath.java 1.1 05/05/19
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import java.net.URL;
12: import java.net.URLClassLoader;
13: import pnuts.lang.PnutsFunction;
14: import pnuts.lang.Context;
15:
16: public class getClassPath extends PnutsFunction {
17:
18: public getClassPath() {
19: super ("getClassPath");
20: }
21:
22: public boolean defined(int nargs) {
23: return nargs == 0;
24: }
25:
26: static URL[] getURLs(Context context) {
27: ClassLoader loader = context.getClassLoader();
28: if (loader == null) {
29: loader = Thread.currentThread().getContextClassLoader();
30: }
31: if (loader instanceof URLClassLoader) {
32: return ((URLClassLoader) loader).getURLs();
33: } else {
34: return null;
35: }
36: }
37:
38: protected Object exec(Object[] args, Context context) {
39: if (args.length != 0) {
40: undefined(args, context);
41: return null;
42: }
43: return getURLs(context);
44: }
45:
46: public String toString() {
47: return "function getClassPath()";
48: }
49: }
|