# HG changeset patch # User Paul Boddie # Date 1102555085 -3600 # Node ID cfb9fe666890c05891a1ca65f5981b94b7faf5b5 # Parent 78da4286ff0a68f4e47507011592d092e73b5fcd Changed the special notation for Java-callable methods so that methods may be more easily written in Python. Added various method implementations so that javax.servlet.http.Cookie can at least be instantiated. diff -r 78da4286ff0a -r cfb9fe666890 java/io.py --- a/java/io.py Thu Dec 09 02:17:22 2004 +0100 +++ b/java/io.py Thu Dec 09 02:18:05 2004 +0100 @@ -9,33 +9,47 @@ self.out.write(value[start:start+length]) else: self.out.write(value) + write___java__lang__String = write + write___java__lang__String____I_____I_ = write def flush(self): self.out.flush() + flush___ = flush def close(self): self.out.close() + close___ = close class InputStream: def read(self, *args): raise NotImplementedError, "read" + read___ = read def skip(self, n): raise NotImplementedError, "skip" + skip___int = skip def available(self): raise NotImplementedError, "available" + available___ = available def close(self): raise NotImplementedError, "close" + close___ = close def mark(self, readlimit): raise NotImplementedError, "mark" + mark___ = mark def reset(self): raise NotImplementedError, "reset" + reset___ = reset def markSupported(self): raise NotImplementedError, "markSupported" + markSupported___ = markSupported class OutputStream: def write(self, b, *args): raise NotImplementedError, "write" + write___java__lang__String = write def flush(self): raise NotImplementedError, "flush" + flush___ = flush def close(self): raise NotImplementedError, "close" + close___ = close # vim: tabstop=4 expandtab shiftwidth=4 diff -r 78da4286ff0a -r cfb9fe666890 java/lang.py --- a/java/lang.py Thu Dec 09 02:17:22 2004 +0100 +++ b/java/lang.py Thu Dec 09 02:18:05 2004 +0100 @@ -91,6 +91,15 @@ # compareTo(self, o) raise NotImplementedError, "compareTo" +# NOTE: Establish a better exception hierarchy. + +class IllegalArgumentException(object): + def __init__(self, *args): + self.args = args + +setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__) +setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__) + class String(object): def init__empty(self): @@ -127,70 +136,126 @@ raise NotImplementedError, "__init__" # __init__(self, buffer) raise NotImplementedError, "__init__" + def length(self): return len(self.value) + length___ = length + def charAt(self, index): - return self.value[index] + return ord(self.value[index]) + charAt____I_ = charAt + def getChars(self, srcBegin, srcEnd, dst, dstBegin): raise NotImplementedError, "getChars" + getChars____I_____I_____C__array_____I_ = getChars + def getBytes(self, *args): # void getBytes(self, srcBegin, srcEnd, dst, dstBegin) # byte[] getBytes(self, enc) # byte[] getBytes(self) raise NotImplementedError, "getBytes" + getBytes___ = getBytes + getBytes____I_____I_____B__array_____I_ = getBytes + def equals(self, anObject): - raise NotImplementedError, "equals" + return isinstance(anObject, self.__class__) and self.value == anObject.value + equals___java__lang__Object = equals + def compareTo(self, obj): - raise NotImplementedError, "compareTo" - # NOTE: Comparator defined using private classes. + if self.value < obj.value: + return -1 + elif self.value == obj.value: + return 0 + else: + return 1 + compareTo___java__lang__String = compareTo + + # NOTE: Comparator defined using private classes. This implementation just + # NOTE: uses Python's lower method. def compareToIgnoreCase(self, str): - raise NotImplementedError, "compareToIgnoreCase" + value = self.value.lower() + value2 = str.value.lower() + if value < value2: + return -1 + elif value == value2: + return 0 + else: + return 1 + compareToIgnoreCase___java__lang__String = compareToIgnoreCase + + # NOTE: Comparator defined using private classes. This implementation just + # NOTE: uses Python's lower method. + def equalsIgnoreCase(self, anotherString): + value = self.value.lower() + value2 = anotherString.value.lower() + return value == value2 + equalsIgnoreCase___java__lang__String = equalsIgnoreCase + def regionMatches(self, *args): # regionMatches(self, toffset, other, ooffset, len) # regionMatches(self, ignoreCase, toffset, other, ooffset, len) raise NotImplementedError, "regionMatches" + def startsWith(self, *args): # startsWith(self, prefix, toffset) # startsWith(self, prefix) raise NotImplementedError, "startsWith" + def endsWith(self, suffix): raise NotImplementedError, "endsWith" + def hashCode(self): raise NotImplementedError, "hashCode" - def indexOf(self, *args): - # indexOf(self, ch) - # indexOf(self, ch, fromIndex) - # indexOf(self, str) - # indexOf(self, str, fromIndex) - raise NotImplementedError, "indexOf" + + def indexOf____I_(self, ch): + return self.value.find(chr(ch)) + + def indexOf____I_____I_(self, ch, fromIndex): + return self.value.find(chr(ch), fromIndex) + + def indexOf___java__lang__String___(self, str): + return self.value.find(str.value) + + def indexOf___java__lang__String____I_(self, str, fromIndex): + return self.value.find(str.value, fromIndex) + def lastIndexOf(self, *args): # lastIndexOf(self, ch) # lastIndexOf(self, ch, fromIndex) # lastIndexOf(self, str) # lastIndexOf(self, str, fromIndex) raise NotImplementedError, "lastIndexOf" + def substring(self, *args): # substring(self, beginIndex) # substring(self, beginIndex, endIndex) raise NotImplementedError, "substring" + def concat(self, str): raise NotImplementedError, "concat" + def replace(self, oldChar, newChar): raise NotImplementedError, "replace" + def toLowerCase(self, *args): # toLowerCase(self, locale) # toLowerCase(self) raise NotImplementedError, "toLowerCase" + def toUpperCase(self, *args): # toUpperCase(self, locale) # toUpperCase(self) raise NotImplementedError, "toUpperCase" + def trim(self): raise NotImplementedError, "trim" + def toString(self): return self + def toCharArray(self): raise NotImplementedError, "toCharArray" + def valueOf(self, *args): # valueOf(self, obj) # valueOf(self, data) @@ -202,15 +267,17 @@ # valueOf(self, d) raise NotImplementedError, "valueOf" valueOf = staticmethod(valueOf) + def copyValueOf(self, *args): # copyValueOf(self, data, offset, count) # copyValueOf(self, data) raise NotImplementedError, "copyValueOf" copyValueOf = staticmethod(copyValueOf) + def intern(self): raise NotImplementedError, "intern" -setattr(String, "__init__$", String.init__empty) -setattr(String, "__init__$java/lang/String", String.init__String) +setattr(String, "__init_____", String.init__empty) +setattr(String, "__init_____java__lang__String", String.init__String) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 78da4286ff0a -r cfb9fe666890 java/text.py --- a/java/text.py Thu Dec 09 02:17:22 2004 +0100 +++ b/java/text.py Thu Dec 09 02:18:05 2004 +0100 @@ -1,6 +1,6 @@ #!/usr/bin/env python -class FilterOutputStream: +class FilterOutputStream(object): def __init__(self, out): self.out = out def write(self, value, *args): @@ -14,7 +14,7 @@ def close(self): self.out.close() -class InputStream: +class InputStream(object): def read(self, *args): raise NotImplementedError, "read" def skip(self, n): @@ -30,7 +30,40 @@ def markSupported(self): raise NotImplementedError, "markSupported" -class OutputStream: +class MessageFormat(object): + def __init__(self, pattern): + self.pattern = pattern + + def applyPattern(self, pattern): + self.pattern = pattern + applyPattern___java__lang__String = applyPattern + + def equals(self, obj): + return self == obj + equals___java__lang__Object = equals + + def format(self, *args): + raise NotImplementedError, "format" + format___java__lang__Object_array____java__lang__StringBuffer___java__text__FieldPosition = format + format___java__lang__Object___java__lang__StringBuffer___java__text__FieldPosition = format + + def format__static(pattern, arguments): + mf = MessageFormat(pattern) + # NOTE: To be implemented. + return "" + format___java__lang__String___java__lang__Object_array_ = staticmethod(format__static) + + def getFormats(self): + raise NotImplementedError, "getFormats" + getFormats___ = getFormats + + def getLocale(self): + raise NotImplementedError, "getLocale" + getLocale___ = getLocale + +setattr(MessageFormat, "__init_____java__lang__String", MessageFormat.__init__) + +class OutputStream(object): def write(self, b, *args): raise NotImplementedError, "write" def flush(self): diff -r 78da4286ff0a -r cfb9fe666890 java/util.py --- a/java/util.py Thu Dec 09 02:17:22 2004 +0100 +++ b/java/util.py Thu Dec 09 02:18:05 2004 +0100 @@ -14,12 +14,13 @@ # NOTE: To be implemented. pass -setattr(Hashtable, "__init__$", Hashtable.__init__) +setattr(Hashtable, "__init_____", Hashtable.__init__) class ResourceBundle(object): def __init__(self, *args): # NOTE: To be implemented. pass + def getBundle(self, *args): # getBundle(self, baseName) # getBundle(self, baseName, locale) @@ -27,9 +28,28 @@ # NOTE: Obviously not the correct implementation. return ResourceBundle(args) getBundle = staticmethod(getBundle) + getBundle___java__lang__String = getBundle + getBundle___java__lang__String___java__util__Locale = getBundle + getBundle___java__lang__String___java__util__Locale___java__lang__ClassLoader = getBundle -setattr(ResourceBundle, "getBundle$java/lang/String", staticmethod(ResourceBundle.getBundle)) -setattr(ResourceBundle, "getBundle$java/lang/String$java/util/Locale", staticmethod(ResourceBundle.getBundle)) -setattr(ResourceBundle, "getBundle$java/lang/String$java/util/Locale$java/lang/ClassLoader", staticmethod(ResourceBundle.getBundle)) + def getObject(self, key): + # NOTE: To be implemented. + return None + getObject___java__lang__String = getObject + + def getString(self, key): + # NOTE: To be implemented. + return None + getString___java__lang__String = getString + + def getStringArray(self, key): + # NOTE: To be implemented. + return None + getStringArray___java__lang__String = getStringArray + + def getLocale(self, key): + # NOTE: To be implemented. + return None + getLocale___ = getLocale # vim: tabstop=4 expandtab shiftwidth=4