Class 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
    • Field Detail

      • UNDEFINED

        public static final Object UNDEFINED
      • resource

        protected final org.apache.sling.api.resource.Resource resource
      • 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:
        get in interface org.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:
        get in interface org.apache.sling.api.resource.ValueMap
        Type Parameters:
        T - the expected type of the value
        Parameters:
        name - the property name or path
        defaultValue - the default value, must not be null
        Returns:
        inherited value if existing, otherwise the default value
      • findInherited

        protected <T> T findInherited​(String name,
                                      Class<T> type)
      • 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 path
        type - the expected type of the value
        Returns:
        the value found or null if no such value found in one of the appropriate parent nodes
      • getRelativePath

        protected String getRelativePath​(String name)
      • 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.