private Map<String, Object> config(List<RadiusConfigMetadata> spec) throws InterruptedException { Map<String, Object> configs = new HashMap<String, Object>(); for (RadiusConfigMetadata metadata : spec) { String type = metadata.getType().toString().toLowerCase(); String def = ""; if (metadata.getDefaultValue() != null) def = "(" + metadata.getDefaultValue() + ") "; context.print(metadata.getName() + " in " + type + " type " + def + "? "); String line = context.readLine(); Object value = metadata.getType().parse(line); configs.put(metadata.getName(), value); } return configs; }
private List<String> select(RadiusModuleType type) throws InterruptedException { // get instance names List<String> names = new ArrayList<String>(); RadiusModule module = server.getModule(type); for (RadiusInstance instance : module.getInstances()) { names.add(instance.getName()); } // print instance list List<String> selected = new ArrayList<String>(); int i = 1; for (String name : names) { context.println("[" + (i++) + "] " + name); } context.println("---------------------------"); while (true) { try { context.print("select index (0 for end): "); int index = Integer.valueOf(context.readLine()); if (index == 0) break; if (index < 0 || index > names.size()) { context.println("no item corresponds to selected index"); continue; } // add to select bucket String name = names.get(index - 1); if (!selected.contains(name)) { selected.add(name); context.println(name + " added"); } } catch (NumberFormatException e) { context.println(""); throw new RuntimeException("invalid number format"); } } return selected; }