From: <cg...@us...> - 2008-11-23 23:46:15
|
Revision: 5623 http://jython.svn.sourceforge.net/jython/?rev=5623&view=rev Author: cgroves Date: 2008-11-23 23:46:11 +0000 (Sun, 23 Nov 2008) Log Message: ----------- Create the java proxy object after __init__ runs if it wasn't created by __init__ Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java branches/newstyle-java-types/src/org/python/core/PyFileDerived.java branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java branches/newstyle-java-types/src/org/python/core/PyJavaType.java branches/newstyle-java-types/src/org/python/core/PyListDerived.java branches/newstyle-java-types/src/org/python/core/PyLongDerived.java branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java branches/newstyle-java-types/src/org/python/core/PyObject.java branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java branches/newstyle-java-types/src/org/python/core/PySetDerived.java branches/newstyle-java-types/src/org/python/core/PySliceDerived.java branches/newstyle-java-types/src/org/python/core/PyStringDerived.java branches/newstyle-java-types/src/org/python/core/PySuperDerived.java branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java branches/newstyle-java-types/src/templates/object.derived Modified: branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1069,6 +1069,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFileDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFileDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyFileDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -29,7 +29,7 @@ @Override public Class<?> getProxyType() { - return underlying_class; + return PyObject.class.isAssignableFrom(underlying_class) ? null : underlying_class; } @Override Modified: branches/newstyle-java-types/src/org/python/core/PyListDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyListDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyListDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyLongDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyLongDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyLongDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1069,6 +1069,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyObject.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -101,8 +101,48 @@ * Dispatch __init__ behavior */ public void dispatch__init__(PyType type,PyObject[] args,String[] keywords) { + proxyInit(); } + /** + * Attempts to automatically initialize our Java proxy if we have one and it wasn't initialized + * by our __init__. + */ + protected void proxyInit() { + if (javaProxy != null || getType().getProxyType() == null) { + return; + } + Class<?> c = getType().getProxyType(); + PyProxy proxy; + ThreadState ts = Py.getThreadState(); + try { + ts.pushInitializingProxy(this); + try { + proxy = (PyProxy)c.newInstance(); + } catch (java.lang.InstantiationException e) { + Class<?> sup = c.getSuperclass(); + String msg = "Default constructor failed for Java superclass"; + if (sup != null) { + msg += " " + sup.getName(); + } + throw Py.TypeError(msg); + } catch (NoSuchMethodError nsme) { + throw Py.TypeError("constructor requires arguments"); + } catch (Exception exc) { + throw Py.JavaError(exc); + } + } finally { + ts.popInitializingProxy(); + } + if (javaProxy != null && javaProxy != proxy) { + throw Py.TypeError("Proxy instance already initialized"); + } + PyObject proxyInstance = proxy._getPyInstance(); + if (proxyInstance != null && proxyInstance != this) { + throw Py.TypeError("Proxy initialized with another instance"); + } + javaProxy = proxy; + } /** * Equivalent to the standard Python __repr__ method. This method Modified: branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySetDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySetDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PySetDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySliceDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySliceDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PySliceDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyStringDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyStringDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyStringDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySuperDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySuperDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PySuperDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1069,6 +1069,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/templates/object.derived =================================================================== --- branches/newstyle-java-types/src/templates/object.derived 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/templates/object.derived 2008-11-23 23:46:11 UTC (rev 5623) @@ -428,6 +428,7 @@ } } } + proxyInit(); } public PyObject __index__() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |