1 package org.andromda.core.metafacade;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.Map;
6
7
8
9
10
11
12
13 public final class MetafacadeCache
14 implements Serializable
15 {
16 private static final long serialVersionUID = 34L;
17
18
19
20
21
22
23 public static MetafacadeCache newInstance()
24 {
25 return new MetafacadeCache();
26 }
27
28 private MetafacadeCache()
29 {
30
31 }
32
33
34
35
36 private String namespace;
37
38
39
40
41
42
43 public final void setNamespace(final String namespace)
44 {
45 this.namespace = namespace;
46 }
47
48
49
50
51 private final Map<Object, Map<Class, Map<String, MetafacadeBase>>> metafacadeCache = new HashMap<Object, Map<Class, Map<String, MetafacadeBase>>>();
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public final MetafacadeBase get(
67 final Object mappingObject,
68 final Class metafacadeClass)
69 {
70 MetafacadeBase metafacade = null;
71 final Map<Class, Map<String, MetafacadeBase>> namespaceMetafacadeCache = this.metafacadeCache.get(mappingObject);
72 if (namespaceMetafacadeCache != null)
73 {
74 final Map<String, MetafacadeBase> metafacadeCache = namespaceMetafacadeCache.get(metafacadeClass);
75 if (metafacadeCache != null)
76 {
77 metafacade = metafacadeCache.get(this.namespace);
78 }
79 }
80 return metafacade;
81 }
82
83
84
85
86
87
88
89
90 public final void add(
91 final Object mappingObject,
92 final MetafacadeBase metafacade)
93 {
94 Map<Class, Map<String, MetafacadeBase>> namespaceMetafacadeCache = this.metafacadeCache.get(mappingObject);
95 if (namespaceMetafacadeCache == null)
96 {
97 namespaceMetafacadeCache = new HashMap<Class, Map<String, MetafacadeBase>>();
98 this.metafacadeCache.put(mappingObject, namespaceMetafacadeCache);
99 }
100 Map<String, MetafacadeBase> metafacadeCache = namespaceMetafacadeCache.get(metafacade.getClass());
101 if (metafacadeCache == null)
102 {
103 metafacadeCache = new HashMap<String, MetafacadeBase>();
104 namespaceMetafacadeCache.put(
105 metafacade.getClass(),
106 metafacadeCache);
107 }
108 metafacadeCache.put(this.namespace, metafacade);
109 }
110
111
112
113
114 public final void clear()
115 {
116 this.metafacadeCache.clear();
117 }
118
119
120
121
122 public String toString()
123 {
124 return this.metafacadeCache.toString();
125 }
126 }