Class AbstractShellCommand

    • Field Detail

      • log

        protected static final org.slf4j.Logger log
    • Constructor Detail

      • AbstractShellCommand

        public AbstractShellCommand()
    • Method Detail

      • get

        public static <T> T get​(Class<T> serviceClass)
        Returns the reference to the implementation of the specified service.
        Type Parameters:
        T - type of service
        Parameters:
        serviceClass - service class
        Returns:
        service implementation
        Throws:
        ServiceNotFoundException - if service is unavailable
      • appId

        protected ApplicationId appId()
        Returns application ID for the CLI.
        Returns:
        command-line application identifier
      • annotations

        public static String annotations​(Annotations annotations)
        Produces a string image of the specified key/value annotations.
        Parameters:
        annotations - key/value annotations
        Returns:
        string image with ", k1=v1, k2=v2, ..." pairs
      • annotations

        public static String annotations​(Annotations annotations,
                                         Set<String> excludedKeys)
        Produces a string image of the specified key/value annotations. Excludes the keys in the given Set.
        Parameters:
        annotations - key/value annotations
        excludedKeys - keys not to add in the resulting string
        Returns:
        string image with ", k1=v1, k2=v2, ..." pairs
      • annotations

        public static com.fasterxml.jackson.databind.node.ObjectNode annotations​(com.fasterxml.jackson.databind.ObjectMapper mapper,
                                                                                 Annotations annotations)
        Produces a JSON object from the specified key/value annotations.
        Parameters:
        mapper - ObjectMapper to use while converting to JSON
        annotations - key/value annotations
        Returns:
        JSON object
      • outputJson

        protected boolean outputJson()
        Indicates whether JSON format should be output.
        Returns:
        true if JSON is requested
      • execute

        public final Object execute()
                             throws Exception
        Specified by:
        execute in interface org.apache.karaf.shell.api.action.Action
        Throws:
        Exception
      • doExecute

        protected abstract void doExecute()
                                   throws Exception
        Body of the shell command.
        Throws:
        Exception - thrown when problem is encountered
      • mapper

        public com.fasterxml.jackson.databind.ObjectMapper mapper()
        Description copied from interface: CodecContext
        Returns the JSON object mapper.
        Specified by:
        mapper in interface CodecContext
        Returns:
        object mapper
      • codec

        public <T> JsonCodec<T> codec​(Class<T> entityClass)
        Description copied from interface: CodecContext
        Returns the JSON codec for the specified entity class.
        Specified by:
        codec in interface CodecContext
        Type Parameters:
        T - entity type
        Parameters:
        entityClass - entity class
        Returns:
        JSON codec; null if no codec available for the class
      • getService

        public <T> T getService​(Class<T> serviceClass)
        Description copied from interface: CodecContext
        Returns reference to the specified service implementation.
        Specified by:
        getService in interface CodecContext
        Type Parameters:
        T - service type
        Parameters:
        serviceClass - service class
        Returns:
        service implementation; null if no implementation available for the class
      • jsonForEntity

        public <T> com.fasterxml.jackson.databind.node.ObjectNode jsonForEntity​(T entity,
                                                                                Class<T> entityClass)
        Generates a Json representation of an object.
        Type Parameters:
        T - Type of the object being formatted
        Parameters:
        entity - object to generate JSON for
        entityClass - class to format with - this chooses which codec to use
        Returns:
        JSON object representation