public abstract class AbstractShellCommand extends org.apache.karaf.shell.console.AbstractAction implements CodecContext
Constructor and Description |
---|
AbstractShellCommand() |
Modifier and Type | Method and Description |
---|---|
static String |
annotations(Annotations annotations)
Produces a string image of the specified key/value annotations.
|
static String |
annotations(Annotations annotations,
Set<String> excludedKeys)
Produces a string image of the specified key/value annotations.
|
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.
|
protected ApplicationId |
appId()
Returns application ID for the CLI.
|
<T> JsonCodec<T> |
codec(Class<T> entityClass)
Returns the JSON codec for the specified entity class.
|
protected Object |
doExecute() |
void |
error(String format,
Object... args)
Prints the arguments using the specified format to error stream.
|
protected abstract void |
execute()
Executes this command.
|
static <T> T |
get(Class<T> serviceClass)
Returns the reference to the implementation of the specified service.
|
<T> T |
getService(Class<T> serviceClass)
Returns reference to the specified service implementation.
|
<T> com.fasterxml.jackson.databind.node.ObjectNode |
jsonForEntity(T entity,
Class<T> entityClass)
Generates a Json representation of an object.
|
com.fasterxml.jackson.databind.ObjectMapper |
mapper()
Returns the JSON object mapper.
|
protected boolean |
outputJson()
Indicates whether JSON format should be output.
|
void |
print(String format,
Object... args)
Prints the arguments using the specified format.
|
checkInterrupted, execute
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
decode, encode
public static <T> T get(Class<T> serviceClass)
T
- type of serviceserviceClass
- service classServiceNotFoundException
- if service is unavailableprotected ApplicationId appId()
public void print(String format, Object... args)
format
- format string; see String.format(java.lang.String, java.lang.Object...)
args
- argumentspublic void error(String format, Object... args)
format
- format string; see String.format(java.lang.String, java.lang.Object...)
args
- argumentspublic static String annotations(Annotations annotations)
annotations
- key/value annotationspublic static String annotations(Annotations annotations, Set<String> excludedKeys)
annotations
- key/value annotationsexcludedKeys
- keys not to add in the resulting stringpublic static com.fasterxml.jackson.databind.node.ObjectNode annotations(com.fasterxml.jackson.databind.ObjectMapper mapper, Annotations annotations)
mapper
- ObjectMapper to use while converting to JSONannotations
- key/value annotationsprotected abstract void execute()
protected boolean outputJson()
protected Object doExecute() throws Exception
doExecute
in class org.apache.karaf.shell.console.AbstractAction
Exception
public com.fasterxml.jackson.databind.ObjectMapper mapper()
CodecContext
mapper
in interface CodecContext
public <T> JsonCodec<T> codec(Class<T> entityClass)
CodecContext
codec
in interface CodecContext
T
- entity typeentityClass
- entity classpublic <T> T getService(Class<T> serviceClass)
CodecContext
getService
in interface CodecContext
T
- service typeserviceClass
- service classpublic <T> com.fasterxml.jackson.databind.node.ObjectNode jsonForEntity(T entity, Class<T> entityClass)
T
- Type of the object being formattedentity
- object to generate JSON forentityClass
- class to format with - this chooses which codec to use