|
1 /* |
|
2 * Copyright (c) 2008 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 */ |
|
17 |
|
18 package com.nokia.s60tools.crashanalyser.containers; |
|
19 |
|
20 import org.w3c.dom.NamedNodeMap; |
|
21 import org.w3c.dom.Node; |
|
22 import com.nokia.s60tools.crashanalyser.model.XmlUtils; |
|
23 import java.util.*; |
|
24 |
|
25 /** |
|
26 * A register bit class. Contains information about a single |
|
27 * bit. Used e.g. in Crash Visualiser's CPSR details group. |
|
28 * One of these bits represents a single bit-textbox in CPSR |
|
29 * details UI group. |
|
30 * |
|
31 */ |
|
32 public final class RegisterBit { |
|
33 |
|
34 // XML tags |
|
35 final static String ATTRIBUTE_INDEX = "index"; |
|
36 final static String ATTRIBUTE_VALUE = "value"; |
|
37 final static String ATTRIBUTE_CATEGORY = "category"; |
|
38 final static String ATTRIBUTE_INTERPRETATION = "interpretation"; |
|
39 final static String ATTRIBUTE_START = "start"; |
|
40 final static String ATTRIBUTE_END = "end"; |
|
41 final static String ATTRIBUTE_CHAR = "char"; |
|
42 final static String ATTRIBUTE_TYPE = "type"; |
|
43 |
|
44 // Data |
|
45 private final int registerIndex; |
|
46 private final String registerValue; |
|
47 private final String registerCategory; |
|
48 private final String registerInterpretation; |
|
49 private String registerChar; |
|
50 |
|
51 /** |
|
52 * Constructor |
|
53 * @param index bit index |
|
54 * @param value bit value |
|
55 * @param category bit category |
|
56 * @param interpretation bit interpretation |
|
57 * @param regChar bit register character |
|
58 */ |
|
59 private RegisterBit(int index, String value, String category, String interpretation, String regChar) { |
|
60 registerIndex = index; |
|
61 registerValue = value; |
|
62 registerCategory = category; |
|
63 registerInterpretation = interpretation; |
|
64 registerChar = regChar; |
|
65 } |
|
66 |
|
67 /** |
|
68 * Constructor |
|
69 * @param index bit index |
|
70 * @param value bit value |
|
71 * @param category bit category |
|
72 * @param interpretation bit interpretation |
|
73 * @param reserved bit is of reserved type |
|
74 */ |
|
75 private RegisterBit(int index, String value, String category, String interpretation, boolean reserved) { |
|
76 registerIndex = index; |
|
77 registerValue = value; |
|
78 registerCategory = category; |
|
79 registerInterpretation = interpretation; |
|
80 registerChar = value; |
|
81 if (reserved) |
|
82 registerChar = "-"; |
|
83 } |
|
84 |
|
85 public int getIndex() { |
|
86 return registerIndex; |
|
87 } |
|
88 |
|
89 public String getValue() { |
|
90 return registerValue; |
|
91 } |
|
92 |
|
93 public String getCategory() { |
|
94 return registerCategory; |
|
95 } |
|
96 |
|
97 public String getInterpretation() { |
|
98 return registerInterpretation; |
|
99 } |
|
100 |
|
101 public String getRegisterChar() { |
|
102 return registerChar; |
|
103 } |
|
104 |
|
105 /** |
|
106 * Reads and creates bit from bit xml node |
|
107 * @param bit |
|
108 * @return created bit or null |
|
109 */ |
|
110 public static RegisterBit readFromBit(Node bit) { |
|
111 NamedNodeMap attributes = bit.getAttributes(); |
|
112 if (attributes == null || attributes.getLength() < 1) |
|
113 return null; |
|
114 |
|
115 String index = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_INDEX)); |
|
116 if (index == null) |
|
117 return null; |
|
118 |
|
119 int i; |
|
120 try { |
|
121 i = Integer.parseInt(index); |
|
122 } catch (Exception e) { |
|
123 return null; |
|
124 } |
|
125 |
|
126 String value = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_VALUE)); |
|
127 if (value == null) |
|
128 return null; |
|
129 |
|
130 String category = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_CATEGORY)); |
|
131 if (category == null) |
|
132 return null; |
|
133 |
|
134 String interpretation = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_INTERPRETATION)); |
|
135 if (interpretation == null) |
|
136 interpretation = ""; |
|
137 |
|
138 String regChar = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_CHAR)); |
|
139 if (regChar == null) |
|
140 regChar = ""; |
|
141 |
|
142 return new RegisterBit(i, value, category, interpretation, regChar); |
|
143 } |
|
144 |
|
145 /** |
|
146 * Reads and creates a range of bits from range xml node |
|
147 * @param range |
|
148 * @return list of created bits or null |
|
149 */ |
|
150 public static List<RegisterBit> readFromRange(Node range) { |
|
151 NamedNodeMap attributes = range.getAttributes(); |
|
152 if (attributes == null || attributes.getLength() < 1) |
|
153 return null; |
|
154 |
|
155 String start = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_START)); |
|
156 if (start == null) |
|
157 return null; |
|
158 |
|
159 String end = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_END)); |
|
160 if (end == null) |
|
161 return null; |
|
162 |
|
163 String value = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_VALUE)); |
|
164 if (value == null) |
|
165 return null; |
|
166 |
|
167 String category = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_CATEGORY)); |
|
168 if (category == null) |
|
169 return null; |
|
170 |
|
171 String interpretation = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_INTERPRETATION)); |
|
172 if (interpretation == null) |
|
173 interpretation = ""; |
|
174 |
|
175 boolean reserved = false; |
|
176 String type = XmlUtils.getNodeValue(attributes.getNamedItem(ATTRIBUTE_TYPE)); |
|
177 if (type != null && !"".equals(type)) |
|
178 reserved = true; |
|
179 |
|
180 List<RegisterBit> bits = new ArrayList<RegisterBit>(); |
|
181 |
|
182 try { |
|
183 int s = Integer.parseInt(start); |
|
184 int e = Integer.parseInt(end); |
|
185 for (int i = 0;s <= e; s++, i++) { |
|
186 bits.add(new RegisterBit(s,value.substring(i,i+1),category,interpretation,reserved)); |
|
187 } |
|
188 } catch (Exception e) { |
|
189 return null; |
|
190 } |
|
191 |
|
192 return bits; |
|
193 } |
|
194 } |