1 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 25 public class DynamicVariable extends StringVariable implements IDynamicVariable { 26 27 30 private IDynamicVariableResolver fResolver; 31 32 35 public String getValue(String argument) throws CoreException { 36 if (!supportsArgument()) { 37 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 []{argument, getName()}), null)); 40 } 41 } 42 if (fResolver == null) { 43 String name = getConfigurationElement().getAttribute("resolver"); 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 []{getName()}), null)); } 47 Object object = getConfigurationElement().createExecutableExtension("resolver"); 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 []{getName()}), null)); } 53 } 54 return fResolver.resolveValue(this, argument); 55 } 56 57 64 public DynamicVariable(String name, String description, IConfigurationElement configurationElement) { 65 super(name, description, configurationElement); 66 } 67 68 71 public boolean supportsArgument() { 72 String arg = getConfigurationElement().getAttribute("supportsArgument"); return arg == null || Boolean.valueOf(arg).booleanValue(); 74 } 75 76 } 77 | Popular Tags |