org.knime.core.node.port
Class AbstractPortObject

java.lang.Object
  extended by org.knime.core.node.port.AbstractPortObject
All Implemented Interfaces:
PortObject

public abstract class AbstractPortObject
extends Object
implements PortObject

Abstract implementation of general port objects. Extending this class (as opposed to just implementing PortObject) has the advantage that the serializing methods are enforced by abstract methods (rather than defining a static method with a particular name as given by the interface).

Subclasses must provide an empty no-arg constructor with public scope (which will be used to restore the content). They are encouraged to also provide a convenience access member such as

   public static final PortType TYPE = new PortType(FooModelPortObject.class);
 
and to narrow the return type of the getSpec() method. Derived classes don't need to provide a static serializer method as required by the interface PortObject.

Author:
Bernd Wiswedel, University of Konstanz

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.knime.core.node.port.PortObject
PortObject.PortObjectSerializer<T extends PortObject>
 
Constructor Summary
AbstractPortObject()
          Public no-arg constructor.
 
Method Summary
static PortObject.PortObjectSerializer<AbstractPortObject> getPortObjectSerializer()
          Abstract serializer method as required by interface PortObject.
protected abstract  void load(PortObjectZipInputStream in, PortObjectSpec spec, ExecutionMonitor exec)
          Loads the content into the freshly instantiated object.
protected abstract  void save(PortObjectZipOutputStream out, ExecutionMonitor exec)
          Saves this object to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.knime.core.node.port.PortObject
getSpec, getSummary, getViews
 

Constructor Detail

AbstractPortObject

public AbstractPortObject()
Public no-arg constructor. Subclasses must also provide such a constructor in order to allow the serializer to instantiate them using reflection.

Method Detail

getPortObjectSerializer

public static final PortObject.PortObjectSerializer<AbstractPortObject> getPortObjectSerializer()
Abstract serializer method as required by interface PortObject.

Returns:
A serializer that reads/writes any implementation of this class.

save

protected abstract void save(PortObjectZipOutputStream out,
                             ExecutionMonitor exec)
                      throws IOException,
                             CanceledExecutionException
Saves this object to an output stream. This method represents the implementation of #savePortObject(PortObject, PortObjectZipOutputStream, ExecutionMonitor).

Parameters:
out - A clean directory to write to.
exec - For progress/cancelation.
Throws:
IOException - If writing fails
CanceledExecutionException - If canceled.

load

protected abstract void load(PortObjectZipInputStream in,
                             PortObjectSpec spec,
                             ExecutionMonitor exec)
                      throws IOException,
                             CanceledExecutionException
Loads the content into the freshly instantiated object. This method is called at most once in the life time of the object (after the serializer has created a new object using the public no-arg constructor.)

Parameters:
in - To restore from
spec - The accompanying spec (which can be safely cast to the expected class).
exec - For progress/cancelation.
Throws:
IOException - If reading fails.
CanceledExecutionException - If canceled.


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.