Knopflerfish OSGi 5.2.0

org.knopflerfish.service.console
Class Util

java.lang.Object
  extended by org.knopflerfish.service.console.Util

public class Util
extends java.lang.Object

Utility methods for building CommandGroups to the console. This is a set of methods that does some useful things for displaying and sorting framework information.

Author:
Gatespace AB

Constructor Summary
Util()
           
 
Method Summary
static void selectBundles(Bundle[] bundles, java.lang.String[] selection)
          Select bundles from an array of Bundle objects.
static void selectBundles(Bundle[] bundles, java.lang.String[] selection, java.util.Set<java.lang.String> selectionMatches)
          Select bundles from an array of Bundle objects.
static java.lang.String shortName(Bundle bundle)
          Get short name of specified bundle.
static java.lang.String showId(Bundle bundle)
          Get bundle identifier as a constant length string.
static java.lang.String showLeft(int width, java.lang.String str)
          Show a string left adjusted in constant length string.
static java.lang.String showObject(java.lang.Object o)
          Get string representation of an object.
static java.lang.String showRight(int width, java.lang.String str)
          Show a string right adjusted in constant length string.
static java.lang.String showServiceClasses(ServiceReference<?> sr)
          Get Service class list as a string.
static java.lang.String showState(Bundle bundle)
          Get bundle state as a constant length string.
static void sortBundles(Bundle[] b, boolean longName)
          Sort an array of bundle objects based on their location or shortname.
static void sortBundlesId(Bundle[] b)
          Sort an array of bundle objects based on their Bundle Id.
static void sortBundlesTime(Bundle[] b)
          Sort an array of bundle objects based on their Last modified time.
static java.lang.String symbolicName(Bundle bundle)
          Get the symbolic name of the specified bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

selectBundles

public static void selectBundles(Bundle[] bundles,
                                 java.lang.String[] selection)
Select bundles from an array of Bundle objects. All the bundles in the bundle array is tested against all the strings in the selection array. If none of the strings match the element in the bundle array is set to NULL. A selection string matches if: It is also possible to start or end the selection string with the wildcard character '*' (Does not work for bundle id).

Parameters:
bundles - array of bundles to be checked, modified with result
selection - array of selection string to match against bundles

selectBundles

public static void selectBundles(Bundle[] bundles,
                                 java.lang.String[] selection,
                                 java.util.Set<java.lang.String> selectionMatches)
Select bundles from an array of Bundle objects. All the bundles in the bundle array is tested against all the strings in the selection array. If none of the strings match the element in the bundle array is set to NULL. A selection string matches if: It is also possible to start or end the selection string with the wildcard character '*' (Does not work for bundle id).

Parameters:
bundles - array of bundles to be checked, modified with result
selection - array of selection string to match against bundles
selectionMatches - Each patterns from selection array that matches a bundle will be added to this set.

sortBundles

public static void sortBundles(Bundle[] b,
                               boolean longName)
Sort an array of bundle objects based on their location or shortname. All entries containing NULL is placed at the end of the array.

Parameters:
b - array of bundles to be sorted, modified with result
longName - if true sort on location otherwise on shortname

sortBundlesId

public static void sortBundlesId(Bundle[] b)
Sort an array of bundle objects based on their Bundle Id. All entries containing NULL are placed at the end of the array.

Parameters:
b - array of bundles to be sorted, modified with result

sortBundlesTime

public static void sortBundlesTime(Bundle[] b)
Sort an array of bundle objects based on their Last modified time. All entries containing NULL are placed at the end of the array.

Parameters:
b - array of bundles to be sorted, modified with result

shortName

public static java.lang.String shortName(Bundle bundle)
Get short name of specified bundle. First, try to get the BUNDLE-NAME header. If it fails use the location of the bundle with all characters upto and including the last '/' or '\' and any trailing ".jar" stripped off.

Parameters:
bundle - the bundle
Returns:
The bundles shortname or null if input was null

symbolicName

public static java.lang.String symbolicName(Bundle bundle)
Get the symbolic name of the specified bundle. All directives and parameters attached to the symbolic name attribute will be stripped.

Parameters:
bundle - the bundle
Returns:
The bundles symbolic name or null if not specified.

showState

public static java.lang.String showState(Bundle bundle)
Get bundle state as a constant length string. Show state left adjusted as 12 character string.

Parameters:
bundle - the bundle
Returns:
The bundles state

showId

public static java.lang.String showId(Bundle bundle)
Get bundle identifier as a constant length string. As long as the id is 5 digits or less it will return a string with length 6.

Parameters:
bundle - the bundle
Returns:
The bundles identifier

showServiceClasses

public static java.lang.String showServiceClasses(ServiceReference<?> sr)
Get Service class list as a string.

Parameters:
sr - The service
Returns:
The bundles identifier

showObject

public static java.lang.String showObject(java.lang.Object o)
Get string representation of an object. If it is an array, collection or Enumeration, do toString() on each element. All other objects are shown with toString.

Parameters:
o - the object to show
Returns:
A string showing the object

showLeft

public static java.lang.String showLeft(int width,
                                        java.lang.String str)
Show a string left adjusted in constant length string. If the string is shorter then the desired length the string is padded with blanks. If it is longer it is cut.

Parameters:
str - the object to show
width - the desired width of the result
Returns:
A constant width string

showRight

public static java.lang.String showRight(int width,
                                         java.lang.String str)
Show a string right adjusted in constant length string. If the string is shorter then the desired length the string is padded with blanks. If it is longer it is cut.

Parameters:
str - the object to show
width - the desired width of the result
Returns:
A constant width string

Knopflerfish OSGi 5.2.0