|
1 /* |
|
2 * Copyright (c) 2007-2010 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 "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 * Instance handler |
|
17 * |
|
18 */ |
|
19 package com.nokia.trace.dictionary.model.handlers; |
|
20 |
|
21 import org.xml.sax.Attributes; |
|
22 |
|
23 import com.nokia.trace.dictionary.TraceDictionaryEngine; |
|
24 import com.nokia.trace.dictionary.model.DecodeObject; |
|
25 import com.nokia.trace.dictionary.model.DictionaryContentHandler; |
|
26 import com.nokia.trace.dictionary.model.DictionaryContentVariables; |
|
27 import com.nokia.trace.dictionary.model.DictionaryDecodeModel; |
|
28 import com.nokia.trace.dictionary.model.Location; |
|
29 import com.nokia.trace.dictionary.model.Trace; |
|
30 import com.nokia.trace.dictionary.model.TraceData; |
|
31 import com.nokia.trace.dictionary.model.TraceGroup; |
|
32 import com.nokia.trace.dictionary.model.DictionaryContentVariables.ParentDecodeObject; |
|
33 import com.nokia.trace.eventrouter.TraceEvent; |
|
34 |
|
35 /** |
|
36 * Instance handler |
|
37 */ |
|
38 final class InstanceHandler extends BaseHandler { |
|
39 |
|
40 /** |
|
41 * Tag name this handler handles |
|
42 */ |
|
43 private static final String INSTANCE_TAG = "instance"; //$NON-NLS-1$ |
|
44 |
|
45 /** |
|
46 * Constructor |
|
47 * |
|
48 * @param model |
|
49 * the model |
|
50 */ |
|
51 InstanceHandler(DictionaryDecodeModel model) { |
|
52 super(model, INSTANCE_TAG); |
|
53 } |
|
54 |
|
55 /* |
|
56 * (non-Javadoc) |
|
57 * |
|
58 * @see |
|
59 * com.nokia.trace.dictionary.model.handlers.BaseHandler#processStartElement |
|
60 * (org.xml.sax.Attributes, |
|
61 * com.nokia.trace.dictionary.model.DictionaryContentHandler) |
|
62 */ |
|
63 @Override |
|
64 public void processStartElement(Attributes atts, |
|
65 DictionaryContentHandler handler) { |
|
66 DictionaryContentVariables variables = handler.getVariables(); |
|
67 // Get parent group |
|
68 TraceGroup parentGroup = variables.getPreviousGroup(); |
|
69 // Get this traces data-ref value |
|
70 int dataRef = variables.getPreviousTraceDataRef(); |
|
71 // Get this traces name |
|
72 String traceName = variables.getPreviousTraceName(); |
|
73 // Get trace data for this data-ref value |
|
74 TraceData traceData = model.getTraceData(dataRef); |
|
75 // Get location for this instance |
|
76 Location location = model.getLocation(Integer.parseInt(atts |
|
77 .getValue(LOCREF))); |
|
78 |
|
79 // Create new trace instance |
|
80 Trace trace = model.getFactory().createTrace( |
|
81 Integer.parseInt(atts.getValue(ID)), traceName, traceData, |
|
82 location, Integer.parseInt(atts.getValue(LINE)), |
|
83 atts.getValue(METHODNAME), atts.getValue(CLASSNAME), |
|
84 parentGroup); |
|
85 |
|
86 // Add trace to the group |
|
87 Trace oldTrace = parentGroup.addTrace(trace); |
|
88 |
|
89 // Check collision |
|
90 trace = checkCollision(oldTrace, trace, handler); |
|
91 |
|
92 // Set this trace to be the previous trace instance and decode object |
|
93 variables.setPreviousTrace(trace); |
|
94 variables.setParentDecodeObject(ParentDecodeObject.TRACEINSTANCE); |
|
95 |
|
96 // Add trace to the trace instance list |
|
97 if (oldTrace != trace) { |
|
98 variables.getTraceInstanceList().addTrace(trace); |
|
99 } |
|
100 } |
|
101 |
|
102 /* |
|
103 * (non-Javadoc) |
|
104 * |
|
105 * @see |
|
106 * com.nokia.trace.dictionary.model.handlers.BaseHandler#processEndElement |
|
107 * (java.lang.StringBuffer, java.lang.Object, |
|
108 * com.nokia.trace.dictionary.model.DictionaryContentHandler, |
|
109 * com.nokia.trace.dictionary.model.DecodeObject) |
|
110 */ |
|
111 @Override |
|
112 public void processEndElement(StringBuffer elementContent, |
|
113 Object unFinishedObject, DictionaryContentHandler handler, |
|
114 DecodeObject parentObject) { |
|
115 // Parent decode object is set back to trace |
|
116 handler.getVariables().setParentDecodeObject(ParentDecodeObject.TRACE); |
|
117 } |
|
118 |
|
119 /** |
|
120 * Check collision |
|
121 * |
|
122 * @param oldTrace |
|
123 * old trace |
|
124 * @param newTrace |
|
125 * new trace |
|
126 * @param handler |
|
127 * dictionary content handler |
|
128 * @return the trace which caused the collision or null if everything is OK |
|
129 */ |
|
130 private Trace checkCollision(Trace oldTrace, Trace newTrace, |
|
131 DictionaryContentHandler handler) { |
|
132 boolean collision = true; |
|
133 // If old trace is null, everything is ok. If not, check collision |
|
134 if (oldTrace != null) { |
|
135 // Trace data must be the same |
|
136 if (oldTrace.getTraceData() == newTrace.getTraceData()) { |
|
137 // Locations must be same |
|
138 if (oldTrace.getLocation() == newTrace.getLocation()) { |
|
139 // Line numbers must be same |
|
140 if (oldTrace.getLineNumber() == newTrace.getLineNumber()) { |
|
141 // Class names must be same |
|
142 String className = oldTrace.getClassName(); |
|
143 String className2 = newTrace.getClassName(); |
|
144 if (className == null) { |
|
145 className = ""; //$NON-NLS-1$ |
|
146 } |
|
147 if (className2 == null) { |
|
148 className2 = ""; //$NON-NLS-1$ |
|
149 } |
|
150 if (className.equals(className2)) { |
|
151 // Method names must be same |
|
152 String methodName = oldTrace.getMethodName(); |
|
153 String methodName2 = newTrace.getMethodName(); |
|
154 if (methodName == null) { |
|
155 methodName = ""; //$NON-NLS-1$ |
|
156 } |
|
157 if (methodName2 == null) { |
|
158 methodName2 = ""; //$NON-NLS-1$ |
|
159 } |
|
160 if (methodName.equals(methodName2)) { |
|
161 collision = false; |
|
162 } |
|
163 } |
|
164 } |
|
165 } |
|
166 } |
|
167 if (collision) { |
|
168 newTrace = oldTrace; |
|
169 TraceEvent event = new TraceEvent(TraceEvent.WARNING, Messages |
|
170 .getString("InstanceHandler.CollisionTraceID") //$NON-NLS-1$ |
|
171 + oldTrace.getId()); |
|
172 event.setCategory(EVENT_CATEGORY); |
|
173 event.setSource(Integer.valueOf(handler.getLocator() |
|
174 .getLineNumber())); |
|
175 TraceDictionaryEngine.postEvent(event); |
|
176 } |
|
177 } |
|
178 return newTrace; |
|
179 } |
|
180 |
|
181 } |