Package org.apache.sling.api.resource

# Class ResourceWrapper

java.lang.Object
org.apache.sling.api.resource.ResourceWrapper

All Implemented Interfaces:
  `Adaptable`, `Resource`

public class ResourceWrapper extends Object implements Resource
The `ResourceWrapper` is a wrapper for any `Resource` delegating all method calls to the wrapped resource by default. Extensions of this class may overwrite any method to return different values as appropriate.

## Field Summary

### Fields inherited from interface org.apache.sling.api.resource.Resource

`RESOURCE_TYPE_NON_EXISTING`

## Constructor Summary

Constructors
Constructor
Description
`ResourceWrapper(@NotNull Resource resource)`
Creates a new wrapper instance delegating all method calls to the given `resource`.

## Method Summary

Modifier and Type
Method
Description
`<AdapterType>
AdapterType`
`adaptTo(@NotNull Class<AdapterType> type)`
Returns the value of calling `adaptTo` on the `wrapped resource`.
`Resource`
`getChild(@NotNull String relPath)`
Returns the value of calling `getChild` on the `wrapped resource`.
`@NotNull Iterable<Resource>`
`getChildren()`
Returns an iterable of the direct children of this resource.
`@NotNull String`
`getName()`
Returns the value of calling `getName` on the `wrapped resource`.
`Resource`
`getParent()`
Returns the value of calling `getParent` on the `wrapped resource`.
`@NotNull String`
`getPath()`
Returns the value of calling `getPath` on the `wrapped resource`.
`@NotNull Resource`
`getResource()`
Returns the `Resource` wrapped by this instance.
`@NotNull ResourceMetadata`
`getResourceMetadata()`
Returns the value of calling `getResourceMetadata` on the `wrapped resource`.
`@NotNull ResourceResolver`
`getResourceResolver()`
Returns the value of calling `getResourceResolver` on the `wrapped resource`.
`String`
`getResourceSuperType()`
Returns the value of calling `getResourceSuperType` on the `wrapped resource`.
`@NotNull String`
`getResourceType()`
Returns the value of calling `getResourceType` on the `wrapped resource`.
`@NotNull ValueMap`
`getValueMap()`
Returns a value map for this resource.
`boolean`
`hasChildren()`
Returns the value of calling `hasChildren` on the `wrapped resource`.
`boolean`
`isResourceType(String resourceType)`
Returns the value of calling `isResourceType` on the `wrapped resource`.
`@NotNull Iterator<Resource>`
`listChildren()`
Returns the value of calling `listChildren` on the `wrapped resource`.
`String`
`toString()`
Returns a string representation of this wrapper consisting of the class' simple name, the `resource type` and `path` as well as the string representation of the `wrapped resource`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### ResourceWrapper

public ResourceWrapper(@NotNull @NotNull Resource resource)
Creates a new wrapper instance delegating all method calls to the given `resource`.

Parameters:
  `resource` - The resource to wrap

## Method Details

### getResource

@NotNull public @NotNull Resource getResource()
Returns the `Resource` wrapped by this instance. This method can be overwritten by subclasses if required. All methods implemented by this class use this method to get the resource object.

Returns:
  The resource wrapped by this instance.

### getPath

@NotNull public @NotNull String getPath()
Returns the value of calling `getPath` on the `wrapped resource`.

Specified by:
  `getPath` in interface `Resource`
Returns:
  The resource path

### getName

@NotNull public @NotNull String getName()
Returns the value of calling `getName` on the `wrapped resource`.

Specified by:
  `getName` in interface `Resource`
Returns:
  The resource name
Since:
  2.1.0 (Sling API Bundle 2.1.0)

### getParent

public Resource getParent()
Returns the value of calling `getParent` on the `wrapped resource`.

Specified by:
  `getParent` in interface `Resource`
Returns:
  The parent resource or `null`.
Since:
  2.1.0 (Sling API Bundle 2.1.0)
See Also:
  - `ResourceResolver.getParent(Resource)`

### getChild

public Resource getChild(@NotNull @NotNull String relPath)
Returns the value of calling `getChild` on the `wrapped resource`.

Specified by:
  `getChild` in interface `Resource`
Parameters:
  `relPath` - relative path to the child resource
Returns:
  The child resource or `null`
Since:
  2.1.0 (Sling API Bundle 2.1.0)
See Also:
  - `ResourceResolver.getResource(Resource, String)`

### listChildren

@NotNull public @NotNull Iterator<Resource> listChildren()
Returns the value of calling `listChildren` on the `wrapped resource`.

Specified by:
  `listChildren` in interface `Resource`
Returns:
  An iterator for child resources.
Since:
  2.1.0 (Sling API Bundle 2.1.0)
See Also:
  - `ResourceResolver.listChildren(Resource)`

### getChildren

@NotNull public @NotNull Iterable<Resource> getChildren()
Description copied from interface: `Resource`
Returns an iterable of the direct children of this resource.

This method is a convenience and returns exactly the same resources as calling `getResourceResolver().getChildren(resource)`.

Specified by:
  `getChildren` in interface `Resource`
Returns:
  An iterable for child resources
See Also:
  - `Resource.getChildren()`

### getResourceMetadata

@NotNull public @NotNull ResourceMetadata getResourceMetadata()
Returns the value of calling `getResourceMetadata` on the `wrapped resource`.

Specified by:
  `getResourceMetadata` in interface `Resource`
Returns:
  The resource meta data
See Also:
  - `ResourceMetadata`

### getResourceResolver

@NotNull public @NotNull ResourceResolver getResourceResolver()
Returns the value of calling `getResourceResolver` on the `wrapped resource`.

Specified by:
  `getResourceResolver` in interface `Resource`
Returns:
  The resource resolver

### getResourceType

@NotNull public @NotNull String getResourceType()
Returns the value of calling `getResourceType` on the `wrapped resource`.

Specified by:
  `getResourceType` in interface `Resource`
Returns:
  The resource type

### getResourceSuperType

public String getResourceSuperType()
Returns the value of calling `getResourceSuperType` on the `wrapped resource`.

Specified by:
  `getResourceSuperType` in interface `Resource`
Returns:
  The super type of the resource or `null`.

### hasChildren

public boolean hasChildren()
Returns the value of calling `hasChildren` on the `wrapped resource`.

Specified by:
  `hasChildren` in interface `Resource`
Returns:
  `true` if the resource has any child resources
Since:
  2.4.4 (Sling API Bundle 2.5.0)

### isResourceType

public boolean isResourceType(String resourceType)
Returns the value of calling `isResourceType` on the `wrapped resource`.

Specified by:
  `isResourceType` in interface `Resource`
Parameters:
  `resourceType` - the resource type to check this resource against
Returns:
  `true` if the resource type or any of the resource's super type(s) equals the given resource type, `false` otherwise; `false` can also be returned if `resourceType` is null
Since:
  2.1.0 (Sling API Bundle 2.1.0)
See Also:
  - `ResourceResolver.isResourceType(Resource, String)`

### adaptTo

public <AdapterType> AdapterType adaptTo(@NotNull @NotNull Class<AdapterType> type)
Returns the value of calling `adaptTo` on the `wrapped resource`.

Specified by:
  `adaptTo` in interface `Adaptable`
Type Parameters:
  `AdapterType` - The generic type to which this object is adapted to
Parameters:
  `type` - The Class object of the target type, such as `javax.jcr.Node.class` or `java.io.File.class`
Returns:
  The adapter target or `null` if the object cannot adapt to the requested type

### getValueMap

@NotNull public @NotNull ValueMap getValueMap()
Description copied from interface: `Resource`
Returns a value map for this resource. The value map allows to read the properties of the resource. Each map is containing at least the mandatory property "sling:resourceType".

Specified by:
  `getValueMap` in interface `Resource`
Returns:
  A value map
See Also:
  - `Resource.getValueMap()`

### toString

public String toString()
Returns a string representation of this wrapper consisting of the class' simple name, the `resource type` and `path` as well as the string representation of the `wrapped resource`.

Overrides:
  `toString` in class `Object`