Class XmlRegionFactory

java.lang.Object
com.tccc.kos.core.service.region.XmlRegionFactory

public class XmlRegionFactory extends Object
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
In our example, we have included two custom fields: 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 Details

  • Constructor Details

    • XmlRegionFactory

      public XmlRegionFactory()
      Creates a new XML region factory object.
  • Method Details

    • addLoader

      public void addLoader(ResourceLoader loader)
      Adds 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 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

      public void load(String file)
      Loads the specified region file using the installed resource loaders.
      Parameters:
      file - the file name to load
    • getRegions

      public Collection<BaseRegion> getRegions()
      Returns a map of loaded regions where the key is the ID of the region.
    • newRegion

      public BaseRegion newRegion()
      Returns a new instance of BaseRegion . Override this to use a subclass of BaseRegion . These instances are passed to parseRegion() .
    • parseRegion

      public void parseRegion(BaseRegion region, Element element)
      Populates a BaseRegion object form the XML element. Subclasses can call super.parseRegion() to populate the base class.
      Parameters:
      region - the region to populate
      element - the region XML element