org.springframework.shell.core.Converter Java Examples

The following examples show how to use org.springframework.shell.core.Converter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LensJLineShellComponent.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public void afterPropertiesSet() {

  Map<String, CommandMarker> commands = BeanFactoryUtils.beansOfTypeIncludingAncestors(
          applicationContext, CommandMarker.class);
  for (CommandMarker command : commands.values()) {
    getSimpleParser().add(command);
  }

  Map<String, Converter> converters = BeanFactoryUtils.beansOfTypeIncludingAncestors(
          applicationContext, Converter.class);
  for (Converter<?> converter : converters.values()) {
    getSimpleParser().add(converter);
  }
  
  setHistorySize(commandLine.getHistorySize());
  if (commandLine.getShellCommandsToExecute() != null) {
    setPrintBanner(false);
  }
}
 
Example #2
Source File: CommandManager.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Looks for a matching {@link Converter}
 * 
 * @param parameterType
 * @param context
 * @return {@link Converter}
 */
public Converter<?> getConverter(Class<?> parameterType, String context) {
  for (Converter<?> converter : converters) {
    if (converter.supports(parameterType, context)) {
      return converter;
    }
  }
  return null;
}
 
Example #3
Source File: CommandManager.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Looks for a matching {@link Converter}
 * 
 * @param parameterType
 * @param context
 * @return {@link Converter}
 */
public Converter<?> getConverter(Class<?> parameterType, String context) {
  for (Converter<?> converter : converters) {
    if (converter.supports(parameterType, context)) {
      return converter;
    }
  }
  return null;
}
 
Example #4
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter localeConverter() {
  return new LocaleConverter();
}
 
Example #5
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter booleanConverter() {
  return new BooleanConverter();
}
 
Example #6
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter characterConverter() {
  return new CharacterConverter();
}
 
Example #7
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter dateConverter() {
  return new DateConverter();
}
 
Example #8
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter doubleConverter() {
  return new DoubleConverter();
}
 
Example #9
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter enumConverter() {
  return new EnumConverter();
}
 
Example #10
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter floatConverter() {
  return new FloatConverter();
}
 
Example #11
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter integerConverter() {
  return new IntegerConverter();
}
 
Example #12
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter availableCommandsConverter() {
  return new AvailableCommandsConverter();
}
 
Example #13
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter longConverter() {
  return new LongConverter();
}
 
Example #14
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter shortConverter() {
  return new ShortConverter();
}
 
Example #15
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter staticFieldConverterImpl() {
  return new StaticFieldConverterImpl();
}
 
Example #16
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter blueprintConverter() {
  return new BlueprintConverter(client);
}
 
Example #17
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter hostConverter() {
  return new HostConverter(client);
}
 
Example #18
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter serviceConverter() {
  return new ServiceConverter(client);
}
 
Example #19
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter configConverter() {
  return new ConfigTypeConverter(client);
}
 
Example #20
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter bigIntegerConverter() {
  return new BigIntegerConverter();
}
 
Example #21
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter bigDecimalConverter() {
  return new BigDecimalConverter();
}
 
Example #22
Source File: Parameter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public Converter<?> getConverter() {
  return converter;
}
 
Example #23
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter stringConverter() {
  return new StringConverter();
}
 
Example #24
Source File: ConverterConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
Converter simpleFileConverter() {
  return new SimpleFileConverter();
}
 
Example #25
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object getConversionObject(Converter<?> converter, String string,
    Class<?> dataType, String context, String valueSeparator) {

  try {
    if (converter != null && converter instanceof MultipleValueConverter) {
        return ((MultipleValueConverter) converter).convertFromText(
            ParserUtils.splitValues(
                ((string != null) ? string.trim() : null),
                valueSeparator), dataType, context);
    }

    // Remove outer single or double quotes if found
    if (string != null && ((string.endsWith("\"") && string.endsWith("\""))
        || (string.startsWith("\'") && string.endsWith("\'")))) {
      string = string.substring(1, string.length() - 1);
    }

    if (converter != null) {
    return converter.convertFromText((string != null) ? string.trim()
        : null, dataType, context);
    }

    //TODO consider multiple value case for primitives
    if (string != null) {
      if (String.class.isAssignableFrom(dataType)) {
        return string.trim();
      } else if (Byte.class.isAssignableFrom(dataType)
          || byte.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Short.class.isAssignableFrom(dataType)
          || short.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Boolean.class.isAssignableFrom(dataType)
          || boolean.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Integer.class.isAssignableFrom(dataType)
          || int.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Long.class.isAssignableFrom(dataType)
          || long.class.isAssignableFrom(dataType)) {
        return Long.parseLong(string);
      } else if (Float.class.isAssignableFrom(dataType)
          || float.class.isAssignableFrom(dataType)) {
        return Float.parseFloat(string);
      } else if (Double.class.isAssignableFrom(dataType)
          || double.class.isAssignableFrom(dataType)) {
        return Double.parseDouble(string);
      } else if (Character.class.isAssignableFrom(dataType)
          || char.class.isAssignableFrom(dataType)) {
        if (string.length() == 1) {
          string.charAt(0);
        } else {
          // FIXME Use a constant here
          return '0';
        }
      }
    }
  } catch (Exception e) {
    // TODO add logging
    // Do nothing, just return null
  }
  return null;
}
 
Example #26
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private boolean getAllPossibleValuesForParameter(
    List<Completion> completionCandidates, Parameter parameter,
    String existingData, GfshMethodTarget gfshMethodTarget) {
  Converter<?> converter = parameter.getConverter();
  // Check if any new converter is available which
  // satisfies the requirements for this argument
  if (converter == null) {
    parameter.setConverter(commandManager.getConverter(
        parameter.getDataType(), parameter.getContext()));
    converter = parameter.getConverter();
  }
  // If still we do not have any matching converters, we return
  if (converter == null) {
    return false;
  } else {
    // Now pass the getAllPossibleValues function of Converter interface
    // all the required parameters

    // Check whether it is a MultipleValueConverter
    String valueSeparator = SyntaxConstants.VALUE_SEPARATOR;
    if (parameter instanceof Option && ((Option) parameter).getValueSeparator() != null) {
      valueSeparator = ((Option) parameter).getValueSeparator();
    }
    if (converter instanceof MultipleValueConverter) {
      ((MultipleValueConverter) converter).getAllPossibleValues(
          completionCandidates,
          parameter.getDataType(),
          ParserUtils.splitValues(existingData, valueSeparator),
          parameter.getContext(),
          new MethodTarget(gfshMethodTarget.getMethod(), gfshMethodTarget
              .getTarget(), gfshMethodTarget.getRemainingBuffer(),
              gfshMethodTarget.getKey()));
    } else {
      converter.getAllPossibleValues(
          completionCandidates,
          parameter.getDataType(),
          existingData,
          parameter.getContext(),
          new MethodTarget(gfshMethodTarget.getMethod(), gfshMethodTarget
              .getTarget(), gfshMethodTarget.getRemainingBuffer(),
              gfshMethodTarget.getKey()));
    }
  }
  if (completionCandidates.size() > 0) {
    return true;
  } else {
    return false;
  }
}
 
Example #27
Source File: Gfsh.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void add(final Converter<?> converter) {
  commandManager.add(converter);
}
 
Example #28
Source File: Parameter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void setConverter(Converter<?> converter) {
  this.converter = converter;
}
 
Example #29
Source File: Parameter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public Converter<?> getConverter() {
  return converter;
}
 
Example #30
Source File: GfshParser.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object getConversionObject(Converter<?> converter, String string,
    Class<?> dataType, String context, String valueSeparator) {

  try {
    if (converter != null && converter instanceof MultipleValueConverter) {
        return ((MultipleValueConverter) converter).convertFromText(
            ParserUtils.splitValues(
                ((string != null) ? string.trim() : null),
                valueSeparator), dataType, context);
    }

    // Remove outer single or double quotes if found
    if (string != null && ((string.endsWith("\"") && string.endsWith("\""))
        || (string.startsWith("\'") && string.endsWith("\'")))) {
      string = string.substring(1, string.length() - 1);
    }

    if (converter != null) {
    return converter.convertFromText((string != null) ? string.trim()
        : null, dataType, context);
    }

    //TODO consider multiple value case for primitives
    if (string != null) {
      if (String.class.isAssignableFrom(dataType)) {
        return string.trim();
      } else if (Byte.class.isAssignableFrom(dataType)
          || byte.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Short.class.isAssignableFrom(dataType)
          || short.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Boolean.class.isAssignableFrom(dataType)
          || boolean.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Integer.class.isAssignableFrom(dataType)
          || int.class.isAssignableFrom(dataType)) {
        return Integer.parseInt(string);
      } else if (Long.class.isAssignableFrom(dataType)
          || long.class.isAssignableFrom(dataType)) {
        return Long.parseLong(string);
      } else if (Float.class.isAssignableFrom(dataType)
          || float.class.isAssignableFrom(dataType)) {
        return Float.parseFloat(string);
      } else if (Double.class.isAssignableFrom(dataType)
          || double.class.isAssignableFrom(dataType)) {
        return Double.parseDouble(string);
      } else if (Character.class.isAssignableFrom(dataType)
          || char.class.isAssignableFrom(dataType)) {
        if (string.length() == 1) {
          string.charAt(0);
        } else {
          // FIXME Use a constant here
          return '0';
        }
      }
    }
  } catch (Exception e) {
    // TODO add logging
    // Do nothing, just return null
  }
  return null;
}