// Create a new command, set name/description/usage
Command apiCommand = new Command();
apiCommand.setName(command);
Implementation impl = clas.getAnnotation(Implementation.class);
if (impl == null) {
impl = clas.getSuperclass().getAnnotation(Implementation.class);
}
if (impl.includeInApiDoc()) {
String commandDescription = impl.description();
if (commandDescription != null && !commandDescription.isEmpty()) {
apiCommand.setDescription(commandDescription);
} else {
System.out.println("Command " + apiCommand.getName() + " misses description");
}
String commandUsage = impl.usage();
if (commandUsage != null && !commandUsage.isEmpty()) {
apiCommand.setUsage(commandUsage);
}
//Set version when the API is added
if(!impl.since().isEmpty()){
apiCommand.setSinceVersion(impl.since());
}
// Set request parameters
Field[] fields = clas.getDeclaredFields();
// Get fields from superclass
Class<?> superClass = clas.getSuperclass();
boolean isAsync = false;
while (superClass != null && superClass != Object.class) {
String superName = superClass.getName();
if (!superName.equals(BaseCmd.class.getName()) && !superName.equals(BaseAsyncCmd.class.getName()) && !superName.equals(BaseAsyncCreateCmd.class.getName())) {
Field[] superClassFields = superClass.getDeclaredFields();
if (superClassFields != null) {
Field[] tmpFields = new Field[fields.length + superClassFields.length];
System.arraycopy(fields, 0, tmpFields, 0, fields.length);
System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length);
fields = tmpFields;
}
}
superClass = superClass.getSuperclass();
// Set Async information for the command
if (superName.equals(BaseAsyncCmd.class.getName()) || superName.equals(BaseAsyncCreateCmd.class.getName())) {
isAsync = true;
}
}
apiCommand.setAsync(isAsync);
request = setRequestFields(fields);
// Get response parameters
Class<?> responseClas = impl.responseObject();
Field[] responseFields = responseClas.getDeclaredFields();
response = setResponseFields(responseFields, responseClas);
apiCommand.setRequest(request);
apiCommand.setResponse(response);