Class BasePlugin

java.lang.Object
org.incenp.obofoundry.odk.BasePlugin
All Implemented Interfaces:
org.obolibrary.robot.Command
Direct Known Subclasses:
NormalizeCommand, SubsetCommand, ValidateCommand

public abstract class BasePlugin extends Object implements org.obolibrary.robot.Command
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

    Fields
    Modifier and Type
    Field
    Description
    protected org.obolibrary.robot.IOHelper
     
    protected org.apache.commons.cli.Options
     

    Fields inherited from interface org.obolibrary.robot.Command

    global, missingFileError
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BasePlugin(String name, String desc, String usage)
    Creates a new command.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.obolibrary.robot.CommandState
    execute(org.obolibrary.robot.CommandState state, String[] args)
     
     
    protected org.semanticweb.owlapi.model.IRI
    getIRI(String term, String field)
    Creates an IRI from a user-specified source.
     
    org.apache.commons.cli.Options
     
     
    void
    main(String[] args)
     
    abstract void
    performOperation(org.obolibrary.robot.CommandState state, org.apache.commons.cli.CommandLine line)
    Performs whatever operation the command is supposed to do.
    protected Set<String>
    readFile(String filename)
    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>
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • options

      protected org.apache.commons.cli.Options options
    • ioHelper

      protected org.obolibrary.robot.IOHelper ioHelper
  • Constructor Details

    • BasePlugin

      protected BasePlugin(String name, String desc, String usage)
      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

      public String getName()
      Specified by:
      getName in interface org.obolibrary.robot.Command
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface org.obolibrary.robot.Command
    • getUsage

      public String getUsage()
      Specified by:
      getUsage in interface org.obolibrary.robot.Command
    • getOptions

      public org.apache.commons.cli.Options getOptions()
      Specified by:
      getOptions in interface org.obolibrary.robot.Command
    • main

      public void main(String[] args)
      Specified by:
      main in interface org.obolibrary.robot.Command
    • execute

      public org.obolibrary.robot.CommandState execute(org.obolibrary.robot.CommandState state, String[] args) throws Exception
      Specified by:
      execute in interface org.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

      protected org.semanticweb.owlapi.model.IRI getIRI(String term, String field)
      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

      protected Set<String> readFile(String filename) throws IOException
      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

      protected Set<org.semanticweb.owlapi.model.IRI> readFileAsIRIs(String filename) throws IOException
      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.