Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7826015d186092038d08235aaca7f1cfd219fd5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*******************************************************************************
 * Copyright (c) 2008, 2011 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 *
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.common.ui.internal;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jpt.common.ui.JptCommonUiPlugin;

/**
 * This tracing class manages to convert the string value into boolean values or
 * integer values that are associated with the tracing debug flags. Those flags
 * are specified in the .options file. The supported keys are defined here as
 * constants for quick reference.
 *
 * @version 2.0
 * @since 2.0
 */
@SuppressWarnings("nls")
public final class Tracing
{
	/**
	 * A constant used to retrieve the value associated with "/debug".
	 */
	public static final String DEBUG = "/debug";

	/**
	 * A constant used to retrieve the value associated with "/debug/ui/db".
	 */
	public static final String UI_DB = "/debug/ui/db";

	/**
	 * A constant used to retrieve the value associated with "/debug/ui/detailsView".
	 */
	public static final String UI_DETAILS_VIEW = "/debug/ui/detailsView";

	/**
	 * A constant used to retrieve the value associated with "/debug/ui/layout".
	 */
	public static final String UI_LAYOUT = "/debug/ui/layout";

	/**
	 * A constant used to retrieve the value associated with "/unit-tests".
	 */
	public static final String UNIT_TESTS = "/unit-tests";

	/**
	 * Can't instantiate this <code>Tracing</code> class.
	 */
	private Tracing()
	{
		super();
		throw new UnsupportedOperationException("Tracing cannot be instantiated");
	}

	/**
	 * Retrieves the debug value associated with the given flag. The default
	 * value is <code>false</code>.
	 *
	 * @param flag The flag to retrieve the debug value, which should be
	 * contained in the .options file, the flag should start with "/"
	 * @return <code>true</code> if the given flag is active; <code>false</code>
	 * otherwise
	 */
	public static boolean booleanDebugOption(String flag)
	{
		return booleanDebugOption(flag, false);
	}

	/**
	 * Retrieves the debug value associated with the given flag.
	 *
	 * @param flag The flag to retrieve the debug value, which should be
	 * contained in the .options file, the flag should start with "/"
	 * @param defaultValue The default value if the value associated with the
	 * given flag could not be found
	 * @return <code>true</code> if the given flag is active; <code>false</code>
	 * otherwise
	 */
	public static boolean booleanDebugOption(String flag, boolean defaultValue)
	{
		String string = Platform.getDebugOption(JptCommonUiPlugin.PLUGIN_ID + flag);
		return (string == null) ? defaultValue : Boolean.parseBoolean(string.trim());
	}

	/**
	 * Retrieves the debug value associated with the given flag. The default value
	 * is 0.
	 *
	 * @param flag The flag to retrieve the debug value, which should be
	 * contained in the .options file, the flag should start with "/"
	 * @return The value associated with the given flag, or the given default
	 * value
	 */
	public static int intDebugOption(String flag)
	{
		return intDebugOption(flag, 0);
	}

	/**
	 * Retrieves the debug value associated with the given flag.
	 *
	 * @param flag The flag to retrieve the debug value, which should be
	 * contained in the .options file, the flag should start with "/"
	 * @param defaultValue The default value if the value associated with the
	 * given flag could not be found
	 * @return The value associated with the given flag, or the given default
	 * value
	 */
	public static int intDebugOption(String flag, int defaultValue)
	{
		String string = Platform.getDebugOption(JptCommonUiPlugin.PLUGIN_ID + flag);
		return (string == null) ?  defaultValue : Integer.parseInt(string);
	}

	/**
	 * Logs the given messages, appends it with this plug-in id.
	 *
	 * @param message The message to be logged
	 */
	public static void log(String message)
	{
		System.out.print("[" + JptCommonUiPlugin.PLUGIN_ID + "] ");
		System.out.println(message);
	}

	/**
	 * Retrieves the debug value associated with the given flag. The default value
	 * is an empty string.
	 *
	 * @param flag The flag to retrieve the debug value, which should be
	 * contained in the .options file, the flag should start with "/"
	 * @return The value associated with the given flag, or the given default
	 * value
	 */
	public static String stringDebugOption(String flag)
	{
		return stringDebugOption(flag, "");
	}

	/**
	 * Retrieves the debug value associated with the given flag.
	 *
	 * @param flag The flag to retrieve the debug value, which should be
	 * contained in the .options file, the flag should start with "/"
	 * @param defaultValue The default value if the value associated with the
	 * given flag could not be found
	 * @return The value associated with the given flag, or the given default
	 * value
	 */
	public static String stringDebugOption(String flag, String defaultValue)
	{
		String string = Platform.getDebugOption(JptCommonUiPlugin.PLUGIN_ID + flag);
		return (string != null) ? string : defaultValue;
	}
}

Back to the top