1 11 package org.eclipse.ui.internal.commands; 12 13 import org.eclipse.core.commands.AbstractParameterValueConverter; 14 import org.eclipse.core.commands.ParameterValueConversionException; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 18 19 26 public final class ParameterValueConverterProxy extends 27 AbstractParameterValueConverter { 28 29 34 private final IConfigurationElement converterConfigurationElement; 35 36 40 private AbstractParameterValueConverter parameterValueConverter; 41 42 50 public ParameterValueConverterProxy( 51 final IConfigurationElement converterConfigurationElement) { 52 if (converterConfigurationElement == null) { 53 throw new NullPointerException ( 54 "converterConfigurationElement must not be null"); } 56 57 this.converterConfigurationElement = converterConfigurationElement; 58 } 59 60 public final Object convertToObject(final String parameterValue) 61 throws ParameterValueConversionException { 62 return getConverter().convertToObject(parameterValue); 63 } 64 65 public final String convertToString(final Object parameterValue) 66 throws ParameterValueConversionException { 67 return getConverter().convertToString(parameterValue); 68 } 69 70 78 private AbstractParameterValueConverter getConverter() 79 throws ParameterValueConversionException { 80 if (parameterValueConverter == null) { 81 try { 82 parameterValueConverter = (AbstractParameterValueConverter) converterConfigurationElement 83 .createExecutableExtension(IWorkbenchRegistryConstants.ATT_CONVERTER); 84 } catch (final CoreException e) { 85 throw new ParameterValueConversionException( 86 "Problem creating parameter value converter", e); } catch (final ClassCastException e) { 88 throw new ParameterValueConversionException( 89 "Parameter value converter was not a subclass of AbstractParameterValueConverter", e); } 91 } 92 return parameterValueConverter; 93 } 94 } 95 | Popular Tags |