@Override public void load(String name) throws ExtensionInitializationException, NoSuchExtensionException, ExtensionAlreadyLoadedException { if (isLoaded(name)) { throw new ExtensionAlreadyLoadedException(name); } get(name).load(); loaded.add(name); }
@Override public void execute(String command) throws InvalidCommandException, AmbiguousCommandException, ConsoleCommandExecutionException { command = command.trim(); String target = ""; if (command.matches("\\S+:.*")) { target = command.substring(0, command.indexOf(":")); command = command.substring(command.indexOf(":") + 1).trim(); for (ProxiedExtensionWrapper wrapper : extensions.values()) { if (wrapper.getNamespace().equals(target)) { wrapper.execute(command); target = ""; break; } } if (!target.isEmpty()) { throw new IllegalStateException("No such namespace: " + target); } return; } final Set<ExtensionWrapper> namespaces = new HashSet<ExtensionWrapper>(); for (String name : loaded) { ProxiedExtensionWrapper wrapper = extensions.get(name); if (wrapper.knows(command)) { namespaces.add(wrapper); } } if (namespaces.isEmpty()) { throw new InvalidCommandException("Invalid command: " + command); } if (namespaces.size() == 1) { final ExtensionWrapper wrapper = namespaces.iterator().next(); wrapper.execute(command); return; } final String[] strings = new String[namespaces.size()]; int i = 0; for (ExtensionWrapper namespace : namespaces) { strings[i++] = namespace.getNamespace(); } throw new AmbiguousCommandException(command, strings); }