felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1442009 - in /felix/trunk/scr/src/main/java/org/apache/felix/scr: ScrInfo.java impl/ScrCommand.java impl/ScrGogoCommand.java impl/ScrShellCommand.java
Date Mon, 04 Feb 2013 02:16:17 GMT
Author: djencks
Date: Mon Feb  4 02:16:16 2013
New Revision: 1442009

URL: http://svn.apache.org/viewvc?rev=1442009&view=rev
Log:
FELIX-3888 change ScrInfo interface style to use single PrintWriter for normal output and
throw IllegalArgumentException for problems

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrInfo.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrInfo.java?rev=1442009&r1=1442008&r2=1442009&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrInfo.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/ScrInfo.java Mon Feb  4 02:16:16 2013
@@ -18,12 +18,12 @@
  */
 package org.apache.felix.scr;
 
-import java.io.PrintStream;
+import java.io.PrintWriter;
 
 /**
  * Abstraction of command interface.
  * 
- * @Since 1.6.4
+ * @Since 1.8
  */
 public interface ScrInfo
 {
@@ -32,23 +32,23 @@ public interface ScrInfo
      * List in text the components for the bundle specified, or all components if null, sorted
by component ID
      * @param bundleIdentifier bundle the components are in or null for all components
      * @param out PrintStream for normal output
-     * @param err PrintStream for errors.
+     * @throws IllegalArgumentException if nothing can be found
      */
-    void list(String bundleIdentifier, PrintStream out, PrintStream err);
+    void list(String bundleIdentifier, PrintWriter out);
 
     /**
      * List in text detailed information about the specified components.  Components can
be specified by 
      * numeric componentId, component name, a regexp to match for component name, or null
for all components.
      * @param componentId specifier for desired components
      * @param out PrintStream for normal output
-     * @param err PrintStream for errors.
+     * @throws IllegalArgumentException if nothing can be found
      */
-    void info(String componentId, PrintStream out, PrintStream err);
+    void info(String componentId, PrintWriter out);
 
     /**
      * List in text the current SCR configuration
      * @param out PrintStream for output.
      */
-    void config(PrintStream out);
+    void config(PrintWriter out);
 
 }
\ No newline at end of file

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java?rev=1442009&r1=1442008&r2=1442009&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java Mon Feb  4 02:16:16
2013
@@ -19,6 +19,7 @@
 package org.apache.felix.scr.impl;
 
 import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -144,7 +145,7 @@ public class ScrCommand implements ScrIn
     /* (non-Javadoc)
      * @see org.apache.felix.scr.impl.ScrInfo#list(java.lang.String, java.io.PrintStream,
java.io.PrintStream)
      */
-    public void list(final String bundleIdentifier, final PrintStream out, final PrintStream
err)
+    public void list(final String bundleIdentifier, final PrintWriter out)
     {
         Component[] components;
 
@@ -172,8 +173,7 @@ public class ScrCommand implements ScrIn
 
             if (bundle == null)
             {
-                err.println("Missing bundle with ID " + bundleIdentifier);
-                return;
+                throw new IllegalArgumentException("Missing bundle with ID " + bundleIdentifier);
             }
             if (ComponentRegistry.isBundleActive(bundle))
             {
@@ -215,14 +215,15 @@ public class ScrCommand implements ScrIn
         {
             out.println( String.format( "[%1$4d] [%2$s] [%3$4d] %4$s", component.getId(),
toStateString( component.getState() ), component.getBundle().getBundleId(), component.getName()
) );
         }
-    }
+        out.flush();
+   }
 
     /* (non-Javadoc)
      * @see org.apache.felix.scr.impl.ScrInfo#info(java.lang.String, java.io.PrintStream,
java.io.PrintStream)
      */
-    public void info(final String componentId, PrintStream out, PrintStream err)
+    public void info(final String componentId, PrintWriter out)
     {
-        Component[] components = getComponentFromArg(componentId, err);
+        Component[] components = getComponentFromArg(componentId);
         if (components == null)
         {
             return;
@@ -394,11 +395,13 @@ public class ScrCommand implements ScrIn
                 }
             }
         }
+        out.flush();
     }
 
-    void change(final String componentIdentifier, PrintStream out, PrintStream err, boolean
enable)
+    void change(final String componentIdentifier, PrintWriter out, boolean enable)
     {
-        Component[] components = getComponentFromArg(componentIdentifier, err);
+        Component[] components = getComponentFromArg(componentIdentifier);
+        ArrayList<String> disposed = new ArrayList<String>();
         if (components == null)
         {
             return;
@@ -408,7 +411,7 @@ public class ScrCommand implements ScrIn
         {
             if ( component.getState() == Component.STATE_DISPOSED )
             {
-                err.println( "Component " + component.getName() + " already disposed, cannot
change state" );
+                disposed.add(component.getName());
             }
             else if ( enable )
             {
@@ -435,12 +438,18 @@ public class ScrCommand implements ScrIn
                 }
             }
         }
+        out.flush();
+        if ( !disposed.isEmpty() )
+        {
+            throw new IllegalArgumentException( "Components " + disposed + " already disposed,
cannot change state" );
+
+        }
     }
 
     /* (non-Javadoc)
      * @see org.apache.felix.scr.impl.ScrInfo#config(java.io.PrintStream)
      */
-    public void config(PrintStream out)
+    public void config(PrintWriter out)
     {
         out.print("Log Level: ");
         out.println(scrConfiguration.getLogLevel());
@@ -481,7 +490,7 @@ public class ScrCommand implements ScrIn
         }
     }
 
-    private Component[] getComponentFromArg(final String componentIdentifier, PrintStream
err)
+    private Component[] getComponentFromArg(final String componentIdentifier)
     {
         Component[] components = null;
         if (componentIdentifier != null)
@@ -492,7 +501,7 @@ public class ScrCommand implements ScrIn
                 Component component = scrService.getComponent(componentId);
                 if (component == null)
                 {
-                    err.println("Missing Component with ID " + componentId);
+                    throw new IllegalArgumentException("Missing Component with ID " + componentId);
                 }
                 else
                 {
@@ -505,10 +514,6 @@ public class ScrCommand implements ScrIn
                 
                 // check whether it is a component name
                 components = scrService.getComponents(componentIdentifier);
-                if (components == null)
-                {
-                    err.println("Missing Component with ID " + componentIdentifier);
-                }
             }
         }
         if ( components == null)
@@ -525,6 +530,10 @@ public class ScrCommand implements ScrIn
                         cs.add( component );
                     }
                 }
+                if (cs.isEmpty())
+                {
+                    throw new IllegalArgumentException("No Component with ID or matching
" + componentIdentifier);
+                }
                 components = cs.toArray( new Component[cs.size()] );
             }
         }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java?rev=1442009&r1=1442008&r2=1442009&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrGogoCommand.java Mon Feb  4
02:16:16 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.scr.impl;
 
+import java.io.PrintWriter;
+
 import org.apache.felix.service.command.Descriptor;
 
 /**
@@ -57,37 +59,72 @@ class ScrGogoCommand
     @Descriptor("List all components")
     public void list()
     {
-        scrCommand.list(null, System.out, System.err);
+        try
+        {
+            scrCommand.list(null, new PrintWriter(System.out));
+        }
+        catch ( IllegalArgumentException e )
+        {
+            System.err.println(e.getMessage());
+        }
     }
 
     @Descriptor("List components of a specific bundle")
     public void list(@Descriptor("Symbolic name or ID of the bundle") final String bundleIdentifier)
     {
-        scrCommand.list(bundleIdentifier, System.out, System.err);
+        try
+        {
+            scrCommand.list(bundleIdentifier, new PrintWriter(System.out));
+        }
+        catch ( IllegalArgumentException e )
+        {
+            System.err.println(e.getMessage());
+        }
     }
 
     @Descriptor("Dump information of a component")
     public void info(@Descriptor("Name or ID of the component") final String componentIdentifier)
     {
-        scrCommand.info(componentIdentifier, System.out, System.err);
+        try
+        {
+            scrCommand.info(componentIdentifier, new PrintWriter(System.out));
+        }
+        catch ( IllegalArgumentException e )
+        {
+            System.err.println(e.getMessage());
+        }
     }
 
     @Descriptor("Enable a disabled component")
     public void enable(@Descriptor("Name or ID of the component") final String componentIdentifier)
     {
-        scrCommand.change(componentIdentifier, System.out, System.err, true);
+        try
+        {
+            scrCommand.change(componentIdentifier, new PrintWriter(System.out), true);
+        }
+        catch ( IllegalArgumentException e )
+        {
+            System.err.println(e.getMessage());
+        }
     }
 
     @Descriptor("Disable an enabled component")
     public void disable(@Descriptor("Name or ID of the component") final String componentIdentifier)
     {
-        scrCommand.change(componentIdentifier, System.out, System.err, false);
+        try
+        {
+            scrCommand.change(componentIdentifier, new PrintWriter(System.out), false);
+        }
+        catch ( IllegalArgumentException e )
+        {
+            System.err.println(e.getMessage());
+        }
     }
 
     @Descriptor("Show the current SCR configuration")
     public void config()
     {
-        scrCommand.config(System.out);
+        scrCommand.config(new PrintWriter(System.out));
     }
 
 }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java?rev=1442009&r1=1442008&r2=1442009&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ScrShellCommand.java Mon Feb 
4 02:16:16 2013
@@ -19,6 +19,7 @@
 package org.apache.felix.scr.impl;
 
 import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.util.StringTokenizer;
 import org.apache.felix.shell.Command;
 
@@ -84,29 +85,37 @@ class ScrShellCommand implements Command
         else
         {
             String arg = (st.hasMoreTokens()) ? st.nextToken() : null;
-            if (command.equals(LIST_CMD))
+            PrintWriter pw = new PrintWriter(out);
+            try
             {
-                scrCommand.list(arg, out, err);
+                if (command.equals(LIST_CMD))
+                {
+                    scrCommand.list(arg, pw);
+                }
+                else if (command.equals(INFO_CMD))
+                {
+                    scrCommand.info(arg, pw);
+                }
+                else if (command.equals(ENABLE_CMD))
+                {
+                    scrCommand.change(arg, pw, true);
+                }
+                else if (command.equals(DISABLE_CMD))
+                {
+                    scrCommand.change(arg, pw, false);
+                }
+                else if (command.equals(CONFIG_CMD))
+                {
+                    scrCommand.config(pw);
+                }
+                else
+                {
+                    err.println("Unknown command: " + command);
+                }
             }
-            else if (command.equals(INFO_CMD))
+            catch ( IllegalArgumentException e )
             {
-                scrCommand.info(arg, out, err);
-            }
-            else if (command.equals(ENABLE_CMD))
-            {
-                scrCommand.change(arg, out, err, true);
-            }
-            else if (command.equals(DISABLE_CMD))
-            {
-                scrCommand.change(arg, out, err, false);
-            }
-            else if (command.equals(CONFIG_CMD))
-            {
-                scrCommand.config(out);
-            }
-            else
-            {
-                err.println("Unknown command: " + command);
+                System.err.println(e.getMessage());
             }
         }
     }



Mime
View raw message