org.wso2.carbon.registry.core.jdbc.handlers
Class Handler

java.lang.Object
  extended by org.wso2.carbon.registry.core.jdbc.handlers.Handler
Direct Known Subclasses:
CachingHandler, CommentCollectionURLHandler, CommentURLHandler, MountHandler, OperationStatisticsHandler, RatingCollectionURLHandler, RatingURLHandler, RegexBaseRestrictionHandler, SimulationHandler, SQLQueryHandler, SymLinkHandler, TagCollectionURLHandler, TagURLHandler, UIEnabledHandler

public abstract class Handler
extends Object

Base class of all handler implementations. Provides the methods that handlers should implement. This class also provides the data source, user realm, registry and repository instances to be used by handler implementations.

Handlers can be chained by providing necessary filter combinations. But in such cases, handler authors should make sure that handlers in the chain do not perform conflicting operations. Unless there is a critical requirement and handler authors are confident that handlers do not have negative impact on each other, it is recommended that handlers are configured to execute only one handler per request.

Handler instances may be accessed concurrently by multiple threads. Therefore, handlers should be thread safe. It is recommended that handlers are made stateless, instead of synchronizing them as it could become a performance bottleneck in highly concurrent environments.

Implementations of handlers should be optimized to take the minimum time for processing. As the handlers are executed are always executed before executing the generic database layer code, time consuming operations in handlers could slow down the whole registry.


Constructor Summary
Handler()
           
 
Method Summary
 void addAssociation(RequestContext requestContext)
          Gets called when an Association is added.
 String addComment(RequestContext requestContext)
          Gets called when adding a comment.
 void applyTag(RequestContext requestContext)
          Gets called when a tag is applied.
 String copy(RequestContext requestContext)
          Copy a resource in the registry.
 void createLink(RequestContext requestContext)
          Create a symbolic link or mount a registry.
 void createVersion(RequestContext requestContext)
          Gets called when creating a version.
 void delete(RequestContext requestContext)
          Processes the DELETE action of the media type.
 void dump(RequestContext requestContext)
          Gets called when dumping an path
 void editComment(RequestContext requestContext)
          Gets called when editing a comment.
 boolean equals(Object obj)
          Revised implementation of the equals comparison to suite the modified hashCode method.
 Collection executeQuery(RequestContext requestContext)
          Gets called when executing Queries.
 Resource get(RequestContext requestContext)
          Processes the GET action for resource path of the requestContext.
 Association[] getAllAssociations(RequestContext requestContext)
          Gets called when getting all Associations.
 Association[] getAssociations(RequestContext requestContext)
          Gets called when getting Associations of given type.
 float getAverageRating(RequestContext requestContext)
          Gets called when getting average rating.
 Comment[] getComments(RequestContext requestContext)
          Gets called when retrieving comments.
 int getRating(RequestContext requestContext)
          Gets called when getting a rating given by a specific user.
 RegistryContext getRegistryContext(RequestContext requestContext)
          Gets called when obtaining the registry context.
 TaggedResourcePath[] getResourcePathsWithTag(RequestContext requestContext)
          Gets called when getting the resource paths corresponding to the given tag.
 Tag[] getTags(RequestContext requestContext)
          Gets called when getting tags.
 String[] getVersions(RequestContext requestContext)
          Gets called when getting versions.
 int hashCode()
          This overrides the default hash code implementation for handler objects, to make sure that each handler of the same type will have identical hash codes unless otherwise it has its own extension.
 void importChild(RequestContext requestContext)
          Invokes when a child resource is imported.
 void importResource(RequestContext requestContext)
          Creates a resource in the given path by fetching the resource content from the given URL.
 void invokeAspect(RequestContext requestContext)
          Gets called when an Associated Aspect gets invoked.
 String move(RequestContext requestContext)
          Move a resource in the registry.
 void put(RequestContext requestContext)
          Processes the PUT action.
 void putChild(RequestContext requestContext)
          Invokes when a child resource is added.
 void rateResource(RequestContext requestContext)
          Gets called when rating a resource.
 void removeAssociation(RequestContext requestContext)
          Gets called when an Association is removed.
 void removeComment(RequestContext requestContext)
          Gets called when removing a comment.
 void removeLink(RequestContext requestContext)
          Remove a symbolic link or un-mount a registry.
 void removeTag(RequestContext requestContext)
          Gets called when a tag is removed.
 String rename(RequestContext requestContext)
          Rename a resource in the registry.
 boolean resourceExists(RequestContext requestContext)
          Gets called when searching for existence of resource.
 void restore(RequestContext requestContext)
          Gets called when restoring a path
 void restoreVersion(RequestContext requestContext)
          Gets called when restoring a version.
 Collection searchContent(RequestContext requestContext)
          Gets called when searching for content.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Handler

public Handler()
Method Detail

get

public Resource get(RequestContext requestContext)
             throws RegistryException
Processes the GET action for resource path of the requestContext.

Parameters:
requestContext - Information about the current request.

requestContext.resourcePath: Path of the resource

requestContext.resource: Resource at the given path. This can be null if no other handler has retrieved that resource so far. If it contains a value, matching handlers are free to do any change to the resource, even they can replace the resource with completely new instance.

Returns:
Resource instance if the handler processed the GET action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the get on the media type and if the get fails due a handler specific error

put

public void put(RequestContext requestContext)
         throws RegistryException
Processes the PUT action. Actual path to which the resource is put may differ from the path given in the requestContext.resourcePath. Therefore, after putting the resource, the actual path to which the resource is put is set in the requestContext.actualPath.

Parameters:
requestContext - Information about the current request.

requestContext.resourcePath: Path to put the resource. requestContext.resource: Resource to put

Throws:
RegistryException - If the media type handler is supposed to handle the put on the media type and if the put fails due a handler specific error

importResource

public void importResource(RequestContext requestContext)
                    throws RegistryException
Creates a resource in the given path by fetching the resource content from the given URL.

Parameters:
requestContext - Information about the current request.

requestContext.resourcePath: Path to add the new resource.

requestContext.sourceURL: URL to fetch the resource content

requestContext.resource: Resource instance containing the meta data for the resource to be imported. Once import is done, new resource is created combining the meta data of this meta data object and the imported content.

Throws:
RegistryException - If the media type handler is supposed to handle the import on the media type and if the import fails due a handler specific error

move

public String move(RequestContext requestContext)
            throws RegistryException
Move a resource in the registry. This is equivalent to 1) delete the resource, then 2) add the resource to the new location. The operation is atomic, so if it fails the old resource will still be there.

Parameters:
requestContext - Information about the current request.

requestContext.sourcePath: Source/Current Path

requestContext.targetPath: Destination/New Path

Returns:
the actual path for the new resource if the handler processed the MOVE action successfully.
Throws:
RegistryException - if something went wrong

copy

public String copy(RequestContext requestContext)
            throws RegistryException
Copy a resource in the registry. This is equivalent to adding the resource to the new location. The operation is atomic, so if it fails the resource won't be added.

Parameters:
requestContext - Information about the current request.

requestContext.sourcePath: Source/Current Path

requestContext.targetPath: Destination/New Path

Returns:
the actual path for the new resource if the handler processed the COPY action successfully.
Throws:
RegistryException - if something went wrong

rename

public String rename(RequestContext requestContext)
              throws RegistryException
Rename a resource in the registry. This is equivalent to 1) delete the resource, then 2) add the resource to the new location. The operation is atomic, so if it fails the old resource will still be there.

Parameters:
requestContext - Information about the current request.

requestContext.sourcePath: Source/Current Path

requestContext.targetPath: Destination/New Path

Returns:
the actual path for the new resource if the handler processed the RENAME action successfully.
Throws:
RegistryException - if something went wrong

createLink

public void createLink(RequestContext requestContext)
                throws RegistryException
Create a symbolic link or mount a registry.

Parameters:
requestContext - Information about the current request.

requestContext.targetPath: Destination/New Path

Throws:
RegistryException - if something went wrong

removeLink

public void removeLink(RequestContext requestContext)
                throws RegistryException
Remove a symbolic link or un-mount a registry.

Parameters:
requestContext - Information about the current request.
Throws:
RegistryException - if something went wrong

delete

public void delete(RequestContext requestContext)
            throws RegistryException
Processes the DELETE action of the media type.

Parameters:
requestContext - Information about the current request.

requestContext.resourcePath: path of the resource to be deleted.

Throws:
RegistryException - If the media type handler is supposed to handle the delete on the media type and if the delete fails due a handler specific error

putChild

public void putChild(RequestContext requestContext)
              throws RegistryException
Invokes when a child resource is added. Only the media type handlers of collection resources may have a meaningful implementation of this method.

Parameters:
requestContext - requestContext.resourcePath: path of the parent collection requestContext.resource: New child resource to be added
Throws:
RegistryException - If the media type handler is supposed to handle the putChild on the media type and if the putChild fails due a handler specific error

importChild

public void importChild(RequestContext requestContext)
                 throws RegistryException
Invokes when a child resource is imported. Only the media type handlers of collection resources may have a meaningful implementation of this method.

Parameters:
requestContext - requestContext.resourcePath
Throws:
RegistryException - If the media type handler is supposed to handle the importChild on the media type and if the importChild fails due a handler specific error

invokeAspect

public void invokeAspect(RequestContext requestContext)
                  throws RegistryException
Gets called when an Associated Aspect gets invoked.

Parameters:
requestContext - requestContext.resourcePath: path of the resource. requestContext.aspect: The Aspect to be invoked requestContext.action: The action to be provided when invoking the Aspect
Throws:
RegistryException - If the media type handler is supposed to handle the invokeAspect on the media type and if the invokeAspect fails due a handler specific error

addAssociation

public void addAssociation(RequestContext requestContext)
                    throws RegistryException
Gets called when an Association is added.

Parameters:
requestContext - Information about the current request. requestContext.sourcePath: Source/Current Path requestContext.targetPath: Destination/New Path requestContext.associationType: Type of Association
Throws:
RegistryException - If the media type handler is supposed to handle the addAssociation on the media type and if the addAssociation fails due a handler specific error

removeAssociation

public void removeAssociation(RequestContext requestContext)
                       throws RegistryException
Gets called when an Association is removed.

Parameters:
requestContext - Information about the current request. requestContext.sourcePath: Source/Current Path requestContext.targetPath: Destination/New Path requestContext.associationType: Type of Association
Throws:
RegistryException - If the media type handler is supposed to handle the removeAssociation on the media type and if the removeAssociation fails due a handler specific error

getAllAssociations

public Association[] getAllAssociations(RequestContext requestContext)
                                 throws RegistryException
Gets called when getting all Associations.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource
Returns:
Array of all associations if the handler processed the GET_ALL_ASSOCIATIONS action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getAllAssociations on the media type and if the getAllAssociations fails due a handler specific error

getAssociations

public Association[] getAssociations(RequestContext requestContext)
                              throws RegistryException
Gets called when getting Associations of given type.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.associationType: Type of Association
Returns:
Array of associations of given type if the handler processed the GET_ASSOCIATIONS action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getAssociations on the media type and if the getAssociations fails due a handler specific error

applyTag

public void applyTag(RequestContext requestContext)
              throws RegistryException
Gets called when a tag is applied.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.tag: Tag
Throws:
RegistryException - If the media type handler is supposed to handle the applyTag on the media type and if the applyTag fails due a handler specific error

removeTag

public void removeTag(RequestContext requestContext)
               throws RegistryException
Gets called when a tag is removed.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.tag: Tag
Throws:
RegistryException - If the media type handler is supposed to handle the removeTag on the media type and if the removeTag fails due a handler specific error

rateResource

public void rateResource(RequestContext requestContext)
                  throws RegistryException
Gets called when rating a resource.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.rating: Rating
Throws:
RegistryException - If the media type handler is supposed to handle the rateResource on the media type and if the rateResource fails due a handler specific error

restoreVersion

public void restoreVersion(RequestContext requestContext)
                    throws RegistryException
Gets called when restoring a version.

Parameters:
requestContext - Information about the current request. requestContext.versionPath: Path of Resource with version This can be used to derive the path of the resource as well.
Throws:
RegistryException - If the media type handler is supposed to handle the restoreVersion on the media type and if the restoreVersion fails due a handler specific error

createVersion

public void createVersion(RequestContext requestContext)
                   throws RegistryException
Gets called when creating a version.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource
Throws:
RegistryException - If the media type handler is supposed to handle the createVersion on the media type and if the createVersion fails due a handler specific error

editComment

public void editComment(RequestContext requestContext)
                 throws RegistryException
Gets called when editing a comment.

Parameters:
requestContext - Information about the current request. requestContext.comment: The comment with associated modifications.
Throws:
RegistryException - If the media type handler is supposed to handle the editComment on the media type and if the editComment fails due a handler specific error

addComment

public String addComment(RequestContext requestContext)
                  throws RegistryException
Gets called when adding a comment.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.comment: The comment to add
Returns:
The comment id of the comment added if the handler processed the ADD_COMMENT action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the addComment on the media type and if the addComment fails due a handler specific error

removeComment

public void removeComment(RequestContext requestContext)
                   throws RegistryException
Gets called when removing a comment.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.comment: The comment to remove
Throws:
RegistryException - If the media type handler is supposed to handle the addComment on the media type and if the addComment fails due a handler specific error

getComments

public Comment[] getComments(RequestContext requestContext)
                      throws RegistryException
Gets called when retrieving comments.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource
Returns:
Array of comments if the handler processed the REMOVE_COMMENT action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getComments on the media type and if the getComments fails due a handler specific error

getAverageRating

public float getAverageRating(RequestContext requestContext)
                       throws RegistryException
Gets called when getting average rating.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource
Returns:
The average rating if the handler processed the GET_AVERAGE_RATING action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getAverageRating on the media type and if the getAverageRating fails due a handler specific error

getRating

public int getRating(RequestContext requestContext)
              throws RegistryException
Gets called when getting a rating given by a specific user.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.userName: The name of the user
Returns:
The rating given by the user if the handler processed the GET_RATING action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getRating on the media type and if the getRating fails due a handler specific error

getVersions

public String[] getVersions(RequestContext requestContext)
                     throws RegistryException
Gets called when getting versions.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource
Returns:
an array of Version paths are returned in the form /projects/resource?v=12 if the handler processed the GET_VERSIONS action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getVersions on the media type and if the getVersions fails due a handler specific error

getTags

public Tag[] getTags(RequestContext requestContext)
              throws RegistryException
Gets called when getting tags.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource
Returns:
Array of tags added to the given resource if the handler processed the GET_TAGS action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getTags on the media type and if the getTags fails due a handler specific error

getResourcePathsWithTag

public TaggedResourcePath[] getResourcePathsWithTag(RequestContext requestContext)
                                             throws RegistryException
Gets called when getting the resource paths corresponding to the given tag.

Parameters:
requestContext - Information about the current request. requestContext.tag: Tag
Returns:
The resource paths tagged with the given tag if the handler processed the GET_TAGGED_RESOURCE_PATHS action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the getResourcePathsWithTag on the media type and if the getResourcePathsWithTag fails due a handler specific error

executeQuery

public Collection executeQuery(RequestContext requestContext)
                        throws RegistryException
Gets called when executing Queries.

Parameters:
requestContext - Information about the current request. requestContext.resourcePath: Path of Resource requestContext.queryParameters: Map of query parameters.
Returns:
A collection containing results as its child resources if the handler processed the EXECUTE_QUERY action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the executeQuery on the media type and if the executeQuery fails due a handler specific error

searchContent

public Collection searchContent(RequestContext requestContext)
                         throws RegistryException
Gets called when searching for content.

Parameters:
requestContext - Information about the current request. requestContext.keywords: Search keywords.
Returns:
The result set as a collection if the handler processed the SEARCH_CONTENT action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the searchContent on the media type and if the searchContent fails due a handler specific error

resourceExists

public boolean resourceExists(RequestContext requestContext)
                       throws RegistryException
Gets called when searching for existence of resource.

Parameters:
requestContext - Information about the current request.
Returns:
True if the resource exists and false if not if the handler processed the RESOURCE_EXISTS action successfully.
Throws:
RegistryException - If the media type handler is supposed to handle the resourceExists on the media type and if the resourceExists fails due a handler specific error

getRegistryContext

public RegistryContext getRegistryContext(RequestContext requestContext)
Gets called when obtaining the registry context.

Parameters:
requestContext - Information about the current request.
Returns:
An instance of the corresponding registry context.

dump

public void dump(RequestContext requestContext)
          throws RegistryException
Gets called when dumping an path

Parameters:
requestContext - Information about the current request. requestContext.keywords: Search keywords.
Throws:
RegistryException - If the media type handler is supposed to handle the resourceExists on the media type and if the resourceExists fails due a handler specific error

restore

public void restore(RequestContext requestContext)
             throws RegistryException
Gets called when restoring a path

Parameters:
requestContext - Information about the current request. requestContext.keywords: Search keywords.
Throws:
RegistryException - If the media type handler is supposed to handle the resourceExists on the media type and if the resourceExists fails due a handler specific error

hashCode

public int hashCode()
This overrides the default hash code implementation for handler objects, to make sure that each handler of the same type will have identical hash codes unless otherwise it has its own extension.

Overrides:
hashCode in class Object
Returns:
hash code for this handler type.

equals

public boolean equals(Object obj)
Revised implementation of the equals comparison to suite the modified hashCode method.

Overrides:
equals in class Object
Parameters:
obj - object to compare for equality.
Returns:
whether equal or not.


Copyright © 2013 WSO2 Inc. All Rights Reserved.