56
|
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 |
* Utilities for trace formatting
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
package com.nokia.tracecompiler.project;
|
|
20 |
|
|
21 |
//import java.util.*;
|
|
22 |
import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
|
|
23 |
import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
|
|
24 |
import com.nokia.tracecompiler.model.TraceCompilerException;
|
|
25 |
import com.nokia.tracecompiler.model.TraceGroup;
|
|
26 |
import com.nokia.tracecompiler.model.TraceModel;
|
|
27 |
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Utilities for trace formatting
|
|
31 |
*
|
|
32 |
*/
|
|
33 |
public final class FormattingUtils {
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Separator for prefix
|
|
37 |
*/
|
|
38 |
private static final String PREFIX_SEPARATOR = ": "; //$NON-NLS-1$
|
|
39 |
|
|
40 |
/**
|
|
41 |
* Gets a group ID based on group name
|
|
42 |
*
|
|
43 |
* @param model
|
|
44 |
* the trace model
|
|
45 |
* @param name
|
|
46 |
* the group name
|
|
47 |
* @return the group ID
|
|
48 |
* @throws TraceCompilerException
|
|
49 |
*/
|
|
50 |
public static int getGroupID(TraceModel model, String name)
|
|
51 |
throws TraceCompilerException {
|
|
52 |
|
|
53 |
// First check that is group one of the default groups
|
|
54 |
int retval = GroupNames.getIdByName(name);
|
|
55 |
// If group was not one of the default groups then get next group Id from model
|
|
56 |
if (retval == 0) {
|
|
57 |
retval = model.getNextGroupID();
|
|
58 |
if (retval < GroupNames.USER_GROUP_ID_FIRST) {
|
|
59 |
retval = GroupNames.USER_GROUP_ID_FIRST;
|
|
60 |
}
|
|
61 |
else if(retval > GroupNames.USER_GROUP_ID_LAST){
|
|
62 |
String msg = "You have exceeded the number of Group IDs you have allocated."; //$NON-NLS-1$
|
|
63 |
TraceCompilerEngineGlobals.getEvents().postErrorMessage(msg, null, true);
|
|
64 |
throw new TraceCompilerException(
|
|
65 |
TraceCompilerErrorCode.RUN_OUT_OF_GROUP_IDS);
|
|
66 |
}
|
|
67 |
}
|
|
68 |
return retval;
|
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Gets the default component prefix
|
|
73 |
*
|
|
74 |
* @param model
|
|
75 |
* the model
|
|
76 |
* @return the prefix
|
|
77 |
*/
|
|
78 |
public static String getDefaultComponentPrefix(TraceModel model) {
|
|
79 |
return model.getName() + PREFIX_SEPARATOR;
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Gets the default component suffix
|
|
84 |
*
|
|
85 |
* @param model
|
|
86 |
* the model
|
|
87 |
* @return the suffix
|
|
88 |
*/
|
|
89 |
public static String getDefaultComponentSuffix(TraceModel model) {
|
|
90 |
return ""; //$NON-NLS-1$
|
|
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Gets the default group prefix
|
|
95 |
*
|
|
96 |
* @param group
|
|
97 |
* the group
|
|
98 |
* @return the prefix
|
|
99 |
*/
|
|
100 |
public static String getDefaultGroupPrefix(TraceGroup group) {
|
|
101 |
String name = group.getName();
|
|
102 |
if (name.startsWith(GroupNames.DEFAULT_GROUP_PREFIX)) {
|
|
103 |
int start = GroupNames.DEFAULT_GROUP_PREFIX.length();
|
|
104 |
// First character retains case, others are converted to lower case
|
|
105 |
name = name.charAt(start) + name.substring(start + 1).toLowerCase();
|
|
106 |
}
|
|
107 |
name += PREFIX_SEPARATOR;
|
|
108 |
return name;
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Gets the default group suffix
|
|
113 |
*
|
|
114 |
* @param group
|
|
115 |
* the group
|
|
116 |
* @return the suffix
|
|
117 |
*/
|
|
118 |
public static String getDefaultGroupSuffix(TraceGroup group) {
|
|
119 |
return ""; //$NON-NLS-1$
|
|
120 |
}
|
|
121 |
|
|
122 |
}
|