javaclass

Changeset

113:0b546623231e
2005-01-10 Paul Boddie raw files shortlog changelog graph Moved the lang module contents into the lang package. Fixed various java.lang and java.io circular imports by introducing a java.lang._object module. Corrected various base classes (object -> java.lang.Object, Exception -> java.lang.Exception) and fixed raising of exceptions in certain cases. Added reflection capabilities.
java/lang/__init__.py (file) java/lang/_object.py (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/lang/__init__.py	Mon Jan 10 23:52:44 2005 +0100
     1.3 @@ -0,0 +1,354 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +import os
     1.7 +import sys
     1.8 +from java.lang._object import *
     1.9 +import java.io
    1.10 +
    1.11 +class Character(Object):
    1.12 +    def __init__(self, value):
    1.13 +        raise NotImplementedError, "__init__"
    1.14 +
    1.15 +    def charValue(self):
    1.16 +        raise NotImplementedError, "charValue"
    1.17 +    charValue___ = charValue
    1.18 +
    1.19 +    def hashCode(self):
    1.20 +        raise NotImplementedError, "hashCode"
    1.21 +    hashCode___ = hashCode
    1.22 +
    1.23 +    def equals(self, anObject):
    1.24 +        raise NotImplementedError, "equals"
    1.25 +    equals___java__lang__Object = equals
    1.26 +
    1.27 +    def toString(self):
    1.28 +        raise NotImplementedError, "toString"
    1.29 +    toString___ = toString
    1.30 +
    1.31 +    def isLowerCase(self, ch):
    1.32 +        raise NotImplementedError, "isLowerCase"
    1.33 +    isLowerCase____C_ = staticmethod(isLowerCase)
    1.34 +
    1.35 +    def isUpperCase(self, ch):
    1.36 +        raise NotImplementedError, "isUpperCase"
    1.37 +    isUpperCase____C_ = staticmethod(isUpperCase)
    1.38 +
    1.39 +    def isTitleCase(self, ch):
    1.40 +        raise NotImplementedError, "isTitleCase"
    1.41 +    isTitleCase____C_ = staticmethod(isTitleCase)
    1.42 +
    1.43 +    def isDigit(self, ch):
    1.44 +        raise NotImplementedError, "isDigit"
    1.45 +    isDigit____C_ = staticmethod(isDigit)
    1.46 +
    1.47 +    def isDefined(self, ch):
    1.48 +        raise NotImplementedError, "isDefined"
    1.49 +    isDefined____C_ = staticmethod(isDefined)
    1.50 +
    1.51 +    def isLetter(self, ch):
    1.52 +        raise NotImplementedError, "isLetter"
    1.53 +    isLetter____C_ = staticmethod(isLetter)
    1.54 +
    1.55 +    def isLetterOrDigit(self, ch):
    1.56 +        raise NotImplementedError, "isLetterOrDigit"
    1.57 +    isLetterOrDigit____C_ = staticmethod(isLetterOrDigit)
    1.58 +
    1.59 +    def isJavaLetter(self, ch):
    1.60 +        raise NotImplementedError, "isJavaLetter"
    1.61 +    isJavaLetter____C_ = staticmethod(isJavaLetter)
    1.62 +
    1.63 +    def isJavaLetterOrDigit(self, ch):
    1.64 +        raise NotImplementedError, "isJavaLetterOrDigit"
    1.65 +    isJavaLetterOrDigit____C_ = staticmethod(isJavaLetterOrDigit)
    1.66 +
    1.67 +    def isJavaIdentifierStart(self, ch):
    1.68 +        raise NotImplementedError, "isJavaIdentifierStart"
    1.69 +    isJavaIdentifierStart____C_ = staticmethod(isJavaIdentifierStart)
    1.70 +
    1.71 +    def isJavaIdentifierPart(self, ch):
    1.72 +        raise NotImplementedError, "isJavaIdentifierPart"
    1.73 +    isJavaIdentifierPart____C_ = staticmethod(isJavaIdentifierPart)
    1.74 +
    1.75 +    def isUnicodeIdentifierStart(self, ch):
    1.76 +        raise NotImplementedError, "isUnicodeIdentifierStart"
    1.77 +    isUnicodeIdentifierStart____C_ = staticmethod(isUnicodeIdentifierStart)
    1.78 +
    1.79 +    def isUnicodeIdentifierPart(self, ch):
    1.80 +        raise NotImplementedError, "isUnicodeIdentifierPart"
    1.81 +    isUnicodeIdentifierPart____C_ = staticmethod(isUnicodeIdentifierPart)
    1.82 +
    1.83 +    def isIdentifierIgnorable(self, ch):
    1.84 +        raise NotImplementedError, "isIdentifierIgnorable"
    1.85 +    isIdentifierIgnorable____C_ = staticmethod(isIdentifierIgnorable)
    1.86 +
    1.87 +    def toLowerCase(self, ch):
    1.88 +        raise NotImplementedError, "toLowerCase"
    1.89 +    toLowerCase____C_ = staticmethod(toLowerCase)
    1.90 +
    1.91 +    def toUpperCase(self, ch):
    1.92 +        raise NotImplementedError, "toUpperCase"
    1.93 +    toUpperCase____C_ = staticmethod(toUpperCase)
    1.94 +
    1.95 +    def toTitleCase(self, ch):
    1.96 +        raise NotImplementedError, "toTitleCase"
    1.97 +    toTitleCase____C_ = staticmethod(toTitleCase)
    1.98 +
    1.99 +    def digit(self, ch, radix):
   1.100 +        raise NotImplementedError, "digit"
   1.101 +    digit____C_____I_ = staticmethod(digit)
   1.102 +
   1.103 +    def getNumericValue(self, ch):
   1.104 +        raise NotImplementedError, "getNumericValue"
   1.105 +    getNumericValue____C_ = staticmethod(getNumericValue)
   1.106 +
   1.107 +    def isSpace(self, ch):
   1.108 +        raise NotImplementedError, "isSpace"
   1.109 +    isSpace____C_ = staticmethod(isSpace)
   1.110 +
   1.111 +    def isSpaceChar(self, ch):
   1.112 +        raise NotImplementedError, "isSpaceChar"
   1.113 +    isSpaceChar____C_ = staticmethod(isSpaceChar)
   1.114 +
   1.115 +    def isWhitespace(self, ch):
   1.116 +        raise NotImplementedError, "isWhitespace"
   1.117 +    isWhitespace____C_ = staticmethod(isWhitespace)
   1.118 +
   1.119 +    def isISOControl(self, ch):
   1.120 +        raise NotImplementedError, "isISOControl"
   1.121 +    isISOControl____C_ = staticmethod(isISOControl)
   1.122 +
   1.123 +    def getType(self, ch):
   1.124 +        raise NotImplementedError, "getType"
   1.125 +    getType____C_ = staticmethod(getType)
   1.126 +
   1.127 +    def forDigit(self, ch, radix):
   1.128 +        raise NotImplementedError, "forDigit"
   1.129 +    forDigit____C_____I_ = staticmethod(forDigit)
   1.130 +
   1.131 +    def compareTo(self, *args):
   1.132 +        # compareTo(self, anotherCharacter)
   1.133 +        # compareTo(self, o)
   1.134 +        raise NotImplementedError, "compareTo"
   1.135 +    compareTo____C_ = compareTo
   1.136 +    compareTo___java__lang__Object = compareTo
   1.137 +
   1.138 +setattr(Character, "__init____C_", Character.__init__)
   1.139 +
   1.140 +class Class(Object):
   1.141 +    def forName(className):
   1.142 +        parts = unicode(className).split(".")
   1.143 +        obj = __import__(".".join(parts[:-1]), globals(), {}, [])
   1.144 +        for part in parts[1:]:
   1.145 +            obj = getattr(obj, part)
   1.146 +        return obj
   1.147 +
   1.148 +    forName___java__lang__String = staticmethod(forName)
   1.149 +    # NOTE: To be enhanced.
   1.150 +    forName___java__lang__String____Z____java__lang__ClassLoader = staticmethod(forName)
   1.151 +
   1.152 +class String(Object):
   1.153 +
   1.154 +    # NOTE: This method should not be needed, really.
   1.155 +    def __str__(self):
   1.156 +        return self.value.encode("utf-8")
   1.157 +
   1.158 +    def __unicode__(self):
   1.159 +        return self.value
   1.160 +
   1.161 +    def init__empty(self):
   1.162 +        self.value = u""
   1.163 +
   1.164 +    def init__String(self, obj):
   1.165 +        self.value = obj.value
   1.166 +
   1.167 +    def __init__(self, *args):
   1.168 +
   1.169 +        "Python string initialisation only."
   1.170 +
   1.171 +        if len(args) == 1 and isinstance(args[0], str):
   1.172 +            self.value = unicode(args[0])
   1.173 +            return
   1.174 +        elif len(args) == 1 and isinstance(args[0], unicode):
   1.175 +            self.value = args[0]
   1.176 +            return
   1.177 +        # __init__(self)
   1.178 +        elif len(args) == 0:
   1.179 +            self.__init__empty()
   1.180 +            return
   1.181 +        # __init__(self, original)
   1.182 +        elif len(args) == 1 and isinstance(args[0], String):
   1.183 +            self.init__String(args[0])
   1.184 +            return
   1.185 +        # __init__(self, value)
   1.186 +        # __init__(self, value, offset, count)
   1.187 +        # __init__(self, ascii, hibyte, offset, count)
   1.188 +        # __init__(self, ascii, hibyte)
   1.189 +        # __init__(self, bytes, offset, length, enc)
   1.190 +        # __init__(self, bytes, enc)
   1.191 +        # __init__(self, bytes, offset, length)
   1.192 +        # __init__(self, bytes)
   1.193 +        elif len(args) >= 1 and isinstance(args[0], list):
   1.194 +            raise NotImplementedError, "__init__"
   1.195 +        # __init__(self, buffer)
   1.196 +        raise NotImplementedError, "__init__"
   1.197 +
   1.198 +    def length(self):
   1.199 +        return len(self.value)
   1.200 +    length___ = length
   1.201 +
   1.202 +    def charAt(self, index):
   1.203 +        return ord(self.value[index])
   1.204 +    charAt____I_ = charAt
   1.205 +
   1.206 +    def getChars(self, srcBegin, srcEnd, dst, dstBegin):
   1.207 +        raise NotImplementedError, "getChars"
   1.208 +    getChars____I_____I_____C__array_____I_ = getChars
   1.209 +
   1.210 +    def getBytes(self, *args):
   1.211 +        # void getBytes(self, srcBegin, srcEnd, dst, dstBegin)
   1.212 +        # byte[] getBytes(self, enc)
   1.213 +        # byte[] getBytes(self)
   1.214 +        raise NotImplementedError, "getBytes"
   1.215 +    getBytes___ = getBytes
   1.216 +    getBytes____I_____I_____B__array_____I_ = getBytes
   1.217 +
   1.218 +    def equals(self, anObject):
   1.219 +        return isinstance(anObject, self.__class__) and self.value == anObject.value
   1.220 +    equals___java__lang__Object = equals
   1.221 +
   1.222 +    def compareTo(self, obj):
   1.223 +        if self.value < obj.value:
   1.224 +            return -1
   1.225 +        elif self.value == obj.value:
   1.226 +            return 0
   1.227 +        else:
   1.228 +            return 1
   1.229 +    compareTo___java__lang__String = compareTo
   1.230 +
   1.231 +    # NOTE: Comparator defined using private classes. This implementation just
   1.232 +    # NOTE: uses Python's lower method.
   1.233 +    def compareToIgnoreCase(self, str):
   1.234 +        value = self.value.lower()
   1.235 +        value2 = str.value.lower()
   1.236 +        if value < value2:
   1.237 +            return -1
   1.238 +        elif value == value2:
   1.239 +            return 0
   1.240 +        else:
   1.241 +            return 1
   1.242 +    compareToIgnoreCase___java__lang__String = compareToIgnoreCase
   1.243 +
   1.244 +    # NOTE: Comparator defined using private classes. This implementation just
   1.245 +    # NOTE: uses Python's lower method.
   1.246 +    def equalsIgnoreCase(self, anotherString):
   1.247 +        value = self.value.lower()
   1.248 +        value2 = anotherString.value.lower()
   1.249 +        return value == value2
   1.250 +    equalsIgnoreCase___java__lang__String = equalsIgnoreCase
   1.251 +
   1.252 +    def regionMatches(self, *args):
   1.253 +        # regionMatches(self, toffset, other, ooffset, len)
   1.254 +        # regionMatches(self, ignoreCase, toffset, other, ooffset, len)
   1.255 +        raise NotImplementedError, "regionMatches"
   1.256 +
   1.257 +    def startsWith(self, *args):
   1.258 +        # startsWith(self, prefix, toffset)
   1.259 +        # startsWith(self, prefix)
   1.260 +        raise NotImplementedError, "startsWith"
   1.261 +
   1.262 +    def endsWith(self, suffix):
   1.263 +        raise NotImplementedError, "endsWith"
   1.264 +
   1.265 +    def hashCode(self):
   1.266 +        raise NotImplementedError, "hashCode"
   1.267 +
   1.268 +    def indexOf____I_(self, ch):
   1.269 +        return self.value.find(chr(ch))
   1.270 +
   1.271 +    def indexOf____I_____I_(self, ch, fromIndex):
   1.272 +        return self.value.find(chr(ch), fromIndex)
   1.273 +
   1.274 +    def indexOf___java__lang__String___(self, str):
   1.275 +        return self.value.find(str.value)
   1.276 +
   1.277 +    def indexOf___java__lang__String____I_(self, str, fromIndex):
   1.278 +        return self.value.find(str.value, fromIndex)
   1.279 +
   1.280 +    def lastIndexOf(self, *args):
   1.281 +        # lastIndexOf(self, ch)
   1.282 +        # lastIndexOf(self, ch, fromIndex)
   1.283 +        # lastIndexOf(self, str)
   1.284 +        # lastIndexOf(self, str, fromIndex)
   1.285 +        raise NotImplementedError, "lastIndexOf"
   1.286 +
   1.287 +    def substring(self, *args):
   1.288 +        # substring(self, beginIndex)
   1.289 +        # substring(self, beginIndex, endIndex)
   1.290 +        raise NotImplementedError, "substring"
   1.291 +
   1.292 +    def concat(self, str):
   1.293 +        raise NotImplementedError, "concat"
   1.294 +
   1.295 +    def replace(self, oldChar, newChar):
   1.296 +        raise NotImplementedError, "replace"
   1.297 +
   1.298 +    def toLowerCase(self, *args):
   1.299 +        # toLowerCase(self, locale)
   1.300 +        # toLowerCase(self)
   1.301 +        raise NotImplementedError, "toLowerCase"
   1.302 +
   1.303 +    def toUpperCase(self, *args):
   1.304 +        # toUpperCase(self, locale)
   1.305 +        # toUpperCase(self)
   1.306 +        raise NotImplementedError, "toUpperCase"
   1.307 +
   1.308 +    def trim(self):
   1.309 +        raise NotImplementedError, "trim"
   1.310 +
   1.311 +    def toString(self):
   1.312 +        return self
   1.313 +
   1.314 +    def toCharArray(self):
   1.315 +        raise NotImplementedError, "toCharArray"
   1.316 +
   1.317 +    def valueOf(self, *args):
   1.318 +        # valueOf(self, obj)
   1.319 +        # valueOf(self, data)
   1.320 +        # valueOf(self, data, offset, count)
   1.321 +        # valueOf(self, b)
   1.322 +        # valueOf(self, c)
   1.323 +        # valueOf(self, l)
   1.324 +        # valueOf(self, f)
   1.325 +        # valueOf(self, d)
   1.326 +        raise NotImplementedError, "valueOf"
   1.327 +    valueOf = staticmethod(valueOf)
   1.328 +
   1.329 +    def copyValueOf(self, *args):
   1.330 +        # copyValueOf(self, data, offset, count)
   1.331 +        # copyValueOf(self, data)
   1.332 +        raise NotImplementedError, "copyValueOf"
   1.333 +    copyValueOf = staticmethod(copyValueOf)
   1.334 +
   1.335 +    def intern(self):
   1.336 +        raise NotImplementedError, "intern"
   1.337 +
   1.338 +setattr(String, "__init_____", String.init__empty)
   1.339 +setattr(String, "__init_____java__lang__String", String.init__String)
   1.340 +
   1.341 +class System(Object):
   1.342 +    # NOTE: Fix this - circular import nonsense!
   1.343 +    in_ = java.io.InputStream(sys.stdin)
   1.344 +    out = java.io.PrintStream(sys.stdout)
   1.345 +    err = java.io.PrintStream(sys.stderr)
   1.346 +
   1.347 +    def getProperty___java__lang__String(key):
   1.348 +        try:
   1.349 +            return os.environ[key]
   1.350 +        except KeyError:
   1.351 +            return None
   1.352 +
   1.353 +    getProperty___java__lang__String = staticmethod(getProperty___java__lang__String)
   1.354 +
   1.355 +setattr(System, "in", System.in_)
   1.356 +
   1.357 +# vim: tabstop=4 expandtab shiftwidth=4
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/lang/_object.py	Mon Jan 10 23:52:44 2005 +0100
     2.3 @@ -0,0 +1,57 @@
     2.4 +#!/usr/bin/env python
     2.5 +
     2.6 +"Special module used to avoid circular imports."
     2.7 +
     2.8 +class Object(object):
     2.9 +    def getClass(self):
    2.10 +        import java.lang.reflect
    2.11 +        return java.lang.reflect.Class(self)
    2.12 +    getClass___ = getClass
    2.13 +
    2.14 +# NOTE: Establish a better exception hierarchy.
    2.15 +
    2.16 +class Error(Object):
    2.17 +    def __init__(self, *args):
    2.18 +        self.args = args
    2.19 +
    2.20 +setattr(Error, "__init_____", Error.__init__)
    2.21 +setattr(Error, "__init_____java__lang__String", Error.__init__)
    2.22 +
    2.23 +class Exception(Object):
    2.24 +    def __init__(self, *args):
    2.25 +        self.args = args
    2.26 +
    2.27 +setattr(Exception, "__init_____", Exception.__init__)
    2.28 +setattr(Exception, "__init_____java__lang__String", Exception.__init__)
    2.29 +
    2.30 +class IndexOutOfBoundsException(Exception):
    2.31 +    pass
    2.32 +
    2.33 +setattr(IndexOutOfBoundsException, "__init_____", IndexOutOfBoundsException.__init__)
    2.34 +setattr(IndexOutOfBoundsException, "__init_____java__lang__String", IndexOutOfBoundsException.__init__)
    2.35 +
    2.36 +class IllegalArgumentException(Exception):
    2.37 +    pass
    2.38 +
    2.39 +setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__)
    2.40 +setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__)
    2.41 +
    2.42 +class NoSuchMethodException(Exception):
    2.43 +    pass
    2.44 +
    2.45 +setattr(NoSuchMethodException, "__init_____", NoSuchMethodException.__init__)
    2.46 +setattr(NoSuchMethodException, "__init_____java__lang__String", NoSuchMethodException.__init__)
    2.47 +
    2.48 +class NullPointerException(Exception):
    2.49 +    pass
    2.50 +
    2.51 +setattr(NullPointerException, "__init_____", NullPointerException.__init__)
    2.52 +setattr(NullPointerException, "__init_____java__lang__String", NullPointerException.__init__)
    2.53 +
    2.54 +class SecurityException(Exception):
    2.55 +    pass
    2.56 +
    2.57 +setattr(SecurityException, "__init_____", SecurityException.__init__)
    2.58 +setattr(SecurityException, "__init_____java__lang__String", SecurityException.__init__)
    2.59 +
    2.60 +# vim: tabstop=4 expandtab shiftwidth=4