|
1 /* |
|
2 * Copyright (c) 2007 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 * Value element parser |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.engine.propertyfile; |
|
20 |
|
21 import org.w3c.dom.Element; |
|
22 |
|
23 import com.nokia.tracebuilder.engine.TraceBuilderErrorCodes.StringErrorParameters; |
|
24 import com.nokia.tracebuilder.engine.TraceBuilderErrorCodes.TraceBuilderErrorCode; |
|
25 import com.nokia.tracebuilder.model.TraceBuilderException; |
|
26 import com.nokia.tracebuilder.model.TraceConstantTable; |
|
27 import com.nokia.tracebuilder.model.TraceModelExtension; |
|
28 |
|
29 /** |
|
30 * Value element parser |
|
31 * |
|
32 */ |
|
33 final class ValueElementParser implements PropertyFileElementParser { |
|
34 |
|
35 /* |
|
36 * (non-Javadoc) |
|
37 * |
|
38 * @see com.nokia.tracebuilder.engine.propertyfile.PropertyFileElementParser# |
|
39 * parse(java.lang.Object, org.w3c.dom.Element) |
|
40 */ |
|
41 public void parse(Object owner, Element element) |
|
42 throws TraceBuilderException { |
|
43 // Value element must be parsed within context of TraceConstantTable |
|
44 // Struct has not yet been implemented |
|
45 if (owner instanceof TraceConstantTable) { |
|
46 parseConstantTableEntry((TraceConstantTable) owner, element); |
|
47 } else { |
|
48 StringErrorParameters parameter = new StringErrorParameters(); |
|
49 parameter.string = PropertyFileConstants.VALUE_ELEMENT; |
|
50 throw new TraceBuilderException( |
|
51 TraceBuilderErrorCode.PROPERTY_FILE_ELEMENT_MISPLACED, |
|
52 parameter, null); |
|
53 } |
|
54 } |
|
55 |
|
56 /** |
|
57 * Parses a constant table entry |
|
58 * |
|
59 * @param table |
|
60 * the constant table |
|
61 * @param element |
|
62 * the table entry |
|
63 * @throws TraceBuilderException |
|
64 * if entry is not valid |
|
65 */ |
|
66 private void parseConstantTableEntry(TraceConstantTable table, |
|
67 Element element) throws TraceBuilderException { |
|
68 String idstr = element.getAttribute(PropertyFileConstants.ID_ATTRIBUTE); |
|
69 if (idstr != null) { |
|
70 try { |
|
71 int id = Integer.parseInt(idstr); |
|
72 String value = element.getTextContent(); |
|
73 table.getModel().getVerifier().checkConstantProperties(table, |
|
74 null, id, value); |
|
75 // Document element reference is stored to the model |
|
76 TraceModelExtension[] exts = new TraceModelExtension[] { new DocumentElementWrapper( |
|
77 element) }; |
|
78 table.getModel().getFactory().createConstantTableEntry(table, |
|
79 id, value, exts); |
|
80 } catch (NumberFormatException e) { |
|
81 StringErrorParameters parameter = new StringErrorParameters(); |
|
82 parameter.string = PropertyFileConstants.ID_ATTRIBUTE; |
|
83 throw new TraceBuilderException( |
|
84 TraceBuilderErrorCode.PROPERTY_FILE_ATTRIBUTE_INVALID, |
|
85 parameter, null); |
|
86 } |
|
87 } |
|
88 } |
|
89 } |