org.knime.core.node
Class Node

java.lang.Object
  extended by org.knime.core.node.Node
All Implemented Interfaces:
EventListener, NodeModelWarningListener

public final class Node
extends Object
implements NodeModelWarningListener

Implementation of a node as basic processing unit within the workflow. A Node object is the place where the data flow starts, ends, or intersects. Thus a Node can be connected with predecessors and successors through its input and output ports, NodeInPort and NodeOutPort, respectively. There are data ports for exchanging data tables, and prediction model ports for transferring computed data models.
A node must contain a NodeModel and may contain NodeViews and a NodeDialogPane implementing the Model-View-Controller paradigm. The node manages the interactions between these components and handles all internal and external data flows. Incoming data is passed to the NodeModel and forwarded from there to the node's ports.
The Node is the part within a workflow holding and managing the user specific NodeModel, NodeDialogPane, and possibly NodeView, thus, it is not intended to extend this class. A NodeFactory is used to bundle model, view and dialog. This factory is passed to the node constructor to create a node of that specific type.

Author:
Thomas Gabriel, University of Konstanz

Nested Class Summary
(package private) static class Node.Input
          Keeps information about incoming connectors (type and name).
static class Node.LoopRole
           
(package private) static class Node.Output
          Keeps outgoing information (specs, objects, HiLiteHandlers...).
(package private) static class Node.SettingsLoaderAndWriter
           
 
Field Summary
static String CFG_MISC_SETTINGS
          Config for node (and node container) settings which are shown in the dialog.
static String CFG_MODEL
          The sub settings entry where the model can save its setup.
static String CFG_VARIABLES
          The sub settings entry containing the flow variable settings.
 
Constructor Summary
Node(NodeFactory<NodeModel> nodeFactory)
          Creates a new node by retrieving the model, dialog, and views, from the specified NodeFactory.
 
Method Summary
 void addMessageListener(NodeMessageListener listener)
          Adds a state listener to this node.
 void addToTemporaryTables(Set<ContainerTable> tempTables)
          Adds the argument set of tables to the set of temporary tables in this node.
 boolean areSettingsValid(NodeSettingsRO settings)
          Validates the argument settings.
 void cleanOutPorts()
           
 void cleanup()
          Deletes any temporary resources associated with this node.
 void clearLoopStatus()
           
 void closeAllViews()
          Closes all views.
 boolean configure(PortObjectSpec[] inSpecs)
          Sets all (new) incoming DataTableSpec elements in the model, calls the model to create output table specs and propagates these new specs to the connected successors.
 boolean configure(PortObjectSpec[] inSpecs, NodePostConfigure postConfigure)
          Allows passing an object that may modify the specs created by the NodeModel, for example in case the node is wrapped and the output is modified.
static PortObject copyPortObject(PortObject portObject, ExecutionMonitor exec)
          Copies the PortObject so that the copy can be given to the node model implementation (and potentially modified).
 CopyNodePersistor createCopyPersistor()
          Create a persistor that is used to paste a copy of this node into the same or a different workflow.
 NodeExecutionResult createNodeExecutionResult(ExecutionMonitor exec)
          Creates an execution result containing all calculated values in a execution.
 void ensureOutputDataIsRead()
          Ensures that any port object is read for later saving with a newer version.
 boolean execute(PortObject[] data, ExecutionContext exec)
          Starts executing this node.
 NodeDialogPane getDialogPane()
          Get reference to the node dialog instance.
 NodeDialogPane getDialogPaneWithSettings(PortObjectSpec[] inSpecs, FlowObjectStack foStack, NodeSettingsRO settings)
           
 NodeFactory<NodeModel> getFactory()
           
 FlowObjectStack getFlowObjectStack()
           
 String getInportName(int index)
          Return name of input connector.
 PortType getInputType(int index)
          Return type of input connector.
 BufferedDataTable[] getInternalHeldTables()
          Get the current set of tables internally held by a NodeModel that implements BufferedDataTableHolder.
static HashMap<Integer,ContainerTable> getLocalTableRepositoryFromContext(ExecutionContext c)
          Delegate method to allow access to the (package scope) method ExecutionContext.getLocalTableRepository().
 Node.LoopRole getLoopRole()
           
 FlowLoopContext getLoopStatus()
           
 String getName()
          Returns the name for this node.
 int getNrInPorts()
           
 int getNrOutPorts()
           
 int getNrViews()
           
 String getOutportName(int index)
          Return name of output connector.
 HiLiteHandler getOutputHiLiteHandler(int index)
           
 PortObject getOutputObject(int index)
           
 String getOutputObjectSummary(int index)
           
 PortObjectSpec getOutputSpec(int index)
           
 PortType getOutputType(int index)
          Return type of output connector.
 NodeFactory.NodeType getType()
          Returns the type for this node.
 AbstractNodeView<?> getView(int viewIndex, String title)
          Return a new instance of the node's view (without opening it).
 String getViewName(int viewIndex)
          Returns the name for this node's view at the given index.
 String getWarningMessageFromModel()
          Getter for the currently set node warning message in the corresponding NodeModel.
 Element getXMLDescription()
          The XML description can be used with the NodeFactoryHTMLCreator in order to get a converted HTML description of it, which fits the overall KNIME HTML style.
(package private)  boolean hasContent()
          Delegate method to node model.
 boolean hasDialog()
          Returns true if this node can show a dialog.
static void invokeCloseView(AbstractNodeView<?> view)
          Widens scope of AbstractNodeView.closeView() method so it can be called from UI framework components.
static void invokeEnsureOpen(BufferedDataTable table)
          Exposes BufferedDataTable.ensureOpen() as public method.
static void invokeOpenView(AbstractNodeView<?> view, String title)
          Widens scope of AbstractNodeView.openView(String) method so it can be called from UI framework components.
 boolean isInterruptible()
           
(package private)  void load(NodePersistor loader, ExecutionMonitor exec, WorkflowPersistor.LoadResult loadResult)
          Load settings and data + internals from a loader instance.
 void loadDataAndInternals(NodeContentPersistor loader, ExecutionMonitor exec, WorkflowPersistor.LoadResult loadResult)
          Loads data from an argument persistor.
(package private)  void loadInternals(File internDir, ExecutionMonitor exec)
           
 void loadSettingsFrom(NodeSettingsRO settings)
          Loads the settings (but not the data) from the given settings object.
 void putOutputTablesIntoGlobalRepository(HashMap<Integer,ContainerTable> rep)
          Enumerates the output tables and puts them into the global workflow repository of tables.
 void removeMessageListener(NodeMessageListener listener)
          Removes a state listener from this node.
 void removeOutputTablesFromGlobalRepository(HashMap<Integer,ContainerTable> rep)
          Reverse operation to putOutputTablesIntoGlobalRepository(HashMap).
 void reset()
          Resets this node without re-configuring it.
(package private)  void saveInternals(File internDir, ExecutionMonitor exec)
           
 void saveSettingsTo(NodeSettingsWO settings)
          Saves the settings (but not the data).
 void setFlowObjectStack(FlowObjectStack scsc)
           
 void setInHiLiteHandler(int index, HiLiteHandler hdl)
           
 void setLoopEndNode(Node tail)
           
 void setLoopStartNode(Node head)
           
 void setName(String nodeName)
          Sets a new name for this node.
 String toString()
          Returns a string summary of this node.
 void warningChanged(String warningMessage)
          Is called, when a warning message is set in the NodeModel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CFG_MISC_SETTINGS

public static final String CFG_MISC_SETTINGS
Config for node (and node container) settings which are shown in the dialog.

See Also:
Constant Field Values

CFG_MODEL

public static final String CFG_MODEL
The sub settings entry where the model can save its setup.

See Also:
Constant Field Values

CFG_VARIABLES

public static final String CFG_VARIABLES
The sub settings entry containing the flow variable settings. These settings are not available in the derived node model.

See Also:
Constant Field Values
Constructor Detail

Node

public Node(NodeFactory<NodeModel> nodeFactory)
Creates a new node by retrieving the model, dialog, and views, from the specified NodeFactory. Also initializes the input and output ports for the given number of data and model port. This node is configured after initialization.

Parameters:
nodeFactory - the node's factory for the creation of model, view, and dialog
Throws:
IllegalArgumentException - If the nodeFactory is null.
Method Detail

createCopyPersistor

public CopyNodePersistor createCopyPersistor()
Create a persistor that is used to paste a copy of this node into the same or a different workflow. (Used by copy&paste actions and undo operations)

Returns:
A new copy persistor that clones this node's settings. The copy has a non-executed state (ports and internals are not copied).

load

void load(NodePersistor loader,
          ExecutionMonitor exec,
          WorkflowPersistor.LoadResult loadResult)
    throws CanceledExecutionException
Load settings and data + internals from a loader instance.

Parameters:
loader - To load from
exec - For progress information/cancelation
loadResult - Where to report errors/warnings to
Throws:
CanceledExecutionException - If canceled.

createNodeExecutionResult

public NodeExecutionResult createNodeExecutionResult(ExecutionMonitor exec)
                                              throws CanceledExecutionException
Creates an execution result containing all calculated values in a execution. The returned value is suitable to be used in #loadDataAndInternals(NodeContentPersistor, ExecutionMonitor, LoadResult). If this node is not executed, it will assign null values to the fields in the returned execution result.

Parameters:
exec - For progress information.
Returns:
A new execution result containing the values being calculated.
Throws:
CanceledExecutionException - If canceled

loadDataAndInternals

public void loadDataAndInternals(NodeContentPersistor loader,
                                 ExecutionMonitor exec,
                                 WorkflowPersistor.LoadResult loadResult)
Loads data from an argument persistor.

Parameters:
loader - To load from.
exec - For progress.
loadResult - to add errors and warnings to (if any)

loadSettingsFrom

public void loadSettingsFrom(NodeSettingsRO settings)
                      throws InvalidSettingsException
Loads the settings (but not the data) from the given settings object.

Parameters:
settings - a settings object
Throws:
InvalidSettingsException - if an expected setting is missing

areSettingsValid

public boolean areSettingsValid(NodeSettingsRO settings)
Validates the argument settings.

Parameters:
settings - a settings object
Returns:
if valid.

getName

public String getName()
Returns the name for this node.

Returns:
The node's name.

getType

public NodeFactory.NodeType getType()
Returns the type for this node.

Returns:
The node's type.

getXMLDescription

public Element getXMLDescription()
The XML description can be used with the NodeFactoryHTMLCreator in order to get a converted HTML description of it, which fits the overall KNIME HTML style.

Returns:
XML description of the node
See Also:
NodeFactory.getXMLDescription()

setName

public void setName(String nodeName)
Sets a new name for this node.

Parameters:
nodeName - The node's new name.
Throws:
NullPointerException - If the name is null.

getNrInPorts

public int getNrInPorts()
Returns:
The total number of input ports.

getNrOutPorts

public int getNrOutPorts()
Returns:
The total number of output ports.

getInportName

public String getInportName(int index)
Return name of input connector.

Parameters:
index - of the connector
Returns:
The description
Throws:
IndexOutOfBoundsException - If argument is out of range.

getInputType

public PortType getInputType(int index)
Return type of input connector.

Parameters:
index - of the connector
Returns:
The type
Throws:
IndexOutOfBoundsException - If argument is out of range.

getOutportName

public String getOutportName(int index)
Return name of output connector.

Parameters:
index - of the connector
Returns:
The description to that port.
Throws:
IndexOutOfBoundsException - If argument is out of range.

getOutputType

public PortType getOutputType(int index)
Return type of output connector.

Parameters:
index - of the connector
Returns:
The type
Throws:
IndexOutOfBoundsException - If argument is out of range.

getOutputSpec

public PortObjectSpec getOutputSpec(int index)

getOutputObject

public PortObject getOutputObject(int index)

getOutputObjectSummary

public String getOutputObjectSummary(int index)

getOutputHiLiteHandler

public HiLiteHandler getOutputHiLiteHandler(int index)

getInternalHeldTables

public BufferedDataTable[] getInternalHeldTables()
Get the current set of tables internally held by a NodeModel that implements BufferedDataTableHolder. It may be null or contain null elements. This array is modified upon load, execute and reset.

Returns:
that array.

setInHiLiteHandler

public void setInHiLiteHandler(int index,
                               HiLiteHandler hdl)

hasContent

boolean hasContent()
Delegate method to node model.

Returns:
Whether the node model has (potentially) content to be displayed.
See Also:
NodeModel.hasContent()

execute

public boolean execute(PortObject[] data,
                       ExecutionContext exec)
Starts executing this node. If the node has been executed already, it does nothing - just returns true. Otherwise, the procedure starts executing all predecessor nodes connected to an input port (which in turn recursively trigger their predecessors) and calls the function #execute() in the model after all connected nodes return successfully. If a port is not connected this function returns false without executing itself (it may have executed some predecessor nodes though). If a predecessor node returns false this method also returns false without executing this node or any further connected node.

Parameters:
exec - The execution monitor.
data - the data from the predecessor.
Returns:
true if execution was successful otherwise false.
See Also:
NodeModel.execute(BufferedDataTable[],ExecutionContext)

copyPortObject

public static PortObject copyPortObject(PortObject portObject,
                                        ExecutionMonitor exec)
                                 throws IOException,
                                        CanceledExecutionException
Copies the PortObject so that the copy can be given to the node model implementation (and potentially modified). The copy is carried out by means of the respective serializer (via streams).

Note that this method is meant to be used by the framework only.

Parameters:
portObject - The object to be copied.
exec - For progress/cancel
Returns:
The (deep) copy.
Throws:
IOException - In case of exceptions while accessing the stream or if the argument is an instance of BufferedDataTable.
CanceledExecutionException - If canceled.

warningChanged

public void warningChanged(String warningMessage)
Is called, when a warning message is set in the NodeModel. Forwards it to registered NodeMessageListeners.

Specified by:
warningChanged in interface NodeModelWarningListener
Parameters:
warningMessage - the new message in the node model.

getWarningMessageFromModel

public String getWarningMessageFromModel()
Getter for the currently set node warning message in the corresponding NodeModel.

Returns:
The currently set warning message (may be null).

reset

public void reset()
Resets this node without re-configuring it.


cleanOutPorts

public void cleanOutPorts()

addToTemporaryTables

public void addToTemporaryTables(Set<ContainerTable> tempTables)
Adds the argument set of tables to the set of temporary tables in this node. Called after execute.

Parameters:
tempTables - Tables to add, not null.

putOutputTablesIntoGlobalRepository

public void putOutputTablesIntoGlobalRepository(HashMap<Integer,ContainerTable> rep)
Enumerates the output tables and puts them into the global workflow repository of tables. This method delegates from the NodeContainer class to access a package-scope method in BufferedDataTable.

Parameters:
rep - The global repository.

removeOutputTablesFromGlobalRepository

public void removeOutputTablesFromGlobalRepository(HashMap<Integer,ContainerTable> rep)
Reverse operation to putOutputTablesIntoGlobalRepository(HashMap). It will remove all output tables and its delegates from the global table repository.

Parameters:
rep - The global table rep.

getLocalTableRepositoryFromContext

public static HashMap<Integer,ContainerTable> getLocalTableRepositoryFromContext(ExecutionContext c)
Delegate method to allow access to the (package scope) method ExecutionContext.getLocalTableRepository(). Called after execution has finished to clean up temporary tables.

Parameters:
c - To access.
Returns:
Its local table repository.

cleanup

public void cleanup()
Deletes any temporary resources associated with this node.


configure

public boolean configure(PortObjectSpec[] inSpecs)
Sets all (new) incoming DataTableSpec elements in the model, calls the model to create output table specs and propagates these new specs to the connected successors.

Parameters:
inSpecs - the tablespecs from the predecessors
Returns:
flag indicating success of configure

configure

public boolean configure(PortObjectSpec[] inSpecs,
                         NodePostConfigure postConfigure)
Allows passing an object that may modify the specs created by the NodeModel, for example in case the node is wrapped and the output is modified.

Parameters:
inSpecs - table specs from the predecessors
postConfigure - object called after node model calculated output specs
Returns:
true if configure finished successfully.

getNrViews

public int getNrViews()
Returns:
The number of available views.

getViewName

public String getViewName(int viewIndex)
Returns the name for this node's view at the given index.

Parameters:
viewIndex - The view index.
Returns:
The view's name.
Throws:
ArrayIndexOutOfBoundsException - If the view index is out of range.

getView

public AbstractNodeView<?> getView(int viewIndex,
                                   String title)
Return a new instance of the node's view (without opening it).

Parameters:
viewIndex - The view's index to show up.
title - the displayed view title.
Returns:
The node view with the specified index.
Throws:
ArrayIndexOutOfBoundsException - If the view index is out of range.

closeAllViews

public void closeAllViews()
Closes all views.


hasDialog

public boolean hasDialog()
Returns true if this node can show a dialog. This is the case either, if the node implementation provides a dialog, if the node has output ports, or if more than one job managers are available.

Returns:
true if a dialog is available.

getDialogPaneWithSettings

public NodeDialogPane getDialogPaneWithSettings(PortObjectSpec[] inSpecs,
                                                FlowObjectStack foStack,
                                                NodeSettingsRO settings)
                                         throws NotConfigurableException
Parameters:
inSpecs - The input specs, which will be forwarded to the dialog's NodeDialogPane.loadSettingsFrom(NodeSettingsRO, PortObjectSpec[]).
foStack - The stack of variables.
settings - The current settings of this node. The settings object will also contain the settings of the outer SNC.
Returns:
The dialog pane which holds all the settings' components. In addition this method loads the settings from the model into the dialog pane.
Throws:
NotConfigurableException - if the dialog cannot be opened because of real invalid settings or if any preconditions are not fulfilled, e.g. no predecessor node, no nominal column in input table, etc.
IllegalStateException - If node has no dialog.
See Also:
hasDialog()

getDialogPane

public NodeDialogPane getDialogPane()
Get reference to the node dialog instance. Used to get the user settings from the dialog without overwriting them as in in getDialogPaneWithSettings(PortObjectSpec[], FlowObjectStack, NodeSettingsRO)

Returns:
Reference to dialog pane.
Throws:
IllegalStateException - If node has no dialog.
See Also:
hasDialog()

saveSettingsTo

public void saveSettingsTo(NodeSettingsWO settings)
Saves the settings (but not the data).

Parameters:
settings - a settings object

saveInternals

void saveInternals(File internDir,
                   ExecutionMonitor exec)
             throws CanceledExecutionException
Throws:
CanceledExecutionException

loadInternals

void loadInternals(File internDir,
                   ExecutionMonitor exec)
             throws CanceledExecutionException
Throws:
CanceledExecutionException

addMessageListener

public void addMessageListener(NodeMessageListener listener)
Adds a state listener to this node. Ignored, if the listener is already registered.

Parameters:
listener - The listener to add.

removeMessageListener

public void removeMessageListener(NodeMessageListener listener)
Removes a state listener from this node. Ignored, if the listener is not registered.

Parameters:
listener - The listener to remove.

toString

public String toString()
Returns a string summary of this node.

Overrides:
toString in class Object

getFactory

public NodeFactory<NodeModel> getFactory()
Returns:
the NodeFactory that constructed this node.

isInterruptible

public boolean isInterruptible()
Returns:
true if this node's model is a interruptible model

ensureOutputDataIsRead

public void ensureOutputDataIsRead()
Ensures that any port object is read for later saving with a newer version.


invokeEnsureOpen

public static void invokeEnsureOpen(BufferedDataTable table)
Exposes BufferedDataTable.ensureOpen() as public method. This method has been added here in order to keep the scope of the above method at a minimum.

Parameters:
table - To invoke this method on.

invokeOpenView

public static void invokeOpenView(AbstractNodeView<?> view,
                                  String title)
Widens scope of AbstractNodeView.openView(String) method so it can be called from UI framework components. This method is not meant for public use and may change in future versions.

Parameters:
view - The view to call the method on.
title - The title for the view (method argument).

invokeCloseView

public static void invokeCloseView(AbstractNodeView<?> view)
Widens scope of AbstractNodeView.closeView() method so it can be called from UI framework components. This method is not meant for public use and may change in future versions.

Parameters:
view - The view to call the method on.

setFlowObjectStack

public void setFlowObjectStack(FlowObjectStack scsc)

getFlowObjectStack

public FlowObjectStack getFlowObjectStack()

clearLoopStatus

public void clearLoopStatus()

getLoopStatus

public FlowLoopContext getLoopStatus()

getLoopRole

public final Node.LoopRole getLoopRole()

setLoopEndNode

public void setLoopEndNode(Node tail)

setLoopStartNode

public void setLoopStartNode(Node head)


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.