Package com.composum.sling.core
Class InheritedValues
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,Object>
-
- com.composum.sling.core.InheritedValues
-
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,Object>,org.apache.sling.api.resource.ValueMap
public class InheritedValues extends HashMap<String,Object> implements org.apache.sling.api.resource.ValueMap
The value map which extends the property retrieval to the context (parents,...) of a resource.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInheritedValues.HierarchyScanResultstatic classInheritedValues.Typethe various types of inheritance contentRelated Each node at the same position relative to the 'jcr:content' nodes is checked for an inherited value.-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.sling.api.resource.ResourceentryPointprotected org.apache.sling.api.resource.ResourceexitPointprotected InheritedValues.TypeinheritanceTypeprotected StringrelativePathprotected org.apache.sling.api.resource.Resourceresourcestatic ObjectUNDEFINED
-
Constructor Summary
Constructors Constructor Description InheritedValues(org.apache.sling.api.resource.Resource resource)InheritedValues(org.apache.sling.api.resource.Resource resource, boolean nodeInheritance)Deprecated.InheritedValues(org.apache.sling.api.resource.Resource resource, boolean nodeInheritance, boolean restrictToSameContent)Deprecated.InheritedValues(org.apache.sling.api.resource.Resource resource, InheritedValues.Type inheritanceType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfindEntryPoint()Retrieves the first parent node for inheritance traversal (that is, the node above jcr:content) and defines the relativePath of the property wrt.protected <T> TfindInherited(String name, Class<T> type)InheritedValues.HierarchyScanResultfindOriginAndValue(String name, Class<?> type)Searches the value along the repositories hierarchy by the entry point and path determined before.<T> Tget(@NotNull String name, @NotNull Class<T> type)Gets an inherited value.<T> Tget(@NotNull String name, T defaultValue)Gets an inherited value.protected StringgetRelativePath(String name)-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
-
-
-
Field Detail
-
UNDEFINED
public static final Object UNDEFINED
-
resource
protected final org.apache.sling.api.resource.Resource resource
-
inheritanceType
protected final InheritedValues.Type inheritanceType
-
exitPoint
protected transient org.apache.sling.api.resource.Resource exitPoint
-
entryPoint
protected transient org.apache.sling.api.resource.Resource entryPoint
-
relativePath
protected transient String relativePath
-
-
Constructor Detail
-
InheritedValues
public InheritedValues(org.apache.sling.api.resource.Resource resource)
-
InheritedValues
public InheritedValues(org.apache.sling.api.resource.Resource resource, InheritedValues.Type inheritanceType)
-
InheritedValues
@Deprecated public InheritedValues(org.apache.sling.api.resource.Resource resource, boolean nodeInheritance)
Deprecated.
-
InheritedValues
@Deprecated public InheritedValues(org.apache.sling.api.resource.Resource resource, boolean nodeInheritance, boolean restrictToSameContent)
Deprecated.
-
-
Method Detail
-
get
@Nullable public <T> T get(@NotNull @NotNull String name, @NotNull @NotNull Class<T> type)Gets an inherited value.- Specified by:
getin interfaceorg.apache.sling.api.resource.ValueMap- Type Parameters:
T- the expected type of the value- Parameters:
name- the property name or path- Returns:
- inherited value if existing or
null
-
get
@NotNull public <T> T get(@NotNull @NotNull String name, @NotNull T defaultValue)Gets an inherited value.- Specified by:
getin interfaceorg.apache.sling.api.resource.ValueMap- Type Parameters:
T- the expected type of the value- Parameters:
name- the property name or pathdefaultValue- the default value, must not benull- Returns:
- inherited value if existing, otherwise the default value
-
findOriginAndValue
public InheritedValues.HierarchyScanResult findOriginAndValue(String name, Class<?> type)
Searches the value along the repositories hierarchy by the entry point and path determined before.- Parameters:
name- the property name or pathtype- the expected type of the value- Returns:
- the value found or
nullif no such value found in one of the appropriate parent nodes
-
findEntryPoint
protected void findEntryPoint()
Retrieves the first parent node for inheritance traversal (that is, the node above jcr:content) and defines the relativePath of the property wrt. this node.
-
-