|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.carbide.cpp.internal.pi.model; |
|
19 |
|
20 import java.util.Enumeration; |
|
21 import java.util.Hashtable; |
|
22 import java.util.Iterator; |
|
23 import java.util.LinkedHashMap; |
|
24 import java.util.Vector; |
|
25 |
|
26 public class TraceDataRepository |
|
27 { |
|
28 private static Hashtable<Integer,LinkedHashMap<Class,ParsedTraceData>> analysisSpecificTraces; |
|
29 private static TraceDataRepository instance; |
|
30 |
|
31 public static TraceDataRepository getInstance() { |
|
32 if (instance == null) { |
|
33 instance = new TraceDataRepository(); |
|
34 } |
|
35 return instance; |
|
36 } |
|
37 |
|
38 // singleton |
|
39 private TraceDataRepository() |
|
40 { |
|
41 if (analysisSpecificTraces == null) |
|
42 analysisSpecificTraces = new Hashtable<Integer,LinkedHashMap<Class,ParsedTraceData>>(); |
|
43 } |
|
44 |
|
45 public void registerTraces(int analysisId) { |
|
46 if (analysisSpecificTraces.get(analysisId) == null) { |
|
47 analysisSpecificTraces.put(new Integer(analysisId), new LinkedHashMap<Class,ParsedTraceData>()); |
|
48 } |
|
49 } |
|
50 |
|
51 public void insertTraceCollection(Class traceClass, ParsedTraceData traceData, int analysisId) |
|
52 { |
|
53 LinkedHashMap<Class,ParsedTraceData> tracesForMyId = getTraceCollection(analysisId); |
|
54 if (tracesForMyId == null) |
|
55 { |
|
56 tracesForMyId = new LinkedHashMap<Class,ParsedTraceData>(); |
|
57 } |
|
58 if (traceClass != null && traceData != null && traceData.traceData != null) |
|
59 { |
|
60 tracesForMyId.put(traceClass, traceData); |
|
61 analysisSpecificTraces.put(new Integer(analysisId), tracesForMyId); |
|
62 } |
|
63 } |
|
64 |
|
65 // public ParsedTraceData getTrace(Class traceClass) |
|
66 // { |
|
67 // return traces.get(traceClass); |
|
68 // } |
|
69 |
|
70 public ParsedTraceData getTrace(int analysisId, Class traceClass) |
|
71 { |
|
72 if (analysisSpecificTraces == null || traceClass == null) |
|
73 return null; |
|
74 |
|
75 LinkedHashMap<Class,ParsedTraceData> tmp = analysisSpecificTraces.get(new Integer(analysisId)); |
|
76 |
|
77 if (tmp == null) |
|
78 return null; |
|
79 |
|
80 return tmp.get(traceClass); |
|
81 } |
|
82 |
|
83 public Enumeration<FunctionResolver> getResolvers(int analysisId) |
|
84 { |
|
85 Vector<FunctionResolver> resolvers = new Vector<FunctionResolver>(); |
|
86 |
|
87 if (analysisSpecificTraces == null) |
|
88 return resolvers.elements(); |
|
89 |
|
90 LinkedHashMap<Class,ParsedTraceData> tmp = analysisSpecificTraces.get(new Integer(analysisId)); |
|
91 |
|
92 Iterator<ParsedTraceData> e = tmp.values().iterator(); |
|
93 while (e.hasNext()) |
|
94 { |
|
95 ParsedTraceData data = (ParsedTraceData)e.next(); |
|
96 if (data.functionResolvers != null) |
|
97 { |
|
98 for (int i = 0; i < data.functionResolvers.length; i++) |
|
99 { |
|
100 resolvers.add(data.functionResolvers[i]); |
|
101 } |
|
102 } |
|
103 } |
|
104 |
|
105 return resolvers.elements(); |
|
106 } |
|
107 |
|
108 public ParsedTraceData getTrace(int analysisId, String className) |
|
109 { |
|
110 Class traceClass; |
|
111 try |
|
112 { |
|
113 traceClass = Class.forName(className); |
|
114 } |
|
115 catch (ClassNotFoundException e2) |
|
116 { |
|
117 return null; |
|
118 } |
|
119 |
|
120 if (analysisSpecificTraces == null) |
|
121 return null; |
|
122 |
|
123 LinkedHashMap<Class,ParsedTraceData> tmp = analysisSpecificTraces.get(new Integer(analysisId)); |
|
124 |
|
125 if (tmp == null) |
|
126 return null; |
|
127 |
|
128 return (ParsedTraceData)tmp.get(traceClass); |
|
129 } |
|
130 |
|
131 public Iterator<ParsedTraceData> getTraceCollectionIter(int analysisId) |
|
132 { |
|
133 if (analysisSpecificTraces == null) |
|
134 return null; |
|
135 |
|
136 LinkedHashMap<Class,ParsedTraceData> tmp = analysisSpecificTraces.get(new Integer(analysisId)); |
|
137 |
|
138 if (tmp == null) |
|
139 return null; |
|
140 |
|
141 return tmp.values().iterator(); |
|
142 } |
|
143 |
|
144 public LinkedHashMap<Class,ParsedTraceData> getTraceCollection(int analysisId) |
|
145 { |
|
146 if (analysisSpecificTraces == null) |
|
147 return null; |
|
148 |
|
149 LinkedHashMap<Class,ParsedTraceData> tmp = analysisSpecificTraces.get(new Integer(analysisId)); |
|
150 |
|
151 if (tmp == null) |
|
152 return null; |
|
153 |
|
154 return tmp; |
|
155 } |
|
156 |
|
157 public void removeTraces(int analysisId) |
|
158 { |
|
159 if (analysisSpecificTraces != null) |
|
160 analysisSpecificTraces.remove(new Integer(analysisId)); |
|
161 } |
|
162 |
|
163 public void removeAll() |
|
164 { |
|
165 if (analysisSpecificTraces != null) |
|
166 analysisSpecificTraces.clear(); |
|
167 } |
|
168 } |