Java Implementation and Usage
This part is about the usage of Elastic Objects in a native java application.
EO.java
Like a Java 8 Optional it contains an object. But it knows
- the EO wrapper of the parent object,
- all EO wrappers for the child objects by fieldName and
- its type rules(Model configuration).
The following classes are provided for this.
The following examples are in the test class
EoHtmlTest.java
Create a new root
The
EoRoot.java
This cache will be usually initialized one time as static or as a (injected) singelton.
It could be also initialized with an object.
A JSON string will automatically resolved to a map or list object.
A typed JSON string will automatically mapped to the object.
Configuration Cache
Instantiating an EoRoot object use always the configration cache object. This objects loads every file named
- ≡ModelConfig.json
- ≡FieldConfig.json
- ≡FileConfig.json
- ≡HostConfig.json
Model Configuration
To hide the differences between different tree type objects model configurations are loaded and provided in a cache object.
The model configurations build the base for all object access in EO.
The cache object
EOConfigsCache.java
Set Values
With the set method one could add childs also via a path pattern
The return value of set method is the child on path "a/b/c". The last test will get the map from the root and then navigate through the map tree.
Path as Array
One can also set the path in an array in java context, which simplify usage there.
With a leading "/" the path will interpreted starting with the root similar than in a file system.
Setting Objects
One can also set an object to an arbitrary path, where the complete object tree will be mapped.
Typed Path
One can also set AnObject via path directive.
Get EO
One could navigate through the object hierarchy in several ways with the getEo method.
Back Navigation
Similar to a file system command there is also a back navigation with "..".
Get Values
A short form for getting the value instead of the combination getEo(<path>).get() is get(<path>).
Call Types
A special
- ≡sourcePath for the location of the input
- ≡targetPath for storing the output
- ≡condition
Other Examples
- Compare: An example to compare an object and a map for equal values.
- Transform: An example to transform an object to a map.
- Merge: An example to merge map values into an object.
Usage as a tool
With about 270 KByte Elastic Objects is rather small. So it could be integrated as a tool in java applications where it's appropriated. Other tool libraries like guava have more than 2MByte.