Interface Converter

All Known Implementing Classes:
CommandSessionImpl

public interface Converter
A converter is a service that can help create specific object types from a string, and vice versa.

The shell is capable of coercing arguments to the their proper type. However, sometimes commands require extra help to do this conversion. This service can implement a converter for a number of types.

The command shell will rank these services in order of service.ranking and will then call them until one of the converters succeeds.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    This property is a string, or array of strings, and defines the classes or interfaces that this converter recognizes.
    static final int
    Print the object in detail.
    static final int
    Print the object as a row in a table.
    static final int
    Print the value in a small format so that it is identifiable.
  • Method Summary

    Modifier and Type
    Method
    Description
    convert(Class<?> desiredType, Object in)
    Convert an object to the desired type.
    format(Object target, int level, Converter escape)
    Convert an objet to a CharSequence object in the requested format.
  • Field Details

    • CONVERTER_CLASSES

      static final String CONVERTER_CLASSES
      This property is a string, or array of strings, and defines the classes or interfaces that this converter recognizes. Recognized classes can be converted from a string to a class and they can be printed in 3 different modes.
      See Also:
    • INSPECT

      static final int INSPECT
      Print the object in detail. This can contain multiple lines.
      See Also:
    • LINE

      static final int LINE
      Print the object as a row in a table. The columns should align for multiple objects printed beneath each other. The print may run over multiple lines but must not end in a CR.
      See Also:
    • PART

      static final int PART
      Print the value in a small format so that it is identifiable. This printed format must be recognizable by the conversion method.
      See Also:
  • Method Details

    • convert

      Object convert(Class<?> desiredType, Object in) throws Exception
      Convert an object to the desired type.

      Return null if the conversion can not be done. Otherwise return and object that extends the desired type or implements it.

      Parameters:
      desiredType - The type that the returned object can be assigned to
      in - The object that must be converted
      Returns:
      An object that can be assigned to the desired type or null.
      Throws:
      Exception
    • format

      CharSequence format(Object target, int level, Converter escape) throws Exception
      Convert an objet to a CharSequence object in the requested format. The format can be INSPECT, LINE, or PART. Other values must throw IllegalArgumentException.
      Parameters:
      target - The object to be converted to a String
      level - One of INSPECT, LINE, or PART.
      escape - Use this object to format sub ordinate objects.
      Returns:
      A printed object of potentially multiple lines
      Throws:
      Exception