org.wso2.registry
Class ResourceImpl

java.lang.Object
  extended by org.wso2.registry.ResourceImpl
All Implemented Interfaces:
Resource
Direct Known Subclasses:
CollectionImpl, Comment, RemoteResourceImpl, ResourceVersionImpl

public class ResourceImpl
extends java.lang.Object
implements Resource

Represents any file or collection stored in the registry. It encapsulates both the content of the entity and its metadata. In addition to files and collections, instances of Resource are used to represent results of runtime queries. In such secenarios, comments, tags, ratings as well as collections of comments, etc. are also represented by Resource objects. Each resource instance contains a unique path within a Registry instance. Registry.get(...) method invocation using this path gives an instance of that resource. This path can be combined with the base URL of the registry server to generate a URI for the resource.


Field Summary
protected  java.lang.String authorUserName
          Username of the user who added the resource to the registry.
protected  java.lang.Object content
          Content of the resource.
protected  java.lang.String contentID
          UUID refering to the content of this resource.
protected  boolean contentModified
          Used to detect whether the resource content is modified after it is retrieved from the Registry.
protected  java.io.InputStream contentStream
          Content of the resource, represented as a input stream.
protected  java.sql.Timestamp createdTime
          Time at which the resource is first added to the registry.
protected  javax.sql.DataSource dataSource
          Registry datasource.
protected  java.lang.String description
          Description about the resource.
protected  boolean directory
          Specified whether the resource is a collection (directory) or a file.
protected  java.lang.String id
          UUID to identify the resource.
protected  java.sql.Timestamp lastModified
          Time at which the resource modified most recently.
protected  java.lang.String lastUpdaterUserName
          Username of the user who modified the resource most recently.
protected  long matchingSnapshotID
           
protected  java.lang.String mediaType
          Media type of the resource.
protected  java.lang.String parentPath
          Path of the parent collection of the resource.
protected  java.lang.String path
          Unique path of the resource within the registry.
protected  java.lang.String permanentPath
           
protected  java.util.Properties properties
          Properties associated with the resource.
protected  boolean propertiesModified
          Used to detect whether properties of this resource is modified since retrieval from the repository.
protected  ResourceDAO resourceDAO
          Resource DAO instance to access the database directly.
protected  long snapshotID
          Snapshot for which this resource instance is created.
protected  int state
          Normal resources have the state RegistryConstants.ACTIVE_STATE (100) Deleted resources have the state RegistryConstants.DELETED_STATE (101)
protected  boolean versionableChange
          Determines whether the resource is subjected to changes, which causes it to create a new version.
protected  long versionNumber
          Version of this instance of the resource.
 
Constructor Summary
ResourceImpl()
           
 
Method Summary
 void addAspect(java.lang.String name)
           
 void addProperty(java.lang.String key, java.lang.String value)
           
 void editPropertyValue(java.lang.String key, java.lang.String oldValue, java.lang.String newValue)
           
 java.util.List<java.lang.String> getAspects()
           
 java.lang.String getAuthorUserName()
           
 java.lang.Object getContent()
           
 java.lang.String getContentID()
           
 java.io.InputStream getContentStream()
           
 java.util.Date getCreatedTime()
           
 java.lang.String getDescription()
           
 java.lang.String getId()
           
 java.util.Date getLastModified()
           
 java.lang.String getLastUpdaterUserName()
           
 long getMatchingSnapshotID()
           
 java.lang.String getMediaType()
           
 java.lang.String getParentPath()
           
 java.lang.String getPath()
           
 java.lang.String getPermanentPath()
          If resource is versioned, the associated version of the resource does not get modified by any means.
 java.util.Properties getProperties()
          Returns all properties of the resource.
 java.lang.String getProperty(java.lang.String key)
           
 java.util.List getPropertyValues(java.lang.String key)
          Returns the list of values for the given property name.
 long getSnapshotID()
           
 int getState()
           
 long getVersionNumber()
           
 boolean isContentModified()
           
 boolean isPropertiesModified()
           
 boolean isVersionableChange()
           
 void removeAspect(java.lang.String name)
           
 void removeProperty(java.lang.String key)
           
 void removePropertyValue(java.lang.String key, java.lang.String value)
           
 void setAuthorUserName(java.lang.String authorUserName)
           
 void setContent(java.lang.Object content)
           
 void setContentID(java.lang.String contentID)
           
 void setContentModified(boolean contentModified)
          This method is used to explicitly set the content modified state of the resource.
 void setContentStream(java.io.InputStream contentStream)
           
 void setCreatedTime(java.util.Date createdTime)
           
 void setDataSource(javax.sql.DataSource dataSource)
           
 void setDescription(java.lang.String description)
           
 void setId(java.lang.String id)
           
 void setLastModified(java.util.Date lastModified)
           
 void setLastUpdaterUserName(java.lang.String lastUpdaterUserName)
           
 void setMatchingSnapshotID(long matchingSnapshotID)
           
 void setMediaType(java.lang.String mediaType)
           
 void setParentPath(java.lang.String parentPath)
           
 void setPath(java.lang.String path)
           
 void setProperties(java.util.Properties properties)
           
 void setPropertiesModified(boolean propertiesModified)
           
 void setProperty(java.lang.String key, java.util.List<java.lang.String> value)
           
 void setProperty(java.lang.String key, java.lang.String value)
           
 void setSnapshotID(long snapshotID)
           
 void setState(int state)
           
 void setVersionableChange(boolean versionableChange)
           
 void setVersionNumber(long versionNumber)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected java.lang.String id
UUID to identify the resource.


snapshotID

protected long snapshotID
Snapshot for which this resource instance is created. Any resource and all its versioned data can be accessed only using the resource ID and the version number. But snapshot ID is required to track currently accessing snapshot. Note that it is not possible to derive snapshot ID from the resource ID and the version number, as there can be multiple snapshots using the same version.


versionNumber

protected long versionNumber
Version of this instance of the resource. Versioned attributes (e.g. content, last modified date) can be accessed by using the combination of id and versionNumber.


authorUserName

protected java.lang.String authorUserName
Username of the user who added the resource to the registry.


createdTime

protected java.sql.Timestamp createdTime
Time at which the resource is first added to the registry.


lastUpdaterUserName

protected java.lang.String lastUpdaterUserName
Username of the user who modified the resource most recently.


lastModified

protected java.sql.Timestamp lastModified
Time at which the resource modified most recently.


description

protected java.lang.String description
Description about the resource. This may contain any text including HTML fragments.


path

protected java.lang.String path
Unique path of the resource within the registry. This is generated by appending all ascendant paths to the resource name separated by "/". For example assume that the resource name is "users.xml". config.xml if inside the collection named "config". config collection is inside the root level collection named "servers". Then the path of the resource is /servers/config/users.xml.


matchingSnapshotID

protected long matchingSnapshotID

permanentPath

protected java.lang.String permanentPath

mediaType

protected java.lang.String mediaType
Media type of the resource. Each resource can have a media type associated with it. This can be either a standart MIME media type or a custom media type defined by the users of the registry. Media type is used to activate media type handlers defined in the registry. Thus, by defining a media type for a resource and by registering a media type handler to handle that media type, it is possible to apply special processing for resources.


parentPath

protected java.lang.String parentPath
Path of the parent collection of the resource. If the resource path is /servers/config/users.xml, parent path is /servers/config.


contentModified

protected boolean contentModified
Used to detect whether the resource content is modified after it is retrieved from the Registry. If this is set to true at the time of adding the resource back to the Registry, new version will be created.


propertiesModified

protected boolean propertiesModified
Used to detect whether properties of this resource is modified since retrieval from the repository. If true, properties will be updated and new version will be created upon putting this resource to the repository.


versionableChange

protected boolean versionableChange
Determines whether the resource is subjected to changes, which causes it to create a new version. If true, a new version will be created upon adding the resource to the repository.


state

protected int state
Normal resources have the state RegistryConstants.ACTIVE_STATE (100) Deleted resources have the state RegistryConstants.DELETED_STATE (101)


properties

protected java.util.Properties properties
Properties associated with the resource. A resource can contain zero or more properties, where each property is a name->value pair. Both name and the value should be strings.


contentID

protected java.lang.String contentID
UUID refering to the content of this resource. Note that the content may be shared by multiple resource. Content ID is not exposed outside the Registry API.


content

protected java.lang.Object content
Content of the resource. Object and the type stored in this field depends on the resource type. If the resource is a file with no special media type handling, this contains an array of bytes (byte[]) conatining the raw bytes of the file. If the resource is a collection, this contains a String[] containing the paths of child resources. If the resource is processed by a media type handler, it is upto the media type handler to set a content. In that case content can be anything ranging from String to custom type. Therefore, clients of the API should be aware of the media type and the content for that media type.


directory

protected boolean directory
Specified whether the resource is a collection (directory) or a file. By default all resources are considered as files. If you want to make a collection, you have to explicitly set the directory field to true.


contentStream

protected java.io.InputStream contentStream
Content of the resource, represented as a input stream.


dataSource

protected javax.sql.DataSource dataSource
Registry datasource. This is to be used only by the resource implemetation and users of the resource are not needed to use this. Some attributes of the resource (e.g. content) is fetched upon the first request to optimize the response time. Getters of such attributes use this datasource to fetch the values from the database.


resourceDAO

protected ResourceDAO resourceDAO
Resource DAO instance to access the database directly. Note that the VersionedResourceDAO is thread safe, so it is possible to keep a single instance for the resource.

Constructor Detail

ResourceImpl

public ResourceImpl()
Method Detail

setDataSource

public void setDataSource(javax.sql.DataSource dataSource)

getId

public java.lang.String getId()
Specified by:
getId in interface Resource

setId

public void setId(java.lang.String id)

getSnapshotID

public long getSnapshotID()

setSnapshotID

public void setSnapshotID(long snapshotID)

getVersionNumber

public long getVersionNumber()

setVersionNumber

public void setVersionNumber(long versionNumber)

getAuthorUserName

public java.lang.String getAuthorUserName()
Specified by:
getAuthorUserName in interface Resource

setAuthorUserName

public void setAuthorUserName(java.lang.String authorUserName)

getCreatedTime

public java.util.Date getCreatedTime()
Specified by:
getCreatedTime in interface Resource

setCreatedTime

public void setCreatedTime(java.util.Date createdTime)

getLastModified

public java.util.Date getLastModified()
Specified by:
getLastModified in interface Resource

setLastModified

public void setLastModified(java.util.Date lastModified)

getDescription

public java.lang.String getDescription()
Specified by:
getDescription in interface Resource

setDescription

public void setDescription(java.lang.String description)
Specified by:
setDescription in interface Resource

getPath

public java.lang.String getPath()
Specified by:
getPath in interface Resource

setPath

public void setPath(java.lang.String path)

getMatchingSnapshotID

public long getMatchingSnapshotID()

setMatchingSnapshotID

public void setMatchingSnapshotID(long matchingSnapshotID)

getPermanentPath

public java.lang.String getPermanentPath()
Description copied from interface: Resource
If resource is versioned, the associated version of the resource does not get modified by any means. Therefore, the path of that version is the permanent path (permalink) of the current state of the resource.

Specified by:
getPermanentPath in interface Resource
Returns:
Permanent path (permalink) of the resource.

getMediaType

public java.lang.String getMediaType()
Specified by:
getMediaType in interface Resource

setMediaType

public void setMediaType(java.lang.String mediaType)
Specified by:
setMediaType in interface Resource

getParentPath

public java.lang.String getParentPath()
Specified by:
getParentPath in interface Resource

setParentPath

public void setParentPath(java.lang.String parentPath)

getState

public int getState()
Specified by:
getState in interface Resource

setState

public void setState(int state)

getProperty

public java.lang.String getProperty(java.lang.String key)
Specified by:
getProperty in interface Resource

getPropertyValues

public java.util.List getPropertyValues(java.lang.String key)
Description copied from interface: Resource
Returns the list of values for the given property name. Note that these values are read-only. Changes made to these values will not be persisted on putting the resource.

Specified by:
getPropertyValues in interface Resource
Parameters:
key - Key of the property.
Returns:
List of values of the given property key.

getProperties

public java.util.Properties getProperties()
Description copied from interface: Resource
Returns all properties of the resource. Properties are stored as key (String) -> values (List) pairs. It is not recommended to use this method to access properties. Instead, use other property related Resource API methods provided. Note that these values are read-only. Changes made to these values will not be persisted on putting the resource.

Specified by:
getProperties in interface Resource
Returns:
All properties of the resource.

removeProperty

public void removeProperty(java.lang.String key)
Specified by:
removeProperty in interface Resource

removePropertyValue

public void removePropertyValue(java.lang.String key,
                                java.lang.String value)
Specified by:
removePropertyValue in interface Resource

editPropertyValue

public void editPropertyValue(java.lang.String key,
                              java.lang.String oldValue,
                              java.lang.String newValue)
Specified by:
editPropertyValue in interface Resource

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Specified by:
setProperty in interface Resource

setProperty

public void setProperty(java.lang.String key,
                        java.util.List<java.lang.String> value)
Specified by:
setProperty in interface Resource

addProperty

public void addProperty(java.lang.String key,
                        java.lang.String value)
Specified by:
addProperty in interface Resource

setProperties

public void setProperties(java.util.Properties properties)
Specified by:
setProperties in interface Resource

getContentID

public java.lang.String getContentID()

setContentID

public void setContentID(java.lang.String contentID)

getContentStream

public java.io.InputStream getContentStream()
                                     throws RegistryException
Specified by:
getContentStream in interface Resource
Throws:
RegistryException

setContentStream

public void setContentStream(java.io.InputStream contentStream)
Specified by:
setContentStream in interface Resource

getContent

public java.lang.Object getContent()
                            throws RegistryException
Specified by:
getContent in interface Resource
Throws:
RegistryException

setContent

public void setContent(java.lang.Object content)
Specified by:
setContent in interface Resource

getLastUpdaterUserName

public java.lang.String getLastUpdaterUserName()
Specified by:
getLastUpdaterUserName in interface Resource

setLastUpdaterUserName

public void setLastUpdaterUserName(java.lang.String lastUpdaterUserName)

isContentModified

public boolean isContentModified()

setContentModified

public void setContentModified(boolean contentModified)
This method is used to explicitly set the content modified state of the resource. Normal users of the Registry API should not call this method.

Parameters:
contentModified - true if we want to add a new version upon putting this to the registry. false otherwise.

isPropertiesModified

public boolean isPropertiesModified()

setPropertiesModified

public void setPropertiesModified(boolean propertiesModified)

isVersionableChange

public boolean isVersionableChange()

setVersionableChange

public void setVersionableChange(boolean versionableChange)

getAspects

public java.util.List<java.lang.String> getAspects()
Specified by:
getAspects in interface Resource

addAspect

public void addAspect(java.lang.String name)
Specified by:
addAspect in interface Resource

removeAspect

public void removeAspect(java.lang.String name)
Specified by:
removeAspect in interface Resource


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