HierarchicalMap Tutorial - Intermediate Level
HierarchicalMap is an interface. So anyone can implement it. This tutorial is based on BasicHierarchicalmap, a reference implementation of HierarchicalMap.
Following subjects are covered in this tutorial:
Intermediate Level10. Accessing Preferences
The org.dhmp.io.MapPreferences is a very simple class which can interact with java.util.prefs.Preferences. It has the following methods:
Basically, the class can transfer the content of a HierarchicalMap into Preferences and vice versa.
Unfortunately, due to the Preferences restriction, only String values are supported. Actually Preferences can accept other types like Boolean, Integer etc. However using Preferences api, there is no indication about which type of data are stored, on the other hand, appropriate method must be used to retrieve them. So, MapPreferences store HierarchicalMap values converting them to String. Therefore most of Objects can not be stored, unless split them into their attributes and save them individually, or convert them into Base64. The org.dhmp.util.xml.Schema's replace() method can be used to simplify conversion between String and other type of Objects like Boolean, Integer etc.
Check below how to use this class.
Note that although comparison returned true, the data held by each of HierarchicalMap are totally different. The node "test/integer1" is Integer on original map and it is String on retrieved map.
Continue to Advanced Level - Template Filling