Class XmlPumpIntentFactory
java.lang.Object
com.tccc.kos.ext.dispense.pipeline.ingredient.XmlPumpIntentFactory
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLoader
(com.tccc.kos.commons.util.resource.ResourceLoader loader) Add aResourceLoader
used to search for referenced xml files.This checks for an intent by checking the following rules in order: pumpPath : Most specific rule as it identifies a specific pump.void
Load the specified pump intent file using the installed resource loaders.lookupIntent
(String ruleType, String ruleKey, String intentType) Return a pump intent for the specified rule type, rule key, and pump information.newPumpIntent
(String name) Return a newPumpIntent
instance for use withparseIntent()
.void
parseIntent
(PumpIntent intent, org.jdom2.Element root) Extract data from the xml element and populate thePumpIntent
.void
setBaseProperties
(PumpOp op, org.jdom2.Element root) Populate the base fields of the op.Extract a PumpOp from the element and add to the specified intent.
-
Field Details
-
XML_TYPE
- See Also:
-
XML_DURATION
- See Also:
-
XML_DILUTED
- See Also:
-
XML_VOLUME
- See Also:
-
XML_RATE
- See Also:
-
XML_GRANTS
- See Also:
-
XML_INHERIT_GRANTS
- See Also:
-
RULE_TYPE_PUMP_PATH
- See Also:
-
RULE_TYPE_PUMP_CATEGORY
- See Also:
-
RULE_TYPE_PUMP_TYPE
- See Also:
-
-
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 aResourceLoader
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
Load the specified pump intent file using the installed resource loaders.- Parameters:
file
- the file name to load
-
lookupIntent
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 defaultlookupIntent()
method uses this to check various rules in priority order. Subclasses are free to overridelookupIntent()
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
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.
lookupIntent()
to check each rule type in the sequence above. Subclasses can override this and change the behavior.- Specified by:
getIntent
in interfacePumpIntentFactory
- 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
Return a newPumpIntent
instance for use withparseIntent()
. This allows developers to subclassPumpIntent
and subclassparseIntent()
and still use this factory.- Parameters:
name
- the name of the intent
-
parseIntent
Extract data from the xml element and populate thePumpIntent
. To use a subclass ofPumpIntent
, overridenewPumpIntent()
and override this method. Subclasses can callsuper.parseIntent()
to populate the base class data.- Parameters:
intent
- the intent to populateroot
- the intent element
-
toPumpOp
Extract a PumpOp from the element and add to the specified intent. The call to add the operation will callPumpOp.validate()
.This handles built-in kOS operations so subclasses can check for custom operations and then call super.toPumpOp().
- Parameters:
type
- the operation typeroot
- the operation element
-
setBaseProperties
Populate the base fields of the op.
-