1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.eclipse.common.launch;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.debug.core.DebugPlugin;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21 import org.eclipse.debug.core.ILaunchConfigurationType;
22 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23 import org.eclipse.debug.core.ILaunchManager;
24 import org.seasar.eclipse.common.CommonPlugin;
25
26
27
28
29
30 public class LaunchConfigurationFactory {
31
32 public static ILaunchConfiguration create(CreationHandler handler) {
33 ILaunchConfiguration config = null;
34 try {
35 ILaunchManager manager = DebugPlugin.getDefault()
36 .getLaunchManager();
37 ILaunchConfigurationType type = manager
38 .getLaunchConfigurationType(handler.getTypeName());
39 ILaunchConfiguration[] configs = manager
40 .getLaunchConfigurations(type);
41 for (ILaunchConfiguration element : configs) {
42 if (element.getName().equals(handler.getConfigName())) {
43 if (handler.equals(element)) {
44 config = element;
45 } else {
46 element.delete();
47 }
48 break;
49 }
50 }
51 if (config == null) {
52 ILaunchConfigurationWorkingCopy copy = type.newInstance(null,
53 handler.getConfigName());
54 handler.setUp(copy);
55 config = copy.doSave();
56 }
57 } catch (CoreException e) {
58 CommonPlugin.log(e);
59 }
60 return config;
61 }
62
63 public interface CreationHandler {
64
65 String getTypeName();
66
67 String getConfigName();
68
69 boolean equals(ILaunchConfiguration config);
70
71 void setUp(ILaunchConfigurationWorkingCopy config);
72 }
73 }