javaclass

Changeset

89:ff7df6e579e9
2004-12-14 Paul Boddie raw files shortlog changelog graph Fixed Class.forName, added some more exceptions and the start of the System class.
java/lang.py (file)
     1.1 --- a/java/lang.py	Tue Dec 14 01:34:44 2004 +0100
     1.2 +++ b/java/lang.py	Tue Dec 14 01:35:21 2004 +0100
     1.3 @@ -1,5 +1,9 @@
     1.4  #!/usr/bin/env python
     1.5  
     1.6 +import java.io
     1.7 +import os
     1.8 +import sys
     1.9 +
    1.10  class Character(object):
    1.11      def __init__(self, value):
    1.12          raise NotImplementedError, "__init__"
    1.13 @@ -132,9 +136,9 @@
    1.14  class Class(object):
    1.15      def forName(className):
    1.16          parts = unicode(className).split(".")
    1.17 -        obj = __import__(className, globals(), {}, [])
    1.18 +        obj = __import__(".".join(parts[:-1]), globals(), {}, [])
    1.19          for part in parts[1:]:
    1.20 -            obj = obj[part]
    1.21 +            obj = getattr(obj, part)
    1.22          return obj
    1.23  
    1.24      forName___java__lang__String = staticmethod(forName)
    1.25 @@ -157,6 +161,13 @@
    1.26  setattr(Exception, "__init_____", Exception.__init__)
    1.27  setattr(Exception, "__init_____java__lang__String", Exception.__init__)
    1.28  
    1.29 +class IndexOutOfBoundsException(object):
    1.30 +    def __init__(self, *args):
    1.31 +        self.args = args
    1.32 +
    1.33 +setattr(IndexOutOfBoundsException, "__init_____", IndexOutOfBoundsException.__init__)
    1.34 +setattr(IndexOutOfBoundsException, "__init_____java__lang__String", IndexOutOfBoundsException.__init__)
    1.35 +
    1.36  class IllegalArgumentException(Exception):
    1.37      def __init__(self, *args):
    1.38          self.args = args
    1.39 @@ -164,6 +175,13 @@
    1.40  setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__)
    1.41  setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__)
    1.42  
    1.43 +class NullPointerException(object):
    1.44 +    def __init__(self, *args):
    1.45 +        self.args = args
    1.46 +
    1.47 +setattr(NullPointerException, "__init_____", NullPointerException.__init__)
    1.48 +setattr(NullPointerException, "__init_____java__lang__String", NullPointerException.__init__)
    1.49 +
    1.50  class SecurityException(Exception):
    1.51      def __init__(self, *args):
    1.52          self.args = args
    1.53 @@ -360,4 +378,19 @@
    1.54  setattr(String, "__init_____", String.init__empty)
    1.55  setattr(String, "__init_____java__lang__String", String.init__String)
    1.56  
    1.57 +class System(object):
    1.58 +    in_ = java.io.InputStream(sys.stdin)
    1.59 +    out = java.io.PrintStream(sys.stdout)
    1.60 +    err = java.io.PrintStream(sys.stderr)
    1.61 +
    1.62 +    def getProperty___java__lang__String(key):
    1.63 +        try:
    1.64 +            return os.environ[key]
    1.65 +        except KeyError:
    1.66 +            return None
    1.67 +
    1.68 +    getProperty___java__lang__String = staticmethod(getProperty___java__lang__String)
    1.69 +
    1.70 +setattr(System, "in", System.in_)
    1.71 +
    1.72  # vim: tabstop=4 expandtab shiftwidth=4