org.openscience.cdk.io
Interface IChemObjectIO

All Superinterfaces:
Closeable
All Known Subinterfaces:
IChemObjectReader, IChemObjectWriter, IEventChemObjectReader, IIteratingChemObjectReader<T>, ISimpleChemObjectReader
All Known Implementing Classes:
CDKOWLReader, CDKOWLWriter, CDKSourceCodeWriter, ChemObjectIO, CIFReader, CMLReader, CMLWriter, CrystClustReader, CrystClustWriter, CTXReader, DefaultChemObjectReader, DefaultChemObjectWriter, DefaultEventChemObjectReader, DefaultIteratingChemObjectReader, EventCMLReader, GamessReader, Gaussian03Reader, Gaussian98Reader, GaussianInputWriter, GhemicalMMReader, HINReader, HINWriter, INChIPlainTextReader, INChIReader, IteratingPCCompoundASNReader, IteratingPCCompoundXMLReader, IteratingPCSubstancesXMLReader, IteratingSDFReader, IteratingSMILESReader, MDLReader, MDLRXNReader, MDLRXNV2000Reader, MDLRXNV3000Reader, MDLRXNWriter, MDLV2000Reader, MDLV2000Writer, MDLV3000Reader, Mol2Reader, Mol2Writer, Mopac7Reader, Mopac7Writer, MoSSOutputReader, PCCompoundASNReader, PCCompoundXMLReader, PCSubstanceXMLReader, PDBReader, PDBWriter, PMPReader, RGroupQueryReader, RGroupQueryWriter, RssWriter, SDFWriter, ShelXReader, ShelXWriter, SMILESReader, SMILESWriter, VASPReader, XYZReader, XYZWriter, ZMatrixReader

public interface IChemObjectIO
extends Closeable

This class is the interface that all IO readers should implement. Programs need only care about this interface for any kind of IO. Currently, database IO and file IO is supported.

The easiest way to implement a new IChemObjectReader is to subclass the DefaultChemObjectReader.

Author:
Egon Willighagen
See Also:
DefaultChemObjectReader
Belongs to CDK module:
io
Source code:
cdk-1.4.x

Method Summary
 boolean accepts(Class<? extends IChemObject> classObject)
          Returns whether the given IChemObject can be read or written.
 void addChemObjectIOListener(IChemObjectIOListener listener)
          Adds a IChemObjectIOListener to this IChemObjectIO.
<S extends IOSetting>
S
addSetting(IOSetting setting)
          Add an IOSetting to the reader/writer.
 void addSettings(Collection<IOSetting> settings)
          Adds a collection of IOSettings to the reader/writer.
 void close()
          Closes this IChemObjectIO's resources.
 IResourceFormat getFormat()
          Returns the IResourceFormat class for this IO class.
 IOSetting[] getIOSettings()
          Returns an array of IOSettings defined by this IChemObjectIO class.
 Collection<IChemObjectIOListener> getListeners()
          Access all the listeners for this ChemObject Reader or Writer.
<S extends IOSetting>
S
getSetting(String name)
          Access a named setting managed by this reader/writer.
<S extends IOSetting>
S
getSetting(String name, Class<S> c)
          Access a named setting managed by this reader/writer.
 Collection<IOSetting> getSettings()
          Access a collection of IOSettings for this reader/writer.
 boolean hasSetting(String name)
          Determine whether this reader/writer has a setting of the provided name.
 void removeChemObjectIOListener(IChemObjectIOListener listener)
          Removes a IChemObjectIOListener from this IChemObjectIO.
 

Method Detail

getFormat

IResourceFormat getFormat()
Returns the IResourceFormat class for this IO class.


accepts

boolean accepts(Class<? extends IChemObject> classObject)
Returns whether the given IChemObject can be read or written.

Parameters:
classObject - IChemObject of which is tested if it can be handled.
Returns:
true, if the IChemObject can be handled.

close

@TestMethod(value="testClose")
void close()
           throws IOException
Closes this IChemObjectIO's resources.

Specified by:
close in interface Closeable
Throws:
throws - an IOException when the wrapper IO class cannot be closed.
IOException

getIOSettings

IOSetting[] getIOSettings()
Returns an array of IOSettings defined by this IChemObjectIO class.

Returns:
the IOSettings for this class.

addChemObjectIOListener

void addChemObjectIOListener(IChemObjectIOListener listener)
Adds a IChemObjectIOListener to this IChemObjectIO.

Parameters:
listener - the reader listener to add.

removeChemObjectIOListener

void removeChemObjectIOListener(IChemObjectIOListener listener)
Removes a IChemObjectIOListener from this IChemObjectIO.

Parameters:
listener - the listener to be removed.

getListeners

Collection<IChemObjectIOListener> getListeners()
Access all the listeners for this ChemObject Reader or Writer. This will returned an unmodifiable list of listeners. Listeners should be added to and removed from the reader/writer using addListener(IChemObjectIOListener) and removeListener(IChemObjectIOListener)

Returns:
all listeners managed by this IO object

addSetting

<S extends IOSetting> S addSetting(IOSetting setting)
Add an IOSetting to the reader/writer. If the name clashes with another setting the original setting will be returned. This method should be called when assigning field settings:
private BooleanIOSetting setting; // field

 ...

 setting = addSetting(new BooleanIOSetting("setting", ...));
 // if setting was already added we are now using the correct instance

Parameters:
setting - setting to add
Returns:
usable setting
See Also:
SettingManager.add(org.openscience.cdk.interfaces.ISetting)

addSettings

void addSettings(Collection<IOSetting> settings)
Adds a collection of IOSettings to the reader/writer. This is useful for transferring/propagating settings between different reader/writer. When the new settings are added if there is a setting with the same name already stored the value for the new setting is set on the managed setting (See. IteratingSDFReader/SDFWriter for propagation examples). Note that if the setting is invalid (a CDKException thrown) then the setting will not be set.
// two different readers (of same or different type)
 IChemObjectReader reader1 = ...;
 IChemObjectReader reader2 = ...;

 // settings transferred from reader2 to reader1
 reader1.addSettings(reader2.getSettings());
 

Parameters:
settings - collection of settings to add
See Also:
getSettings()

hasSetting

boolean hasSetting(String name)
Determine whether this reader/writer has a setting of the provided name.

Parameters:
name - name of a setting
Returns:
whether the setting is available
See Also:
SettingManager.has(String)

getSetting

<S extends IOSetting> S getSetting(String name)
Access a named setting managed by this reader/writer.

Type Parameters:
S - type to cast to
Parameters:
name - name of the setting
Returns:
instance of the setting for the name (InvalidParameterException is thrown if no setting for the provided name is found)
See Also:
getSetting(String, Class), SettingManager.get(String)

getSetting

<S extends IOSetting> S getSetting(String name,
                                   Class<S> c)
Access a named setting managed by this reader/writer.

Type Parameters:
S - type to cast to
Parameters:
name - name of the setting
c - the class of the setting (matching generic return type). This is need as due to type erasure we don't know the class of 'S' at runtime.
Returns:
instance of the setting for the name (InvalidParameterException is thrown if no setting for the provided name is found)
See Also:
getSetting(String), SettingManager.get(String, Class)

getSettings

Collection<IOSetting> getSettings()
Access a collection of IOSettings for this reader/writer.

Returns:
collection of IOSetting's
See Also:
addSettings(java.util.Collection)