From: <cg...@us...> - 2008-11-23 02:36:12
|
Revision: 5607 http://jython.svn.sourceforge.net/jython/?rev=5607&view=rev Author: cgroves Date: 2008-11-23 02:36:05 +0000 (Sun, 23 Nov 2008) Log Message: ----------- Rip out PyJavaClass and friends. This isn't even close to passing regrtest, but it runs well enough to start the interpreter and get through the first few. Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/IdImpl.java branches/newstyle-java-types/src/org/python/core/Py.java branches/newstyle-java-types/src/org/python/core/PyBeanEventProperty.java branches/newstyle-java-types/src/org/python/core/PyClass.java branches/newstyle-java-types/src/org/python/core/PyFile.java branches/newstyle-java-types/src/org/python/core/PyInstance.java branches/newstyle-java-types/src/org/python/core/PyJavaPackage.java branches/newstyle-java-types/src/org/python/core/PyObject.java branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java branches/newstyle-java-types/src/org/python/core/PyType.java branches/newstyle-java-types/src/org/python/core/StdoutWrapper.java branches/newstyle-java-types/src/org/python/core/__builtin__.java branches/newstyle-java-types/src/org/python/core/imp.java branches/newstyle-java-types/src/org/python/modules/cPickle.java branches/newstyle-java-types/src/org/python/modules/cStringIO.java Removed Paths: ------------- branches/newstyle-java-types/Lib/jreload.py branches/newstyle-java-types/Lib/jxxload_help/ branches/newstyle-java-types/src/org/python/core/AutoInternalTables.java branches/newstyle-java-types/src/org/python/core/CollectionProxy.java branches/newstyle-java-types/src/org/python/core/InternalTables.java branches/newstyle-java-types/src/org/python/core/PyJavaClass.java branches/newstyle-java-types/src/org/python/core/PyJavaInnerClass.java branches/newstyle-java-types/src/org/python/core/PyJavaInstance.java branches/newstyle-java-types/src/org/python/core/SoftIInternalTables.java branches/newstyle-java-types/src/org/python/core/WeakInternalTables.java branches/newstyle-java-types/src/org/python/modules/_jython.java Deleted: branches/newstyle-java-types/Lib/jreload.py =================================================================== --- branches/newstyle-java-types/Lib/jreload.py 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/Lib/jreload.py 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,119 +0,0 @@ -# java classes reload support (experimental) -# Copyright 2000 Samuele Pedroni - -# ?? could have problem with import pkg.jclass.inner (this should not be used in any case) -# ?? using import * with a load-set together with reloading can be confusing -# cannot be fixed => anyway import * is not for production code - -__version__ = "0.3" - -import sys -from org.python.core import imp,PyJavaPackage,PyJavaClass -from _jython import is_lazy as _is_lazy - -import jxxload_help - - -class _LoaderFactory(jxxload_help.JavaLoaderFactory): - def __init__(self,path): - vfs = jxxload_help.PathVFS() - for fname in path: - vfs.addVFS(fname) - self.vfs = vfs - - def makeLoader(self): - return jxxload_help.PathVFSJavaLoader(self.vfs,imp.getSyspathJavaLoader()) - -class _Unload: - - def __init__(self,ls): - self.ls = ls - self.ls_name = ls._name - self.loader = ls._mgr.loader - - def do_unload(self,pkg): - for n in pkg.__dict__.keys(): - e = pkg.__dict__[n] - if isinstance(e,PyJavaClass): - if _is_lazy(e): continue - if e.classLoader is self.loader: - del pkg.__dict__[n] - if pkg.__name__: - n = self.ls_name + '.' + pkg.__name__ + '.' +n - else: - n = self.ls_name + '.' + n - if sys.modules.has_key(n): del sys.modules[n] - - elif isinstance(e,PyJavaPackage): - self.do_unload(e) - - def __call__(self): - if self.loader: - if self.ls._mgr.checkLoader() is self.loader: - self.do_unload(self.ls._top) - self.ls._mgr.resetLoader() - loader = self.loader - jxxload_help.DiscardHelp.discard(loader,loader.interfaces) - self.loader = None - -class LoadSet: -# ?? for the moment from import * and dir do not work for LoadSet, but work for -# contained pkgs -# need java impl as PyObject - - def __init__(self,name,path): - mgr = jxxload_help.PackageManager(path,_LoaderFactory(path)) - self._name = name - self._mgr = mgr - self._top = mgr.topLevelPackage - - def __getattr__(self,name): - try: - return getattr(self._top,name) - except: - if name == 'unload': return _Unload(self) - raise - - - def __repr__(self): - return "<java load-set %s>" % self._name - -def unloadf(ls): - if not isinstance(ls,LoadSet): raise TypeError,"unloadf(): arg is not a load-set" - return _Unload(ls) - -def makeLoadSet(name,path): - if sys.modules.has_key(name): return sys.modules[name] - sys.modules[name] = ls = LoadSet(name,path) - return ls - -_reload = reload - -def _do_reload(ls_name,mgr,pkg): - pkg_name = pkg.__name__ - for n in pkg.__dict__.keys(): - e = pkg.__dict__[n] - if isinstance(e,PyJavaClass): - if _is_lazy(e): continue - del pkg.__dict__[n] - try : - c = mgr.findClass(pkg_name,n); - if c: - pkg.__dict__[n] = c - if pkg_name: - n = ls_name + '.' + pkg_name + '.' + n - else: - n = ls_name + '.' + n - if sys.modules.has_key(n): sys.modules[n] = c - except: - pass - elif isinstance(e,PyJavaPackage): - _do_reload(ls_name,mgr,e) - -def reload(ls): - if isinstance(ls,LoadSet): - ls._mgr.resetLoader() - _do_reload(ls._name,ls._mgr,ls._top) - return ls - else: - return _reload(ls) Deleted: branches/newstyle-java-types/src/org/python/core/AutoInternalTables.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/AutoInternalTables.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/AutoInternalTables.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,155 +0,0 @@ -// Copyright 2000 Samuele Pedroni - -package org.python.core; - -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.util.Map; - -public abstract class AutoInternalTables extends InternalTables { - - protected transient ReferenceQueue queue = new ReferenceQueue(); - - protected abstract Reference newAutoRef(short type, Object key, - Object obj); - protected abstract short getAutoRefType(Reference ref); - protected abstract Object getAutoRefKey(Reference ref); - - private synchronized void cleanup() { - if (this.keepstable >= this.GSTABLE) - return; - this.adapters.remove(null); // trick - Reference ref; - while ((ref = this.queue.poll()) != null) { - Object key = getAutoRefKey(ref); - switch(getAutoRefType(ref)) { - case JCLASS: - Class cl = (Class)key; - this.classes.remove(cl); - classesDec(cl.getName()); - break; - case LAZY_JCLASS: - this.lazyClasses.remove(key); - break; - case ADAPTER_CLASS: - this.adapterClasses.remove(key); - } - } - } - - - protected boolean queryCanonical(String name) { - cleanup(); - return super.queryCanonical(name); - } - - protected PyJavaClass getCanonical(Class c) { - cleanup(); - Reference ref = (Reference)classesGet(c); - if (ref == null) return null; - return (PyJavaClass)ref.get(); - } - - protected PyJavaClass getLazyCanonical(String name) { - cleanup(); - Reference ref = (Reference)this.lazyClasses.get(name); - if (ref == null) return null; - return (PyJavaClass)ref.get(); - } - - protected void putCanonical(Class c,PyJavaClass canonical) { - cleanup(); - classesPut(c,newAutoRef(JCLASS,c,canonical)); - } - - protected void putLazyCanonical(String name,PyJavaClass canonical) { - cleanup(); - this.lazyClasses.put(name,newAutoRef(LAZY_JCLASS,name,canonical)); - } - - protected Class getAdapterClass(Class c) { - cleanup(); - Reference ref = (Reference)this.adapterClasses.get(c); - if (ref == null) return null; - return (Class)ref.get(); - } - - protected void putAdapterClass(Class c,Class ac) { - cleanup(); - this.adapterClasses.put(c,newAutoRef(ADAPTER_CLASS,c,ac)); - } - - protected Object getAdapter(Object o,String evc) { - cleanup(); - return super.getAdapter(o,evc); - } - - protected void putAdapter(Object o,String evc,Object ad) { - cleanup(); - super.putAdapter(o,evc,ad); - } - - - public boolean _doesSomeAutoUnload() { return true; } - - public void _forceCleanup() { cleanup(); } - - public void _beginCanonical() { - cleanup(); - super._beginCanonical(); - } - - public void _beginLazyCanonical() { - cleanup(); - super._beginLazyCanonical(); - } - - public void _beginOverAdapterClasses() { - cleanup(); - super._beginOverAdapterClasses(); - - } - - public void _beginOverAdapters() { - cleanup(); - super._beginOverAdapters(); - } - - public Object _next() { - if (this.iterType == ADAPTER) { - Object ret = super._next(); - if (ret != null) return ret; - } else { - while(this.iter.hasNext()) { - this.cur = this.iter.next(); - switch(this.iterType) { - case JCLASS: - PyJavaClass jc = (PyJavaClass)((Reference)this.cur).get(); - if (jc == null ) continue; - this.cur = jc; - return jc; - case LAZY_JCLASS: - PyJavaClass lazy = (PyJavaClass)((Reference)this.cur).get(); - if (lazy == null) continue; - return new _LazyRep(lazy.__name__,lazy.__mgr__); - case ADAPTER_CLASS: - Map.Entry entry = (Map.Entry)this.cur; - if (((Reference)entry.getValue()).get() == null ) - continue; - return entry.getKey(); - } - } - this.cur = null; - this.iter = null; - endStable(); - } - cleanup(); - return null; - } - - public void _flush(PyJavaClass jc) { - cleanup(); - super._flush(jc); - } - -} Deleted: branches/newstyle-java-types/src/org/python/core/CollectionProxy.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/CollectionProxy.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/CollectionProxy.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,295 +0,0 @@ -// Copyright (c) Corporation for National Research Initiatives - -package org.python.core; - -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -class CollectionProxy { - public static final CollectionProxy NoProxy = new EnumerationProxy(null); - - public static CollectionProxy findCollection(Object object) { - if (object == null) - return NoProxy; - - if (object instanceof List) { - return new ListProxy(((List) object)); - } - if (object instanceof Map) { - return new MapProxy(((Map) object)); - } - if (object instanceof Iterable) { - return new IteratorProxy(((Iterable) object).iterator()); - } - if (object instanceof Iterator) { - return new IteratorProxy(((Iterator) object)); - } - - - if (object instanceof Vector) { - return new VectorProxy(((Vector) object)); - } - if (object instanceof Enumeration) { - return new EnumerationProxy(((Enumeration) object)); - } - if (object instanceof Dictionary) { - return new DictionaryProxy(((Dictionary) object)); - } - - return NoProxy; - } - - /** The basic functions to implement a mapping */ - public int __len__() { - throw Py.AttributeError("__len__"); - } - - public PyObject __finditem__(int key) { - return __finditem__(new PyInteger(key)); - } - - public PyObject __finditem__(PyObject key) { - throw Py.AttributeError("__getitem__"); - } - - public PyObject __getitem__(int key) { - PyObject ret = __finditem__(key); - if (ret == null) - throw Py.KeyError("" + key); - return ret; - } - - public PyObject __getitem__(PyObject key) { - PyObject ret = __finditem__(key); - if (ret == null) - throw Py.KeyError(key.toString()); - return ret; - } - - public void __setitem__(PyObject key, PyObject value) { - throw Py.AttributeError("__setitem__"); - } - - public void __delitem__(PyObject key) { - throw Py.AttributeError("__delitem__"); - } -} - -class EnumerationProxy extends CollectionProxy { - Enumeration proxy; - - int counter; - - public EnumerationProxy(Enumeration proxy) { - this.proxy = proxy; - this.counter = 0; - } - - public PyObject __finditem__(int key) { - if (key != this.counter) { - throw Py.ValueError("enumeration indices must be consecutive ints starting at 0"); - } - this.counter++; - if (this.proxy.hasMoreElements()) { - return Py.java2py(this.proxy.nextElement()); - } else { - return null; - } - } - - public PyObject __finditem__(PyObject key) { - if (key instanceof PyInteger) { - return __finditem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } -} - -class VectorProxy extends CollectionProxy { - Vector proxy; - - public VectorProxy(Vector proxy) { - this.proxy = proxy; - } - - public int __len__() { - return this.proxy.size(); - } - - public PyObject __finditem__(int key) { - try { - return Py.java2py(this.proxy.elementAt(key)); - } catch (ArrayIndexOutOfBoundsException exc) { - return null; - } - } - - public PyObject __finditem__(PyObject key) { - if (key instanceof PyInteger) { - return __finditem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } - - public void __setitem__(PyObject key, PyObject value) { - if (key instanceof PyInteger) { - this.proxy.setElementAt(Py.tojava(value, Object.class), ((PyInteger)key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } - - public void __delitem__(PyObject key) { - if (key instanceof PyInteger) { - this.proxy.removeElementAt(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } -} - -class DictionaryProxy extends CollectionProxy { - Dictionary proxy; - - public DictionaryProxy(Dictionary proxy) { - this.proxy = proxy; - } - - public int __len__() { - return this.proxy.size(); - } - - public PyObject __finditem__(int key) { - throw Py.TypeError("loop over non-sequence"); - } - - public PyObject __finditem__(PyObject key) { - return Py.java2py(this.proxy.get(Py.tojava(key, Object.class))); - } - - public void __setitem__(PyObject key, PyObject value) { - this.proxy.put(Py.tojava(key, Object.class), Py.tojava(value, - Object.class)); - } - - public void __delitem__(PyObject key) { - this.proxy.remove(Py.tojava(key, Object.class)); - } -} -class ListProxy extends CollectionProxy { - List proxy; - - public ListProxy(List proxy) { - this.proxy = proxy; - } - - public int __len__() { - return this.proxy.size(); - } - - public PyObject __finditem__(int key) { - try { - return Py.java2py(this.proxy.get(key)); - } catch (IndexOutOfBoundsException exc) { - return null; - } - } - - public PyObject __finditem__(PyObject key) { - if (key instanceof PyInteger) { - return __finditem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } - - public void __setitem__(int key, PyObject value) { - this.proxy.set(key, Py.tojava(value, Object.class)); - } - - public void __setitem__(PyObject key, PyObject value) { - if (key instanceof PyInteger) { - __setitem__(((PyInteger) key).getValue(), value); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } - - public void __delitem__(int key) { - this.proxy.remove(key); - } - - public void __delitem__(PyObject key) { - if (key instanceof PyInteger) { - __delitem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } -} - -class MapProxy extends CollectionProxy { - Map proxy; - - public MapProxy(Map proxy) { - this.proxy = proxy; - } - - public int __len__() { - return this.proxy.size(); - } - - public PyObject __finditem__(int key) { - throw Py.TypeError("loop over non-sequence"); - } - - public PyObject __finditem__(PyObject key) { - return Py.java2py(this.proxy.get(Py.tojava(key, Object.class))); - } - - public void __setitem__(PyObject key, PyObject value) { - this.proxy.put(Py.tojava(key, Object.class), Py.tojava(value, - Object.class)); - } - - public void __delitem__(PyObject key) { - this.proxy.remove(Py.tojava(key, Object.class)); - } -} - -class IteratorProxy extends CollectionProxy { - Iterator proxy; - - int counter; - - public IteratorProxy(Iterator proxy) { - this.proxy = proxy; - this.counter = 0; - } - - public PyObject __finditem__(int key) { - if (key != this.counter) { - throw Py.ValueError("iterator indices must be consecutive ints starting at 0"); - } - this.counter++; - if (this.proxy.hasNext()) { - return Py.java2py(this.proxy.next()); - } else { - return null; - } - } - - public PyObject __finditem__(PyObject key) { - if (key instanceof PyInteger) { - return __finditem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } - } -} Modified: branches/newstyle-java-types/src/org/python/core/IdImpl.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/IdImpl.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/IdImpl.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -7,48 +7,48 @@ public class IdImpl { public static class WeakIdentityMap { - + private transient ReferenceQueue refqueue = new ReferenceQueue(); private HashMap hashmap = new HashMap(); - + private void cleanup() { Object k; while ((k = this.refqueue.poll()) != null) { this.hashmap.remove(k); } } - + private class WeakIdKey extends WeakReference { private int hashcode; - + WeakIdKey(Object obj) { super(obj,WeakIdentityMap.this.refqueue); - this.hashcode = System.identityHashCode(obj); + this.hashcode = System.identityHashCode(obj); } - + public int hashCode() { return this.hashcode; } - + public boolean equals(Object other) { Object obj = this.get(); if (obj != null) { return obj == ((WeakIdKey)other).get(); } else { return this == other; - } + } } } - + public int _internal_map_size() { return this.hashmap.size(); } - + public void put(Object key,Object val) { cleanup(); this.hashmap.put(new WeakIdKey(key),val); } - + public Object get(Object key) { cleanup(); return this.hashmap.get(new WeakIdKey(key)); @@ -56,20 +56,20 @@ public void remove(Object key) { cleanup(); - this.hashmap.remove(new WeakIdKey(key)); + this.hashmap.remove(new WeakIdKey(key)); } } private WeakIdentityMap id_map = new WeakIdentityMap(); - private long sequential_id = 0; + private long sequential_id = 0; public long id(PyObject o) { - if (o instanceof PyJavaInstance) { - return java_obj_id(((PyJavaInstance)o).javaProxy); + if (o.getType() instanceof PyJavaType) { + return java_obj_id(o.javaProxy); } else { return java_obj_id(o); - } + } } // XXX maybe should display both this id and identityHashCode @@ -82,9 +82,9 @@ Long cand = (Long)this.id_map.get(o); if (cand == null) { this.sequential_id++; - long new_id = this.sequential_id; + long new_id = this.sequential_id; this.id_map.put(o,new Long(new_id)); - return new_id; + return new_id; } return cand.longValue(); } Deleted: branches/newstyle-java-types/src/org/python/core/InternalTables.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/InternalTables.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/InternalTables.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,292 +0,0 @@ -// Copyright 2000 Samuele Pedroni -package org.python.core; - -import java.lang.ref.WeakReference; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.WeakHashMap; - -import org.python.core.packagecache.PackageManager; - -public class InternalTables { - - // x__ --> org.python.core.X__InternalTables - // (x|X)__> --> org.python.core.X__InternalTables - // other (X__|__.__) --> other - // - private static InternalTables tryImpl(String id) { - try { - if(id.indexOf('.') < 0) { - if(id.charAt(id.length() - 1) == '>') { - id = makeCoreInternalTablesClass(id.substring(0, id.length() - 1)); - } else if(Character.isLowerCase(id.charAt(0))) { - id = makeCoreInternalTablesClass(id); - } - } - // System.err.println("*InternalTables*-create-try: "+id); - return (InternalTables)Class.forName(id).newInstance(); - } catch(Throwable e) { - // System.err.println(" exc: "+e); // ??dbg - return null; - } - } - - private static String makeCoreInternalTablesClass(String id) { - if(Character.isLowerCase(id.charAt(0))) { - id = Character.toUpperCase(id.charAt(0)) + id.substring(1); - } - return "org.python.core." + id + "InternalTables"; - } - - static InternalTables createInternalTables() { - if(PySystemState.registry == null) { - throw new IllegalStateException("Jython interpreter state not initialized. " - + "You need to call PySystemState.initialize or PythonInterpreter.initialize."); - } - String cands = PySystemState.registry.getProperty("python.options.internalTablesImpl"); - if(cands == null) { - return new InternalTables(); - } - StringTokenizer candEnum = new StringTokenizer(cands, ":"); - while(candEnum.hasMoreTokens()) { - InternalTables tbl = tryImpl(candEnum.nextToken().trim()); - if(tbl != null) { - return tbl; - } - } - return new InternalTables(); - } - - final protected static short JCLASS = 0; - - final protected static short LAZY_JCLASS = 1; - - final protected static short ADAPTER_CLASS = 2; - - final protected static short ADAPTER = 3; - - protected Map classes = new HashMap(); - - protected Map temp = new HashMap();; - - protected Map counters = new HashMap();; - - protected Map lazyClasses = new HashMap();; - - protected Map adapterClasses = new HashMap();; - - protected final short GSTABLE = 1; - - protected final short JCSTABLE = 2; - - protected short keepstable; - - protected void commitTemp() { - this.classes.putAll(this.temp); - this.temp.clear(); - } - - protected WeakHashMap adapters = new WeakHashMap();; - - protected Object getAdapter(Object o, String evc) { - HashMap ads = (HashMap)this.adapters.get(o); - if(ads == null) { - return null; - } - WeakReference adw = (WeakReference)ads.get(evc); - if(adw == null) { - return null; - } - return adw.get(); - } - - protected void putAdapter(Object o, String evc, Object ad) { - HashMap ads = (HashMap)this.adapters.get(o); - if(ads == null) { - ads = new HashMap(); - this.adapters.put(o, ads); - } - ads.put(evc, new WeakReference(ad)); - } - - protected Iterator iter; - - protected Iterator grand; - - protected short iterType; - - protected Object cur; - - protected void beginStable(short lvl) { - this.keepstable = lvl; - } - - protected void endStable() { - if(this.keepstable == this.JCSTABLE) - commitTemp(); - this.keepstable = 0; - } - - protected void classesPut(Class c, Object jc) { - if(this.keepstable == this.JCSTABLE) { - this.temp.put(c, jc); - // System.err.println("temp-defer-canonical: "+c.getName()); - } else { - this.classes.put(c, jc); - } - String name = c.getName(); - Integer cnt = (Integer)this.counters.get(name); - if(cnt == null) { - this.counters.put(name, new Integer(1)); - this.lazyClasses.remove(name); - } else { - this.counters.put(name, new Integer(cnt.intValue() + 1)); - } - } - - protected Object classesGet(Class c) { - Object o = this.classes.get(c); - if(o != null || this.keepstable != this.JCSTABLE) - return o; - return this.temp.get(c); - } - - public void _beginCanonical() { - beginStable(this.JCSTABLE); - this.iter = this.classes.values().iterator(); - this.iterType = JCLASS; - } - - public void _beginLazyCanonical() { - beginStable(this.GSTABLE); - this.iter = this.lazyClasses.values().iterator(); - this.iterType = LAZY_JCLASS; - } - - public void _beginOverAdapterClasses() { - beginStable(this.GSTABLE); - this.iter = this.adapterClasses.entrySet().iterator(); - this.iterType = ADAPTER_CLASS; - } - - public void _beginOverAdapters() { - beginStable((short)0); - this.grand = this.adapters.values().iterator(); - this.iter = null; - this.iterType = ADAPTER; - } - - public Object _next() { - if(this.iterType == ADAPTER) { - for(;;) { - if(this.iter == null || !this.iter.hasNext()) { - if(this.grand.hasNext()) { - this.cur = this.grand.next(); - this.iter = ((HashMap)this.cur).values().iterator(); - } else { - this.iter = null; - } - } - if(this.iter != null) { - WeakReference adw = (WeakReference)this.iter.next(); - Object ad = adw.get(); - if(ad != null) { - return ad.getClass().getInterfaces()[0]; - } else { - continue; - } - } - this.grand = null; - break; - } - } else if(this.iter.hasNext()) { - this.cur = this.iter.next(); - switch(this.iterType){ - case JCLASS: - return this.cur; - case LAZY_JCLASS: - PyJavaClass lazy = (PyJavaClass)this.cur; - return new _LazyRep(lazy.__name__, lazy.__mgr__); - case ADAPTER_CLASS: - Map.Entry entry = (Map.Entry)this.cur; - return entry.getKey(); - } - } - this.cur = null; - endStable(); - this.iter = null; - return null; - } - - public void _flushCurrent() { - this.iter.remove(); - switch(this.iterType){ - case JCLASS: - classesDec(((PyJavaClass)this.cur).__name__); - break; - case ADAPTER: - if(((HashMap)this.cur).size() == 0) - this.grand.remove(); - } - } - - public void _flush(PyJavaClass jc) { - Class c = jc.proxyClass; - if(c == null) { - this.lazyClasses.remove(jc.__name__); - } else { - this.classes.remove(c); - classesDec(jc.__name__); - } - } - - protected Class getAdapterClass(Class c) { - return (Class)this.adapterClasses.get(c); - } - - protected PyJavaClass getCanonical(Class c) { - return (PyJavaClass)classesGet(c); - } - - protected PyJavaClass getLazyCanonical(String name) { - return (PyJavaClass)this.lazyClasses.get(name); - } - - protected void putAdapterClass(Class c, Class ac) { - this.adapterClasses.put(c, ac); - } - - protected void putCanonical(Class c, PyJavaClass canonical) { - classesPut(c, canonical); - } - - protected void putLazyCanonical(String name, PyJavaClass canonical) { - this.lazyClasses.put(name, canonical); - } - - protected boolean queryCanonical(String name) { - return this.counters.get(name) != null || this.lazyClasses.get(name) != null; - } - - protected void classesDec(String name) { - int c = ((Integer)this.counters.get(name)).intValue(); - if(c == 1) - this.counters.remove(name); - else - this.counters.put(name, new Integer(c - 1)); - } - - static public class _LazyRep { - - public String name; - - public PackageManager mgr; - - _LazyRep(String name, PackageManager mgr) { - this.name = name; - this.mgr = mgr; - } - } -} Modified: branches/newstyle-java-types/src/org/python/core/Py.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/Py.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/Py.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -435,8 +435,8 @@ } else if (t instanceof OutOfMemoryError) { memory_error((OutOfMemoryError) t); } - PyJavaInstance exc = new PyJavaInstance(t); - PyException pyex = new PyException(exc.instclass, exc); + PyObject exc = PyJavaType.wrapJavaObject(t); + PyException pyex = new PyException(exc.getType(), exc); // Set the cause to the original throwable to preserve // the exception chain. pyex.initCause(t); @@ -722,7 +722,7 @@ // Pre-initialize the PyJavaClass for OutOfMemoryError so when we need // it it creating the pieces for it won't cause an additional out of // memory error. Fix for bug #1654484 - PyJavaClass.lookup(OutOfMemoryError.class); + PyType.fromClass(OutOfMemoryError.class); } public static PySystemState defaultSystemState; // This is a hack to get initializations to work in proper order @@ -981,7 +981,7 @@ } } - if (value instanceof PyJavaInstance) { + if (value.getType() instanceof PyJavaType) { Object javaError = value.__tojava__(Throwable.class); if (javaError != null && javaError != Py.NoConversion) { @@ -1134,14 +1134,14 @@ // java.io.IOExceptions. This is a hack for 1.0.x until I can do // it right in 1.1 if (exc == Py.IOError) { - if (__builtin__.isinstance(pye.value, PyJavaClass.lookup(IOException.class))) { + if (__builtin__.isinstance(pye.value, PyType.fromClass(IOException.class))) { return true; } } // FIXME too, same approach for OutOfMemoryError if (exc == Py.MemoryError) { if (__builtin__.isinstance(pye.value, - PyJavaClass.lookup(OutOfMemoryError.class))) { + PyType.fromClass(OutOfMemoryError.class))) { return true; } } @@ -1518,7 +1518,7 @@ if (doc != null && dict.__finditem__("__doc__") == null) { dict.__setitem__("__doc__", doc); } - return makeClass(name, bases, dict, null); + return makeClass(name, bases, dict); } public static PyObject makeClass(String name, PyObject base, PyObject dict) { @@ -1526,10 +1526,6 @@ return makeClass(name, bases, dict); } - public static PyObject makeClass(String name, PyObject[] bases, PyObject dict) { - return makeClass(name, bases, dict, null); - } - /** * Create a new Python class. * @@ -1537,11 +1533,9 @@ * @param bases an array of PyObject base classes * @param dict the class's namespace, containing the class body * definition - * @param proxyClass an optional underlying Java class * @return a new Python Class PyObject */ - public static PyObject makeClass(String name, PyObject[] bases, PyObject dict, - Class proxyClass) { + public static PyObject makeClass(String name, PyObject[] bases, PyObject dict) { PyFrame frame = getFrame(); if (dict.__finditem__("__module__") == null) { @@ -1568,9 +1562,7 @@ } } - if (metaclass == null || metaclass == CLASS_TYPE || - (metaclass instanceof PyJavaClass && - ((PyJavaClass)metaclass).proxyClass == Class.class)) { + if (metaclass == null || metaclass == CLASS_TYPE) { boolean moreGeneral = false; for (PyObject base : bases) { if (!(base instanceof PyClass)) { @@ -1580,14 +1572,10 @@ } } if (!moreGeneral) { - return new PyClass(name, new PyTuple(bases), dict, proxyClass); + return new PyClass(name, new PyTuple(bases), dict); } } - if (proxyClass != null) { - throw Py.TypeError("the meta-class cannot handle java subclassing"); - } - try { return metaclass.__call__(new PyString(name), new PyTuple(bases), dict); } catch (PyException pye) { @@ -1946,7 +1934,7 @@ name = "fixed file"; this.file = file; - if (file instanceof PyJavaInstance) { + if (file.getType() instanceof PyJavaType) { Object tojava = file.__tojava__(OutputStream.class); if (tojava != null && tojava != Py.NoConversion) { this.file = new PyFile((OutputStream) tojava); Modified: branches/newstyle-java-types/src/org/python/core/PyBeanEventProperty.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBeanEventProperty.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/PyBeanEventProperty.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,9 +1,14 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Map; +import java.util.WeakHashMap; +import org.python.util.Generic; + public class PyBeanEventProperty extends PyReflectedField { public Method addMethod; @@ -51,22 +56,40 @@ } private synchronized static Class<?> getAdapterClass(Class<?> c) { - InternalTables tbl = PyJavaClass.getInternalTables(); - Class<?> o = tbl.getAdapterClass(c); - if (o != null) - return o; Class<?> pc = Py.findClass("org.python.proxies." + c.getName() + "$Adapter"); if (pc == null) { pc = MakeProxies.makeAdapter(c); } - tbl.putAdapterClass(c, pc); return pc; } + protected Map<Object, Map<String, WeakReference<Object>>> adapters = + new WeakHashMap<Object, Map<String, WeakReference<Object>>>(); + + protected Object getAdapter(Object o, String evc) { + Map<String, WeakReference<Object>> ads = adapters.get(o); + if (ads == null) { + return null; + } + WeakReference<Object> adw = ads.get(evc); + if (adw == null) { + return null; + } + return adw.get(); + } + + protected void putAdapter(Object o, String evc, Object ad) { + Map<String, WeakReference<Object>> ads = adapters.get(o); + if(ads == null) { + ads = Generic.map(); + adapters.put(o, ads); + } + ads.put(evc, new WeakReference<Object>(ad)); + } + private synchronized Object getAdapter(Object self) { - InternalTables tbl = PyJavaClass.getInternalTables(); String eventClassName = eventClass.getName(); - Object adapter = tbl.getAdapter(self, eventClassName); + Object adapter = getAdapter(self, eventClassName); if (adapter != null) return adapter; try { @@ -75,7 +98,7 @@ } catch (Exception e) { throw Py.JavaError(e); } - tbl.putAdapter(self, eventClassName, adapter); + putAdapter(self, eventClassName, adapter); return adapter; } Modified: branches/newstyle-java-types/src/org/python/core/PyClass.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyClass.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/PyClass.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,15 +1,9 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - /** * A python class. */ - public class PyClass extends PyObject { /** * Holds the namespace for this class @@ -31,13 +25,6 @@ PyObject __getattr__, __setattr__, __delattr__, __tojava__, __del__, __contains__; - // Holds the classes for which this is a proxy - // Only used when subclassing from a Java class - protected Class<?> proxyClass; - - // xxx map 'super__*' names -> array of methods - protected java.util.HashMap super__methods; - protected PyClass() { super(); } @@ -53,120 +40,12 @@ * @see org.python.core.Py#makeClass(String, PyObject[], PyCode, PyObject) */ public PyClass(String name, PyTuple bases, PyObject dict) { - this(name, bases, dict, null); - } - - /** - * Create a python class which inherits from a java class and where we - * already have generated a proxyclass. If we do not have a pre-generated - * proxyclass, the class initialization method will create such a proxyclass - * if bases contain a java class. - * - * @param name name of the class. - * @param bases A list of base classes. - * @param dict The class dict. Normally this dict is returned by the class - * code object. - * - * @see org.python.core.Py#makeClass(String, PyObject[], PyCode, PyObject, - * Class) - */ - public PyClass(String name, PyTuple bases, PyObject dict, Class proxyClass) { - this.proxyClass = proxyClass; - init(name, bases, dict); - } - - protected Class<?> getProxyClass() { - return proxyClass; - } - - void init(String name, PyTuple bases, PyObject dict) { __name__ = name; __bases__ = bases; __dict__ = dict; findModule(dict); - if (proxyClass == null) { - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - Class<?> baseClass = null; - for (int i = 0; i < bases.size(); i++) { - Object base = bases.pyget(i); - if (base instanceof PyType) { - // xxx this works in CPython, which checks for a callable here - throw Py.TypeError("can't transmogrify old-style class into new-style " - + "class inheriting from " + ((PyType)base).getName()); - } else if (!(base instanceof PyClass)) { - throw Py.TypeError("base must be a class"); - } - Class<?> proxy = ((PyClass) base).getProxyClass(); - if (proxy != null) { - if (proxy.isInterface()) { - interfaces.add(proxy); - } else { - if (baseClass != null) { - throw Py.TypeError("no multiple inheritance for Java classes: " - + proxy.getName() + " and " + baseClass.getName()); - } - baseClass = proxy; - } - } - } - if (baseClass != null || interfaces.size() != 0) { - String proxyName = __name__; - PyObject module = dict.__finditem__("__module__"); - if (module != null) { - proxyName = module.toString() + "$" + __name__; - } - proxyClass = MakeProxies.makeProxy(baseClass, interfaces, - __name__, proxyName, __dict__); - } - } - - if (proxyClass != null) { - // xxx more efficient way without going through a PyJavaClass? - PyObject superDict = PyJavaClass.lookup(proxyClass).__findattr__( - "__dict__"); // xxx getDict perhaps? - // This code will add in the needed super__ methods to the class - PyObject snames = superDict.__finditem__("__supernames__"); - if (snames != null) { - for (PyObject item : snames.asIterable()) { - if (__dict__.__finditem__(item) == null) { - PyObject superFunc = superDict.__finditem__(item); - if (superFunc != null) { - __dict__.__setitem__(item, superFunc); - } - } - } - } - - // xxx populate super__methods, experiment. - - java.lang.reflect.Method proxy_methods[] = proxyClass.getMethods(); - - super__methods = new java.util.HashMap(); - - for (Method meth : proxy_methods) { - String meth_name = meth.getName(); - if (meth_name.startsWith("super__")) { - java.util.ArrayList samename = (java.util.ArrayList) super__methods - .get(meth_name); - if (samename == null) { - samename = new java.util.ArrayList(); - super__methods.put(meth_name, samename); - } - samename.add(meth); - } - } - - java.lang.reflect.Method[] empty_methods = new java.lang.reflect.Method[0]; - for (java.util.Iterator iter = super__methods.entrySet().iterator(); iter - .hasNext();) { - java.util.Map.Entry entry = (java.util.Map.Entry) iter.next(); - entry.setValue(((java.util.ArrayList) entry.getValue()) - .toArray(empty_methods)); - } - } - if (dict.__finditem__("__doc__") == null) { dict.__setitem__("__doc__", Py.None); } @@ -193,14 +72,6 @@ } } - public Object __tojava__(Class<?> c) { - if ((c == Object.class || c == Class.class || c == Serializable.class) - && proxyClass != null) { - return proxyClass; - } - return super.__tojava__(c); - } - // returns [PyObject, PyClass] PyObject[] lookupGivingClass(String name, boolean stop_at_java) { PyObject result = __dict__.__finditem__(name); @@ -348,11 +219,6 @@ if (this == superclass) { return true; } - if (getProxyClass() != null && superclass.getProxyClass() != null) { - if (superclass.proxyClass.isAssignableFrom(this.proxyClass)) { - return true; - } - } if (this.__bases__ == null || superclass.__bases__ == null) { return false; } Modified: branches/newstyle-java-types/src/org/python/core/PyFile.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFile.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/PyFile.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -473,7 +473,7 @@ @ExposedMethod final PyObject file_fileno() { - return new PyJavaInstance(file.fileno()); + return PyJavaType.wrapJavaObject(file.fileno()); } @ExposedMethod(names = {"__str__", "__repr__"}) Modified: branches/newstyle-java-types/src/org/python/core/PyInstance.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyInstance.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/PyInstance.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,8 +1,6 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; import java.util.Hashtable; -import java.util.StringTokenizer; -import java.io.Serializable; /** * A python class instance. @@ -38,8 +36,6 @@ PyClass pyc = (PyClass)mod.__getattr__(name.intern()); instclass = pyc; - if (javaProxy != null) - ((PyProxy) javaProxy)._setPySystemState(Py.getSystemState()); } private void writeObject(java.io.ObjectOutputStream out) @@ -82,47 +78,7 @@ private static Hashtable primitiveMap; - protected void makeProxy() { - Class c = instclass.proxyClass; - 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) { - // The javaProxy can be initialized in Py.jfindattr() - throw Py.TypeError("Proxy instance already initialized"); - } - PyObject proxyInstance = proxy._getPyInstance(); - if (proxyInstance != null && proxyInstance != this) { - // The proxy was initialized to another instance!! - throw Py.TypeError("Proxy initialization conflict"); - } - - javaProxy = proxy; - } - public Object __tojava__(Class c) { - if ((c == Object.class || c == Serializable.class) && - javaProxy != null) { - return javaProxy; - } if (c.isInstance(this)) return this; @@ -143,15 +99,9 @@ c = tmp; } - if (javaProxy == null && instclass.proxyClass != null) { - makeProxy(); - } - if (c.isInstance(javaProxy)) - return javaProxy; - if (instclass.__tojava__ != null) { // try { - PyObject ret = instclass.__tojava__.__call__(this, PyJavaClass.lookup(c)); + PyObject ret = instclass.__tojava__.__call__(this, PyType.fromClass(c)); if (ret == Py.None) return Py.NoConversion; @@ -185,10 +135,6 @@ else if (ret != Py.None) { throw Py.TypeError("__init__() should return None"); } - // Now init all superclasses that haven't already been initialized - if (javaProxy == null && instclass.proxyClass != null) { - makeProxy(); - } } public PyObject __jfindattr__(String name) { @@ -325,16 +271,7 @@ if (setter != null) { setter.__call__(this, new PyString(name), value); } else { - if (instclass.getProxyClass() != null) { - PyObject field = instclass.lookup(name, false); - if (field == null) { - noField(name, value); - } else if (!field.jtryset(this, value)) { - unassignableField(name, value); - } - } else { - __dict__.__setitem__(name, value); - } + __dict__.__setitem__(name, value); } } @@ -548,11 +485,6 @@ } catch (PyException exc) { } if (meth == null) { - // Copied form __len__() - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__len__() != 0 ? true : false; - } try { meth = __findattr__("__len__"); } catch (PyException exc) { } @@ -564,20 +496,7 @@ return ret.__nonzero__(); } - private CollectionProxy collectionProxy=null; - - private CollectionProxy getCollection() { - if (collectionProxy == null) - collectionProxy = CollectionProxy.findCollection(javaProxy); - return collectionProxy; - } - public int __len__() { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__len__(); - } - PyObject ret = invoke("__len__"); if (ret instanceof PyInteger) return ((PyInteger)ret).getValue(); @@ -585,10 +504,6 @@ } public PyObject __finditem__(int key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__finditem__(key); - } return __finditem__(new PyInteger(key)); } @@ -614,11 +529,6 @@ } public PyObject __finditem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__finditem__(key); - } - try { return invoke("__getitem__", key); } catch (PyException e) { @@ -631,32 +541,14 @@ } public PyObject __getitem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - PyObject ret = proxy.__finditem__(key); - if (ret == null) { - throw Py.KeyError(key.toString()); - } - return ret; - } return invoke("__getitem__", key); } public void __setitem__(PyObject key, PyObject value) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - proxy.__setitem__(key, value); - return; - } invoke("__setitem__", key, value); } public void __delitem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - proxy.__delitem__(key); - return; - } invoke("__delitem__", key); } @@ -688,10 +580,6 @@ } public PyObject __iter__() { - PyObject iter = getCollectionIter(); - if (iter != null) { - return iter; - } PyObject func = __findattr__("__iter__"); if (func != null) return func.__call__(); @@ -715,37 +603,6 @@ throw Py.TypeError("instance has no next() method"); } - private static CollectionIter[] iterFactories; - - private PyObject getCollectionIter() { - if (iterFactories == null) - initializeIterators(); - for (int i = 0; iterFactories[i] != null; i++) { - PyObject iter = iterFactories[i].findCollection(javaProxy); - if (iter != null) - return iter; - } - return null; - } - - private static synchronized void initializeIterators() { - if (iterFactories != null) - return; - String factories = PySystemState.registry.getProperty("python.collections", ""); - int i = 0; - StringTokenizer st = new StringTokenizer(factories, ","); - iterFactories = new CollectionIter[st.countTokens() + 2]; - iterFactories[0] = new CollectionIter(); - while (st.hasMoreTokens()) { - String s = st.nextToken(); - try { - Class factoryClass = Class.forName(s); - CollectionIter factory = (CollectionIter)factoryClass.newInstance(); - iterFactories[i++] = factory; - } catch (Throwable t) { } - } - } - public boolean __contains__(PyObject o) { PyObject func = __findattr__("__contains__"); if (func == null) Deleted: branches/newstyle-java-types/src/org/python/core/PyJavaClass.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaClass.java 2008-11-23 01:57:09 UTC (rev 5606) +++ branches/newstyle-java-types/src/org/python/core/PyJavaClass.java 2008-11-23 02:36:05 UTC (rev 5607) @@ -1,774 +0,0 @@ -// Copyright (c) Corporation for National Research Initiatives -package org.python.core; - -import java.beans.Introspector; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.EventListener; - -import org.python.core.packagecache.PackageManager; - -/** - * A wrapper around a java class. - */ -public class PyJavaClass extends PyClass { - - private static InternalTables tbl; - - public PyReflectedConstructor __init__; - - public PackageManager __mgr__; - - public String __module__; - - private boolean initialized = false; - - // Prevent recursive calls to initialize() - private boolean initializing = false; - - public synchronized final static InternalTables getInternalTables() { - if (tbl == null) { - tbl = InternalTables.createInternalTables(); - } - return tbl; - } - - public final boolean isLazy() { - return proxyClass == null; - } - - public static final PyJavaClass lookup(String name, PackageManager mgr) { - if (tbl.queryCanonical(name)) { - Class<?> c = mgr.findClass(null, name, "forced java class"); - check_lazy_allowed(c); // xxx - return lookup(c); - } - PyJavaClass ret = new PyJavaClass(name, mgr); - tbl.putLazyCanonical(name, ret); - return ret; - } - - public synchronized static final PyJavaClass lookup(Class<?> c) { - if (tbl == null) { - tbl = new InternalTables(); - PyJavaClass jc = new PyJavaClass(); - jc.init(PyJavaClass.class); - tbl.putCanonical(PyJavaClass.class, jc); - } - PyJavaClass ret = tbl.getCanonical(c); - if (ret != null) - return ret; - PyJavaClass lazy = tbl.getLazyCanonical(c.getName()); - if (lazy != null) { - initLazy(lazy); - if (lazy.proxyClass == c) { - return lazy; - } - } - Class<?> parent = c.getDeclaringClass(); - ret = parent == null ? new PyJavaClass(c) : new PyJavaInnerClass(c, lookup(parent)); - tbl.putCanonical(c, ret); - return ret; - } - - private PyJavaClass() {} - - protected PyJavaClass(Class<?> c) { - init(c); - } - - /** - * Set the full name of this class. - */ - private void setName(String name) { - int dotIndex = name.lastIndexOf("."); - if (dotIndex == -1) { - __name__ = name; - __module__ = ""; - } else { - __name__ = name.substring(name.lastIndexOf(".") + 1, name.length()); - __module__ = name.substring(0, name.lastIndexOf(".")); - } - } - - private String fullName() { - if (__module__ == "") - return __name__; - else - return __module__ + "." + __name__; - } - - protected PyJavaClass(String name, PackageManager mgr) { - setName(name); - this.__mgr__ = mgr; - } - - protected void findModule(PyObject dict) {} - - protected Class<?> getProxyClass() { - initialize(); - return proxyClass; - } - - // for the moment trying to lazily load a PyObject subclass - // is not allowed, (because of the PyJavaClass vs PyType class mismatch) - // pending PyJavaClass becoming likely a subclass of PyType - private static final void check_lazy_allowed(Class<?> c) { - if (PyObject.class.isAssignableFrom(c)) { // xxx - throw Py.TypeError("cannot lazy load PyObject subclass"); - } - } - - private static final void initLazy(PyJavaClass jc) { - Class<?> c = jc.__mgr__.findClass(null, jc.fullName(), "lazy java class"); - check_lazy_allowed(c); // xxx - jc.init(c); - tbl.putCanonical(jc.proxyClass, jc); - jc.__mgr__ = null; - } - - private synchronized void initialize() { - if (initialized || initializing) { - return; - } - initializing = true; - synchronized (PyJavaClass.class) { - if (proxyClass == null) { - initLazy(this); - } - } - init__bases__(proxyClass); - ... [truncated message content] |