Package org.apache.sling.api.resource

# Class SyntheticResource

java.lang.Object
org.apache.sling.api.adapter.SlingAdaptable
org.apache.sling.api.resource.AbstractResource
org.apache.sling.api.resource.SyntheticResource

All Implemented Interfaces:
  `Adaptable`, `Resource`

Direct Known Subclasses:
  `NonExistingResource`

public class SyntheticResource extends AbstractResource
The `SyntheticResource` class is a simple implementation of the `Resource` interface which may be used to provide a resource object which has no actual resource data (except for the mandatory property "sling:resourceType").

## Field Summary

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

`RESOURCE_TYPE_NON_EXISTING`

## Constructor Summary

Constructors
Constructor
Description
`SyntheticResource(@NotNull ResourceResolver resourceResolver, @NotNull String path, @NotNull String resourceType)`
Creates a synthetic resource with the given `path` and `resourceType`.
`SyntheticResource(@NotNull ResourceResolver resourceResolver, @NotNull ResourceMetadata rm, @NotNull String resourceType)`
Creates a synthetic resource with the given `ResourceMetadata` and `resourceType`.

## Method Summary

Modifier and Type
Method
Description
`<AdapterType>
AdapterType`
`adaptTo(Class<AdapterType> type)`
Merges the original value map with one containing the single property "sling:resourceType".
`@NotNull String`
`getPath()`
Returns the absolute path of this resource in the resource tree.
`@NotNull ResourceMetadata`
`getResourceMetadata()`
Returns a resource metadata object containing just the path of this resource as the `ResourceMetadata.RESOLUTION_PATH` property.
`@NotNull ResourceResolver`
`getResourceResolver()`
Returns the `ResourceResolver` with which this synthetic resource is related or `null` if none.
`String`
`getResourceSuperType()`
Synthetic resources by default do not have a resource super type.
`@NotNull String`
`getResourceType()`
The resource type is meant to point to rendering/processing scripts, editing dialogs, etc.
`String`
`toString()`

### Methods inherited from class org.apache.sling.api.resource.AbstractResource

`getChild, getChildren, getName, getParent, getValueMap, hasChildren, isResourceType, listChildren`

### Methods inherited from class org.apache.sling.api.adapter.SlingAdaptable

`setAdapterManager, unsetAdapterManager`

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

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

## Constructor Details

### SyntheticResource

public SyntheticResource(@NotNull @NotNull ResourceResolver resourceResolver, @NotNull @NotNull String path, @NotNull @NotNull String resourceType)
Creates a synthetic resource with the given `path` and `resourceType`.

Parameters:
  `resourceResolver` - The resource resolver
  `path` - The absolute resource path including the name. Make sure that each segment of the path only contains valid characters in Sling API resource names.
  `resourceType` - The type of the resource
See Also:
  - `ResourceUtil.escapeName(String)`

### SyntheticResource

public SyntheticResource(@NotNull @NotNull ResourceResolver resourceResolver, @NotNull @NotNull ResourceMetadata rm, @NotNull @NotNull String resourceType)
Creates a synthetic resource with the given `ResourceMetadata` and `resourceType`.

Parameters:
  `resourceResolver` - The resource resolver
  `rm` - The resource meta data
  `resourceType` - The type of the resource

## Method Details

### getPath

@NotNull public @NotNull String getPath()
Description copied from interface: `Resource`
Returns the absolute path of this resource in the resource tree.

Returns:
  The resource path
See Also:
  - `Resource.getPath()`

### getResourceType

@NotNull public @NotNull String getResourceType()
Description copied from interface: `Resource`
The resource type is meant to point to rendering/processing scripts, editing dialogs, etc. It is usually a path in the repository, where scripts and other tools definitions are found, but the `ResourceResolver` is free to set this to any suitable value such as the primary node type of the JCR node from which the resource is created.

If the resource instance represents a resource which is not actually existing, this method returns `Resource.RESOURCE_TYPE_NON_EXISTING`.

Returns:
  The resource type
See Also:
  - `Resource.getResourceType()`

### getResourceSuperType

public String getResourceSuperType()
Synthetic resources by default do not have a resource super type.

Returns:
  The super type of the resource or `null`.

### getResourceMetadata

@NotNull public @NotNull ResourceMetadata getResourceMetadata()
Returns a resource metadata object containing just the path of this resource as the `ResourceMetadata.RESOLUTION_PATH` property.

Returns:
  The resource meta data
See Also:
  - `ResourceMetadata`

### getResourceResolver

@NotNull public @NotNull ResourceResolver getResourceResolver()
Returns the `ResourceResolver` with which this synthetic resource is related or `null` if none.

Returns:
  The resource resolver

### adaptTo

public <AdapterType> AdapterType adaptTo(Class<AdapterType> type)
Merges the original value map with one containing the single property "sling:resourceType".

Specified by:
  `adaptTo` in interface `Adaptable`
Overrides:
  `adaptTo` in class `SlingAdaptable`
Type Parameters:
  `AdapterType` - The generic type to which this resource 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 resource cannot adapt to the requested type

### toString

public String toString()

Overrides:
  `toString` in class `Object`