01: /*
02: * @(#)versionInfo.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 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.util;
10:
11: import pnuts.lang.*;
12: import java.lang.Package;
13: import java.io.*;
14:
15: /*
16: * function versionInfo(class|moduleName)
17: */
18: public class versionInfo extends PnutsFunction {
19:
20: public versionInfo() {
21: super ("versionInfo");
22: }
23:
24: public boolean defined(int narg) {
25: return (narg == 1);
26: }
27:
28: public Object exec(Object[] args, Context context) {
29: int nargs = args.length;
30: if (nargs != 1) {
31: undefined(args, context);
32: return null;
33: }
34: Object arg = args[0];
35: Class cls = null;
36: if (arg instanceof String) {
37: String name = (String) arg;
38: String cname = name.replace('/', '.').replace('-', '_');
39: try {
40: cls = Pnuts.loadClass(cname + ".init", context);
41: } catch (ClassNotFoundException e) {
42: return null;
43: }
44: } else if (arg instanceof Class) {
45: cls = (Class) arg;
46: } else {
47: return null;
48: }
49: return cls.getPackage();
50: }
51:
52: public String toString() {
53: return "function versionInfo(moduleName)";
54: }
55: }
|