public abstract class AbstractResource extends Object implements Resource
Resource
representation.Constructor and Description |
---|
AbstractResource(Resource parent,
String resourceType,
String name)
Constructs resource representation by using parent resoruce representation, resource type name and resource name.
|
AbstractResource(String resourceType)
Construct resource representation by using resource type name.
|
AbstractResource(String resourceType,
String name)
Constructs resource representation by using resource type name and resource name.
|
Modifier and Type | Method and Description |
---|---|
protected static <T> T |
convertValueOfBasicType(Object value,
Class<T> expectedType)
Convert the
value of a basic type to one of the expectedType . |
long |
getChildCount()
Returns child resource count of this resource representation.
|
ResourceCollection |
getChildren()
Return a
ResourceCollection of child resource representations. |
Object |
getDefaultValue()
Resolves the default property value of this resource if available, or null if unavailable.
|
<T> T |
getDefaultValue(Class<T> type)
Resolves the default property value of this resource if available and converts it into the given type, or
null if unavailable.
|
String |
getName()
Returns the name of this resource representation if there's any.
|
Object |
getNodeData()
Return the underlying, internal node data that this
Resource represents. |
Resource |
getParent()
Returns parent resource representation if there's any.
|
String |
getPath()
Returns the path of this resource representation if there's any.
|
String |
getResourceType()
Returns the resource type name of this resource representation if there's any.
|
Object |
getValue(String relPath)
Resolves a property value of this resource by the given
relPath . |
<T> T |
getValue(String relPath,
Class<T> type)
Resolves a property value of this resource by the given
relPath and converts it into the given type. |
boolean |
isAnyChildContained()
Returns true if this resource representation contains any child resource representation.
|
boolean |
isArray()
Returns true if this resource representation is purely for an array (e.g, JSON Array if underlying data is based on JSON).
|
boolean |
isResourceType(String resourceType)
Returns true if this resource representation is typed and of the specific
resourceType name. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dump, getChildren, getMetadata, getValueMap
public AbstractResource(String resourceType)
resourceType
- resource type namepublic AbstractResource(String resourceType, String name)
resourceType
- resource type namename
- resource namepublic AbstractResource(Resource parent, String resourceType, String name)
parent
- parent resource representationresourceType
- resource type namename
- resource nameprotected static <T> T convertValueOfBasicType(Object value, Class<T> expectedType)
value
of a basic type to one of the expectedType
.value
- the input value of a basic typeexpectedType
- the expected type to convert toexpectedType
public String getResourceType()
javax.jcr.Node#getPrimaryNodeType().getName()
.getResourceType
in interface Resource
public boolean isResourceType(String resourceType)
resourceType
name.isResourceType
in interface Resource
resourceType
- resource type nameresourceType
namepublic String getName()
javax.jcr.Item#getName()
.public String getPath()
javax.jcr.Item#getPath()
.public Resource getParent()
public boolean isAnyChildContained()
isAnyChildContained
in interface Resource
public boolean isArray()
public long getChildCount()
getChildCount
in interface Resource
public ResourceCollection getChildren()
ResourceCollection
of child resource representations.getChildren
in interface Resource
ResourceCollection
of child resource representationspublic Object getValue(String relPath)
relPath
. Or null if not resolved by the relPath
.
If relPath
is a relative value path, like "content/title"
, then the return should
be equivalent to the result of the call, ((Resource) getValueMap().get("content")).getValueMap().get("title")
if existing.
In addition, a path segment may contain an array index notation like "content/images[1]/title"
.
In this case, the value at content/images
must be an array type Resource
object which
returns true on Resource.isArray()
.
public <T> T getValue(String relPath, Class<T> type)
relPath
and converts it into the given type.
Or null if not resolved by the relPath
.
If relPath
is a relative value path, like "content/title"
, then the return should
be equivalent to the result of the call, ((Resource) getValueMap().get("content")).getValueMap().get("title")
if existing.
In addition, a path segment may contain an array index notation like "content/images[1]/title"
.
In this case, the value at content/images
must be an array type Resource
object which
returns true on Resource.isArray()
.
public Object getDefaultValue()
This default implementation is equivalent to getValueMap().get("")
if not overriden.
getDefaultValue
in interface Resource
public <T> T getDefaultValue(Class<T> type)
This default implementation is equivalent to getValueMap().get("", type)
if not overriden.
getDefaultValue
in interface Resource
public Object getNodeData()
Resource
Resource
represents.
WARNING: This method is for experts only who understands the risk of accessing the underlying internal, node data, and who is willing to change and upgrade their applications if the type of the underlying, internal data changes at any time in the future. The return object and its type of the underlying, internal data is not guaranteed in the future versions because this method is really implementation specific.
NOTE: The return of this method is really implementation specific. If a underlying ResourceResolver
maintains a Jackson node object for a Resource
object, then it might support this method by
returning the Jackson node or just return null
when it doesn't support this method.
getNodeData
in interface Resource
ResourceResolver
or null
otherwise.Copyright © 2017–2020 Hippo B.V. (http://www.onehippo.com). All rights reserved.