KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > variables > StringVariableManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.variables;
12
13 import java.io.ByteArrayInputStream JavaDoc;
14 import java.io.ByteArrayOutputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.io.UnsupportedEncodingException JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.xml.parsers.DocumentBuilder JavaDoc;
23 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
24 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
25 import javax.xml.parsers.ParserConfigurationException JavaDoc;
26 import javax.xml.transform.OutputKeys JavaDoc;
27 import javax.xml.transform.Transformer JavaDoc;
28 import javax.xml.transform.TransformerException JavaDoc;
29 import javax.xml.transform.TransformerFactory JavaDoc;
30 import javax.xml.transform.dom.DOMSource JavaDoc;
31 import javax.xml.transform.stream.StreamResult JavaDoc;
32
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IConfigurationElement;
35 import org.eclipse.core.runtime.IExtensionPoint;
36 import org.eclipse.core.runtime.ISafeRunnable;
37 import org.eclipse.core.runtime.IStatus;
38 import org.eclipse.core.runtime.ListenerList;
39 import org.eclipse.core.runtime.MultiStatus;
40 import org.eclipse.core.runtime.Platform;
41 import org.eclipse.core.runtime.Preferences;
42 import org.eclipse.core.runtime.SafeRunner;
43 import org.eclipse.core.runtime.Status;
44 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
45 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
46 import org.eclipse.core.variables.IDynamicVariable;
47 import org.eclipse.core.variables.IStringVariable;
48 import org.eclipse.core.variables.IStringVariableManager;
49 import org.eclipse.core.variables.IValueVariable;
50 import org.eclipse.core.variables.IValueVariableListener;
51 import org.eclipse.core.variables.VariablesPlugin;
52 import org.eclipse.osgi.util.NLS;
53 import org.w3c.dom.Document JavaDoc;
54 import org.w3c.dom.Element JavaDoc;
55 import org.w3c.dom.Node JavaDoc;
56 import org.w3c.dom.NodeList JavaDoc;
57 import org.xml.sax.SAXException JavaDoc;
58 import org.xml.sax.helpers.DefaultHandler JavaDoc;
59
60 /**
61  * Singleton string variable manager.
62  */

63 public class StringVariableManager implements IStringVariableManager, IPropertyChangeListener {
64     
65     /**
66      * Dynamic variables - maps variable names to variables.
67      */

68     private Map JavaDoc fDynamicVariables;
69     
70     /**
71      * Value variables - maps variable names to variables.
72      */

73     private Map JavaDoc fValueVariables;
74     
75     /**
76      * Variable listeners
77      */

78     private ListenerList fListeners;
79     
80     // notifications
81
private static final int ADDED = 0;
82     private static final int CHANGED = 1;
83     private static final int REMOVED = 2;
84     
85     /**
86      * Singleton variable manager.
87      */

88     private static StringVariableManager fgManager;
89     
90     // true during internal updates indicates that change notification
91
// should be suppressed/ignored.
92
private boolean fInternalChange = false;
93     
94     // Variable extension point constants
95
private static final String JavaDoc ATTR_NAME= "name"; //$NON-NLS-1$
96
private static final String JavaDoc ATTR_DESCRIPTION="description"; //$NON-NLS-1$
97
private static final String JavaDoc ATTR_READ_ONLY="readOnly"; //$NON-NLS-1$
98
// Persisted variable XML constants
99
private static final String JavaDoc VALUE_VARIABLES_TAG= "valueVariables"; //$NON-NLS-1$
100
private static final String JavaDoc VALUE_VARIABLE_TAG= "valueVariable"; //$NON-NLS-1$
101
private static final String JavaDoc NAME_TAG= "name"; //$NON-NLS-1$
102
private static final String JavaDoc VALUE_TAG= "value"; //$NON-NLS-1$
103
private static final String JavaDoc DESCRIPTION_TAG="description"; //$NON-NLS-1$
104
private static final String JavaDoc READ_ONLY_TAG="readOnly"; //$NON-NLS-1$
105
// XML values
106
private static final String JavaDoc TRUE_VALUE= "true"; //$NON-NLS-1$
107
private static final String JavaDoc FALSE_VALUE= "false"; //$NON-NLS-1$
108
// preference store key for value variables
109
private static final String JavaDoc PREF_VALUE_VARIABLES= VariablesPlugin.getUniqueIdentifier() + ".valueVariables"; //$NON-NLS-1$
110

111     /**
112      * Notifies a string variable listener in a safe runnable to handle
113      * exceptions.
114      */

115     class StringVariableNotifier implements ISafeRunnable {
116         
117         private IValueVariableListener fListener;
118         private int fType;
119         private IValueVariable[] fVariables;
120         
121         /**
122          * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
123          */

124         public void handleException(Throwable JavaDoc exception) {
125             IStatus status = new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, "An exception occurred during string variable change notification", exception); //$NON-NLS-1$
126
VariablesPlugin.log(status);
127         }
128
129         /**
130          * @see org.eclipse.core.runtime.ISafeRunnable#run()
131          */

132         public void run() throws Exception JavaDoc {
133             switch (fType) {
134                 case ADDED:
135                     fListener.variablesAdded(fVariables);
136                     break;
137                 case REMOVED:
138                     fListener.variablesRemoved(fVariables);
139                     break;
140                 case CHANGED:
141                     fListener.variablesChanged(fVariables);
142                     break;
143             }
144         }
145
146         /**
147          * Notifies the given listener of the add/change/remove
148          *
149          * @param listener the listener to notify
150          * @param launch the launch that has changed
151          * @param update the type of change
152          */

153         public void notify(IValueVariable[] variables, int update) {
154             fVariables = variables;
155             fType = update;
156             Object JavaDoc[] copiedListeners= fListeners.getListeners();
157             for (int i= 0; i < copiedListeners.length; i++) {
158                 fListener = (IValueVariableListener)copiedListeners[i];
159                 SafeRunner.run(this);
160             }
161             fVariables = null;
162             fListener = null;
163             // persist variables whenever there is an add/change/remove
164
storeValueVariables();
165         }
166     }
167     
168     /**
169      * Returns a new notifier.
170      *
171      * @return a new notifier
172      */

173     private StringVariableNotifier getNotifier() {
174         return new StringVariableNotifier();
175     }
176     
177     /**
178      * Returns the default string variable manager
179      *
180      * @return string variable manager
181      */

182     public static StringVariableManager getDefault() {
183         if (fgManager == null) {
184             fgManager = new StringVariableManager();
185         }
186         return fgManager;
187     }
188     
189     /**
190      * Constructs a new string variable manager.
191      */

192     private StringVariableManager() {
193         fListeners = new ListenerList();
194     }
195
196     /**
197      * Load contributed variables and persisted variables
198      */

199     private synchronized void initialize() {
200         if (fDynamicVariables == null) {
201             fInternalChange = true;
202             fDynamicVariables = new HashMap JavaDoc(5);
203             fValueVariables = new HashMap JavaDoc(5);
204             loadContributedValueVariables();
205             loadPersistedValueVariables();
206             loadDynamicVariables();
207             VariablesPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this);
208             fInternalChange = false;
209         }
210     }
211     
212     /**
213      * Loads contributed dynamic variables
214      */

215     private void loadDynamicVariables() {
216         IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(VariablesPlugin.PI_CORE_VARIABLES, EXTENSION_POINT_DYNAMIC_VARIABLES);
217         IConfigurationElement elements[]= point.getConfigurationElements();
218         for (int i = 0; i < elements.length; i++) {
219             IConfigurationElement element = elements[i];
220             String JavaDoc name= element.getAttribute(ATTR_NAME);
221             if (name == null) {
222                 VariablesPlugin.logMessage(NLS.bind("Variable extension missing required 'name' attribute: {0}", new String JavaDoc[] {element.getDeclaringExtension().getLabel()}), null); //$NON-NLS-1$
223
continue;
224             }
225             String JavaDoc description= element.getAttribute(ATTR_DESCRIPTION);
226             DynamicVariable variable= new DynamicVariable(name, description, element);
227             fDynamicVariables.put(variable.getName(), variable);
228         }
229     }
230
231     /**
232      * Loads contributed value variables. This is done before loading persisted values.
233      */

234     private void loadContributedValueVariables() {
235         IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(VariablesPlugin.PI_CORE_VARIABLES, EXTENSION_POINT_VALUE_VARIABLES);
236         IConfigurationElement elements[]= point.getConfigurationElements();
237         for (int i = 0; i < elements.length; i++) {
238             IConfigurationElement element = elements[i];
239             String JavaDoc name= element.getAttribute(ATTR_NAME);
240             if (name == null) {
241                 VariablesPlugin.logMessage(NLS.bind("Variable extension missing required 'name' attribute: {0}", new String JavaDoc[] {element.getDeclaringExtension().getLabel()}), null); //$NON-NLS-1$
242
continue;
243             }
244             String JavaDoc description= element.getAttribute(ATTR_DESCRIPTION);
245             boolean isReadOnly = TRUE_VALUE.equals(element.getAttribute(ATTR_READ_ONLY));
246             
247             IValueVariable variable = new ContributedValueVariable(name, description, isReadOnly, element);
248             fValueVariables.put(name, variable);
249         }
250     }
251
252     /**
253      * Loads persisted value variables from the preference store. This is done after
254      * loading value variables from the extension point. If a persisted variable has the
255      * same name as a extension contributed variable the variable's value will be set to
256      * the persisted value unless either a) The persisted value is <code>null</code>, or
257      * b) the variable is read-only.
258      */

259     private void loadPersistedValueVariables() {
260         String JavaDoc variablesString= VariablesPlugin.getDefault().getPluginPreferences().getString(PREF_VALUE_VARIABLES);
261         if (variablesString.length() == 0) {
262             return;
263         }
264         Element root= null;
265         Throwable JavaDoc ex = null;
266         try {
267             ByteArrayInputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(variablesString.getBytes("UTF-8")); //$NON-NLS-1$
268
DocumentBuilder JavaDoc parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
269             parser.setErrorHandler(new DefaultHandler JavaDoc());
270             root = parser.parse(stream).getDocumentElement();
271         } catch (UnsupportedEncodingException JavaDoc e) {
272             ex = e;
273         } catch (ParserConfigurationException JavaDoc e) {
274             ex = e;
275         } catch (FactoryConfigurationError JavaDoc e) {
276             ex = e;
277         } catch (SAXException JavaDoc e) {
278             ex = e;
279         } catch (IOException JavaDoc e) {
280             ex = e;
281         }
282         if (ex != null) {
283             VariablesPlugin.logMessage("An exception occurred while loading persisted value variables.", ex); //$NON-NLS-1$
284
return;
285         }
286         if (!root.getNodeName().equals(VALUE_VARIABLES_TAG)) {
287             VariablesPlugin.logMessage("Invalid format encountered while loading persisted value variables.", null); //$NON-NLS-1$
288
return;
289         }
290         NodeList JavaDoc list= root.getChildNodes();
291         for (int i= 0, numItems= list.getLength(); i < numItems; i++) {
292             Node JavaDoc node= list.item(i);
293             if (node.getNodeType() == Node.ELEMENT_NODE) {
294                 Element element= (Element) node;
295                 if (!element.getNodeName().equals(VALUE_VARIABLE_TAG)) {
296                     VariablesPlugin.logMessage(NLS.bind("Invalid XML element encountered while loading value variables: {0}", new String JavaDoc[] {node.getNodeName()}), null); //$NON-NLS-1$
297
continue;
298                 }
299                 String JavaDoc name= element.getAttribute(NAME_TAG);
300                 if (name.length() > 0) {
301                     String JavaDoc value= element.getAttribute(VALUE_TAG);
302                     String JavaDoc description= element.getAttribute(DESCRIPTION_TAG);
303                     boolean readOnly= TRUE_VALUE.equals(element.getAttribute(READ_ONLY_TAG));
304                 
305                     IValueVariable existing = getValueVariable(name);
306                     if (existing == null){
307                         ValueVariable variable = new ValueVariable(name, description, readOnly, value);
308                         fValueVariables.put(name, variable);
309                     } else if (!existing.isReadOnly() && value != null){
310                         existing.setValue(value);
311                     }
312                 } else {
313                     VariablesPlugin.logMessage("Invalid variable entry encountered while loading value variables. Variable name is null.", null); //$NON-NLS-1$
314
}
315             }
316         }
317     }
318     
319     /* (non-Javadoc)
320      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getVariables()
321      */

322     public synchronized IStringVariable[] getVariables() {
323         initialize();
324         List JavaDoc list = new ArrayList JavaDoc(fDynamicVariables.size() + fValueVariables.size());
325         list.addAll(fDynamicVariables.values());
326         list.addAll(fValueVariables.values());
327         return (IStringVariable[]) list.toArray(new IStringVariable[list.size()]);
328     }
329
330     /* (non-Javadoc)
331      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getValueVariables()
332      */

333     public synchronized IValueVariable[] getValueVariables() {
334         initialize();
335         return (IValueVariable[]) fValueVariables.values().toArray(new IValueVariable[fValueVariables.size()]);
336     }
337
338     /* (non-Javadoc)
339      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getDynamicVariables()
340      */

341     public synchronized IDynamicVariable[] getDynamicVariables() {
342         initialize();
343         return (IDynamicVariable[]) fDynamicVariables.values().toArray(new IDynamicVariable[fDynamicVariables.size()]);
344     }
345
346     /* (non-Javadoc)
347      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#performStringSubstitution(java.lang.String)
348      */

349     public String JavaDoc performStringSubstitution(String JavaDoc expression) throws CoreException {
350         return performStringSubstitution(expression, true);
351     }
352
353     /* (non-Javadoc)
354      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#newValueVariable(java.lang.String, java.lang.String)
355      */

356     public IValueVariable newValueVariable(String JavaDoc name, String JavaDoc description) {
357         return newValueVariable(name, description, false, null);
358     }
359     
360     /* (non-Javadoc)
361      * @see org.eclipse.core.variables.IStringVariableManager#newValueVariable(java.lang.String, java.lang.String, boolean, java.lang.String)
362      */

363     public IValueVariable newValueVariable(String JavaDoc name, String JavaDoc description, boolean readOnly, String JavaDoc value) {
364         return new ValueVariable(name, description, readOnly, value);
365     }
366     
367     /* (non-Javadoc)
368      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#addVariables(org.eclipse.debug.internal.core.stringsubstitution.IValueVariable[])
369      */

370     public synchronized void addVariables(IValueVariable[] variables) throws CoreException {
371         initialize();
372         MultiStatus status = new MultiStatus(VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, VariablesMessages.StringVariableManager_26, null);
373         for (int i = 0; i < variables.length; i++) {
374             IValueVariable variable = variables[i];
375             if (getValueVariable(variable.getName()) != null) {
376                 status.add(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, NLS.bind(VariablesMessages.StringVariableManager_27, new String JavaDoc[]{variable.getName()}), null));
377             }
378         }
379         if (status.isOK()) {
380             for (int i = 0; i < variables.length; i++) {
381                 IValueVariable variable = variables[i];
382                 fValueVariables.put(variable.getName(), variable);
383             }
384             IValueVariable[] copy = new IValueVariable[variables.length];
385             System.arraycopy(variables, 0, copy, 0, variables.length);
386             getNotifier().notify(copy, ADDED);
387             return;
388         }
389         throw new CoreException(status);
390     }
391
392     /* (non-Javadoc)
393      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#removeVariables(org.eclipse.debug.internal.core.stringsubstitution.IValueVariable[])
394      */

395     public synchronized void removeVariables(IValueVariable[] variables) {
396         initialize();
397         List JavaDoc removed = new ArrayList JavaDoc(variables.length);
398         for (int i = 0; i < variables.length; i++) {
399             IValueVariable variable = variables[i];
400             if (fValueVariables.remove(variable.getName()) != null) {
401                 removed.add(variable);
402             }
403         }
404         if (removed.size() > 0) {
405             getNotifier().notify((IValueVariable[])removed.toArray(new IValueVariable[removed.size()]), REMOVED);
406         }
407     }
408
409     /* (non-Javadoc)
410      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getDynamicVariable(java.lang.String)
411      */

412     public synchronized IDynamicVariable getDynamicVariable(String JavaDoc name) {
413         initialize();
414         return (IDynamicVariable) fDynamicVariables.get(name);
415     }
416
417     /* (non-Javadoc)
418      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#getValueVariable(java.lang.String)
419      */

420     public synchronized IValueVariable getValueVariable(String JavaDoc name) {
421         initialize();
422         return (IValueVariable) fValueVariables.get(name);
423     }
424
425
426     /* (non-Javadoc)
427      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#addValueVariableListener(org.eclipse.debug.internal.core.stringsubstitution.IValueVariableListener)
428      */

429     public void addValueVariableListener(IValueVariableListener listener) {
430         fListeners.add(listener);
431     }
432
433     /* (non-Javadoc)
434      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#removeValueVariableListener(org.eclipse.debug.internal.core.stringsubstitution.IValueVariableListener)
435      */

436     public void removeValueVariableListener(IValueVariableListener listener) {
437         fListeners.remove(listener);
438     }
439     
440     /**
441      * Returns a memento representing the value variables currently registered.
442      *
443      * @return memento representing the value variables currently registered
444      * @throws IOException if an I/O exception occurs while creating the XML.
445      */

446     private String JavaDoc getValueVariablesAsXML() throws IOException JavaDoc, ParserConfigurationException JavaDoc, TransformerException JavaDoc {
447         IValueVariable[] variables = getValueVariables();
448
449         Document JavaDoc document= getDocument();
450         Element rootElement= document.createElement(VALUE_VARIABLES_TAG);
451         document.appendChild(rootElement);
452         for (int i = 0; i < variables.length; i++) {
453             IValueVariable variable = variables[i];
454             if (!variable.isReadOnly()){
455                 // don't persist read-only variables or un-initialized contributed variables
456
if (!variable.isContributed() || ((ContributedValueVariable)variable).isInitialized()) {
457                     Element element= document.createElement(VALUE_VARIABLE_TAG);
458                     element.setAttribute(NAME_TAG, variable.getName());
459                     String JavaDoc value= variable.getValue();
460                     if (value != null) {
461                         element.setAttribute(VALUE_TAG, value);
462                     }
463                     element.setAttribute(READ_ONLY_TAG, variable.isReadOnly() ? TRUE_VALUE : FALSE_VALUE);
464                     String JavaDoc description= variable.getDescription();
465                     if (description != null) {
466                         element.setAttribute(DESCRIPTION_TAG, description);
467                     }
468                     rootElement.appendChild(element);
469                 }
470             }
471         }
472         return serializeDocument(document);
473     }
474     
475     private Document JavaDoc getDocument() throws ParserConfigurationException JavaDoc {
476         DocumentBuilderFactory JavaDoc dfactory = DocumentBuilderFactory.newInstance();
477         DocumentBuilder JavaDoc docBuilder = dfactory.newDocumentBuilder();
478         Document JavaDoc doc =docBuilder.newDocument();
479         return doc;
480     }
481     
482     /**
483      * Serializes a XML document into a string - encoded in UTF8 format,
484      * with platform line separators.
485      *
486      * @param doc document to serialize
487      * @return the document as a string
488      * @throws TransformerException if an unrecoverable error occurs during the serialization
489      * @throws IOException if the encoding attempted to be used is not supported
490      */

491     private String JavaDoc serializeDocument(Document JavaDoc doc) throws TransformerException JavaDoc, UnsupportedEncodingException JavaDoc {
492         ByteArrayOutputStream JavaDoc s= new ByteArrayOutputStream JavaDoc();
493         
494         TransformerFactory JavaDoc factory= TransformerFactory.newInstance();
495         Transformer JavaDoc transformer= factory.newTransformer();
496         transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
497
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
498

499         DOMSource JavaDoc source= new DOMSource JavaDoc(doc);
500         StreamResult JavaDoc outputTarget= new StreamResult JavaDoc(s);
501         transformer.transform(source, outputTarget);
502         
503         return s.toString("UTF8"); //$NON-NLS-1$
504
}
505     
506     /**
507      * Saves the value variables currently registered in the
508      * preference store.
509      */

510     private synchronized void storeValueVariables() {
511         Preferences prefs= VariablesPlugin.getDefault().getPluginPreferences();
512         String JavaDoc variableString= ""; //$NON-NLS-1$
513
if (!fValueVariables.isEmpty()) {
514             try {
515                 variableString= getValueVariablesAsXML();
516             } catch (IOException JavaDoc e) {
517                 VariablesPlugin.log(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), IStatus.ERROR, "An exception occurred while storing launch configuration variables.", e)); //$NON-NLS-1$
518
return;
519             } catch (ParserConfigurationException JavaDoc e) {
520                 VariablesPlugin.log(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), IStatus.ERROR, "An exception occurred while storing launch configuration variables.", e)); //$NON-NLS-1$
521
return;
522             } catch (TransformerException JavaDoc e) {
523                 VariablesPlugin.log(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), IStatus.ERROR, "An exception occurred while storing launch configuration variables.", e)); //$NON-NLS-1$
524
return;
525             }
526         }
527         fInternalChange = true;
528         prefs.setValue(PREF_VALUE_VARIABLES, variableString);
529         VariablesPlugin.getDefault().savePluginPreferences();
530         fInternalChange = false;
531     }
532
533     /**
534      * Fire a change notification for the given variable.
535      *
536      * @param variable the variable that has changed
537      */

538     protected void notifyChanged(IValueVariable variable) {
539         if (!fInternalChange) {
540             IValueVariable existing = getValueVariable(variable.getName());
541             if (variable.equals(existing)) {
542                 // do not do change notification for unregistered variables
543
getNotifier().notify(new IValueVariable[]{variable}, CHANGED);
544             }
545         }
546     }
547
548     /* (non-Javadoc)
549      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#generateVariableExpression(java.lang.String, java.lang.String)
550      */

551     public String JavaDoc generateVariableExpression(String JavaDoc varName, String JavaDoc arg) {
552         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
553         buffer.append("${"); //$NON-NLS-1$
554
buffer.append(varName);
555         if (arg != null) {
556             buffer.append(":"); //$NON-NLS-1$
557
buffer.append(arg);
558         }
559         buffer.append("}"); //$NON-NLS-1$
560
return buffer.toString();
561     }
562     
563     /* (non-Javadoc)
564      * @see org.eclipse.debug.internal.core.stringsubstitution.IStringVariableManager#performStringSubstitution(java.lang.String, boolean)
565      */

566     public String JavaDoc performStringSubstitution(String JavaDoc expression, boolean reportUndefinedVariables) throws CoreException {
567         return new StringSubstitutionEngine().performStringSubstitution(expression, reportUndefinedVariables, true, this);
568     }
569
570     /* (non-Javadoc)
571      * @see org.eclipse.core.variables.IStringVariableManager#validateStringVariables(java.lang.String)
572      */

573     public void validateStringVariables(String JavaDoc expression) throws CoreException {
574         new StringSubstitutionEngine().validateStringVariables(expression, this);
575     }
576
577     /* (non-Javadoc)
578      * @see org.eclipse.core.variables.IStringVariableManager#getContributingPluginId(org.eclipse.core.variables.IStringVariable)
579      */

580     public String JavaDoc getContributingPluginId(IStringVariable variable) {
581         if (variable instanceof StringVariable) {
582             return ((StringVariable) variable).getConfigurationElement().getContributor().getName();
583         }
584         return null;
585     }
586
587     /* (non-Javadoc)
588      * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
589      */

590     public void propertyChange(PropertyChangeEvent event) {
591         if (PREF_VALUE_VARIABLES.equals(event.getProperty())) {
592             synchronized (this) {
593                 if (!fInternalChange) {
594                     fValueVariables.clear();
595                     loadPersistedValueVariables();
596                     loadContributedValueVariables();
597                 }
598             }
599         }
600     }
601 }
602
Popular Tags