|
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 * Group 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.DictionaryDecodeModel; |
|
27 import com.nokia.trace.dictionary.model.TraceComponent; |
|
28 import com.nokia.trace.dictionary.model.TraceGroup; |
|
29 import com.nokia.trace.dictionary.model.DictionaryContentVariables.ParentDecodeObject; |
|
30 import com.nokia.trace.eventrouter.TraceEvent; |
|
31 |
|
32 /** |
|
33 * Group handler |
|
34 */ |
|
35 final class GroupHandler extends BaseHandler { |
|
36 |
|
37 /** |
|
38 * Tag name this handler handles |
|
39 */ |
|
40 private static final String GROUP_TAG = "group"; //$NON-NLS-1$ |
|
41 |
|
42 /** |
|
43 * Constructor |
|
44 * |
|
45 * @param model |
|
46 * the model |
|
47 */ |
|
48 GroupHandler(DictionaryDecodeModel model) { |
|
49 super(model, GROUP_TAG); |
|
50 } |
|
51 |
|
52 /* |
|
53 * (non-Javadoc) |
|
54 * |
|
55 * @see |
|
56 * com.nokia.trace.dictionary.model.handlers.BaseHandler#processStartElement |
|
57 * (org.xml.sax.Attributes, |
|
58 * com.nokia.trace.dictionary.model.DictionaryContentHandler) |
|
59 */ |
|
60 @Override |
|
61 public void processStartElement(Attributes atts, |
|
62 DictionaryContentHandler handler) { |
|
63 |
|
64 // Get parent component |
|
65 TraceComponent parentComponent = handler.getVariables() |
|
66 .getPreviousComponent(); |
|
67 |
|
68 // Create new group |
|
69 TraceGroup group = model.getFactory().createTraceGroup( |
|
70 Integer.parseInt(atts.getValue(ID)), atts.getValue(NAME), |
|
71 atts.getValue(PREFIX), atts.getValue(SUFFIX), parentComponent); |
|
72 |
|
73 // Add group to the component |
|
74 TraceGroup oldGroup = parentComponent.addGroup(group); |
|
75 |
|
76 // Check collision |
|
77 group = checkCollision(oldGroup, group, handler); |
|
78 |
|
79 // Set this group as the previous group and decode object |
|
80 handler.getVariables().setPreviousGroup(group); |
|
81 handler.getVariables().setParentDecodeObject(ParentDecodeObject.GROUP); |
|
82 } |
|
83 |
|
84 /* |
|
85 * (non-Javadoc) |
|
86 * |
|
87 * @see |
|
88 * com.nokia.trace.dictionary.model.handlers.BaseHandler#processEndElement |
|
89 * (java.lang.StringBuffer, java.lang.Object, |
|
90 * com.nokia.trace.dictionary.model.DictionaryContentHandler, |
|
91 * com.nokia.trace.dictionary.model.DecodeObject) |
|
92 */ |
|
93 @Override |
|
94 public void processEndElement(StringBuffer elementContent, |
|
95 Object unFinishedObject, DictionaryContentHandler handler, |
|
96 DecodeObject parentObject) { |
|
97 // Parent decode object is set back to component |
|
98 handler.getVariables().setParentDecodeObject( |
|
99 ParentDecodeObject.COMPONENT); |
|
100 } |
|
101 |
|
102 /** |
|
103 * Check collision |
|
104 * |
|
105 * @param oldGroup |
|
106 * old group |
|
107 * @param newGroup |
|
108 * new group |
|
109 * @param handler |
|
110 * dictionary content handler |
|
111 * @return old group if there was collision, new group if not |
|
112 */ |
|
113 private TraceGroup checkCollision(TraceGroup oldGroup, TraceGroup newGroup, |
|
114 DictionaryContentHandler handler) { |
|
115 boolean collision = true; |
|
116 // If old group is null, everything is OK. If not, check collision |
|
117 if (oldGroup != null) { |
|
118 // Classes must be same |
|
119 if (oldGroup.getClass() == newGroup.getClass()) { |
|
120 // Names must be same |
|
121 if (oldGroup.getName().equals(newGroup.getName())) { |
|
122 // Prefixes must be same |
|
123 String prefix = oldGroup.getPrefix(); |
|
124 String prefix2 = newGroup.getPrefix(); |
|
125 if (prefix == null) { |
|
126 prefix = ""; //$NON-NLS-1$ |
|
127 } |
|
128 if (prefix2 == null) { |
|
129 prefix2 = ""; //$NON-NLS-1$ |
|
130 } |
|
131 if (prefix.equals(prefix2)) { |
|
132 // Suffixes must be same |
|
133 String suffix = oldGroup.getSuffix(); |
|
134 String suffix2 = newGroup.getSuffix(); |
|
135 if (suffix == null) { |
|
136 suffix = ""; //$NON-NLS-1$ |
|
137 } |
|
138 if (suffix2 == null) { |
|
139 suffix2 = ""; //$NON-NLS-1$ |
|
140 } |
|
141 if (suffix.equals(suffix2)) { |
|
142 collision = false; |
|
143 } |
|
144 } |
|
145 } |
|
146 } |
|
147 if (collision) { |
|
148 newGroup = oldGroup; |
|
149 TraceEvent event = new TraceEvent(TraceEvent.WARNING, Messages |
|
150 .getString("GroupHandler.CollisionGroupID") //$NON-NLS-1$ |
|
151 + Integer.toHexString(oldGroup.getId())); |
|
152 event.setCategory(EVENT_CATEGORY); |
|
153 event.setSource(Integer.valueOf(handler.getLocator() |
|
154 .getLineNumber())); |
|
155 TraceDictionaryEngine.postEvent(event); |
|
156 } |
|
157 } |
|
158 return newGroup; |
|
159 } |
|
160 |
|
161 } |