public ValueCompleter(final String attrName) {
super(new CandidatesProvider() {
@Override
public List<String> getAllCandidates(CommandContext ctx) {
ModelControllerClient client = ctx.getModelControllerClient();
if(client == null) {
return Collections.emptyList();
}
DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
if (ctx.isDomainMode()) {
final String profileName = profile.getValue(ctx.getParsedCommandLine());
if (profileName == null) {
return Collections.emptyList();
}
builder.addNode("profile", profileName);
}
builder.addNode("subsystem", "datasources");
final String dsName = jndiName.getValue(ctx.getParsedCommandLine());
if(dsName == null) {
return Collections.emptyList();
}
builder.addNode(dsType, dsName);
builder.setOperationName("read-attribute");
builder.addProperty("name", attrName);
try {
ModelNode result = client.execute(builder.buildRequest());
if(!result.hasDefined("result"))
return Collections.emptyList();
return Collections.singletonList(result.get("result").asString());
} catch (Exception e) {
return Collections.emptyList();