geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r699623 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle: BundleSupport.java CommandBundle.java
Date Sat, 27 Sep 2008 12:13:13 GMT
Author: jdillon
Date: Sat Sep 27 05:13:13 2008
New Revision: 699623

URL: http://svn.apache.org/viewvc?rev=699623&view=rev
Log:
Add BundleSupport to hide some of the state details, make the state relevant bits synchronized

Added:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
  (contents, props changed)
      - copied, changed from r699621, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
Modified:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java

Copied: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
(from r699621, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java?p2=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java&p1=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java&r1=699621&r2=699623&rev=699623&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
Sat Sep 27 05:13:13 2008
@@ -19,40 +19,24 @@
 
 package org.apache.geronimo.gshell.wisdom.plugin.bundle;
 
-import org.apache.geronimo.gshell.command.Command;
-import org.apache.geronimo.gshell.registry.CommandRegistry;
-import org.apache.geronimo.gshell.registry.AliasRegistry;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Map;
-
 /**
- * A bundle of {@link Command} instances.
+ * Support for {@link Bundle} components.
  *
  * @version $Rev$ $Date$
  */
-public class CommandBundle
+public abstract class BundleSupport
     implements Bundle
 {
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    @Autowired
-    private CommandRegistry commandRegistry;
-
-    @Autowired
-    private AliasRegistry aliasRegistry;
+    protected final Logger log = LoggerFactory.getLogger(getClass());
 
+    private final String name;
+    
     private boolean enabled = false;
 
-    private String name;
-
-    private Map<String,Command> commands;
-
-    private Map<String,String> aliases;
-
-    public CommandBundle(final String name) {
+    protected BundleSupport(final String name) {
         assert name != null;
 
         this.name = name;
@@ -62,63 +46,35 @@
         return name;
     }
 
-    public Map<String, Command> getCommands() {
-        return commands;
-    }
-
-    public void setCommands(final Map<String, Command> commands) {
-        assert commands != null;
-        
-        this.commands = commands;
-    }
-
-    public Map<String, String> getAliases() {
-        return aliases;
-    }
-
-    public void setAliases(final Map<String, String> aliases) {
-        assert aliases != null;
-
-        this.aliases = aliases;
-    }
-
-    public boolean isEnabled() {
+    public synchronized boolean isEnabled() {
         return enabled;
     }
 
-    public void enable() throws Exception {
+    public synchronized void enable() throws Exception {
         if (enabled) {
-            throw new IllegalStateException("Already enabled");
+            throw new IllegalStateException("Bundle already enabled: " + name);
         }
 
-        log.debug("Enabling");
+        log.debug("Enabling bundle: {}", name);
 
-        for (String name : commands.keySet()) {
-            commandRegistry.registerCommand(name, commands.get(name));
-        }
-
-        for (String name : aliases.keySet()) {
-            aliasRegistry.registerAlias(name, aliases.get(name));
-        }
+        doEnable();
 
         enabled = true;
     }
 
-    public void disable() throws Exception {
+    protected abstract void doEnable() throws Exception;
+
+    public synchronized void disable() throws Exception {
         if (!enabled) {
-            throw new IllegalStateException("Not enabled");
+            throw new IllegalStateException("Bundle not enabled: " + name);
         }
 
-        log.debug("Disabling");
-        
-        for (String name : commands.keySet()) {
-            commandRegistry.removeCommand(name);
-        }
+        log.debug("Disabling bundle: {}", name);
 
-        for (String name : aliases.keySet()) {
-            aliasRegistry.removeAlias(name);
-        }
+        doDisable();
 
         enabled = false;
     }
+
+    protected abstract void doDisable() throws Exception;
 }
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/BundleSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java?rev=699623&r1=699622&r2=699623&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
Sat Sep 27 05:13:13 2008
@@ -20,11 +20,9 @@
 package org.apache.geronimo.gshell.wisdom.plugin.bundle;
 
 import org.apache.geronimo.gshell.command.Command;
-import org.apache.geronimo.gshell.registry.CommandRegistry;
 import org.apache.geronimo.gshell.registry.AliasRegistry;
+import org.apache.geronimo.gshell.registry.CommandRegistry;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.util.Map;
 
@@ -34,32 +32,20 @@
  * @version $Rev$ $Date$
  */
 public class CommandBundle
-    implements Bundle
+    extends BundleSupport
 {
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
     @Autowired
     private CommandRegistry commandRegistry;
 
     @Autowired
     private AliasRegistry aliasRegistry;
 
-    private boolean enabled = false;
-
-    private String name;
-
     private Map<String,Command> commands;
 
     private Map<String,String> aliases;
 
     public CommandBundle(final String name) {
-        assert name != null;
-
-        this.name = name;
-    }
-
-    public String getName() {
-        return name;
+        super(name);
     }
 
     public Map<String, Command> getCommands() {
@@ -82,43 +68,27 @@
         this.aliases = aliases;
     }
 
-    public boolean isEnabled() {
-        return enabled;
-    }
-
-    public void enable() throws Exception {
-        if (enabled) {
-            throw new IllegalStateException("Already enabled");
-        }
-
-        log.debug("Enabling");
-
+    protected void doEnable() throws Exception {
+        assert commandRegistry != null;
         for (String name : commands.keySet()) {
             commandRegistry.registerCommand(name, commands.get(name));
         }
 
+        assert aliasRegistry != null;
         for (String name : aliases.keySet()) {
             aliasRegistry.registerAlias(name, aliases.get(name));
         }
-
-        enabled = true;
     }
 
-    public void disable() throws Exception {
-        if (!enabled) {
-            throw new IllegalStateException("Not enabled");
-        }
-
-        log.debug("Disabling");
-        
+    protected void doDisable() throws Exception {
+        assert commandRegistry != null;
         for (String name : commands.keySet()) {
             commandRegistry.removeCommand(name);
         }
 
+        assert aliasRegistry != null;
         for (String name : aliases.keySet()) {
             aliasRegistry.removeAlias(name);
         }
-
-        enabled = false;
     }
 }
\ No newline at end of file



Mime
View raw message