Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 50d444e98408ccb123bb1c31bea8210794a9412e (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
package org.eclipse.debug.internal.core;

/*
 * Licensed Materials - Property of IBM,
 * WebSphere Studio Workbench
 * (c) Copyright IBM Corp 2000
 */
 
import org.eclipse.debug.core.ILauncher;
import org.eclipse.debug.core.model.ILauncherDelegate;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * A handle to a launcher extension that instantiates the actual
 * extension lazily.
 */
public class Launcher implements ILauncher {
	
	/**
	 * The configuration element that defines this launcher handle
	 */
	protected IConfigurationElement fConfigElement = null;
	
	/**
	 * The underlying launcher, which is <code>null</code> until the
	 * it needs to be instantiated.
	 */
	protected ILauncherDelegate fDelegate = null;
	
	/**
	 * Cache of the modes this launcher supports
	 */
	protected Set fModes;
	
	/**
	 * Constructs a handle for a launcher extension.
	 */
	public Launcher(IConfigurationElement element) {
		fConfigElement = element;
	}
	
	/**
	 * @see ILauncher
	 */
	public String getIdentifier() {
		return fConfigElement.getAttribute("id");
	}
	
	/**
	 * Returns the set of modes specified in the configuration data.
	 * The set contains "mode" constants defined in <code>ILaunchManager</code>
	 */
	public Set getModes() {
		if (fModes == null) {
			String modes= fConfigElement.getAttribute("modes");
			if (modes == null) {
				return null;
			}
			StringTokenizer tokenizer= new StringTokenizer(modes, ",");
			fModes = new HashSet(tokenizer.countTokens());
			while (tokenizer.hasMoreTokens()) {
				fModes.add(tokenizer.nextToken().trim());
			}
		}
		return fModes;
	}
	
	/**
	 * Returns the label specified in the configuration data.
	 */
	public String getLabel() {
		return fConfigElement.getAttribute("label");
	}
	
	/**
	 * @see ILauncher
	 */
	public String getPerspectiveIdentifier() {
		return fConfigElement.getAttribute("perspective");
	}

	/**
	 * Returns the launcher for this handle, instantiating it if required.
	 */
	public ILauncherDelegate getDelegate() {
		if (fDelegate == null) {
			try {
				fDelegate = (ILauncherDelegate)fConfigElement.createExecutableExtension("class");
			} catch (CoreException e) {
				//status logged in the #createExecutableExtension code
			}
		}	
		return fDelegate;
	}
		
	/**
	 * @see ILauncher
	 */
	public boolean launch(Object[] elements, String mode) {
		return getDelegate().launch(elements, mode, this);
	}
		
	/**
	 * Returns the configuration element for this extension
	 */
	public IConfigurationElement getConfigurationElement() {
		return fConfigElement;
	}
}

Back to the top