2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.corext.template;
7 import java.util.HashMap;
8 import java.util.Iterator;
11 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
12 import net.sourceforge.phpdt.internal.corext.template.php.PHPContextType;
13 import net.sourceforge.phpdt.internal.corext.template.php.PHPDocContextType;
18 * A singleton to keep track of all known context types.
20 public class ContextTypeRegistry {
23 private static ContextTypeRegistry fInstance;
25 /** all known context types */
26 private final Map fContextTypes= new HashMap();
29 * Returns the single instance of this class.
31 public static ContextTypeRegistry getInstance() {
32 if (fInstance == null)
33 fInstance= new ContextTypeRegistry();
39 * Adds a context type to the registry.
41 public void add(ContextType contextType) {
42 fContextTypes.put(contextType.getName(), contextType);
46 * Removes a context type from the registry.
48 public void remove(ContextType contextType) {
49 fContextTypes.remove(contextType.getName());
53 * Returns the context type if the name is valid, <code>null</code> otherwise.
55 public ContextType getContextType(String name) {
56 return (ContextType) fContextTypes.get(name);
60 * Returns an iterator over the registered context type names.
62 public Iterator iterator() {
63 return fContextTypes.keySet().iterator();
66 // XXX bootstrap with java and javadoc context types
67 private ContextTypeRegistry() {
68 add(new PHPContextType());
69 add(new PHPDocContextType());
70 add(new HTMLContextType());