Package org.openscience.cdk.io
Class ChemObjectIO
- java.lang.Object
-
- org.openscience.cdk.io.ChemObjectIO
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,IChemObjectIO
- Direct Known Subclasses:
DefaultChemObjectReader
,DefaultChemObjectWriter
,DefaultEventChemObjectReader
,DefaultIteratingChemObjectReader
public abstract class ChemObjectIO extends Object implements IChemObjectIO
Provides some basic functionality for readers and writers. This includes managing theIChemObjectIOListener
's and managing ofIOSetting
's. The IOSettings are managed via theSettingManager
class with most method's wrapped to more descriptive method names (e.g.SettingManager.get(String)
is invoked bygetSetting(String)
).- Author:
- johnmay
- Source code:
- main
- Belongs to CDK module:
- io
- Created on:
- 20.03.2012
-
-
Constructor Summary
Constructors Constructor Description ChemObjectIO()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChemObjectIOListener(IChemObjectIOListener listener)
Adds aIChemObjectIOListener
to this IChemObjectIO.<S extends IOSetting>
SaddSetting(IOSetting setting)
Add an IOSetting to the reader/writer.void
addSettings(Collection<IOSetting> settings)
Adds a collection ofIOSetting
s to the reader/writer.protected void
fireIOSettingQuestion(IOSetting setting)
FiresIChemObjectIOListener.processIOSettingQuestion(org.openscience.cdk.io.setting.IOSetting)
for all managed listeners.IOSetting[]
getIOSettings()
Returns an array ofIOSetting
s defined by this IChemObjectIO class.List<IChemObjectIOListener>
getListeners()
Access all the listeners for this ChemObject Reader or Writer.<S extends IOSetting>
SgetSetting(String name)
Access a named setting managed by this reader/writer.<S extends IOSetting>
SgetSetting(String name, Class<S> c)
Access a named setting managed by this reader/writer.Collection<IOSetting>
getSettings()
Access a collection ofIOSetting
s 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 aIChemObjectIOListener
from this IChemObjectIO.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openscience.cdk.io.IChemObjectIO
accepts, close, getFormat
-
-
-
-
Method Detail
-
getListeners
public List<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 usingIChemObjectIO.addChemObjectIOListener(org.openscience.cdk.io.listener.IChemObjectIOListener)
andIChemObjectIO.removeChemObjectIOListener(org.openscience.cdk.io.listener.IChemObjectIOListener)
- Specified by:
getListeners
in interfaceIChemObjectIO
- Returns:
- all listeners managed by this IO object
-
addChemObjectIOListener
public void addChemObjectIOListener(IChemObjectIOListener listener)
Adds aIChemObjectIOListener
to this IChemObjectIO.- Specified by:
addChemObjectIOListener
in interfaceIChemObjectIO
- Parameters:
listener
- the reader listener to add.
-
removeChemObjectIOListener
public void removeChemObjectIOListener(IChemObjectIOListener listener)
Removes aIChemObjectIOListener
from this IChemObjectIO.- Specified by:
removeChemObjectIOListener
in interfaceIChemObjectIO
- Parameters:
listener
- the listener to be removed.
-
addSetting
public <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
- Specified by:
addSetting
in interfaceIChemObjectIO
- Parameters:
setting
- setting to add- Returns:
- usable setting
- See Also:
SettingManager.add(org.openscience.cdk.interfaces.ISetting)
-
addSettings
public void addSettings(Collection<IOSetting> settings)
Adds a collection ofIOSetting
s 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());
- Specified by:
addSettings
in interfaceIChemObjectIO
- Parameters:
settings
- collection of settings to add- See Also:
IChemObjectIO.getSettings()
-
hasSetting
public boolean hasSetting(String name)
Determine whether this reader/writer has a setting of the provided name.- Specified by:
hasSetting
in interfaceIChemObjectIO
- Parameters:
name
- name of a setting- Returns:
- whether the setting is available
- See Also:
SettingManager.has(String)
-
getSetting
public <S extends IOSetting> S getSetting(String name)
Access a named setting managed by this reader/writer.- Specified by:
getSetting
in interfaceIChemObjectIO
- 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:
IChemObjectIO.getSetting(String, Class)
,SettingManager.get(String)
-
getSetting
public <S extends IOSetting> S getSetting(String name, Class<S> c)
Access a named setting managed by this reader/writer.- Specified by:
getSetting
in interfaceIChemObjectIO
- Type Parameters:
S
- type to cast to- Parameters:
name
- name of the settingc
- 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:
IChemObjectIO.getSetting(String)
,SettingManager.get(String, Class)
-
getIOSettings
public IOSetting[] getIOSettings()
Returns an array ofIOSetting
s defined by this IChemObjectIO class.- Specified by:
getIOSettings
in interfaceIChemObjectIO
- Returns:
- the
IOSetting
s for this class.
-
getSettings
public Collection<IOSetting> getSettings()
Access a collection ofIOSetting
s for this reader/writer.- Specified by:
getSettings
in interfaceIChemObjectIO
- Returns:
- collection of IOSetting's
- See Also:
IChemObjectIO.addSettings(java.util.Collection)
-
fireIOSettingQuestion
protected void fireIOSettingQuestion(IOSetting setting)
FiresIChemObjectIOListener.processIOSettingQuestion(org.openscience.cdk.io.setting.IOSetting)
for all managed listeners.- Parameters:
setting
- the setting to process
-
-