Extension SDK 10.1.2

oracle.ide.runner
Class RunProcess

java.lang.Object
  extended byoracle.ide.runner.RunProcess
All Implemented Interfaces:
Data, Displayable, Element, Helpable
Direct Known Subclasses:
JRunProcess

public abstract class RunProcess
extends java.lang.Object
implements Element, Helpable

An abstract class that represents a process that can be run in some way.


Field Summary
protected  boolean addToProcessesFolder
          Whether this process should be added to the Run Manager's process folder
protected  boolean addToTerminateMenu
          Whether a terminate menu for this process should be add to the Run Terminate menu.
protected  boolean allowInput
          Whether the user wants to allow input to be sent to the process.
protected  Context context
          The Context that is associated with this process.
protected  boolean determineTargetAndStarterAlready
          Whether the target Node and Starter have already been determined.
protected  java.util.List errors
          The list of errors that occurred when trying to start the process.
protected  java.lang.String labelOverride
          The label to use instead of the normal label.
protected  boolean logCommandString
          Whether the command string should be logged.
protected  boolean logError
          Whether standard error from the process should be logged.
protected  boolean logExit
          Whether to log a message when the process exits.
protected  boolean logOutput
          Whether standard output from the process should be logged.
protected  boolean logStartDirectory
          Whether the start directory should be logged.
protected  RunProcessListener runProcessListener
          The RunProcessListener for this process.
protected  boolean showStartStatus
          Whether to show a start status message in the status bar.
protected  Starter starter
          The starter for this RunProcess.
protected  Node target
          The target for this RunProcess.
protected  long timeCreated
          The time this RunProcess was created.
protected  boolean useLogPage
          Whether a log page should be used to print process information.
protected  boolean userCanceled
           
 
Constructor Summary
RunProcess(Context context)
          The constructor simply initializes the fields of this RunProcess.
 
Method Summary
 java.lang.String canGetStarterForTarget(Node node, java.lang.Class starterFactorySubClass, java.util.List errors)
          Tests whether the given node is runnable.
 boolean canStart()
          Tests whether this process can be started.
 boolean canTerminate()
          Tests whether this RunProcess can be terminated.
protected  boolean checkStarter(Starter starter, java.util.List errors)
          Returns whether the given starter can really be used to start a process.
protected  java.lang.Object copyTo(java.lang.Object o)
           
protected  void determineTargetAndStarter()
          Determines what should be the target and starter for this process.
protected  void determineTargetAndStarter(java.lang.Class starterFactorySubClass)
          Determines what should be the target and starter for this process.
 void doubleClicked()
          This method is called when this process is double clicked in the run manager navigator.
protected  void doUI(java.lang.Runnable r)
          Uses either SwingUtilities.invokeLater(java.lang.Runnable) or SwingUtilities.invokeAndWait(java.lang.Runnable) to invoke the Runnable.
 boolean doUILater()
          Returns whether SwingUtilities.invokeLater(java.lang.Runnable) should be used to do UI, instead of SwingUtilities.invokeAndWait(java.lang.Runnable).
 java.io.PipedInputStream duplicateErrorStream()
          Returns a PipedInputStream which duplicates the error (System.err) from this process.
 java.io.PipedInputStream duplicateOutputStream()
          Returns a PipedInputStream which duplicates the output (System.out) from this process.
 void finished()
          This method will be called by the Starter, when this process finishes.
protected  java.lang.String fixCommandStringForLog(java.lang.String[] command)
          Returns a the command string for display purposes.
 Attributes getAttributes()
          Returns a this Element's Attributes.
 java.util.Iterator getChildren()
          Gets the children of this RunProcess element.
 Context getContext()
          Returns the Context that is associated with this RunProcess.
static Document getContextDocumentForRun(Context context)
          Returns the Document for the given Context.
 java.lang.Object getData()
          Gets the data object that implements this interface.
 HelpInfo getHelpInfo()
          Returns the help info to be used when the user presses F1 in the log page for this run process.
 javax.swing.Icon getIcon()
          Gets the Icon for this RunProcess element.
 LogPage getLogPage()
          Returns the LogPage for this process.
 LogPage getLogPage(boolean create)
           
 java.lang.String getLongLabel()
          Gets a fully qualified label for display purpose.
abstract  java.lang.String getProcessLabelPrefix()
          Returns the prefix that will be used in the short and long labels for this RunProcess.
 IdeLayout getProcessLayout()
          Returns the layout that should be shown when this process is selected in the run manager navigator.
 Project getProject()
          Returns the Project associated with the RunProcess.
static Project getProject(Context context)
           
 RunnableItem[] getRunnableItems()
           
protected  RunnableItem[] getRunnableItemsForTarget(Node node, java.lang.Class starterFactorySubClass)
           
 java.lang.String getShortLabel()
          Gets a short label for display purpose.
 java.lang.String getShortLabelWithPrefix()
          Returns a short label containing the process label prefix, for display purposes.
 java.lang.String[] getStartCommand()
          Returns the command line that will be executed to start the process.
 java.io.File getStartDirectory()
          Returns the directory that should be used as the working directory of this process, or null if this process should inherit the working directory of the current process.
 java.lang.String[] getStartEnvironmentParams()
          Returns the environment parameters that are defined for this process.
 Starter getStarter()
          Returns the Starter that will be used to start this process.
protected  java.lang.Class getStarterFactorySubClass()
           
protected  Starter getStarterForTarget(Node node, java.lang.Class starterFactorySubClass)
          Tests whether the given node is runnable and returns the starter that can start the process.
static javax.swing.text.SimpleAttributeSet getSystemErrAttributeSet()
           
static javax.swing.text.SimpleAttributeSet getSystemOutAttributeSet()
           
 Node getTarget()
          Returns the target.
 long getTimeCreated()
          Returns the time this RunProcess was created.
 java.lang.String getToolTipText()
          Gets the tool tip for this RunProcess element
protected  boolean getUseLogPage()
          Returns whether a log page will be used to print process information.
 Workspace getWorkspace()
          Returns the Workspace associated with the RunProcess.
 boolean hasFinished()
          Tests whether this process has finished.
 void log(java.lang.Object msg)
          Display the specified msg in the log window.
 void logCommandString(java.lang.String[] command)
          If logCommandString is true, the command string is displayed in the log window.
 void logStartDirectory()
          If logStartDirectory is true, the start directory is displayed in the log window.
protected  void logStartErrors()
           
protected  LogPage makeLogPage(boolean create)
          Creates the RunLogPage for this process.
 boolean mayHaveChildren()
          Tests if this RunProcess element may contain children.
protected  boolean mustPrepareToStart()
          Calls the Starter.mustPrepareToStart() method.
protected  boolean prepareToStart()
          Calls the Starter.prepareToStart() method.
 void redirectInput(java.io.OutputStream input)
          This method will be called by the Starter, if the Starter captured standard input for this process.
 void redirectOutput(java.io.InputStream systemOutStream, java.io.InputStream systemErrStream)
          This method will be called by the Starter, if the Starter captured standard output/error for this process.
protected  boolean reuseLogPage(RunLogPage runLogPage)
          Returns true if the specified RunLogPage should be reused for this RunProcess.
 void selected()
          This method is called when this process is selected in the run manager navigator.
 void setLabelOverride(java.lang.String labelOverride)
          Explicitly sets the string to be shown as the display name of the running process in the run manager.
 boolean showStartStatus()
          Returns whether a start message should be shown in the status bar.
 void start()
          Causes this process to begin execution.
 void start(Node node, AbstractStarterFactory abstractStarterFactory, java.lang.Object cookie)
           
 void started()
          This method will be called by the start method, when this process has been started.
protected  boolean startTarget()
          Determines the target Node and Starter for this RunProcess and if successful, calls the Starter.start() method.
 void terminate()
          Terminates this process.
 java.lang.String toString()
          Returns the short label for this RunProcess.
 void unselected()
          This method is called when this process is unselected in the run manager navigator.
 void waitForRedirectOutput()
          This call waits until the threads that are redirecting output (System.out and System.err) have processed all output available so far.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

timeCreated

protected long timeCreated
The time this RunProcess was created.


context

protected Context context
The Context that is associated with this process. The context can not be null.


logStartDirectory

protected boolean logStartDirectory
Whether the start directory should be logged.


logCommandString

protected boolean logCommandString
Whether the command string should be logged.


logOutput

protected boolean logOutput
Whether standard output from the process should be logged.


allowInput

protected boolean allowInput
Whether the user wants to allow input to be sent to the process.


logError

protected boolean logError
Whether standard error from the process should be logged.


logExit

protected boolean logExit
Whether to log a message when the process exits.


showStartStatus

protected boolean showStartStatus
Whether to show a start status message in the status bar.


addToProcessesFolder

protected boolean addToProcessesFolder
Whether this process should be added to the Run Manager's process folder


addToTerminateMenu

protected boolean addToTerminateMenu
Whether a terminate menu for this process should be add to the Run Terminate menu.


useLogPage

protected boolean useLogPage
Whether a log page should be used to print process information.


runProcessListener

protected RunProcessListener runProcessListener
The RunProcessListener for this process. The runProcessListener can be null.


userCanceled

protected boolean userCanceled

errors

protected java.util.List errors
The list of errors that occurred when trying to start the process.

Each StarterFactory can add errors to the list.
If we are not able to start the process, the errors are displayed in the log window.
If we are able to start the process, the errors are not displayed.


determineTargetAndStarterAlready

protected boolean determineTargetAndStarterAlready
Whether the target Node and Starter have already been determined.


labelOverride

protected java.lang.String labelOverride
The label to use instead of the normal label. The normal label is usually the name of the project.


target

protected Node target
The target for this RunProcess.


starter

protected Starter starter
The starter for this RunProcess.

Constructor Detail

RunProcess

public RunProcess(Context context)
The constructor simply initializes the fields of this RunProcess.

Parameters:
context - the context to be associated with this RunProcess
Method Detail

copyTo

protected java.lang.Object copyTo(java.lang.Object o)

duplicateOutputStream

public java.io.PipedInputStream duplicateOutputStream()
Returns a PipedInputStream which duplicates the output (System.out) from this process. This method will work only if it is called before the subprocess is executed. This method returns a PipedInputStream that will not be connected to a PipedOutputStream until the subprocess is started. Attempting to read from the PipedInputStream before it has been connected will cause an IOException to be thrown.


duplicateErrorStream

public java.io.PipedInputStream duplicateErrorStream()
Returns a PipedInputStream which duplicates the error (System.err) from this process. This method will work only if it is called before the subprocess is executed. This method returns a PipedInputStream that will not be connected to a PipedOutputStream until the subprocess is started. Attempting to read from the PipedInputStream before it has been connected will cause an IOException to be thrown.


getStarterFactorySubClass

protected java.lang.Class getStarterFactorySubClass()

determineTargetAndStarter

protected void determineTargetAndStarter()
Determines what should be the target and starter for this process.

Checks to see if the context document is runnable.


getContextDocumentForRun

public static Document getContextDocumentForRun(Context context)
Returns the Document for the given Context.


determineTargetAndStarter

protected void determineTargetAndStarter(java.lang.Class starterFactorySubClass)
Determines what should be the target and starter for this process.

Checks to see if the context document is runnable.

Parameters:
starterFactorySubClass - the chosen StarterFactory must extend this class

getStarterForTarget

protected Starter getStarterForTarget(Node node,
                                      java.lang.Class starterFactorySubClass)
Tests whether the given node is runnable and returns the starter that can start the process.

If any registered starters claim that they can start this process with the given node as the target, then this method returns the starter.

Parameters:
node - the target
starterFactorySubClass - the chosen StarterFactory must extend this class
Returns:
Starter if the node is runnable, null otherwise

getRunnableItems

public RunnableItem[] getRunnableItems()

getRunnableItemsForTarget

protected RunnableItem[] getRunnableItemsForTarget(Node node,
                                                   java.lang.Class starterFactorySubClass)

canGetStarterForTarget

public java.lang.String canGetStarterForTarget(Node node,
                                               java.lang.Class starterFactorySubClass,
                                               java.util.List errors)
Tests whether the given node is runnable.

If any registered starter factory claims that it can start this process with the given node as the target, then this method returns the name of that starter factory.

Parameters:
node - the target
starterFactorySubClass - the chosen StarterFactory must extend this class ¶m errors the list of errors showing why the node may not be runnable
Returns:
the name of the starter factory if the node is runnable, null otherwise

checkStarter

protected boolean checkStarter(Starter starter,
                               java.util.List errors)
Returns whether the given starter can really be used to start a process.


getTimeCreated

public long getTimeCreated()
Returns the time this RunProcess was created.


getContext

public Context getContext()
Returns the Context that is associated with this RunProcess.


getWorkspace

public Workspace getWorkspace()
Returns the Workspace associated with the RunProcess.


getProject

public Project getProject()
Returns the Project associated with the RunProcess.


getProject

public static Project getProject(Context context)

getTarget

public Node getTarget()
Returns the target.


getStarter

public Starter getStarter()
Returns the Starter that will be used to start this process.


canStart

public boolean canStart()
Tests whether this process can be started.

Returns:
true if the process can be started

start

public void start(Node node,
                  AbstractStarterFactory abstractStarterFactory,
                  java.lang.Object cookie)

start

public void start()
Causes this process to begin execution. The appropriate Starter for this process will be used to start the process.

If the process can not be started, error messages will be logged.


mustPrepareToStart

protected boolean mustPrepareToStart()
Calls the Starter.mustPrepareToStart() method.

This method is called on the event thread.


prepareToStart

protected boolean prepareToStart()
Calls the Starter.prepareToStart() method.

This method is called on a non-event thread.


startTarget

protected boolean startTarget()
Determines the target Node and Starter for this RunProcess and if successful, calls the Starter.start() method.

If the Starter can not be determined, all errors in the errors list are displayed in the log window.

Returns:
true if the process was started

logStartErrors

protected void logStartErrors()

started

public void started()
This method will be called by the start method, when this process has been started.

If the start method was not used to start the process, then this method should be called when the process has been started.

This method adds the process to the processes folder in the run manager navigator and if this process can be terminated, it adds a terminate menu item to the Run Terminate submenu.


redirectOutput

public void redirectOutput(java.io.InputStream systemOutStream,
                           java.io.InputStream systemErrStream)
This method will be called by the Starter, if the Starter captured standard output/error for this process.

This method will create two LogOutputThread threads to redirect System.out and System.err to the log page.


getSystemOutAttributeSet

public static javax.swing.text.SimpleAttributeSet getSystemOutAttributeSet()

getSystemErrAttributeSet

public static javax.swing.text.SimpleAttributeSet getSystemErrAttributeSet()

redirectInput

public void redirectInput(java.io.OutputStream input)
This method will be called by the Starter, if the Starter captured standard input for this process.

Parameters:
input - the standard input

waitForRedirectOutput

public void waitForRedirectOutput()
This call waits until the threads that are redirecting output (System.out and System.err) have processed all output available so far.

If this method is called on the AWT event dispatching thread, it does nothing.


getStartEnvironmentParams

public java.lang.String[] getStartEnvironmentParams()
Returns the environment parameters that are defined for this process.

The default implementation returns null.

Returns:
array of strings, each element of which has environment variable settings in format name=value.

getStartDirectory

public java.io.File getStartDirectory()
Returns the directory that should be used as the working directory of this process, or null if this process should inherit the working directory of the current process.

The default implementation returns null.

Returns:
the working directory

logStartDirectory

public void logStartDirectory()
If logStartDirectory is true, the start directory is displayed in the log window.


getStartCommand

public java.lang.String[] getStartCommand()
Returns the command line that will be executed to start the process.

The default implementation returns null. Subclasses should either override this method or ensure that the Starter.getStartCommand() method is overridden.

Returns:
the command line

logCommandString

public void logCommandString(java.lang.String[] command)
If logCommandString is true, the command string is displayed in the log window.


fixCommandStringForLog

protected java.lang.String fixCommandStringForLog(java.lang.String[] command)
Returns a the command string for display purposes.


showStartStatus

public boolean showStartStatus()
Returns whether a start message should be shown in the status bar.

Returns:
true if the message should be shown.

getUseLogPage

protected boolean getUseLogPage()
Returns whether a log page will be used to print process information.

Returns:
true if a log page will be used.

getLogPage

public LogPage getLogPage()
Returns the LogPage for this process.

Creates the LogPage if necessary.

Returns:
the LogPage for this process

getLogPage

public LogPage getLogPage(boolean create)

makeLogPage

protected LogPage makeLogPage(boolean create)
Creates the RunLogPage for this process.

Returns:
the log page

reuseLogPage

protected boolean reuseLogPage(RunLogPage runLogPage)
Returns true if the specified RunLogPage should be reused for this RunProcess.

First, the Starter.reuseLogPage(oracle.ide.runner.RunLogPage) is called, in case the Starter wants to overide the default behavior.

The default behavior is to reuse the page if the previous process is not still alive, and the name, workspace, project, icon, tooltip, titleName, and helpInfo match.


log

public void log(java.lang.Object msg)
Display the specified msg in the log window.

Parameters:
msg - the message to display.

doUILater

public boolean doUILater()
Returns whether SwingUtilities.invokeLater(java.lang.Runnable) should be used to do UI, instead of SwingUtilities.invokeAndWait(java.lang.Runnable).


doUI

protected void doUI(java.lang.Runnable r)
Uses either SwingUtilities.invokeLater(java.lang.Runnable) or SwingUtilities.invokeAndWait(java.lang.Runnable) to invoke the Runnable.


getProcessLabelPrefix

public abstract java.lang.String getProcessLabelPrefix()
Returns the prefix that will be used in the short and long labels for this RunProcess.

Returns:
the prefix that will be used in the short and long labels

getProcessLayout

public IdeLayout getProcessLayout()
Returns the layout that should be shown when this process is selected in the run manager navigator.

Returns:
the layout

selected

public void selected()
This method is called when this process is selected in the run manager navigator.

The implementation of this method should not change layouts. Changing layouts based on what process is selected in the run manager navigator should be accomplished by returning the appropriate layout from the getProcessLayout method.


doubleClicked

public void doubleClicked()
This method is called when this process is double clicked in the run manager navigator.


unselected

public void unselected()
This method is called when this process is unselected in the run manager navigator.


canTerminate

public boolean canTerminate()
Tests whether this RunProcess can be terminated.

Returns:
true if this RunProcess can be terminated.

terminate

public void terminate()
Terminates this process.


hasFinished

public boolean hasFinished()
Tests whether this process has finished.

Returns:
true if this process has finished

finished

public void finished()
This method will be called by the Starter, when this process finishes.

If the start method was not used to start the process, then this method should be called when the process finishes.

This method removes the process from the processes folder in the run manager navigator and removes the terminate menu, if a terminate menu item was added to the Run Terminate submenu for this process.


setLabelOverride

public void setLabelOverride(java.lang.String labelOverride)
Explicitly sets the string to be shown as the display name of the running process in the run manager.


getShortLabelWithPrefix

public java.lang.String getShortLabelWithPrefix()
Returns a short label containing the process label prefix, for display purposes.


getShortLabel

public java.lang.String getShortLabel()
Gets a short label for display purpose.

Specified by:
getShortLabel in interface Displayable
Returns:
a short descriptive label.

getLongLabel

public java.lang.String getLongLabel()
Gets a fully qualified label for display purpose.

Specified by:
getLongLabel in interface Displayable
Returns:
a long descriptive label.

getData

public java.lang.Object getData()
Gets the data object that implements this interface.

Specified by:
getData in interface Data
Returns:
object implementing this interface.

getIcon

public javax.swing.Icon getIcon()
Gets the Icon for this RunProcess element.

Specified by:
getIcon in interface Displayable
Returns:
the Icon for this RunProcess element.

getToolTipText

public java.lang.String getToolTipText()
Gets the tool tip for this RunProcess element

The default implementation returns the long label.

Specified by:
getToolTipText in interface Displayable
Returns:
the tool tip for this RunProcess element

mayHaveChildren

public boolean mayHaveChildren()
Tests if this RunProcess element may contain children.

The implementation of this method returns false; a RunProcess may not have children.

Specified by:
mayHaveChildren in interface Element
Returns:
false because a RunProcess may not have children.

getChildren

public java.util.Iterator getChildren()
Gets the children of this RunProcess element.

The implementation of this method returns null; a RunProcess element may not have children.

Specified by:
getChildren in interface Element
Returns:
null because a RunProcess may not have children.

getAttributes

public Attributes getAttributes()
Returns a this Element's Attributes. This class does not define any attributes.

Specified by:
getAttributes in interface Element
Returns:
this element's attributes

getHelpInfo

public HelpInfo getHelpInfo()
Returns the help info to be used when the user presses F1 in the log page for this run process.

Specified by:
getHelpInfo in interface Helpable
Returns:
the HelpInfo

toString

public java.lang.String toString()
Returns the short label for this RunProcess.

Specified by:
toString in interface Displayable

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.