a401fe86d2c1878e5b081140ec6ff4e05d1339ef
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / objects / PCMMResourceSet.java
1 /**
2  @header@
3  */
4 package org.pcmm.objects;
5
6 import java.util.HashMap;
7 import java.util.Map;
8
9 /**
10  * This stores and handles the PCMM resources.
11  *
12  */
13 public class PCMMResourceSet {
14
15     private Map<Object, PCMMResourcesMapper<?, ?>> mapper;
16
17     private static PCMMResourceSet instance;
18
19     private PCMMResourceSet() {
20         mapper = new HashMap<Object, PCMMResourcesMapper<?, ?>>();
21     }
22
23     public static PCMMResourceSet getInstance() {
24         if (instance == null)
25             instance = new PCMMResourceSet();
26         return instance;
27     }
28
29     /**
30      * adds a new mapping
31      *
32      * @param key
33      *            to be used for identifying mapped structure
34      * @return resource mapper
35      */
36     @SuppressWarnings("unchecked")
37     public <M, T extends PCMMResource> PCMMResourcesMapper<M, T> getMappedResources(
38         Object key) {
39         return (PCMMResourcesMapper<M, T>) mapper.get(key);
40     }
41
42     public <M, T extends PCMMResource> void mapResources(Object key,
43             PCMMResourcesMapper<M, T> resources) {
44         mapper.put(key, resources);
45     }
46
47     public void removeMapping(Object key) {
48         mapper.remove(key);
49     }
50
51     public void removeAllMappings() {
52         mapper.clear();
53     }
54
55 }