org.wso2.registry.jdbc.mediatypes
Class MediaTypeHandler

java.lang.Object
  extended by org.wso2.registry.jdbc.mediatypes.MediaTypeHandler
Direct Known Subclasses:
Axis2RepositoryMediaTypeHandler, DefaultMediaTypeHandler, SQLQueryMediaTypeHandler, SynapseRepositoryMediaTypeHandler, WSDLMediaTypeHandler, XSDMediaTypeHandler

public abstract class MediaTypeHandler
extends java.lang.Object

Base class of all media type handlers. It defines the six basic methods to be implemented by all media type handlers. This is initialized with the objects required for handling media type specific operations, so that extending media type handlers can easily access them. One such object is the instance of the MediaTypeManager.


Field Summary
protected  AuthorizationUtil authorizationUtil
          Some common authorization tasks are implemented in this util.
protected  javax.sql.DataSource dataSource
          Data source for obtaining database connections.
protected  MediaTypeManager mediaTypeManager
          While processing media types, handlers may want to access resources with other media types.
protected  org.wso2.usermanager.Realm realm
          User manager realm, which can be used to set permissions on resources.
protected  VersionedResourceDAO resourceDAO
          ResourceDAO for directly accessing resources.
 
Constructor Summary
MediaTypeHandler(javax.sql.DataSource dataSource, org.wso2.usermanager.Realm realm, MediaTypeManager mediaTypeManager)
           
 
Method Summary
abstract  boolean delete(java.lang.String path)
          Processes the DELETE action of the media type.
abstract  Resource get(java.lang.String path, Resource rawArtifact)
          Processes the GET action of the media type.
abstract  boolean importChild(java.lang.String childPath, java.lang.String sourceURL)
          Invokes when a child resource is imported.
abstract  java.lang.String importResource(java.lang.String path, java.lang.String sourceURL, Resource metadata)
          Creates a resource in the given path by fetching the resource content from the given URL.
abstract  boolean put(java.lang.String path, Resource resource)
          Processes the PUT action of the media type.
abstract  boolean putChild(java.lang.String childPath, Resource resource)
          Invokes when a child resource is added.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataSource

protected javax.sql.DataSource dataSource
Data source for obtaining database connections. Media type handlers need to access the database for performing almost all the tasks.


realm

protected org.wso2.usermanager.Realm realm
User manager realm, which can be used to set permissions on resources. Media type handlers may want to add other resources (e.g. imports) than the originally given resource. So it is necessary to allow media type handler to set permissions for the resources it is dealing with.


mediaTypeManager

protected MediaTypeManager mediaTypeManager
While processing media types, handlers may want to access resources with other media types. Then they can just call the appropriate methods of the MediaTypeManager for doing that.

e.g. "text" mediatype handler may just want to change the content of the resource from String to byte[] before PUT. So that users can set Strings as the content of text resources. But after changing that, text handler want PUT the resource using normal process. In that case, text handler can execute the put(...) method of the DefaultMediaTypeHandler after doing the relevent changes to the resource.


resourceDAO

protected VersionedResourceDAO resourceDAO
ResourceDAO for directly accessing resources.


authorizationUtil

protected AuthorizationUtil authorizationUtil
Some common authorization tasks are implemented in this util.

Constructor Detail

MediaTypeHandler

public MediaTypeHandler(javax.sql.DataSource dataSource,
                        org.wso2.usermanager.Realm realm,
                        MediaTypeManager mediaTypeManager)
Method Detail

get

public abstract Resource get(java.lang.String path,
                             Resource rawArtifact)
                      throws RegistryException
Processes the GET action of the media type.

Parameters:
path - Path of the resource
rawArtifact - Raw artifact at the given path, which is retrieved directly from the database. This can be used by media type handlers, which need to alter contents of the raw artifact, etc.
Returns:
Resource instance if the media type handler processes the GET action. If resource is returned it should perform all tasks to fulfill the GET request. Returns null if the media type handler does not process the GET action. If null is returned, get(...) method of the DefaultMediaTypeHandler will be invoked.
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 abstract boolean put(java.lang.String path,
                            Resource resource)
                     throws RegistryException
Processes the PUT action of the media type.

Parameters:
path - to put the resource.
resource - to put.
Returns:
true if the media type handler processes the PUT action. If true is returned it should perform all tasks to fulfill the PUT request. Returns false if the media type handler does not process the PUT action. If false is returned, put(...) method of the DefaultMediaTypeHandler will be invoked.
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 abstract java.lang.String importResource(java.lang.String path,
                                                java.lang.String sourceURL,
                                                Resource metadata)
                                         throws RegistryException
Creates a resource in the given path by fetching the resource content from the given URL.

Parameters:
path - Path to add the new resource.
sourceURL - URL to fetch the resource content
metadata - Resource instance containing the metadata for the resource to be imported. Once import is done, new resource is created combining the metadata of this metadata object and the imported content.
Returns:
true if the media type handler processes the import action. If true is returned it should perform all tasks to fulfill the import request. Returns false if the media type handler does not process the import action. If false is returned, importResource(...) method of the DefaultMediaTypeHandler will be invoked.
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

delete

public abstract boolean delete(java.lang.String path)
                        throws RegistryException
Processes the DELETE action of the media type.

Parameters:
path - path of the resource to be deleted.
Returns:
true if the media type handler processes the DELETE action. If true is returned it should perform all tasks to fulfill the DELETE request. Returns false if the media type handler does not process the DELETE action. If false is returned, delete(...) method of the DefaultMediaTypeHandler will be invoked.
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 abstract boolean putChild(java.lang.String childPath,
                                 Resource resource)
                          throws RegistryException
Invokes when a child resource is added. Only the media type handlers of collection resources may have a meaningfull implementation of this method.

Parameters:
childPath - Path of the child resource
resource - Child resource
Returns:
True if the child resource is allowed to be added. False if the child resource is rejected.
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 abstract boolean importChild(java.lang.String childPath,
                                    java.lang.String sourceURL)
                             throws RegistryException
Invokes when a child resource is imported. Only the media type handlers of collection resources may have a meaningfull implementation of this method.

Parameters:
childPath - Path of the child resource
sourceURL - URL to import child resource content
Returns:
True if the child resource is allowed to be imported. False if the child resource is rejected.
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


Copyright © 2007 Apache Web Services Project. All Rights Reserved.