Class XmlPumpIntentFactory

java.lang.Object
com.tccc.kos.ext.dispense.pipeline.ingredient.XmlPumpIntentFactory
All Implemented Interfaces:
PumpIntentFactory

public class XmlPumpIntentFactory extends Object implements PumpIntentFactory
Implementation of PumpIntentFactory that leverages xml data files to describe operations, intents and rules to map intent types for specific pumps to named intents. This supports those PumpOp types that are part of kOS, but this class can be extended to add support for additional operations while still leveraging all the xml infrastructure.
Since:
1.0
Version:
2023-01-22
  • Field Details

  • Constructor Details

    • XmlPumpIntentFactory

      public XmlPumpIntentFactory()
      Create a new intent factory.
  • Method Details

    • addLoader

      public void addLoader(com.tccc.kos.commons.util.resource.ResourceLoader loader)
      Add a ResourceLoader used to search for referenced xml files. Since xml files may include other xml files, this is an easy way to establish search paths that can search filesystem files as well as ClassLoader resources. Loaders will be searched in the reverse order they are added which allows later loaders to override resources from earlier loaders.
      Parameters:
      loader - the resource loader to add
    • load

      public void load(String file)
      Load the specified pump intent file using the installed resource loaders.
      Parameters:
      file - the file name to load
    • lookupIntent

      public PumpIntent lookupIntent(String ruleType, String ruleKey, String intentType)
      Return a pump intent for the specified rule type, rule key, and pump information. This will lookup the corresponding pump intent mapping and then use the ref to lookup the actual intent. The default lookupIntent() method uses this to check various rules in priority order. Subclasses are free to override lookupIntent() to implement whatever rules are desired.
      Parameters:
      ruleType - the ruleType to check ("pumpType", "pumpCategory", "pumpPath")
      ruleKey - the key for the rule (pump type, pump category, pump path)
      intentType - the desired intent (prime, purge, etc...)
    • getIntent

      public PumpIntent getIntent(String intentType, Pump<?> pump)
      This checks for an intent by checking the following rules in order:
      • pumpPath : Most specific rule as it identifies a specific pump.
      • pumpCategory : An Assembly can generally map categories to specific pumps.
      • pumpType : Least specific as it matches all pumps of a given type.
      This simply uses lookupIntent() to check each rule type in the sequence above. Subclasses can override this and change the behavior.
      Specified by:
      getIntent in interface PumpIntentFactory
      Parameters:
      intentType - the type of intent to return (prime / purge / etc...)
      pump - the pump to return the intent for
      Returns:
      the intent or null if no match
    • newPumpIntent

      public PumpIntent newPumpIntent(String name)
      Return a new PumpIntent instance for use with parseIntent() . This allows developers to subclass PumpIntent and subclass parseIntent() and still use this factory.
      Parameters:
      name - the name of the intent
    • parseIntent

      public void parseIntent(PumpIntent intent, org.jdom2.Element root)
      Extract data from the xml element and populate the PumpIntent . To use a subclass of PumpIntent , override newPumpIntent() and override this method. Subclasses can call super.parseIntent() to populate the base class data.
      Parameters:
      intent - the intent to populate
      root - the intent element
    • toPumpOp

      public PumpOp toPumpOp(String type, org.jdom2.Element root)
      Extract a PumpOp from the element and add to the specified intent. The call to add the operation will call PumpOp.validate() .

      This handles built-in kOS operations so subclasses can check for custom operations and then call super.toPumpOp().

      Parameters:
      type - the operation type
      root - the operation element
    • setBaseProperties

      public void setBaseProperties(PumpOp op, org.jdom2.Element root)
      Populate the base fields of the op.