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 ClassLoader(Object): 150 pass 151 152 class Integer(Object): 153 def init_int(self, i): 154 self.i = i 155 156 def init_String(self, s): 157 self.i = int(s.value) 158 159 def __init__(self, *args): 160 if len(args) == 1 and isinstance(args[0], int): 161 self.init_int(args[0]) 162 elif len(args) == 1 and isinstance(args[0], String): 163 self.init_String(args[0]) 164 165 def toString(self): 166 return String(str(self.i)) 167 toString___ = toString 168 169 setattr(Integer, "__init______I_", Integer.init_int) 170 setattr(Integer, "__init_____java__lang__String", Integer.init_String) 171 172 class String(Object): 173 174 # NOTE: This method should not be needed, really. 175 def __str__(self): 176 return self.value.encode("utf-8") 177 178 def __unicode__(self): 179 return self.value 180 181 def init_empty(self): 182 "__init__(self)" 183 self.value = u"" 184 185 def init_String(self, obj): 186 "__init__(self, original)" 187 self.value = obj.value 188 189 # __init__(self, value) 190 # __init__(self, value, offset, count) 191 # __init__(self, ascii, hibyte, offset, count) 192 # __init__(self, ascii, hibyte) 193 # __init__(self, bytes, offset, length, enc) 194 # __init__(self, bytes, enc) 195 # __init__(self, bytes, offset, length) 196 # __init__(self, bytes) 197 # __init__(self, buffer) 198 199 def __init__(self, *args): 200 201 "Python string initialisation only." 202 203 if len(args) == 0: 204 self.init_empty() 205 elif len(args) == 1 and isinstance(args[0], str): 206 self.value = unicode(args[0]) 207 elif len(args) == 1 and isinstance(args[0], unicode): 208 self.value = args[0] 209 elif len(args) == 1 and isinstance(args[0], String): 210 self.init_String(args[0]) 211 212 def length(self): 213 return len(self.value) 214 length___ = length 215 216 def charAt(self, index): 217 return ord(self.value[index]) 218 charAt____I_ = charAt 219 220 def getChars(self, srcBegin, srcEnd, dst, dstBegin): 221 raise NotImplementedError, "getChars" 222 getChars____I_____I_____C__array_____I_ = getChars 223 224 def getBytes(self, *args): 225 # void getBytes(self, srcBegin, srcEnd, dst, dstBegin) 226 # byte[] getBytes(self, enc) 227 # byte[] getBytes(self) 228 raise NotImplementedError, "getBytes" 229 getBytes___ = getBytes 230 getBytes____I_____I_____B__array_____I_ = getBytes 231 232 def equals(self, anObject): 233 return isinstance(anObject, self.__class__) and self.value == anObject.value 234 equals___java__lang__Object = equals 235 236 def compareTo(self, obj): 237 if self.value < obj.value: 238 return -1 239 elif self.value == obj.value: 240 return 0 241 else: 242 return 1 243 compareTo___java__lang__String = compareTo 244 245 # NOTE: Comparator defined using private classes. This implementation just 246 # NOTE: uses Python's lower method. 247 def compareToIgnoreCase(self, str): 248 value = self.value.lower() 249 value2 = str.value.lower() 250 if value < value2: 251 return -1 252 elif value == value2: 253 return 0 254 else: 255 return 1 256 compareToIgnoreCase___java__lang__String = compareToIgnoreCase 257 258 # NOTE: Comparator defined using private classes. This implementation just 259 # NOTE: uses Python's lower method. 260 def equalsIgnoreCase(self, anotherString): 261 value = self.value.lower() 262 value2 = anotherString.value.lower() 263 return value == value2 264 equalsIgnoreCase___java__lang__String = equalsIgnoreCase 265 266 def regionMatches(self, *args): 267 # regionMatches(self, toffset, other, ooffset, len) 268 # regionMatches(self, ignoreCase, toffset, other, ooffset, len) 269 raise NotImplementedError, "regionMatches" 270 271 def startsWith(self, *args): 272 # startsWith(self, prefix, toffset) 273 # startsWith(self, prefix) 274 raise NotImplementedError, "startsWith" 275 276 def endsWith(self, suffix): 277 raise NotImplementedError, "endsWith" 278 279 def hashCode(self): 280 raise NotImplementedError, "hashCode" 281 282 def indexOf____I_(self, ch): 283 return self.value.find(chr(ch)) 284 285 def indexOf____I_____I_(self, ch, fromIndex): 286 return self.value.find(chr(ch), fromIndex) 287 288 def indexOf___java__lang__String___(self, str): 289 return self.value.find(str.value) 290 291 def indexOf___java__lang__String____I_(self, str, fromIndex): 292 return self.value.find(str.value, fromIndex) 293 294 def lastIndexOf(self, *args): 295 # lastIndexOf(self, ch) 296 # lastIndexOf(self, ch, fromIndex) 297 # lastIndexOf(self, str) 298 # lastIndexOf(self, str, fromIndex) 299 raise NotImplementedError, "lastIndexOf" 300 301 def substring(self, *args): 302 # substring(self, beginIndex) 303 # substring(self, beginIndex, endIndex) 304 raise NotImplementedError, "substring" 305 306 def concat(self, str): 307 raise NotImplementedError, "concat" 308 309 def replace(self, oldChar, newChar): 310 raise NotImplementedError, "replace" 311 312 def toLowerCase(self, *args): 313 # toLowerCase(self, locale) 314 # toLowerCase(self) 315 raise NotImplementedError, "toLowerCase" 316 317 def toUpperCase(self, *args): 318 # toUpperCase(self, locale) 319 # toUpperCase(self) 320 raise NotImplementedError, "toUpperCase" 321 322 def trim(self): 323 raise NotImplementedError, "trim" 324 325 def toString(self): 326 return self 327 328 def toCharArray(self): 329 raise NotImplementedError, "toCharArray" 330 331 def valueOf(self, *args): 332 # valueOf(self, obj) 333 # valueOf(self, data) 334 # valueOf(self, data, offset, count) 335 # valueOf(self, b) 336 # valueOf(self, c) 337 # valueOf(self, l) 338 # valueOf(self, f) 339 # valueOf(self, d) 340 raise NotImplementedError, "valueOf" 341 valueOf = staticmethod(valueOf) 342 343 def copyValueOf(self, *args): 344 # copyValueOf(self, data, offset, count) 345 # copyValueOf(self, data) 346 raise NotImplementedError, "copyValueOf" 347 copyValueOf = staticmethod(copyValueOf) 348 349 def intern(self): 350 raise NotImplementedError, "intern" 351 352 setattr(String, "__init_____", String.init_empty) 353 setattr(String, "__init_____java__lang__String", String.init_String) 354 355 class StringBuffer(Object): 356 357 "Used when adding String objects." 358 359 def __unicode__(self): 360 return u"".join(self.buffer) 361 362 def __str__(self): 363 unicode(self).encode("utf-8") 364 365 def init_empty(self): 366 self.buffer = [] 367 368 def init_int(self, length): 369 self.buffer = [] 370 371 def init_String(self, s): 372 self.buffer = [unicode(s)] 373 374 def __init__(self, *args): 375 if len(args) == 0: 376 self.init_empty() 377 elif len(args) == 1 and isinstance(args[0], int): 378 self.init_int(args[0]) 379 elif len(args) == 1 and isinstance(args[0], String): 380 self.init_String(args[0]) 381 382 def append(self, s): 383 sb = StringBuffer(String(unicode(self) + unicode(s))) 384 return sb 385 append____Z_ = append 386 append____C_ = append 387 append____C__array_ = append 388 append____C__array_____I_____I_ = append 389 append____D_ = append 390 append____F_ = append 391 append____I_ = append 392 append____J_ = append 393 append___java__lang__Object = append 394 append___java__lang__String = append 395 396 def toString(self): 397 return String("".join(self.buffer)) 398 toString___ = toString 399 400 setattr(StringBuffer, "__init_____", StringBuffer.init_empty) 401 setattr(StringBuffer, "__init______I_", StringBuffer.init_int) 402 setattr(StringBuffer, "__init_____java__lang__String", StringBuffer.init_String) 403 404 class System(Object): 405 # NOTE: Fix this - circular import nonsense! 406 in_ = java.io.InputStream(sys.stdin) 407 out = java.io.PrintStream(sys.stdout) 408 err = java.io.PrintStream(sys.stderr) 409 410 def getProperty___java__lang__String(key): 411 try: 412 return os.environ[key] 413 except KeyError: 414 return None 415 416 getProperty___java__lang__String = staticmethod(getProperty___java__lang__String) 417 418 setattr(System, "in", System.in_) 419 420 # vim: tabstop=4 expandtab shiftwidth=4