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