Package com.tccc.kos.core.service.region
Class XmlRegionFactory
java.lang.Object
com.tccc.kos.core.service.region.XmlRegionFactory
Factory for loading
BaseRegion
objects from one or more XML files.
The XML file format is:
<regionDefs>
<regions>
<region id="factory"/>
<region id="us-east">
<country>USA</country>
<unitSystemId>us</unitSystemId>
<timeFormatId>t_hhmma</timeFormatId>
<dateFormatId>d_MMddyy</dateFormatId>
<rfidFreq>123.456</rfidFreq>
<telephoneNumber>888-555-1234</telephoneNumber>
</region>
<region id="united-kingdom">
<country>GBR</country>
<unitSystemId>si</unitSystemId>
<timeFormatId>t_HHmm</timeFormatId>
<dateFormatId>d_yyyyMMdd</dateFormatId>
<rfidFreq>888.999</rfidFreq>
<telephoneNumber>866-555-1234</telephoneNumber>
</region>
</regions>
</regionDefs>
The "factory" region is the default used by kOS during start up.
All other regions are defined by the application developers.
Each region has an ID, which is any string used as a unique identifier. Inside each region there are a few built-in properties:
- ISO country code
- ID of unit system (mass, presssue, temperature, volume) to use
- ID of date formatter
- ID of time formatter
rfidFreq
and
telephoneNumber
. Inside each region, you can define any number of custom
fields, which may vary between regions.- Since:
- 1.0
- Version:
- 2023-02-24
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLoader
(ResourceLoader loader) Adds aResourceLoader
used to search for referenced XML files.Returns a map of loaded regions where the key is the ID of the region.void
Loads the specified region file using the installed resource loaders.Returns a new instance ofBaseRegion
.void
parseRegion
(BaseRegion region, Element element) Populates aBaseRegion
object form the XML element.
-
Field Details
-
XML_ID
- See Also:
-
XML_COUNTRY
- See Also:
-
XML_UNIT_SYSTEM_ID
- See Also:
-
XML_TIME_FORMAT_ID
- See Also:
-
XML_DATE_FORMAT_ID
- See Also:
-
XML_TIME_ZONES
- See Also:
-
-
Constructor Details
-
XmlRegionFactory
public XmlRegionFactory()Creates a new XML region factory object.
-
-
Method Details
-
addLoader
Adds 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 are 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
Loads the specified region file using the installed resource loaders.- Parameters:
file
- the file name to load
-
getRegions
Returns a map of loaded regions where the key is the ID of the region. -
newRegion
Returns a new instance ofBaseRegion
. Override this to use a subclass ofBaseRegion
. These instances are passed toparseRegion()
. -
parseRegion
Populates aBaseRegion
object form the XML element. Subclasses can callsuper.parseRegion()
to populate the base class.- Parameters:
region
- the region to populateelement
- the region XML element
-