コード例 #1
0
 @Override
 public void load(String name)
     throws ExtensionInitializationException, NoSuchExtensionException,
         ExtensionAlreadyLoadedException {
   if (isLoaded(name)) {
     throw new ExtensionAlreadyLoadedException(name);
   }
   get(name).load();
   loaded.add(name);
 }
コード例 #2
0
 @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);
 }
コード例 #3
0
 @Override
 public void unload(String name) throws ExtensionUnloadingException, NoSuchExtensionException {
   get(name).unload();
   loaded.remove(name);
 }
コード例 #4
0
 @Override
 public boolean isLoaded(String name) {
   return loaded.contains(name);
 }