# HG changeset patch # User Paul Boddie # Date 1102984521 -3600 # Node ID ff7df6e579e99aaa87acb781c98013bfe04b15b3 # Parent 6837caf38a992d83e46e9398fcd0b91addfd6577 Fixed Class.forName, added some more exceptions and the start of the System class. diff -r 6837caf38a99 -r ff7df6e579e9 java/lang.py --- a/java/lang.py Tue Dec 14 01:34:44 2004 +0100 +++ b/java/lang.py Tue Dec 14 01:35:21 2004 +0100 @@ -1,5 +1,9 @@ #!/usr/bin/env python +import java.io +import os +import sys + class Character(object): def __init__(self, value): raise NotImplementedError, "__init__" @@ -132,9 +136,9 @@ class Class(object): def forName(className): parts = unicode(className).split(".") - obj = __import__(className, globals(), {}, []) + obj = __import__(".".join(parts[:-1]), globals(), {}, []) for part in parts[1:]: - obj = obj[part] + obj = getattr(obj, part) return obj forName___java__lang__String = staticmethod(forName) @@ -157,6 +161,13 @@ setattr(Exception, "__init_____", Exception.__init__) setattr(Exception, "__init_____java__lang__String", Exception.__init__) +class IndexOutOfBoundsException(object): + def __init__(self, *args): + self.args = args + +setattr(IndexOutOfBoundsException, "__init_____", IndexOutOfBoundsException.__init__) +setattr(IndexOutOfBoundsException, "__init_____java__lang__String", IndexOutOfBoundsException.__init__) + class IllegalArgumentException(Exception): def __init__(self, *args): self.args = args @@ -164,6 +175,13 @@ setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__) setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__) +class NullPointerException(object): + def __init__(self, *args): + self.args = args + +setattr(NullPointerException, "__init_____", NullPointerException.__init__) +setattr(NullPointerException, "__init_____java__lang__String", NullPointerException.__init__) + class SecurityException(Exception): def __init__(self, *args): self.args = args @@ -360,4 +378,19 @@ setattr(String, "__init_____", String.init__empty) setattr(String, "__init_____java__lang__String", String.init__String) +class System(object): + in_ = java.io.InputStream(sys.stdin) + out = java.io.PrintStream(sys.stdout) + err = java.io.PrintStream(sys.stderr) + + def getProperty___java__lang__String(key): + try: + return os.environ[key] + except KeyError: + return None + + getProperty___java__lang__String = staticmethod(getProperty___java__lang__String) + +setattr(System, "in", System.in_) + # vim: tabstop=4 expandtab shiftwidth=4