public abstract class AbstractShellCommand extends Object implements org.apache.karaf.shell.api.action.Action, CodecContext
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
log |
| 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 abstract void |
doExecute()
Body of the shell command.
|
void |
error(String format,
Object... args)
Prints the arguments using the specified format to error stream.
|
Object |
execute() |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdecode, encodepublic 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 boolean outputJson()
public final Object execute() throws Exception
execute in interface org.apache.karaf.shell.api.action.ActionExceptionprotected abstract void doExecute()
throws Exception
Exception - thrown when problem is encounteredpublic com.fasterxml.jackson.databind.ObjectMapper mapper()
CodecContextmapper in interface CodecContextpublic <T> JsonCodec<T> codec(Class<T> entityClass)
CodecContextcodec in interface CodecContextT - entity typeentityClass - entity classpublic <T> T getService(Class<T> serviceClass)
CodecContextgetService in interface CodecContextT - 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