KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.debug.internal.core;
12
13 import com.ibm.icu.text.MessageFormat;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.debug.core.DebugPlugin;
19 import org.eclipse.debug.core.ILaunchMode;
20
21 /**
22  * Proxy to a launch mode extension.
23  */

24 public class LaunchMode implements ILaunchMode {
25
26     private IConfigurationElement fConfigurationElement;
27     
28     /**
29      * Constructs a new launch mode.
30      *
31      * @param element configuration element
32      * @exception CoreException if required attributes are missing
33      */

34     public LaunchMode(IConfigurationElement element) throws CoreException {
35         fConfigurationElement = element;
36         verifyAttributes();
37     }
38
39     /**
40      * Verifies required attributes.
41      *
42      * @exception CoreException if required attributes are missing
43      */

44     private void verifyAttributes() throws CoreException {
45         verifyAttributeExists("mode"); //$NON-NLS-1$
46
verifyAttributeExists("label"); //$NON-NLS-1$
47
}
48     
49     /**
50      * Verifies the given attribute exists
51      *
52      * @exception CoreException if attribute does not exist
53      */

54     private void verifyAttributeExists(String JavaDoc name) throws CoreException {
55         if (fConfigurationElement.getAttribute(name) == null) {
56             missingAttribute(name);
57         }
58     }
59
60     private void missingAttribute(String JavaDoc attrName) throws CoreException {
61         throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, MessageFormat.format(DebugCoreMessages.LaunchMode_1,new String JavaDoc[]{attrName}), null));
62     }
63     
64     /* (non-Javadoc)
65      * @see org.eclipse.debug.core.ILaunchMode#getIdentifier()
66      */

67     public String JavaDoc getIdentifier() {
68         return fConfigurationElement.getAttribute("mode"); //$NON-NLS-1$;
69
}
70     /* (non-Javadoc)
71      * @see org.eclipse.debug.core.ILaunchMode#getLabel()
72      */

73     public String JavaDoc getLabel() {
74         return fConfigurationElement.getAttribute("label"); //$NON-NLS-1$;
75
}
76
77     /* (non-Javadoc)
78      * @see org.eclipse.debug.core.ILaunchMode#getLaunchAsLabel()
79      */

80     public String JavaDoc getLaunchAsLabel() {
81         String JavaDoc label = fConfigurationElement.getAttribute("launchAsLabel"); //$NON-NLS-1$
82
if (label == null) {
83             return MessageFormat.format(DebugCoreMessages.LaunchMode_0, new String JavaDoc[]{getLabel()});
84         }
85         return label;
86     }
87 }
88
Popular Tags