1 3 package org.python.core; 4 5 import java.util.StringTokenizer ; 6 7 public abstract class InternalTables { 8 9 static private InternalTables tryImpl(String id) { 14 try { 15 if(id.indexOf('.') < 0) { 16 boolean glue = true; 17 boolean front = true; 18 if (id.charAt(0) == '>') { 19 id = id.substring(1); 20 front = false; 21 } else if (id.charAt(id.length()-1)=='>') { 22 id = id.substring(0,id.length()-1); 23 } else if (!Character.isLowerCase(id.charAt(0))) glue = false; 24 if (glue) { 25 StringBuffer buf = new StringBuffer ("org.python.core."); 26 if (!front) buf.append("InternalTables"); 27 if (Character.isLowerCase(id.charAt(0))) { 28 buf.append(Character.toUpperCase(id.charAt(0))); 29 buf.append(id.substring(1)); 30 } else 31 buf.append(id); 32 if (front) buf.append("InternalTables"); 33 id = buf.toString(); 34 } 35 } 36 return (InternalTables)Class.forName(id).newInstance(); 38 } 39 catch(Throwable e) { 40 return null; 42 } 43 } 44 45 static InternalTables createInternalTables() { 46 java.util.Properties registry = PySystemState.registry; 47 if (registry == null) { 48 throw new java.lang.IllegalStateException ( 49 "Jython interpreter state not initialized. " + 50 "You need to call PySystemState.initialize or " + 51 "PythonInterpreter.initialize."); 52 } 53 String cands = registry.getProperty( 54 "python.options.internalTablesImpl"); 55 if (cands == null) { 56 String version = System.getProperty("java.version"); 57 if (version.compareTo("1.2") >= 0) 58 cands = ">2:>1"; 59 else 60 cands = ">1"; 61 } else 62 cands = cands + ":>2:>1"; 63 StringTokenizer candEnum = new StringTokenizer (cands,":"); 64 while (candEnum.hasMoreTokens()) { 65 InternalTables tbl = tryImpl(candEnum.nextToken().trim()); 66 if (tbl != null) return tbl; 67 } 68 return null; } 70 71 protected abstract boolean queryCanonical(String name); 72 protected abstract PyJavaClass getCanonical(Class c); 73 protected abstract PyJavaClass getLazyCanonical(String name); 74 75 protected abstract void putCanonical(Class c, PyJavaClass canonical); 76 protected abstract void putLazyCanonical(String name, 77 PyJavaClass canonical); 78 79 protected abstract Class getAdapterClass(Class c); 80 protected abstract void putAdapterClass(Class c,Class ac); 81 82 protected abstract Object getAdapter(Object o,String evc); 83 protected abstract void putAdapter(Object o,String evc,Object ad); 84 85 public boolean _doesSomeAutoUnload() { return false; } 86 87 public void _forceCleanup() {} 88 89 public abstract void _beginCanonical(); 90 public abstract void _beginLazyCanonical(); 91 92 public abstract void _beginOverAdapterClasses(); 93 public abstract void _beginOverAdapters(); 94 95 public abstract Object _next(); 96 public abstract void _flushCurrent(); 97 98 public abstract void _flush(PyJavaClass jc); 99 100 101 static public class _LazyRep { 102 public String name; 103 public PackageManager mgr; 104 105 _LazyRep(String name, PackageManager mgr) { 106 this.name = name; 107 this.mgr = mgr; 108 } 109 } 110 111 } 112 | Popular Tags |