javaclass

java/lang/__init__.py

158:a52e70c3f294
2005-01-23 Paul Boddie Added "safety measures" for exception offset insertion, although better measures are necessary to avoid bizarre JDK 1.4 exception tables.
     1 #!/usr/bin/env python     2      3 import os     4 import sys     5 from java.lang._object import *     6 import java.io     7      8 class Character(Object):     9     def __init__(self, value):    10         raise NotImplementedError, "__init__"    11     12     def charValue(self):    13         raise NotImplementedError, "charValue"    14     charValue___ = charValue    15     16     def hashCode(self):    17         raise NotImplementedError, "hashCode"    18     hashCode___ = hashCode    19     20     def equals(self, anObject):    21         raise NotImplementedError, "equals"    22     equals___java__lang__Object = equals    23     24     def toString(self):    25         raise NotImplementedError, "toString"    26     toString___ = toString    27     28     def isLowerCase(self, ch):    29         raise NotImplementedError, "isLowerCase"    30     isLowerCase____C_ = staticmethod(isLowerCase)    31     32     def isUpperCase(self, ch):    33         raise NotImplementedError, "isUpperCase"    34     isUpperCase____C_ = staticmethod(isUpperCase)    35     36     def isTitleCase(self, ch):    37         raise NotImplementedError, "isTitleCase"    38     isTitleCase____C_ = staticmethod(isTitleCase)    39     40     def isDigit(self, ch):    41         raise NotImplementedError, "isDigit"    42     isDigit____C_ = staticmethod(isDigit)    43     44     def isDefined(self, ch):    45         raise NotImplementedError, "isDefined"    46     isDefined____C_ = staticmethod(isDefined)    47     48     def isLetter(self, ch):    49         raise NotImplementedError, "isLetter"    50     isLetter____C_ = staticmethod(isLetter)    51     52     def isLetterOrDigit(self, ch):    53         raise NotImplementedError, "isLetterOrDigit"    54     isLetterOrDigit____C_ = staticmethod(isLetterOrDigit)    55     56     def isJavaLetter(self, ch):    57         raise NotImplementedError, "isJavaLetter"    58     isJavaLetter____C_ = staticmethod(isJavaLetter)    59     60     def isJavaLetterOrDigit(self, ch):    61         raise NotImplementedError, "isJavaLetterOrDigit"    62     isJavaLetterOrDigit____C_ = staticmethod(isJavaLetterOrDigit)    63     64     def isJavaIdentifierStart(self, ch):    65         raise NotImplementedError, "isJavaIdentifierStart"    66     isJavaIdentifierStart____C_ = staticmethod(isJavaIdentifierStart)    67     68     def isJavaIdentifierPart(self, ch):    69         raise NotImplementedError, "isJavaIdentifierPart"    70     isJavaIdentifierPart____C_ = staticmethod(isJavaIdentifierPart)    71     72     def isUnicodeIdentifierStart(self, ch):    73         raise NotImplementedError, "isUnicodeIdentifierStart"    74     isUnicodeIdentifierStart____C_ = staticmethod(isUnicodeIdentifierStart)    75     76     def isUnicodeIdentifierPart(self, ch):    77         raise NotImplementedError, "isUnicodeIdentifierPart"    78     isUnicodeIdentifierPart____C_ = staticmethod(isUnicodeIdentifierPart)    79     80     def isIdentifierIgnorable(self, ch):    81         raise NotImplementedError, "isIdentifierIgnorable"    82     isIdentifierIgnorable____C_ = staticmethod(isIdentifierIgnorable)    83     84     def toLowerCase(self, ch):    85         raise NotImplementedError, "toLowerCase"    86     toLowerCase____C_ = staticmethod(toLowerCase)    87     88     def toUpperCase(self, ch):    89         raise NotImplementedError, "toUpperCase"    90     toUpperCase____C_ = staticmethod(toUpperCase)    91     92     def toTitleCase(self, ch):    93         raise NotImplementedError, "toTitleCase"    94     toTitleCase____C_ = staticmethod(toTitleCase)    95     96     def digit(self, ch, radix):    97         raise NotImplementedError, "digit"    98     digit____C_____I_ = staticmethod(digit)    99    100     def getNumericValue(self, ch):   101         raise NotImplementedError, "getNumericValue"   102     getNumericValue____C_ = staticmethod(getNumericValue)   103    104     def isSpace(self, ch):   105         raise NotImplementedError, "isSpace"   106     isSpace____C_ = staticmethod(isSpace)   107    108     def isSpaceChar(self, ch):   109         raise NotImplementedError, "isSpaceChar"   110     isSpaceChar____C_ = staticmethod(isSpaceChar)   111    112     def isWhitespace(self, ch):   113         raise NotImplementedError, "isWhitespace"   114     isWhitespace____C_ = staticmethod(isWhitespace)   115    116     def isISOControl(self, ch):   117         raise NotImplementedError, "isISOControl"   118     isISOControl____C_ = staticmethod(isISOControl)   119    120     def getType(self, ch):   121         raise NotImplementedError, "getType"   122     getType____C_ = staticmethod(getType)   123    124     def forDigit(self, ch, radix):   125         raise NotImplementedError, "forDigit"   126     forDigit____C_____I_ = staticmethod(forDigit)   127    128     def compareTo(self, *args):   129         # compareTo(self, anotherCharacter)   130         # compareTo(self, o)   131         raise NotImplementedError, "compareTo"   132     compareTo____C_ = compareTo   133     compareTo___java__lang__Object = compareTo   134    135 setattr(Character, "__init____C_", Character.__init__)   136    137 class Class(Object):   138     def forName(className):   139         parts = unicode(className).split(".")   140         obj = __import__(".".join(parts[:-1]), globals(), {}, [])   141         for part in parts[1:]:   142             obj = getattr(obj, part)   143         return obj   144    145     forName___java__lang__String = staticmethod(forName)   146     # NOTE: To be enhanced.   147     forName___java__lang__String____Z____java__lang__ClassLoader = staticmethod(forName)   148    149 class Integer(Object):   150     def init_int(self, i):   151         self.i = i   152    153     def init_String(self, s):   154         self.i = int(s.value)   155    156     def __init__(self, *args):   157         if len(args) == 1 and isinstance(args[0], int):   158             self.init_int(args[0])   159         elif len(args) == 1 and isinstance(args[0], String):   160             self.init_String(args[0])   161    162     def toString(self):   163         return String(str(self.i))   164     toString___ = toString   165    166 setattr(Integer, "__init______I_", Integer.init_int)   167 setattr(Integer, "__init_____java__lang__String", Integer.init_String)   168    169 class String(Object):   170    171     # NOTE: This method should not be needed, really.   172     def __str__(self):   173         return self.value.encode("utf-8")   174    175     def __unicode__(self):   176         return self.value   177    178     def init_empty(self):   179         "__init__(self)"   180         self.value = u""   181    182     def init_String(self, obj):   183         "__init__(self, original)"   184         self.value = obj.value   185    186         # __init__(self, value)   187         # __init__(self, value, offset, count)   188         # __init__(self, ascii, hibyte, offset, count)   189         # __init__(self, ascii, hibyte)   190         # __init__(self, bytes, offset, length, enc)   191         # __init__(self, bytes, enc)   192         # __init__(self, bytes, offset, length)   193         # __init__(self, bytes)   194         # __init__(self, buffer)   195    196     def __init__(self, *args):   197    198         "Python string initialisation only."   199    200         if len(args) == 0:   201             self.init_empty()   202         elif len(args) == 1 and isinstance(args[0], str):   203             self.value = unicode(args[0])   204         elif len(args) == 1 and isinstance(args[0], unicode):   205             self.value = args[0]   206         elif len(args) == 1 and isinstance(args[0], String):   207             self.init_String(args[0])   208    209     def length(self):   210         return len(self.value)   211     length___ = length   212    213     def charAt(self, index):   214         return ord(self.value[index])   215     charAt____I_ = charAt   216    217     def getChars(self, srcBegin, srcEnd, dst, dstBegin):   218         raise NotImplementedError, "getChars"   219     getChars____I_____I_____C__array_____I_ = getChars   220    221     def getBytes(self, *args):   222         # void getBytes(self, srcBegin, srcEnd, dst, dstBegin)   223         # byte[] getBytes(self, enc)   224         # byte[] getBytes(self)   225         raise NotImplementedError, "getBytes"   226     getBytes___ = getBytes   227     getBytes____I_____I_____B__array_____I_ = getBytes   228    229     def equals(self, anObject):   230         return isinstance(anObject, self.__class__) and self.value == anObject.value   231     equals___java__lang__Object = equals   232    233     def compareTo(self, obj):   234         if self.value < obj.value:   235             return -1   236         elif self.value == obj.value:   237             return 0   238         else:   239             return 1   240     compareTo___java__lang__String = compareTo   241    242     # NOTE: Comparator defined using private classes. This implementation just   243     # NOTE: uses Python's lower method.   244     def compareToIgnoreCase(self, str):   245         value = self.value.lower()   246         value2 = str.value.lower()   247         if value < value2:   248             return -1   249         elif value == value2:   250             return 0   251         else:   252             return 1   253     compareToIgnoreCase___java__lang__String = compareToIgnoreCase   254    255     # NOTE: Comparator defined using private classes. This implementation just   256     # NOTE: uses Python's lower method.   257     def equalsIgnoreCase(self, anotherString):   258         value = self.value.lower()   259         value2 = anotherString.value.lower()   260         return value == value2   261     equalsIgnoreCase___java__lang__String = equalsIgnoreCase   262    263     def regionMatches(self, *args):   264         # regionMatches(self, toffset, other, ooffset, len)   265         # regionMatches(self, ignoreCase, toffset, other, ooffset, len)   266         raise NotImplementedError, "regionMatches"   267    268     def startsWith(self, *args):   269         # startsWith(self, prefix, toffset)   270         # startsWith(self, prefix)   271         raise NotImplementedError, "startsWith"   272    273     def endsWith(self, suffix):   274         raise NotImplementedError, "endsWith"   275    276     def hashCode(self):   277         raise NotImplementedError, "hashCode"   278    279     def indexOf____I_(self, ch):   280         return self.value.find(chr(ch))   281    282     def indexOf____I_____I_(self, ch, fromIndex):   283         return self.value.find(chr(ch), fromIndex)   284    285     def indexOf___java__lang__String___(self, str):   286         return self.value.find(str.value)   287    288     def indexOf___java__lang__String____I_(self, str, fromIndex):   289         return self.value.find(str.value, fromIndex)   290    291     def lastIndexOf(self, *args):   292         # lastIndexOf(self, ch)   293         # lastIndexOf(self, ch, fromIndex)   294         # lastIndexOf(self, str)   295         # lastIndexOf(self, str, fromIndex)   296         raise NotImplementedError, "lastIndexOf"   297    298     def substring(self, *args):   299         # substring(self, beginIndex)   300         # substring(self, beginIndex, endIndex)   301         raise NotImplementedError, "substring"   302    303     def concat(self, str):   304         raise NotImplementedError, "concat"   305    306     def replace(self, oldChar, newChar):   307         raise NotImplementedError, "replace"   308    309     def toLowerCase(self, *args):   310         # toLowerCase(self, locale)   311         # toLowerCase(self)   312         raise NotImplementedError, "toLowerCase"   313    314     def toUpperCase(self, *args):   315         # toUpperCase(self, locale)   316         # toUpperCase(self)   317         raise NotImplementedError, "toUpperCase"   318    319     def trim(self):   320         raise NotImplementedError, "trim"   321    322     def toString(self):   323         return self   324    325     def toCharArray(self):   326         raise NotImplementedError, "toCharArray"   327    328     def valueOf(self, *args):   329         # valueOf(self, obj)   330         # valueOf(self, data)   331         # valueOf(self, data, offset, count)   332         # valueOf(self, b)   333         # valueOf(self, c)   334         # valueOf(self, l)   335         # valueOf(self, f)   336         # valueOf(self, d)   337         raise NotImplementedError, "valueOf"   338     valueOf = staticmethod(valueOf)   339    340     def copyValueOf(self, *args):   341         # copyValueOf(self, data, offset, count)   342         # copyValueOf(self, data)   343         raise NotImplementedError, "copyValueOf"   344     copyValueOf = staticmethod(copyValueOf)   345    346     def intern(self):   347         raise NotImplementedError, "intern"   348    349 setattr(String, "__init_____", String.init_empty)   350 setattr(String, "__init_____java__lang__String", String.init_String)   351    352 class StringBuffer(Object):   353    354     "Used when adding String objects."   355    356     def __unicode__(self):   357         return u"".join(self.buffer)   358    359     def __str__(self):   360         unicode(self).encode("utf-8")   361    362     def init_empty(self):   363         self.buffer = []   364    365     def init_int(self, length):   366         self.buffer = []   367    368     def init_String(self, s):   369         self.buffer = [unicode(s)]   370    371     def __init__(self, *args):   372         if len(args) == 0:   373             self.init_empty()   374         elif len(args) == 1 and isinstance(args[0], int):   375             self.init_int(args[0])   376         elif len(args) == 1 and isinstance(args[0], String):   377             self.init_String(args[0])   378    379     def append(self, s):   380         sb = StringBuffer(String(unicode(self) + unicode(s)))   381         return sb   382     append____Z_ = append   383     append____C_ = append   384     append____C__array_ = append   385     append____C__array_____I_____I_ = append   386     append____D_ = append   387     append____F_ = append   388     append____I_ = append   389     append____J_ = append   390     append___java__lang__Object = append   391     append___java__lang__String = append   392    393     def toString(self):   394         return String("".join(self.buffer))   395     toString___ = toString   396    397 setattr(StringBuffer, "__init_____", StringBuffer.init_empty)   398 setattr(StringBuffer, "__init______I_", StringBuffer.init_int)   399 setattr(StringBuffer, "__init_____java__lang__String", StringBuffer.init_String)   400    401 class System(Object):   402     # NOTE: Fix this - circular import nonsense!   403     in_ = java.io.InputStream(sys.stdin)   404     out = java.io.PrintStream(sys.stdout)   405     err = java.io.PrintStream(sys.stderr)   406    407     def getProperty___java__lang__String(key):   408         try:   409             return os.environ[key]   410         except KeyError:   411             return None   412    413     getProperty___java__lang__String = staticmethod(getProperty___java__lang__String)   414    415 setattr(System, "in", System.in_)   416    417 # vim: tabstop=4 expandtab shiftwidth=4