added Context.java
[org.ibex.classgen.git] / src / org / ibex / classgen / Context.java
diff --git a/src/org/ibex/classgen/Context.java b/src/org/ibex/classgen/Context.java
new file mode 100644 (file)
index 0000000..99d9819
--- /dev/null
@@ -0,0 +1,20 @@
+package org.ibex.classgen;
+import java.util.*;
+
+/**
+ *  a Context is like a ClassLoader in that it maps from class names
+ *  to bytecode-implementations of classes, except that it doesn't
+ *  actually load the resolved class -- it simply creates a (cached)
+ *  ClassFile for it.
+ */
+public class Context {
+
+    private Hashtable cache = new Hashtable();
+
+    public Context() { }
+
+    public void add(ClassFile cf) { cache.put(cf.getType().getName(), cf); }
+    public Collection enumerateClassFiles() { return cache.values(); }
+    public ClassFile resolve(String classname) { return (ClassFile)cache.get(classname); }
+
+}