Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9c3cfc189f2e8ad90eda818619f72cc41bb5f31b (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*******************************************************************************
 * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.runtime.stepper;

import org.eclipse.core.runtime.Assert;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId;

/**
 * A stepper attributes utility provides a set of static methods
 * to access the attributes of a step.
 */
public class StepperAttributeUtil {
	/**
	 * Get the full qualified key to get or set data in the data.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @return The full qualified key.
	 */
	protected final static String getFullQualifiedKey(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		return (fullQualifiedId != null ? fullQualifiedId.toString() : "") + key; //$NON-NLS-1$
	}

	/**
	 * Get a property from the data. If the value is not stored within the full qualified id, the
	 * value stored within the parent id will be returned.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @return The property value or <code>null</code> if either the data has no property container
	 *         or the property is not set.
	 */
	public final static Object getProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		if (fullQualifiedId == null || data.getProperty(getFullQualifiedKey(key, fullQualifiedId, data)) != null) {
			return data.getProperty(getFullQualifiedKey(key, fullQualifiedId, data));
		}
		return getProperty(key, fullQualifiedId.getParentId(), data);
	}

	/**
	 * Get a string property from the data. If the value is not stored within the full qualified id,
	 * the value stored within the parent id will be returned.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @return The string property value or <code>null</code> if either the data has no property
	 *         container or the property is not set.
	 */
	public final static String getStringProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		if (fullQualifiedId == null || data.getProperty(getFullQualifiedKey(key, fullQualifiedId, data)) != null) {
			return data.getStringProperty(getFullQualifiedKey(key, fullQualifiedId, data));
		}
		return getStringProperty(key, fullQualifiedId.getParentId(), data);
	}

	/**
	 * Get a boolean property from the data. If the value is not stored within the full qualified
	 * id, the value stored within the parent id will be returned.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @return The boolean property value or <code>false</code> if either the data has no property
	 *         container or the property is not set.
	 */
	public final static boolean getBooleanProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		if (fullQualifiedId == null || data.getProperty(getFullQualifiedKey(key, fullQualifiedId, data)) != null) {
			return data.getBooleanProperty(getFullQualifiedKey(key, fullQualifiedId, data));
		}
		return getBooleanProperty(key, fullQualifiedId.getParentId(), data);
	}

	/**
	 * Get a int property from the data.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @return The int property value or <code>-1</code> if either the data has no property
	 *         container or the property is not set.
	 */
	public final static int getIntProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		if (fullQualifiedId == null || data.getProperty(getFullQualifiedKey(key, fullQualifiedId, data)) != null) {
			return data.getIntProperty(getFullQualifiedKey(key, fullQualifiedId, data));
		}
		return getIntProperty(key, fullQualifiedId.getParentId(), data);
	}

	/**
	 * Check if a property is set.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @return <code>true</code> if a property value is set.
	 */
	public final static boolean isPropertySet(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		return data.getProperty(getFullQualifiedKey(key, fullQualifiedId, data)) != null;
	}

	/**
	 * Set a property value to the data.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @param value The new value.
	 * @return <code>true</code> if the value was set.
	 */
	public final static boolean setProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data, Object value) {
		return setProperty(key, fullQualifiedId, data, value, false);
	}

	/**
	 * Set a property value to the data and optional share it through the parent full qualified id.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @param value The new value.
	 * @param share When <code>true</code>, the value is also stored within the parent full
	 *            qualified id to share the value with other steps within the same parent (group).
	 * @return <code>true</code> if the value was set.
	 */
	public final static boolean setProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data, Object value, boolean share) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		if (share && fullQualifiedId != null) {
			data.setProperty(getFullQualifiedKey(key, fullQualifiedId.getParentId(), data), value);
		}
		return data.setProperty(getFullQualifiedKey(key, fullQualifiedId, data), value);
	}

	/**
	 * Set a boolean property value to the data.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @param value The new boolean value.
	 * @return <code>true</code> if the value was set.
	 */
	public final static boolean setProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data, boolean value) {
		return setProperty(key, fullQualifiedId, data, value, false);
	}

	/**
	 * Set a boolean property value to the data and optional share it through the parent full
	 * qualified id.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @param value The new boolean value.
	 * @param share When <code>true</code>, the value is also stored within the parent full
	 *            qualified id to share the value with other steps within the same parent (group).
	 * @return <code>true</code> if the value was set.
	 */
	public final static boolean setProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data, boolean value, boolean share) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		if (share && fullQualifiedId != null) {
			data.setProperty(getFullQualifiedKey(key, fullQualifiedId.getParentId(), data), value);
		}
		return data.setProperty(getFullQualifiedKey(key, fullQualifiedId, data), value);
	}

	/**
	 * Set a int property value to the data.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @param value The new int value.
	 * @return <code>true</code> if the value was set.
	 */
	public final static boolean setProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data, int value) {
		return setProperty(key, fullQualifiedId, data, value, false);
	}

	/**
	 * Set an int property value to the data and optional share it through the parent full qualified
	 * id.
	 *
	 * @param key The key for the value.
	 * @param fullQualifiedId The full qualified id for this step.
	 * @param data The data.
	 * @param value The new int value.
	 * @param share When <code>true</code>, the value is also stored within the parent full
	 *            qualified id to share the value with other steps within the same parent (group).
	 * @return <code>true</code> if the value was set.
	 */
	public final static boolean setProperty(String key, IFullQualifiedId fullQualifiedId, IPropertiesContainer data, int value, boolean share) {
		Assert.isNotNull(key);
		Assert.isNotNull(data);

		if (share && fullQualifiedId != null) {
			data.setProperty(getFullQualifiedKey(key, fullQualifiedId.getParentId(), data), value);
		}
		return data.setProperty(getFullQualifiedKey(key, fullQualifiedId, data), value);
	}
}

Back to the top