jDotNotation

Java library to access class attributes via dot notation.

View the Project on GitHub uscexp/jDotNotation

jDotNotation

Introduction

Java library to access class attributes via dot notation.

News

15.Aug.2014: New release v1.1.0 which adds the new map access feature.

Features

Description

With this library one can access values of attributes via a defined path from a root element. To access an attrubute value use the dot notation:

Attention!

Accessing collections e.g. HashSets via index doesn't make alway sense, because the order of the set isn't fix. So if you set a value at index 0 and later you want to access it, it is very probable that you won't find it at index 0 anymore.

Example

...
DotNotationAccessor dotNotationAccessor = new DotNotationAccessor(true, false, false);
RootClass rootClass = new RootClass();
String attributePath = "simpleChildLevel1Class.simpleChildLevel2Class.simpleChildLevel3Class.simpleString";

Object result = dotNotationAccessor.getAttribute(rootClass, attributePath);
...

First it creates an instance of DotNotationAccessor only permitting accessing the attributes via getters and setters. Then it creates RootClass which has a more or less complex class hierarchy. Afterwards the attribute path, from the root class to the final attribute one want to read or set, is defined. Then it is called the getAttribute method in the DotNotationAccessor instance to read the attribute simpleString and save it in the result variable.

Installation

To use the library in your java project just put the binary jar file to your classpath. The maven dependency can be found here: mvnrepository

(C) 2014 by haui