db8650a33e95ffeeeb423a5568b395884498c288
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / template / ContextTypeRegistry.java
1 /*
2  * (c) Copyright IBM Corp. 2000, 2001.
3  * All Rights Reserved.
4  */
5 package net.sourceforge.phpdt.internal.corext.template;
6
7 import java.util.HashMap;
8 import java.util.Iterator;
9 import java.util.Map;
10
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;
14
15
16
17 /**
18  * A singleton to keep track of all known context types.
19  */
20 public class ContextTypeRegistry {
21
22         /** the singleton */
23         private static ContextTypeRegistry fInstance;
24         
25         /** all known context types */
26         private final Map fContextTypes= new HashMap();
27         
28         /**
29          * Returns the single instance of this class.
30          */
31         public static ContextTypeRegistry getInstance() {
32                 if (fInstance == null)
33                         fInstance= new ContextTypeRegistry();
34                         
35                 return fInstance;       
36         }
37
38         /**
39          * Adds a context type to the registry.
40          */     
41         public void add(ContextType contextType) {
42                 fContextTypes.put(contextType.getName(), contextType);
43         }
44         
45         /**
46          * Removes a context type from the registry.
47          */
48         public void remove(ContextType contextType) {
49                 fContextTypes.remove(contextType.getName());
50         }
51
52         /**
53          * Returns the context type if the name is valid, <code>null</code> otherwise.
54          */
55         public ContextType getContextType(String name) {
56                 return (ContextType) fContextTypes.get(name);
57         }
58         
59         /**
60          * Returns an iterator over the registered context type names.
61          */
62         public Iterator iterator() {
63                 return fContextTypes.keySet().iterator();       
64         }
65
66         // XXX bootstrap with java and javadoc context types
67         private ContextTypeRegistry() {
68                 add(new PHPContextType());
69     add(new PHPDocContextType());
70                 add(new HTMLContextType());
71         }
72
73 }