org.eclipse.osgi.framework.internal.core
Class FrameworkCommandProvider

java.lang.Object
  extended by org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider
All Implemented Interfaces:
java.util.EventListener, CommandProvider, BundleListener, SynchronousBundleListener

public class FrameworkCommandProvider
extends java.lang.Object
implements CommandProvider, SynchronousBundleListener

This class provides methods to execute commands from the command line. It registers itself as a CommandProvider so it can be invoked by a CommandInterpreter. The FrameworkCommandProvider registers itself with the highest ranking (Integer.MAXVALUE) so it will always be called first. Other CommandProviders should register with lower rankings. The commands provided by this class are: ---Controlling the OSGi framework--- close - shutdown and exit exit - exit immediately (System.exit) gc - perform a garbage collection init - uninstall all bundles launch - start the Service Management Framework setprop = - set the OSGI property shutdown - shutdown the Service Management Framework ---Controlliing Bundles--- install {s[tart]} - install and optionally start bundle from the given URL refresh (|) - refresh the packages of the specified bundles start (|) - start the specified bundle(s) stop (|) - stop the specified bundle(s) uninstall (|) - uninstall the specified bundle(s) update (||<*>) - update the specified bundle(s) ---Displaying Status--- bundle (|) - display details for the specified bundle(s) bundles - display details for all installed bundles headers (|) - print bundle headers packages {||} - display imported/exported package details props - display System properties services {filter} - display registered service details ss - display installed bundles (short status) status - display installed bundles and registered services threads - display threads and thread groups ---Log Commands--- log {(|)} - display log entries ---Extras--- exec - execute a command in a separate process and wait fork - execute a command in a separate process getprop - Displays the system properties with the given name, or all of them. ---Controlling StartLevel--- sl {(|)} - display the start level for the specified bundle, or for the framework if no bundle specified setfwsl - set the framework start level setbsl (|) - set the start level for the bundle(s) setibsl - set the initial bundle start level There is a method for each command which is named '_'+method. The methods are invoked by a CommandInterpreter's execute method.


Constructor Summary
FrameworkCommandProvider(org.eclipse.osgi.framework.internal.core.OSGi osgi)
          Constructor.
 
Method Summary
 void _b(CommandInterpreter intp)
          Handle the bundle command's abbreviation.
 void _bundle(CommandInterpreter intp)
          Handle the bundle command.
 void _bundles(CommandInterpreter intp)
          Handle the bundles command.
 void _classSpaces(CommandInterpreter intp)
           
 void _close(CommandInterpreter intp)
          Handle the close command.
 void _exec(CommandInterpreter intp)
          Executes the given system command in a separate system process and waits for it to finish.
 void _exit(CommandInterpreter intp)
          Handle the exit command.
 void _fork(CommandInterpreter intp)
          Executes the given system command in a separate system process.
 void _gc(CommandInterpreter intp)
          Handle the gc command.
 void _getPackages(CommandInterpreter intp)
           
 void _getprop(CommandInterpreter ci)
           
 void _h(CommandInterpreter intp)
          Handle the headers command's abbreviation.
 void _headers(CommandInterpreter intp)
          Handle the headers command.
 void _i(CommandInterpreter intp)
          Handle the install command's abbreviation.
 void _init(CommandInterpreter intp)
          Handle the init command.
 void _install(CommandInterpreter intp)
          Handle the install command.
 void _l(CommandInterpreter intp)
          Handle the log command's abbreviation.
 void _launch(CommandInterpreter intp)
          Handle the launch command.
 void _log(CommandInterpreter intp)
          Handle the log command.
 void _p(CommandInterpreter intp)
          Handle the packages command's abbreviation.
 void _packages(CommandInterpreter intp)
          Handle the packages command.
 void _pr(CommandInterpreter intp)
          Handles the props command's abbreviation.
 void _profilelog(CommandInterpreter intp)
          Handles the profilelog command.
 void _props(CommandInterpreter intp)
          Handles the _props command.
 void _r(CommandInterpreter intp)
          Handle the refresh command's abbreviation.
 void _refresh(CommandInterpreter intp)
          Handle the refresh command.
 void _requiredBundles(CommandInterpreter intp)
           
 void _s(CommandInterpreter intp)
          Handle the status command's abbreviation.
 void _se(CommandInterpreter intp)
          Handle the services command's abbreviation.
 void _services(CommandInterpreter intp)
          Handle the services command.
 void _setbsl(CommandInterpreter intp)
          Handles the setbsl (set bundle startlevel) command.
 void _setfwsl(CommandInterpreter intp)
          Handles the setfwsl (set framework startlevel) command.
 void _setibsl(CommandInterpreter intp)
          Handles the setibsl (set initial bundle startlevel) command.
 void _setp(CommandInterpreter intp)
          Handles the setprop command's abbreviation.
 void _setprop(CommandInterpreter intp)
          Handles the setprop command.
 void _shutdown(CommandInterpreter intp)
          Handle the shutdown command.
 void _sl(CommandInterpreter intp)
          Handles the sl (startlevel) command.
 void _ss(CommandInterpreter intp)
          Prints the short version of the status.
 void _sta(CommandInterpreter intp)
          Handle the start command's abbreviation.
 void _start(CommandInterpreter intp)
          Handle the start command.
 void _status(CommandInterpreter intp)
          Handle the status command.
 void _sto(CommandInterpreter intp)
          Handle the stop command's abbreviation.
 void _stop(CommandInterpreter intp)
          Handle the stop command.
 void _t(CommandInterpreter intp)
          Handles the threads command abbreviation.
 void _threads(CommandInterpreter intp)
          Prints the information about the currently running threads in the embedded system.
 void _un(CommandInterpreter intp)
          Handle the uninstall command's abbreviation.
 void _uninstall(CommandInterpreter intp)
          Handle the uninstall command.
 void _up(CommandInterpreter intp)
          Handle the update command's abbreviation.
 void _update(CommandInterpreter intp)
          Handle the update command.
 void bundleChanged(BundleEvent event)
          This is used to track lazily activated bundles.
protected  org.eclipse.osgi.framework.internal.core.AbstractBundle getBundleFromToken(CommandInterpreter intp, java.lang.String token, boolean error)
          Given a number or a token representing a bundle symbolic name or bundle location, retrieve the Bundle object with that id.
 java.lang.String getHelp()
          Answer a string (may be as many lines as you like) with help texts that explain the command.
protected  int getStartLevelFromToken(CommandInterpreter intp, java.lang.String value)
          Given a string containing a startlevel value, validate it and convert it to an int
protected  java.lang.String getStateName(Bundle bundle)
          Given a state value, return the string describing that state.
protected  java.lang.ThreadGroup[] getThreadGroups()
          Answers all thread groups in the system.
protected  java.lang.ThreadGroup getTopThreadGroup()
          Answers the top level group of the current thread.
 FrameworkCommandProvider intialize()
          Intialize this CommandProvider.
protected  boolean isStartLevelSvcPresent(CommandInterpreter intp)
          Checks for the presence of the StartLevel Service.
 java.lang.String simpleClassName(java.lang.Object o)
          Returns the simple class name of an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FrameworkCommandProvider

public FrameworkCommandProvider(org.eclipse.osgi.framework.internal.core.OSGi osgi)
Constructor. initialize must be called after creating this object.

Parameters:
osgi - The current instance of OSGi
Method Detail

intialize

public FrameworkCommandProvider intialize()
Intialize this CommandProvider. Registers this object as a CommandProvider with the highest ranking possible. Adds this object as a SynchronousBundleListener.

Returns:
this

getHelp

public java.lang.String getHelp()
Answer a string (may be as many lines as you like) with help texts that explain the command. This getHelp() method uses the ConsoleMsg class to obtain the correct NLS data to display to the user.

Specified by:
getHelp in interface CommandProvider
Returns:
The help string

_exit

public void _exit(CommandInterpreter intp)
           throws java.lang.Exception
Handle the exit command. Exit immediately (System.exit)

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_launch

public void _launch(CommandInterpreter intp)
             throws java.lang.Exception
Handle the launch command. Start the OSGi framework.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_shutdown

public void _shutdown(CommandInterpreter intp)
               throws java.lang.Exception
Handle the shutdown command. Shutdown the OSGi framework.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_sta

public void _sta(CommandInterpreter intp)
          throws java.lang.Exception
Handle the start command's abbreviation. Invoke _start()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_start

public void _start(CommandInterpreter intp)
            throws java.lang.Exception
Handle the start command. Start the specified bundle(s).

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_sto

public void _sto(CommandInterpreter intp)
          throws java.lang.Exception
Handle the stop command's abbreviation. Invoke _stop()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_stop

public void _stop(CommandInterpreter intp)
           throws java.lang.Exception
Handle the stop command. Stop the specified bundle(s).

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_i

public void _i(CommandInterpreter intp)
        throws java.lang.Exception
Handle the install command's abbreviation. Invoke _install()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_install

public void _install(CommandInterpreter intp)
              throws java.lang.Exception
Handle the install command. Install and optionally start bundle from the given URL\r\n"

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_up

public void _up(CommandInterpreter intp)
         throws java.lang.Exception
Handle the update command's abbreviation. Invoke _update()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_update

public void _update(CommandInterpreter intp)
             throws java.lang.Exception
Handle the update command. Update the specified bundle(s).

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_un

public void _un(CommandInterpreter intp)
         throws java.lang.Exception
Handle the uninstall command's abbreviation. Invoke _uninstall()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_uninstall

public void _uninstall(CommandInterpreter intp)
                throws java.lang.Exception
Handle the uninstall command. Uninstall the specified bundle(s).

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_s

public void _s(CommandInterpreter intp)
        throws java.lang.Exception
Handle the status command's abbreviation. Invoke _status()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_status

public void _status(CommandInterpreter intp)
             throws java.lang.Exception
Handle the status command. Display installed bundles and registered services.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_se

public void _se(CommandInterpreter intp)
         throws java.lang.Exception
Handle the services command's abbreviation. Invoke _services()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_services

public void _services(CommandInterpreter intp)
               throws java.lang.Exception
Handle the services command. Display registered service details.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_p

public void _p(CommandInterpreter intp)
        throws java.lang.Exception
Handle the packages command's abbreviation. Invoke _packages()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_packages

public void _packages(CommandInterpreter intp)
               throws java.lang.Exception
Handle the packages command. Display imported/exported package details.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_bundles

public void _bundles(CommandInterpreter intp)
              throws java.lang.Exception
Handle the bundles command. Display details for all installed bundles.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_b

public void _b(CommandInterpreter intp)
        throws java.lang.Exception
Handle the bundle command's abbreviation. Invoke _bundle()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_bundle

public void _bundle(CommandInterpreter intp)
             throws java.lang.Exception
Handle the bundle command. Display details for the specified bundle(s).

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_l

public void _l(CommandInterpreter intp)
        throws java.lang.Exception
Handle the log command's abbreviation. Invoke _log()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_log

public void _log(CommandInterpreter intp)
          throws java.lang.Exception
Handle the log command. Display log entries.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_gc

public void _gc(CommandInterpreter intp)
         throws java.lang.Exception
Handle the gc command. Perform a garbage collection.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_init

public void _init(CommandInterpreter intp)
           throws java.lang.Exception
Handle the init command. Uninstall all bundles.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_close

public void _close(CommandInterpreter intp)
            throws java.lang.Exception
Handle the close command. Shutdown and exit.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_r

public void _r(CommandInterpreter intp)
        throws java.lang.Exception
Handle the refresh command's abbreviation. Invoke _refresh()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_refresh

public void _refresh(CommandInterpreter intp)
              throws java.lang.Exception
Handle the refresh command. Refresh the packages of the specified bundles.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_exec

public void _exec(CommandInterpreter intp)
           throws java.lang.Exception
Executes the given system command in a separate system process and waits for it to finish.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_fork

public void _fork(CommandInterpreter intp)
           throws java.lang.Exception
Executes the given system command in a separate system process. It does not wait for a result.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_h

public void _h(CommandInterpreter intp)
        throws java.lang.Exception
Handle the headers command's abbreviation. Invoke _headers()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_headers

public void _headers(CommandInterpreter intp)
              throws java.lang.Exception
Handle the headers command. Display headers for the specified bundle(s).

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_pr

public void _pr(CommandInterpreter intp)
         throws java.lang.Exception
Handles the props command's abbreviation. Invokes _props()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_props

public void _props(CommandInterpreter intp)
            throws java.lang.Exception
Handles the _props command. Prints the system properties sorted.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_setp

public void _setp(CommandInterpreter intp)
           throws java.lang.Exception
Handles the setprop command's abbreviation. Invokes _setprop()

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_setprop

public void _setprop(CommandInterpreter intp)
              throws java.lang.Exception
Handles the setprop command. Sets the CDS property in the given argument.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_ss

public void _ss(CommandInterpreter intp)
         throws java.lang.Exception
Prints the short version of the status. For the long version use "status".

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_t

public void _t(CommandInterpreter intp)
        throws java.lang.Exception
Handles the threads command abbreviation. Invokes _threads().

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_threads

public void _threads(CommandInterpreter intp)
              throws java.lang.Exception
Prints the information about the currently running threads in the embedded system.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_sl

public void _sl(CommandInterpreter intp)
         throws java.lang.Exception
Handles the sl (startlevel) command.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_setfwsl

public void _setfwsl(CommandInterpreter intp)
              throws java.lang.Exception
Handles the setfwsl (set framework startlevel) command.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_setbsl

public void _setbsl(CommandInterpreter intp)
             throws java.lang.Exception
Handles the setbsl (set bundle startlevel) command.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_setibsl

public void _setibsl(CommandInterpreter intp)
              throws java.lang.Exception
Handles the setibsl (set initial bundle startlevel) command.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_requiredBundles

public void _requiredBundles(CommandInterpreter intp)

_classSpaces

public void _classSpaces(CommandInterpreter intp)

_profilelog

public void _profilelog(CommandInterpreter intp)
                 throws java.lang.Exception
Handles the profilelog command.

Parameters:
intp - A CommandInterpreter object containing the command and it's arguments.
Throws:
java.lang.Exception

_getPackages

public void _getPackages(CommandInterpreter intp)

isStartLevelSvcPresent

protected boolean isStartLevelSvcPresent(CommandInterpreter intp)
Checks for the presence of the StartLevel Service. Outputs a message if it is not present.

Parameters:
intp - The CommandInterpreter object to be used to write to the console
Returns:
true or false if service is present or not

getBundleFromToken

protected org.eclipse.osgi.framework.internal.core.AbstractBundle getBundleFromToken(CommandInterpreter intp,
                                                                                     java.lang.String token,
                                                                                     boolean error)
Given a number or a token representing a bundle symbolic name or bundle location, retrieve the Bundle object with that id. The bundle symbolic name token is parsed as symbolicname[@version]

Parameters:
intp - The CommandInterpreter
token - A string containing a potential bundle it
error - A boolean indicating whether or not to output a message
Returns:
The requested Bundle object

getStartLevelFromToken

protected int getStartLevelFromToken(CommandInterpreter intp,
                                     java.lang.String value)
Given a string containing a startlevel value, validate it and convert it to an int

Parameters:
intp - A CommandInterpreter object used for printing out error messages
value - A string containing a potential startlevel
Returns:
The start level or an int <0 if it was invalid

getStateName

protected java.lang.String getStateName(Bundle bundle)
Given a state value, return the string describing that state.

Parameters:
state - An int containing a state value
Returns:
A String describing the state

getThreadGroups

protected java.lang.ThreadGroup[] getThreadGroups()
Answers all thread groups in the system.

Returns:
An array of all thread groups.

getTopThreadGroup

protected java.lang.ThreadGroup getTopThreadGroup()
Answers the top level group of the current thread.

It is the 'system' or 'main' thread group under which all 'user' thread groups are allocated.

Returns:
The parent of all user thread groups.

simpleClassName

public java.lang.String simpleClassName(java.lang.Object o)
Returns the simple class name of an object.

Parameters:
o - The object for which a class name is requested
Returns:
The simple class name.

_getprop

public void _getprop(CommandInterpreter ci)
              throws java.lang.Exception
Throws:
java.lang.Exception

bundleChanged

public void bundleChanged(BundleEvent event)
This is used to track lazily activated bundles.

Specified by:
bundleChanged in interface BundleListener
Parameters:
event - The BundleEvent.