KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.internal.variables;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.variables.IDynamicVariable;
18 import org.eclipse.core.variables.IDynamicVariableResolver;
19 import org.eclipse.core.variables.VariablesPlugin;
20 import org.eclipse.osgi.util.NLS;
21
22 /**
23  * Dynamic variable
24  */

25 public class DynamicVariable extends StringVariable implements IDynamicVariable {
26     
27     /**
28      * Resolver, or <code>null</code> until needed
29      */

30     private IDynamicVariableResolver fResolver;
31
32     /* (non-Javadoc)
33      * @see org.eclipse.debug.internal.core.stringsubstitution.IContextVariable#getValue(java.lang.String)
34      */

35     public String JavaDoc getValue(String JavaDoc argument) throws CoreException {
36         if (!supportsArgument()) {
37             // check for an argument - not supported
38
if (argument != null && argument.length() > 0) {
39                 throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, NLS.bind(VariablesMessages.DynamicVariable_0, new String JavaDoc[]{argument, getName()}), null));
40             }
41         }
42         if (fResolver == null) {
43             String JavaDoc name = getConfigurationElement().getAttribute("resolver"); //$NON-NLS-1$
44
if (name == null) {
45                 throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, NLS.bind("Contributed context variable {0} must specify a resolver.",new String JavaDoc[]{getName()}), null)); //$NON-NLS-1$
46
}
47             Object JavaDoc object = getConfigurationElement().createExecutableExtension("resolver"); //$NON-NLS-1$
48
if (object instanceof IDynamicVariableResolver) {
49                 fResolver = (IDynamicVariableResolver)object;
50             } else {
51                 throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, NLS.bind("Contributed context variable resolver for {0} must be an instance of IContextVariableResolver.",new String JavaDoc[]{getName()}), null)); //$NON-NLS-1$
52
}
53         }
54         return fResolver.resolveValue(this, argument);
55     }
56
57     /**
58      * Constructs a new context variable.
59      *
60      * @param name variable name
61      * @param description variable description or <code>null</code>
62      * @param configurationElement configuration element
63      */

64     public DynamicVariable(String JavaDoc name, String JavaDoc description, IConfigurationElement configurationElement) {
65         super(name, description, configurationElement);
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.core.variables.IDynamicVariable#supportsArgument()
70      */

71     public boolean supportsArgument() {
72         String JavaDoc arg = getConfigurationElement().getAttribute("supportsArgument"); //$NON-NLS-1$
73
return arg == null || Boolean.valueOf(arg).booleanValue();
74     }
75     
76 }
77
Popular Tags