41
|
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 |
* Writes Trace objects
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
|
|
20 |
|
|
21 |
/**
|
|
22 |
* Writes Trace objects
|
|
23 |
*
|
|
24 |
*/
|
|
25 |
public class Trace {
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Starts <trace data-ref=""> structure
|
|
29 |
*
|
|
30 |
* @param dataRef
|
|
31 |
* reference to actual data stored in <data> structure
|
|
32 |
* @param name
|
|
33 |
* name of the trace. Can be null if trace doesn't have name
|
|
34 |
*/
|
|
35 |
static void startTrace(int dataRef, String name) {
|
|
36 |
StringBuffer sb = new StringBuffer();
|
|
37 |
sb.append(TagWriter.TRACE_START_OPEN);
|
|
38 |
if (dataRef >= 0) {
|
|
39 |
TagWriter.appendAttribute(sb, TagWriter.DATA_REF_ATTR, String
|
|
40 |
.valueOf(dataRef), false);
|
|
41 |
|
|
42 |
if (name != null && name != "") { //$NON-NLS-1$
|
|
43 |
TagWriter.appendAttribute(sb, TagWriter.NAME_ATTR, name, true);
|
|
44 |
}
|
|
45 |
}
|
|
46 |
sb.append(TagWriter.TAG_CLOSE);
|
|
47 |
TagWriter.write(sb.toString(), TagWriter.INDENT_3);
|
|
48 |
|
|
49 |
}
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Writes </trace>
|
|
53 |
*/
|
|
54 |
static void endTrace() {
|
|
55 |
TagWriter.write(TagWriter.TRACE_END, TagWriter.INDENT_3);
|
|
56 |
}
|
|
57 |
|
|
58 |
/**
|
|
59 |
* Writes <options>
|
|
60 |
*/
|
|
61 |
public static void startOptions() {
|
|
62 |
Options.startOptions(TagWriter.INDENT_4);
|
|
63 |
}
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Writes </options>
|
|
67 |
*/
|
|
68 |
public static void endOptions() {
|
|
69 |
Options.endOptions(TagWriter.INDENT_4);
|
|
70 |
}
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Writes user defined tags <mytagXXX>value</mytagXXX>
|
|
74 |
*
|
|
75 |
* @param tag
|
|
76 |
* user defined tag
|
|
77 |
* @param value
|
|
78 |
* value of the tag
|
|
79 |
*/
|
|
80 |
public static void writeOption(String tag, String value) {
|
|
81 |
Options.writeOptions(tag, value, TagWriter.INDENT_5);
|
|
82 |
}
|
|
83 |
|
|
84 |
/**
|
|
85 |
* Writes <instance id="" locRef="" line="" methodName=""
|
|
86 |
* className=""/> structure
|
|
87 |
*
|
|
88 |
* @param id
|
|
89 |
* unique id number for this instance in current group structure
|
|
90 |
* @param locRef
|
|
91 |
* unique location reference for instance (reference to
|
|
92 |
* <locations> structure
|
|
93 |
* @param line
|
|
94 |
* positive number of line where data were founded in source file
|
|
95 |
* @param methodName
|
|
96 |
* name of the function from which trace was generated
|
|
97 |
* @param className
|
|
98 |
* this is class name or namespace name for method described in
|
|
99 |
* methodname attribute
|
|
100 |
*/
|
|
101 |
public static void writeInstance(int id, int locRef, int line,
|
|
102 |
String methodName, String className) {
|
|
103 |
StringBuffer sb = new StringBuffer();
|
|
104 |
sb.append(TagWriter.INSTANCE_START_OPEN);
|
|
105 |
TagWriter.appendAttribute(sb, TagWriter.ID_ATTR, String.valueOf(id),
|
|
106 |
false);
|
|
107 |
TagWriter.appendAttribute(sb, TagWriter.LOC_REF_ATTR, String
|
|
108 |
.valueOf(locRef), true);
|
|
109 |
TagWriter.appendAttribute(sb, TagWriter.LINE_ATTR,
|
|
110 |
String.valueOf(line), true);
|
|
111 |
TagWriter.appendAttribute(sb, TagWriter.METHODNAME_ATTR, methodName,
|
|
112 |
true);
|
|
113 |
if (className != null) {
|
|
114 |
TagWriter.appendAttribute(sb, TagWriter.CLASSNAME_ATTR, className,
|
|
115 |
true);
|
|
116 |
}
|
|
117 |
sb.append(TagWriter.TAG_END);
|
|
118 |
TagWriter.write(sb.toString(), TagWriter.INDENT_4);
|
|
119 |
}
|
|
120 |
}
|