Package com.day.cq.commons.inherit
Class ComponentInheritanceValueMap
java.lang.Object
com.day.cq.commons.ValueMapWrapper
com.day.cq.commons.inherit.ComponentInheritanceValueMap
- All Implemented Interfaces:
InheritanceValueMap,Map<String,,Object> ValueMap
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
null.
Note that ComponentInheritanceValueMap searches only the component
hierarchy. It will not (for instance), look in:
/content/parent/jcr:content/footer/image/@width
HierarchyNodeInheritanceValueMap for that
functionality.-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionComponentInheritanceValueMap(Resource resource) Will wrap theValueMapreturned byresource.adaptTo(ValueMap.class), or use an empty map ifresourceis null or if it doesn't adapt to a ValueMap. -
Method Summary
Modifier and TypeMethodDescription<T> TGet a named property and convert it into the given type.<T> TgetInherited(String name, 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> TgetInherited(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 com.day.cq.commons.ValueMapWrapper
clear, containsKey, containsValue, entrySet, get, get, isEmpty, keySet, put, putAll, remove, size, toString, valuesMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
-
Constructor Details
-
ComponentInheritanceValueMap
Will wrap theValueMapreturned byresource.adaptTo(ValueMap.class), or use an empty map ifresourceis null or if it doesn't adapt to a ValueMap. The inheritance is internally resolved by fetching the parent resource and wrapping it into anComponentInheritanceValueMapas well.- Parameters:
resource- the resource to start from
-
ComponentInheritanceValueMap
Use this if the underlyingResourcefor aValueMapis not available and no inheritance is needed. Using the inheritance-enabledgettermethodswill behave exactly like the normal ValueMap getters.- Parameters:
map- a ValueMap to wrap
-
-
Method Details
-
get
Description copied from interface:ValueMapGet 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 returnnullin this case.- Specified by:
getin interfaceValueMap- Overrides:
getin classValueMapWrapper- Type Parameters:
T- The class of the type- Parameters:
name- The name of the propertytype- The class of the type- Returns:
- Return named value converted to type T or
nullif non existing or can't be converted.
-
getInherited
Description copied from interface:InheritanceValueMapGet 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:
getInheritedin interfaceInheritanceValueMap- Type Parameters:
T- type parameter- Parameters:
name- The name of the propertytype- The class of the type- Returns:
- Return named value converted to type T or
nullif non existing or can't be converted.
-
getInherited
Description copied from interface:InheritanceValueMapGet 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:
getInheritedin interfaceInheritanceValueMap- Type Parameters:
T- type parameter- Parameters:
name- The name of the propertydefaultValue- 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 isnullany 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.
-