Package org.incenp.obofoundry.odk
Class BasePlugin
java.lang.Object
org.incenp.obofoundry.odk.BasePlugin
- All Implemented Interfaces:
org.obolibrary.robot.Command
- Direct Known Subclasses:
NormalizeCommand
,SubsetCommand
,ValidateCommand
Helper base class for ROBOT commands.
This class is intended to serve as a base class for ROBOT commands, to avoid
duplicating boilerplate across several commands. Subclasses should call the
constructor with the desired name, description, and help message, add any
option they need, and implement the
performOperation(CommandState, CommandLine)
method.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.obolibrary.robot.IOHelper
protected org.apache.commons.cli.Options
Fields inherited from interface org.obolibrary.robot.Command
global, missingFileError
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BasePlugin
(String name, String desc, String usage) Creates a new command. -
Method Summary
Modifier and TypeMethodDescriptionorg.obolibrary.robot.CommandState
protected org.semanticweb.owlapi.model.IRI
Creates an IRI from a user-specified source.getName()
org.apache.commons.cli.Options
getUsage()
void
abstract void
performOperation
(org.obolibrary.robot.CommandState state, org.apache.commons.cli.CommandLine line) Performs whatever operation the command is supposed to do.Reads a file and gets its contents as a set, one entry per line, excluding any blank line and lines starting with a '#' character.protected Set<org.semanticweb.owlapi.model.IRI>
readFileAsIRIs
(String filename) Reads a file and gets its contents as a set of IRIs, assuming one IRI per line, excluding any blank line and lines starting with a '#' character.
-
Field Details
-
options
protected org.apache.commons.cli.Options options -
ioHelper
protected org.obolibrary.robot.IOHelper ioHelper
-
-
Constructor Details
-
BasePlugin
Creates a new command.- Parameters:
name
- The command name, as it should be invoked on the command line.desc
- The description of the command that ROBOT will display.usage
- The help message for the command.
-
-
Method Details
-
getName
- Specified by:
getName
in interfaceorg.obolibrary.robot.Command
-
getDescription
- Specified by:
getDescription
in interfaceorg.obolibrary.robot.Command
-
getUsage
- Specified by:
getUsage
in interfaceorg.obolibrary.robot.Command
-
getOptions
public org.apache.commons.cli.Options getOptions()- Specified by:
getOptions
in interfaceorg.obolibrary.robot.Command
-
main
- Specified by:
main
in interfaceorg.obolibrary.robot.Command
-
execute
public org.obolibrary.robot.CommandState execute(org.obolibrary.robot.CommandState state, String[] args) throws Exception - Specified by:
execute
in interfaceorg.obolibrary.robot.Command
- Throws:
Exception
-
performOperation
public abstract void performOperation(org.obolibrary.robot.CommandState state, org.apache.commons.cli.CommandLine line) throws Exception Performs whatever operation the command is supposed to do.- Parameters:
state
- The internal state of ROBOT.line
- The command line used to invoke the command.- Throws:
Exception
- If any error occurs when attempting to execute the operation.
-
getIRI
Creates an IRI from a user-specified source. This delegates the task of expanding CURIEs to ROBOT, which may use whatever information it has (such as prefix mappings specified on the command line with the--prefix
option).- Parameters:
term
- The term to transform into an IRI.field
- The source where the term comes from. Used in ROBOT's error message, if the term cannot be transformed into an IRI.- Returns:
- The resulting IRI.
- Throws:
IllegalArgumentException
- If the term cannot be transformed into an IRI.
-
readFile
Reads a file and gets its contents as a set, one entry per line, excluding any blank line and lines starting with a '#' character.- Parameters:
filename
- The name of the file to read.- Returns:
- The file's lines as a set of unique strings.
- Throws:
IOException
- If any I/O error occurs when reading the file.
-
readFileAsIRIs
Reads a file and gets its contents as a set of IRIs, assuming one IRI per line, excluding any blank line and lines starting with a '#' character. CURIEs that cannot be converted to a full-length IRI are silently ignored.- Parameters:
filename
- The name of the file to read.- Returns:
- The set of IRIs contained in the file.
- Throws:
IOException
- If any I/O error occurs when reading the file.
-