01: /*
02: * @(#)getLocalHost.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.lib;
10:
11: import pnuts.lang.Context;
12: import pnuts.lang.PnutsFunction;
13: import pnuts.lang.PnutsException;
14: import java.net.InetAddress;
15: import java.net.UnknownHostException;
16:
17: public class getLocalHost extends PnutsFunction {
18:
19: public getLocalHost() {
20: super ("getLocalHost");
21: }
22:
23: public boolean defined(int nargs) {
24: return nargs == 0;
25: }
26:
27: protected Object exec(Object[] args, Context context) {
28: if (args.length == 0) {
29: try {
30: return InetAddress.getLocalHost();
31: } catch (UnknownHostException e) {
32: throw new PnutsException(e, context);
33: }
34: } else {
35: undefined(args, context);
36: return null;
37: }
38: }
39:
40: public String toString() {
41: return "function getLocalHost()";
42: }
43: }
|