You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/10/05 12:05:12 UTC
svn commit: r582187 -
/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java
Author: jdillon
Date: Fri Oct 5 03:05:09 2007
New Revision: 582187
URL: http://svn.apache.org/viewvc?rev=582187&view=rev
Log:
Hook up exceptions
Modified:
geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java
Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java?rev=582187&r1=582186&r2=582187&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java Fri Oct 5 03:05:09 2007
@@ -19,17 +19,16 @@
package org.apache.geronimo.gshell.registry;
-import org.apache.geronimo.gshell.command.Command;
-import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
-import org.codehaus.plexus.component.annotations.Component;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.apache.geronimo.gshell.command.Command;
+import org.codehaus.plexus.component.annotations.Component;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Registers command components as they are discovered by the container.
*
@@ -43,36 +42,42 @@
private Map<String, Command> commands = new HashMap<String, Command>();
- public void register(final Command command) {
+ public void register(final Command command) throws DuplicateRegistrationException {
assert command != null;
String id = command.getId();
if (commands.containsKey(id)) {
- log.error("Ignoring duplicate: {}", id);
+ throw new DuplicateRegistrationException(id);
}
- else {
- commands.put(id, command);
- log.debug("Registered: {}", id);
+
+ commands.put(id, command);
+ log.debug("Registered: {}", id);
+ }
+
+ private void ensureRegistered(final String id) throws NotRegisteredException {
+ assert id != null;
+
+ if (!commands.containsKey(id)) {
+ throw new NotRegisteredException(id);
}
}
- public void unregister(final Command command) {
+ public void unregister(final Command command) throws NotRegisteredException {
assert command != null;
String id = command.getId();
- if (!commands.containsKey(id)) {
- log.error("Ignoring uregistered: {}", id);
- }
- else {
- commands.remove(id);
- log.debug("Unregistered: {}", id);
- }
+ ensureRegistered(id);
+
+ commands.remove(id);
+ log.debug("Unregistered: {}", id);
}
- public Command lookup(final String id) {
+ public Command lookup(final String id) throws NotRegisteredException {
assert id != null;
+
+ ensureRegistered(id);
return commands.get(id);
}