KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > core > InternalTables


1 // Copyright 2000 Samuele Pedroni
2

3 package org.python.core;
4
5 import java.util.StringTokenizer JavaDoc;
6
7 public abstract class InternalTables {
8
9     // x__ --> org.python.core.X__InternalTables
10
// (x|X)__> --> org.python.core.X__InternalTables
11
// >(x|X)__ --> org.python.core.InternalTablesX__
12
// other (X__|__.__) --> other
13
static private InternalTables tryImpl(String JavaDoc 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 JavaDoc buf = new StringBuffer JavaDoc("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             // System.err.println("*InternalTables*-create-try: "+id);
37
return (InternalTables)Class.forName(id).newInstance();
38         }
39         catch(Throwable JavaDoc e) {
40             // System.err.println(" exc: "+e); // ??dbg
41
return null;
42         }
43     }
44
45     static InternalTables createInternalTables() {
46         java.util.Properties JavaDoc registry = PySystemState.registry;
47         if (registry == null) {
48             throw new java.lang.IllegalStateException JavaDoc(
49                 "Jython interpreter state not initialized. " +
50                 "You need to call PySystemState.initialize or " +
51                 "PythonInterpreter.initialize.");
52         }
53         String JavaDoc cands = registry.getProperty(
54                                     "python.options.internalTablesImpl");
55         if (cands == null) {
56             String JavaDoc 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 JavaDoc candEnum = new StringTokenizer JavaDoc(cands,":");
64         while (candEnum.hasMoreTokens()) {
65             InternalTables tbl = tryImpl(candEnum.nextToken().trim());
66             if (tbl != null) return tbl;
67         }
68         return null; // never reached
69
}
70
71     protected abstract boolean queryCanonical(String JavaDoc name);
72     protected abstract PyJavaClass getCanonical(Class JavaDoc c);
73     protected abstract PyJavaClass getLazyCanonical(String JavaDoc name);
74
75     protected abstract void putCanonical(Class JavaDoc c, PyJavaClass canonical);
76     protected abstract void putLazyCanonical(String JavaDoc name,
77                                              PyJavaClass canonical);
78
79     protected abstract Class JavaDoc getAdapterClass(Class JavaDoc c);
80     protected abstract void putAdapterClass(Class JavaDoc c,Class JavaDoc ac);
81
82     protected abstract Object JavaDoc getAdapter(Object JavaDoc o,String JavaDoc evc);
83     protected abstract void putAdapter(Object JavaDoc o,String JavaDoc evc,Object JavaDoc 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 JavaDoc _next();
96     public abstract void _flushCurrent();
97
98     public abstract void _flush(PyJavaClass jc);
99
100
101     static public class _LazyRep {
102         public String JavaDoc name;
103         public PackageManager mgr;
104
105         _LazyRep(String JavaDoc name, PackageManager mgr) {
106             this.name = name;
107             this.mgr = mgr;
108         }
109     }
110
111 }
112
Popular Tags