Class LazyBindings

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
org.apache.sling.api.scripting.LazyBindings
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>, Bindings
Direct Known Subclasses:
ProtectedBindings, SlingBindings

@ConsumerType public class LazyBindings extends HashMap<String,Object> implements Bindings

The LazyBindings wraps another map and dynamically provides entries for the wrapped map through a map of LazyBindings.Suppliers.

When get(Object) is called with a key that's not present in the wrapped map, then the LazyBindings.Suppliers map will be queried and, if an entry exists for that key, the LazyBindings.Supplier-generated value will be used to populate the wrapped map.

While the keySet() and containsKey(Object) will also check the keys present in the LazyBindings.Suppliers map, all other methods (e.g. values(), HashMap.containsValue(Object)) will only deal with the contents of the wrapped map.

entrySet() will however return a merged view of both the LazyBindings.Suppliers and the wrapped map, so that copies to other LazyBindings maps preserve the functionality of having lazily-evaluated bindings.

This class does not provide any thread-safety guarantees. If this Bindings map needs to be used in a concurrent setup it's the responsibility of the caller to synchronize access. The simplest way would be to wrap it through Collections.synchronizedMap(Map).

See Also: