Class BaseToolImpl

java.lang.Object
org.episteme.natural.chemistry.loaders.cml.cmlimpl.BaseToolImpl
All Implemented Interfaces:
BaseTool

public class BaseToolImpl extends Object implements BaseTool
Performs editing functions on a generic CMLObject
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Field Details

    • jumboLogger

      protected static JumboLogger jumboLogger
    • editorPackageName

      protected static String editorPackageName
    • CONSTRUCT

      protected static String CONSTRUCT
    • TEST

      protected static String TEST
    • baseToolTable

      protected static Hashtable<String,BaseTool> baseToolTable
    • abstractBase

      protected AbstractBase abstractBase
    • document

      protected AbstractCMLDocument document
    • debug

      protected boolean debug
    • ignoreAttributeTable

      protected Hashtable<String,Boolean> ignoreAttributeTable
    • workflow

      protected Workflow workflow
    • declaredPublicMethods

      protected Method[] declaredPublicMethods
    • declaredPublicConstructors

      protected Constructor<?>[] declaredPublicConstructors
  • Constructor Details

    • BaseToolImpl

      protected BaseToolImpl()
      new BaseTool.

      only for use by subclasses

    • BaseToolImpl

      public BaseToolImpl(AbstractCMLDocument document)
      new BaseTool containing a new AbstractBase.

      uses document as owner

      Parameters:
      document - the owner document
    • BaseToolImpl

      protected BaseToolImpl(AbstractBase base)
  • Method Details

    • superInit

      protected void superInit(AbstractBase base)
    • getTool

      public static BaseTool getTool(AbstractBase base)
      gets tool or creates new one.
      Parameters:
      base -
      Returns:
      the tool (null if molecule is null)
    • getTool

      public static BaseTool getTool(AbstractBase base, BaseTool tool)
      gets existing tool for base or returns tool after initialising it with base.
      Parameters:
      base - the item that you want a tool for
      tool - the tool to use should base not already have one
      Returns:
      the tool (null if molecule is null)
    • getCMLDocument

      public AbstractCMLDocument getCMLDocument()
    • getAbstractBase

      public AbstractBase getAbstractBase()
      get abstract base

      only defined for implemented editors (default => null)

      Specified by:
      getAbstractBase in interface BaseTool
      Returns:
      the element associated with this editor (null for default)
    • setAbstractBase

      public void setAbstractBase(AbstractBase ab)
      set abstract base

      only defined for implemented editors (default => null) should not be required in user code

      Specified by:
      setAbstractBase in interface BaseTool
      Parameters:
      ab - the element associated with this editor
    • equals

      public boolean equals(BaseTool baseTool)
      is the contained object equal to the other contained object.

      The two objects contained in the elements are compared. The default is to use an element-by-element and attribute-by-attribute comparison. This can be overridden for subclasses. For example the order of children in some elements matters while in others (e.g. molecules) it does not. The compared object must be of the same class but may have different namespace prefix, etc. By default ownerDocuments are ignored (thus molecules in different documents can be compared.)

      childElements are compared using their equals() methods

      The editors may have special methods to affect of control equality. Thus it is possible to ignore Ids.

      If the reason for non-equality is required, the mustEqual() method should be used.

      Specified by:
      equals in interface BaseTool
      Parameters:
      baseTool - the other element editor (must be of same class)
    • mustEqual

      public void mustEqual(BaseTool otherTool) throws CMLException
      throws exception if the contained object is not equal to the other contained object.

      see equals() for strategy.

      Specified by:
      mustEqual in interface BaseTool
      Parameters:
      otherTool - the other element (must be of same class)
      Throws:
      CMLException - the reason for non-equality
    • mustEqualAttributes

      public void mustEqualAttributes(BaseTool otherTool) throws CMLException
      Throws:
      CMLException
    • mustEqualChildNodes

      public void mustEqualChildNodes(BaseTool otherTool) throws CMLException
      Throws:
      CMLException
    • setIgnoreAttribute

      public void setIgnoreAttribute(String name, boolean descend)
      ignore an attribute
      Specified by:
      setIgnoreAttribute in interface BaseTool
      Parameters:
      name - attribute to ignore
      descend - carry over to descendants
    • removeElement

      public Element removeElement(String elementName)
      removes the first element by tagName

      finds first element with that name and removes it from its parent. mainly for debugging

      Specified by:
      removeElement in interface BaseTool
      Parameters:
      elementName -
      Returns:
      the element removed
    • characters

      public void characters(SaxHandler saxHandler, String content) throws CMLException
      SAX2 parsing routine - called from characters() callback

      NOT namespace aware

      Specified by:
      characters in interface BaseTool
      Parameters:
      saxHandler - SaxHandler
      content - throws exception (probably application specific)
      Throws:
      CMLException
    • endElement

      public void endElement(SaxHandler saxHandler) throws CMLException
      SAX2 parsing routine - called from endElement() callback

      NOT namespace aware

      Specified by:
      endElement in interface BaseTool
      Parameters:
      saxHandler - Saxhandler throws exception (probably application specific)
      Throws:
      CMLException
    • startElement

      public void startElement(SaxHandler saxHandler, Attributes attributes) throws CMLException
      SAX2 parsing routine - called from startElement() callback

      NOT namespace aware

      Specified by:
      startElement in interface BaseTool
      Parameters:
      saxHandler - Saxhandler
      attributes - the attribute list throws exception (probably application specific)
      Throws:
      CMLException
    • writeXML

      public void writeXML(Writer w, String control) throws CMLException, IOException
      write XML, using class-specific information

      NOT namespace aware

      Specified by:
      writeXML in interface BaseTool
      Parameters:
      w - the writer
      control - (concatenation of CML version and array)
    • setDebug

      public void setDebug(boolean d)
      toggle debugging
      Parameters:
      d - debug
    • getDebug

      public boolean getDebug()
      debug status
      Returns:
      is debug set
    • debug

      protected void debug(String s)
      output string if debug set
      Parameters:
      s - string to output
    • copyAttributesFromTo

      public void copyAttributesFromTo(AbstractBase from, AbstractBase to)
      copy attributes from one AbstractBase to another.

      overwrites existing atts

      Specified by:
      copyAttributesFromTo in interface BaseTool
      Parameters:
      from - element to copy from
      to - element to copy to
    • transferChildrenFromTo

      public void transferChildrenFromTo(AbstractBase from, AbstractBase to)
      transfer children from one AbstractBase to another.
      Specified by:
      transferChildrenFromTo in interface BaseTool
      Parameters:
      from - element to copy from
      to - element to copy to
    • clear

      public static void clear(Hashtable<?,?> editorTable)
      clears an editorTable.
      Parameters:
      editorTable - the table to clear
    • setToolPackage

      public static void setToolPackage(String pName)
      set Tool package.
      Parameters:
      pName - the package in which Tools will be found
    • createToolForName

      public static BaseTool createToolForName(String baseName)
      constructs a tools class object.

      at present converts "moleculeTool" to [currentPackage].MoleculeToolImpl Does NOT use or create a DOM, so only use for accesing class methods e.g. in workflow

      Returns:
      object (or null if cannot create)
    • processCurrentCommand

      public void processCurrentCommand(Workflow workflow) throws CMLException
      run workflow script or object.

      sets workflow to the tool and runs the current command all information (current command, symbolTables can be accessed from workflow

      Specified by:
      processCurrentCommand in interface BaseTool
      Parameters:
      workflow - to process.
      Throws:
      CMLException
    • getWorkflow

      public Workflow getWorkflow()
      get the workflow.
      Specified by:
      getWorkflow in interface BaseTool
      Returns:
      workflow
    • formatNumber

      public String formatNumber(String s)
    • getDeclaredPublicConstructors

      public Constructor<?>[] getDeclaredPublicConstructors()
      get all public constructors belonging just to this class.
      Returns:
      array of constructors
    • getDeclaredPublicMethods

      public Method[] getDeclaredPublicMethods()
      get all public methods belonging just to this class.
      Specified by:
      getDeclaredPublicMethods in interface BaseTool
      Returns:
      array of methods
    • runConstructor

      public Object runConstructor(List<Object> argVector)
      run any public constructor introspects the above constructors Example: CMLVector3 projectOnto(CMLVector3 v) is called with v as arg v1, v2 and floatArg as dontCare and returns Object of type CMLVector3
      Parameters:
      argVector - arguments in order.
      Returns:
      the constructor value
    • runMethod

      public Object runMethod(String methodS, List<Object> argVector)
      run any public method introspects the above methods Example: CMLVector3 projectOnto(CMLVector3 v) is called with v as arg v1, v2 and floatArg as dontCare and returns Object of type CMLVector3 Returns without action if duplicate method name
      Specified by:
      runMethod in interface BaseTool
      Parameters:
      methodS - case-sensitive method.
      argVector - arguments in order. First arg is instance of this
      Returns:
      any return value (see Method.invoke for classes)
    • getMethod

      protected Method getMethod(String methodS, List<Object> argVector)
    • getConstructor

      protected Constructor<?> getConstructor(List<Object> argVector)
    • getUniqueMethod

      protected Method getUniqueMethod(String methodS)
      gets unique method if possible does not use args at present
      Parameters:
      methodS - method name
      Returns:
      unique method for that name
    • getDoubleArgs

      protected static double[] getDoubleArgs(int start, int nargs, String[] args)
    • usage

      protected void usage(String className)
    • constructorsUsage

      protected void constructorsUsage()
    • methodsUsage

      protected void methodsUsage()
    • testMethods

      public void testMethods()
      test all declared public methods. introspects args and creates test instances from primitives or getTestInstance(); cannot create arg which require arrays so skips method also may skip some superclasses
    • convertInterfaceToClass

      public static String convertInterfaceToClass(String interfaceName)
      converts CMLInterface to class. e.g. converts org.episteme.natural.chemistry.loaders.cml.CMLVector3 to org.episteme.natural.chemistry.loaders.cml.cmlimpl.Vector3Impl and AbstractBase to CMLBaseImpl
      Parameters:
      interfaceName - the interface
      Returns:
      the class name
    • convertClassToInterface

      public static String convertClassToInterface(String className)
      converts CML classname to interface. e.g. converts org.episteme.natural.chemistry.loaders.cml.cmlimpl.Vector3Impl to org.episteme.natural.chemistry.loaders.cml.CMLVector3 and CMLBaseImpl to AbstractBase
      Parameters:
      className -
      Returns:
      the interface name
    • processArgs

      public void processArgs(String[] args)
      process args.
      Parameters:
      args -
    • getTestInstance

      public BaseTool getTestInstance(AbstractCMLDocument doc, int serial)
      a standard instance for testing. returns null unless subclassed
      Specified by:
      getTestInstance in interface BaseTool
      Parameters:
      doc - the owner document
      serial - the instance (1,2,3)
      Returns:
      null
    • processCommandLine

      public int processCommandLine(String[] args, int offset, List<Object> argVector, AbstractCMLDocument doc)
      process the commandline from main routines. normally subclassed
      Specified by:
      processCommandLine in interface BaseTool
      Parameters:
      args - the arguments
      offset - current position in args
      argVector - vector to accumulate arguments
      doc - owner document
      Returns:
      position in args after parsing