felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1055094 - /felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
Date Tue, 04 Jan 2011 16:39:47 GMT
Author: gnodet
Date: Tue Jan  4 16:39:47 2011
New Revision: 1055094

URL: http://svn.apache.org/viewvc?rev=1055094&view=rev
Log:
[FELIX-2761] Add a way to intercept execution of command lines

Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java?rev=1055094&r1=1055093&r2=1055094&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
(original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
Tue Jan  4 16:39:47 2011
@@ -21,16 +21,22 @@
 // DWB10: add SCOPE support: https://www.osgi.org/bugzilla/show_bug.cgi?id=51
 package org.apache.felix.gogo.runtime;
 
-import org.apache.felix.service.command.CommandSession;
-import org.apache.felix.service.command.Converter;
-import org.apache.felix.service.command.Function;
-import org.apache.felix.service.threadio.ThreadIO;
-
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Formatter;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.service.command.CommandSession;
+import org.apache.felix.service.command.Converter;
+import org.apache.felix.service.command.Function;
+import org.apache.felix.service.threadio.ThreadIO;
 
 public class CommandSessionImpl implements CommandSession, Converter
 {
@@ -75,9 +81,20 @@ public class CommandSessionImpl implemen
             throw new IllegalStateException(SESSION_CLOSED);
         }
 
-        Closure impl = new Closure(this, null, commandline);
-        Object result = impl.execute(this, null);
-        return result;
+        beforeExecute(commandline);
+
+        try
+        {
+            Closure impl = new Closure(this, null, commandline);
+            Object result = impl.execute(this, null);
+            afterExecute(commandline, result);
+            return result;
+        }
+        catch (Exception e)
+        {
+            afterExecute(commandline, e);
+            throw e;
+        }
     }
 
     public InputStream getKeyboard()
@@ -368,4 +385,20 @@ public class CommandSessionImpl implemen
             return "<can not format " + result + ":" + e;
         }
     }
+
+    protected void beforeExecute(CharSequence commandline)
+    {
+        // Centralized callback for derived implementation
+    }
+
+    protected void afterExecute(CharSequence commandline, Exception exception)
+    {
+        // Centralized callback for derived implementation
+    }
+
+    protected void afterExecute(CharSequence commandline, Object result)
+    {
+        // Centralized callback for derived implementation
+    }
+
 }



Mime
View raw message