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
|
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.core.internal.variables;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.variables.IValueVariable;
import org.eclipse.core.variables.IValueVariableInitializer;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.osgi.util.NLS;
/**
* Implementation of a value variable.
*/
public class ValueVariable extends StringVariable implements IValueVariable {
/**
* Variable value or <code>null</code> if none
*/
private String fValue;
/**
* Whether this variable's value has been initialized
*/
private boolean fInitialized = false;
/**
* Constructs a new value variable with the given name, description, and
* associated configuration element.
*
* @param name variable name
* @param description variable description, or <code>null</code>
* @param configurationElement configuration element or <code>null</code>
*/
public ValueVariable(String name, String description, IConfigurationElement configurationElement) {
super(name, description, configurationElement);
}
/* (non-Javadoc)
* @see org.eclipse.debug.internal.core.stringsubstitution.IValueVariable#setValue(java.lang.String)
*/
public void setValue(String value) {
fValue = value;
setInitialized(true);
StringVariableManager.getDefault().notifyChanged(this);
}
/* (non-Javadoc)
* @see org.eclipse.debug.internal.core.stringsubstitution.IValueVariable#getValue()
*/
public String getValue() {
if (!isInitialized()) {
initialize();
}
return fValue;
}
/**
* Initialize this variable's value.
*/
private void initialize() {
if (getConfigurationElement() != null) {
// check for a explicit value specified in plug-in XML
String value = getConfigurationElement().getAttribute("initialValue"); //$NON-NLS-1$
if (value == null) {
// check for initializer
String className = getConfigurationElement().getAttribute("initializerClass"); //$NON-NLS-1$
if (className != null) {
try {
Object object = getConfigurationElement().createExecutableExtension("initializerClass"); //$NON-NLS-1$
if (object instanceof IValueVariableInitializer) {
IValueVariableInitializer initializer = (IValueVariableInitializer)object;
initializer.initialize(this);
} else {
VariablesPlugin.logMessage(NLS.bind("Unable to initialize variable {0} - initializer must be an instance of IValueVariableInitializer.", new String[]{getName()}), null); //$NON-NLS-1$
}
} catch (CoreException e) {
VariablesPlugin.logMessage(NLS.bind("Unable to initialize variable {0}",new String[]{getName()}), e); //$NON-NLS-1$
}
}
} else {
setValue(value);
}
}
setInitialized(true);
}
/**
* Returns whether this variable has been initialized with a value by one of:
* <ul>
* <li><code>setValue(String)</code></li>
* <li>its configuration element's <code>initialValue</code> attribute</li>
* <li>its configuration element's initializer</li>
* </ul>
* @return whether this variable has been initialized with a value
*/
protected boolean isInitialized() {
return fInitialized;
}
/**
* Sets whether this variable has been initialized with a value.
*
* @param initialized whether this variable has been initialized
*/
protected void setInitialized(boolean initialized) {
fInitialized = initialized;
}
/* (non-Javadoc)
* @see org.eclipse.debug.internal.core.stringsubstitution.IValueVariable#isContributed()
*/
public boolean isContributed() {
return getConfigurationElement() != null;
}
}
|