001: // Copyright 2000 Samuele Pedroni
002:
003: package org.python.core;
004:
005: import java.util.*;
006:
007: /**
008: *
009: * @deprecated Java1 no longer supported.
010: *
011: */
012: public class InternalTables1 extends InternalTables {
013:
014: protected static interface Table {
015: public Object put(Object key, Object obj);
016:
017: public Object get(Object key);
018:
019: public Object remove(Object key);
020:
021: public void clear();
022: }
023:
024: private static class TableProvid1 extends Hashtable implements
025: Table {
026: }
027:
028: final protected static short JCLASS = 0;
029:
030: final protected static short LAZY_JCLASS = 1;
031:
032: final protected static short ADAPTER_CLASS = 2;
033:
034: final protected static short ADAPTER = 3;
035:
036: protected Table classes;
037:
038: protected Table temp;
039:
040: protected Table counters;
041:
042: protected Table lazyClasses;
043:
044: protected Table adapterClasses;
045:
046: protected final short GSTABLE = 1;
047:
048: protected final short JCSTABLE = 2;
049:
050: protected short keepstable;
051:
052: protected void beginStable(short lvl) {
053: this .keepstable = lvl;
054: }
055:
056: protected void classesPut(Class c, Object jc) {
057: if (this .keepstable == this .JCSTABLE) {
058: this .temp.put(c, jc);
059: // System.err.println("temp-defer-canonical: "+c.getName());
060: } else {
061: this .classes.put(c, jc);
062: }
063: String name = c.getName();
064: Integer cnt = (Integer) this .counters.get(name);
065: if (cnt == null) {
066: this .counters.put(name, new Integer(1));
067: this .lazyClasses.remove(name);
068: } else {
069: this .counters.put(name, new Integer(cnt.intValue() + 1));
070: }
071: }
072:
073: protected Object classesGet(Class c) {
074: Object o = this .classes.get(c);
075: if (o != null || this .keepstable != this .JCSTABLE)
076: return o;
077: return this .temp.get(c);
078: }
079:
080: protected void endStable() {
081: if (this .keepstable == this .JCSTABLE)
082: commitTemp();
083: this .keepstable = 0;
084: }
085:
086: protected void classesDec(String name) {
087: int c = ((Integer) this .counters.get(name)).intValue();
088: if (c == 1)
089: this .counters.remove(name);
090: else
091: this .counters.put(name, new Integer(c - 1));
092: }
093:
094: protected void commitTemp() {
095: for (Enumeration e = ((Hashtable) this .temp).keys(); e
096: .hasMoreElements();) {
097: Object c = e.nextElement();
098: this .classes.put(c, this .temp.get(c));
099: }
100: this .temp.clear();
101: }
102:
103: protected boolean queryCanonical(String name) {
104: return this .counters.get(name) != null
105: || this .lazyClasses.get(name) != null;
106: }
107:
108: protected PyJavaClass getCanonical(Class c) {
109: return (PyJavaClass) classesGet(c);
110: }
111:
112: protected PyJavaClass getLazyCanonical(String name) {
113: return (PyJavaClass) this .lazyClasses.get(name);
114: }
115:
116: protected void putCanonical(Class c, PyJavaClass canonical) {
117: classesPut(c, canonical);
118: }
119:
120: protected void putLazyCanonical(String name, PyJavaClass canonical) {
121: this .lazyClasses.put(name, canonical);
122: }
123:
124: protected Class getAdapterClass(Class c) {
125: return (Class) this .adapterClasses.get(c);
126: }
127:
128: protected void putAdapterClass(Class c, Class ac) {
129: this .adapterClasses.put(c, ac);
130: }
131:
132: private Hashtable adapters;
133:
134: protected Object getAdapter(Object o, String evc) {
135: return this .adapters
136: .get(evc + '$' + System.identityHashCode(o));
137: }
138:
139: protected void putAdapter(Object o, String evc, Object ad) {
140: this .adapters.put(evc + '$' + System.identityHashCode(o), ad);
141: }
142:
143: protected short iterType;
144:
145: protected Object cur;
146:
147: private Enumeration enumm;
148:
149: private Hashtable enumTable;
150:
151: public void _beginCanonical() {
152: beginStable(this .JCSTABLE);
153: this .enumm = ((TableProvid1) this .classes).keys();
154: this .enumTable = (TableProvid1) this .classes;
155: this .iterType = JCLASS;
156: }
157:
158: public void _beginLazyCanonical() {
159: this .enumm = ((TableProvid1) this .lazyClasses).keys();
160: this .enumTable = (TableProvid1) this .lazyClasses;
161: this .iterType = LAZY_JCLASS;
162: }
163:
164: public void _beginOverAdapterClasses() {
165: this .enumm = ((TableProvid1) this .adapterClasses).keys();
166: this .enumTable = (TableProvid1) this .adapterClasses;
167: this .iterType = ADAPTER_CLASS;
168:
169: }
170:
171: public void _beginOverAdapters() {
172: this .enumm = this .adapters.keys();
173: this .enumTable = this .adapters;
174: this .iterType = ADAPTER;
175: }
176:
177: public Object _next() {
178: if (this .enumm.hasMoreElements()) {
179: this .cur = this .enumm.nextElement();
180: switch (this .iterType) {
181: case JCLASS:
182: return (PyJavaClass) this .classes.get(this .cur);
183: case LAZY_JCLASS:
184: PyJavaClass lazy = (PyJavaClass) this .lazyClasses
185: .get(this .cur);
186: return new _LazyRep(lazy.__name__, lazy.__mgr__);
187: case ADAPTER_CLASS:
188: return this .cur;
189: case ADAPTER:
190: return this .adapters.get(this .cur).getClass()
191: .getInterfaces()[0];
192: }
193: }
194: this .cur = null;
195: this .enumm = null;
196: endStable();
197: return null;
198: }
199:
200: public void _flushCurrent() {
201: this .enumTable.remove(this .cur);
202: if (this .iterType == JCLASS)
203: classesDec(((Class) this .cur).getName());
204: }
205:
206: public void _flush(PyJavaClass jc) {
207: Class c = jc.proxyClass;
208: if (c == null) {
209: this .lazyClasses.remove(jc.__name__);
210: } else {
211: this .classes.remove(c);
212: classesDec(jc.__name__);
213: }
214: }
215:
216: protected InternalTables1(boolean fake) {
217: }
218:
219: public InternalTables1() {
220: this .classes = new TableProvid1();
221: this .temp = new TableProvid1();
222: this .counters = new TableProvid1();
223: this .lazyClasses = new TableProvid1();
224:
225: this .adapterClasses = new TableProvid1();
226:
227: this .adapters = new Hashtable();
228: }
229: }
|