Class ComponentInheritanceValueMap

  • All Implemented Interfaces:
    InheritanceValueMap, java.util.Map<java.lang.String,​java.lang.Object>, ValueMap

    public class ComponentInheritanceValueMap
    extends ValueMapWrapper
    implements InheritanceValueMap
    An InheritanceValueMap for a given Resource that will inherit values from ancestors up to its ancestral component, but no higher.

    For example, given: /content/parent/page/jcr:content/footer/image/@width, the ComponentInheritanceValueMap will search for a width property in:

    • /content/parent/page/jcr:content/footer/image/@width
    • /content/parent/page/jcr:content/footer/@width
    • /content/parent/page/jcr:content/@width
    Having not found it in any of those locations, it will then return null.

    Note that ComponentInheritanceValueMap searches only the component hierarchy. It will not (for instance), look in:

    • /content/parent/jcr:content/footer/image/@width
    See HierarchyNodeInheritanceValueMap for that functionality.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      • Fields inherited from interface org.apache.sling.api.resource.ValueMap

        EMPTY
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T get​(java.lang.String name, java.lang.Class<T> type)
      Get a named property and convert it into the given type.
      <T> T getInherited​(java.lang.String name, java.lang.Class<T> type)
      Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.
      <T> T getInherited​(java.lang.String name, T defaultValue)
      Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, 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
      • Methods inherited from interface org.apache.sling.api.resource.ValueMap

        get
    • Constructor Detail

      • ComponentInheritanceValueMap

        public ComponentInheritanceValueMap​(Resource resource)
        Will wrap the ValueMap returned by resource.adaptTo(ValueMap.class), or use an empty map if resource is null or if it doesn't adapt to a ValueMap. The inheritance is internally resolved by fetching the parent resource and wrapping it into an ComponentInheritanceValueMap as well.
        Parameters:
        resource - the resource to start from
      • ComponentInheritanceValueMap

        public ComponentInheritanceValueMap​(ValueMap map)
        Use this if the underlying Resource for a ValueMap is not available and no inheritance is needed. Using the inheritance-enabled getter methods will behave exactly like the normal ValueMap getters.
        Parameters:
        map - a ValueMap to wrap
    • Method Detail

      • get

        public <T> T get​(java.lang.String name,
                         java.lang.Class<T> type)
        Description copied from interface: ValueMap
        Get a named property and convert it into the given type. This method does not support conversion into a primitive type or an array of a primitive type. It should return null in this case.
        Specified by:
        get in interface ValueMap
        Overrides:
        get in class ValueMapWrapper
        Type Parameters:
        T - The class of the type
        Parameters:
        name - The name of the property
        type - The class of the type
        Returns:
        Return named value converted to type T or null if non existing or can't be converted.
      • getInherited

        public <T> T getInherited​(java.lang.String name,
                                  java.lang.Class<T> type)
        Description copied from interface: InheritanceValueMap
        Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.

        The exact inheritance mechanism depends on the implementation.

        Specified by:
        getInherited in interface InheritanceValueMap
        Type Parameters:
        T - type parameter
        Parameters:
        name - The name of the property
        type - The class of the type
        Returns:
        Return named value converted to type T or null if non existing or can't be converted.
      • getInherited

        public <T> T getInherited​(java.lang.String name,
                                  T defaultValue)
        Description copied from interface: InheritanceValueMap
        Get a named property and convert it into the given type, and take the properties of parent resources / pages into account, if the property is not found locally.

        The exact inheritance mechanism depends on the implementation.

        Specified by:
        getInherited in interface InheritanceValueMap
        Type Parameters:
        T - type parameter
        Parameters:
        name - The name of the property
        defaultValue - The default value to use if the named property does not exist or cannot be converted to the requested type. The default value is also used to define the type to convert the value to. If this is null any existing property is not converted.
        Returns:
        Return named value converted to type T or the default value if non existing or can't be converted.