org.apache.sling.api.resource
Class SyntheticResource

java.lang.Object
  extended by org.apache.sling.api.resource.SyntheticResource
All Implemented Interfaces:
Adaptable, Resource
Direct Known Subclasses:
NonExistingResource

public class SyntheticResource
extends java.lang.Object
implements Resource

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.


Field Summary
 
Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING
 
Constructor Summary
SyntheticResource(ResourceResolver resourceResolver, ResourceMetadata rm, java.lang.String resourceType)
          Creates a synthetic resource with the given ResourceMetadata and resourceType.
SyntheticResource(ResourceResolver resourceResolver, java.lang.String path, java.lang.String resourceType)
          Creates a synthetic resource with the given path and resourceType.
 
Method Summary
<Type> Type
adaptTo(java.lang.Class<Type> type)
          If a adapter manager has been set through setAdapterManager(AdapterManager) this adapter manager is used to adapt the resource to the given class.
 java.lang.String getPath()
          This resource's path - for now that could be a JCR path.
 ResourceMetadata getResourceMetadata()
          Returns a resource metadata object containing just the path of this resource as the ResourceMetadata.RESOLUTION_PATH property.
 ResourceResolver getResourceResolver()
          Returns the ResourceResolver with which this synthetic resource is related or null if none.
 java.lang.String getResourceSuperType()
          Synthetic resources by default do not have a resource super type.
 java.lang.String getResourceType()
          The resource type is meant to point to rendering/processing scripts, editing dialogs, etc.
static void setAdapterManager(AdapterManager adapterMgr)
          Set the adapter manager to be used by a synthetic resource.
protected  void setResourceType(java.lang.String resourceType)
          Deprecated. The resource type should be set through the constructor.
 java.lang.String toString()
           
static void unsetAdapterManager(AdapterManager adapterMgr)
          Unset an adapter manager previously set with setAdapterManager(AdapterManager)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SyntheticResource

public SyntheticResource(ResourceResolver resourceResolver,
                         java.lang.String path,
                         java.lang.String resourceType)
Creates a synthetic resource with the given path and resourceType.


SyntheticResource

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

Method Detail

setAdapterManager

public static void setAdapterManager(AdapterManager adapterMgr)
Set the adapter manager to be used by a synthetic resource. A bundle implementing the adapter manager can set the manager through this method. The set adapter manager will be used in the adaptTo(Class) method of a synthetic resource.

Parameters:
adapterMgr - The adapter manager.

unsetAdapterManager

public static void unsetAdapterManager(AdapterManager adapterMgr)
Unset an adapter manager previously set with setAdapterManager(AdapterManager)

Parameters:
adapterMgr - The adapter manager

getPath

public java.lang.String getPath()
Description copied from interface: Resource
This resource's path - for now that could be a JCR path. It's also possible to have an URI for other data sources.

Specified by:
getPath in interface Resource
See Also:
Resource.getPath()

getResourceType

public java.lang.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 the Resource.RESOURCE_TYPE_NON_EXISTING.

Specified by:
getResourceType in interface Resource
See Also:
Resource.getResourceType()

setResourceType

@Deprecated
protected void setResourceType(java.lang.String resourceType)
Deprecated. The resource type should be set through the constructor.

Helper method for sub classes to set the resource type

Parameters:
resourceType - The resource type

getResourceSuperType

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

Specified by:
getResourceSuperType in interface Resource

getResourceMetadata

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

Specified by:
getResourceMetadata in interface Resource
See Also:
ResourceMetadata

getResourceResolver

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

Specified by:
getResourceResolver in interface Resource

adaptTo

public <Type> Type adaptTo(java.lang.Class<Type> type)
If a adapter manager has been set through setAdapterManager(AdapterManager) this adapter manager is used to adapt the resource to the given class. Otherwise this method returns null.

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2007-2009 The Apache Software Foundation. All Rights Reserved.