KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > core > ContributedDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.debug.internal.core;
12
13 import com.ibm.icu.text.MessageFormat;
14 import java.util.HashSet JavaDoc;
15 import java.util.Set JavaDoc;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
22
23 /**
24  * A placeholder for a launch delegate contributed for a launch mode for an
25  * existing launch configuration type.
26  */

27 public class ContributedDelegate {
28
29     /**
30      * The configuration element of the extension.
31      */

32     private IConfigurationElement fElement;
33     
34     /**
35      * Modes this delegate supports.
36      */

37     private Set JavaDoc fModes;
38     
39     /**
40      * Delegate, or <code>null</code> if not yet instantiated.
41      */

42     private ILaunchConfigurationDelegate fDelegate;
43     
44     /**
45      * Constructs a new contributed delegate on the
46      * given configuration element.
47      *
48      * @param element configuration element
49      */

50     protected ContributedDelegate(IConfigurationElement element) {
51         setConfigurationElement(element);
52     }
53     
54     /**
55      * Sets this delegate's configuration element.
56      *
57      * @param element this delegate's configuration element
58      */

59     private void setConfigurationElement(IConfigurationElement element) {
60         fElement = element;
61     }
62     
63     /**
64      * Returns this delegate's configuration element.
65      *
66      * @return this delegate's configuration element
67      */

68     protected IConfigurationElement getConfigurationElement() {
69         return fElement;
70     }
71     
72     /**
73      * Returns the set of modes specified in the configuration data.
74      *
75      * @return the set of modes specified in the configuration data
76      */

77     protected Set JavaDoc getModes() {
78         if (fModes == null) {
79             String JavaDoc modes= getConfigurationElement().getAttribute("modes"); //$NON-NLS-1$
80
if (modes == null) {
81                 return new HashSet JavaDoc(0);
82             }
83             String JavaDoc[] strings = modes.split(","); //$NON-NLS-1$
84
fModes = new HashSet JavaDoc(3);
85             for (int i = 0; i < strings.length; i++) {
86                 String JavaDoc string = strings[i];
87                 fModes.add(string.trim());
88             }
89         }
90         return fModes;
91     }
92     
93     /**
94      * Returns the type identifier of launch configuration type this delegate is
95      * contributed to.
96      */

97     protected String JavaDoc getLaunchConfigurationType() {
98         return getConfigurationElement().getAttribute("type"); //$NON-NLS-1$
99
}
100     
101     protected ILaunchConfigurationDelegate getDelegate() throws CoreException {
102         if (fDelegate == null) {
103             Object JavaDoc object = getConfigurationElement().createExecutableExtension("delegate"); //$NON-NLS-1$
104
if (object instanceof ILaunchConfigurationDelegate) {
105                 fDelegate = (ILaunchConfigurationDelegate)object;
106             } else {
107                 throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format(DebugCoreMessages.LaunchConfigurationType_Launch_delegate_for__0__does_not_implement_required_interface_ILaunchConfigurationDelegate__1, new String JavaDoc[]{getIdentifier()}), null));
108             }
109         }
110         return fDelegate;
111     }
112     
113     /**
114      * Returns the identifier of this extension point.
115      */

116     protected String JavaDoc getIdentifier() {
117         return getConfigurationElement().getAttribute("id"); //$NON-NLS-1$
118
}
119     
120     /**
121      * Returns the source path computer id specified by this launch delegate
122      * or <code>null</code> if none.
123      *
124      * @return the source path computer id specified by this launch delegate
125      * or <code>null</code> if none
126      *
127      * @since 3.1
128      */

129     protected String JavaDoc getSourcePathComputerId() {
130         return getConfigurationElement().getAttribute("sourcePathComputerId"); //$NON-NLS-1$
131
}
132     
133     /**
134      * Returns the source locater id specified by this launch delegate
135      * or <code>null</code> if none.
136      *
137      * @return the source locater id specified by this launch delegate
138      * or <code>null</code> if none
139      *
140      * @since 3.1
141      */

142     protected String JavaDoc getSourceLocaterId() {
143         return getConfigurationElement().getAttribute("sourceLocatorId"); //$NON-NLS-1$
144
}
145 }
146
Popular Tags