|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.wso2.carbon.registry.core.ResourceImpl
public class ResourceImpl
Represents any file or collection stored in the registry. It encapsulates both the content of the entity and its meta data. In addition to files and collections, instances of Resource are used to represent results of runtime queries. In such scenarios, 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.CoreRegistry.get(String)
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.
Handling content
Contents of resource can be set either as an input stream or an object. If an input stream is
set, an unique file based content will be created for the given input stream. If an object of
type byte[] or String is set, an in-memory input stream will be created from it and then a
unique file based input stream is created. If an object of any other type is set, there should be
a handler to convert it to an input stream before reaching the repository.
When a resource is retrieved from the database layer, its content is not retrieved from the
database. Instead, UUID referring to the database content is stored in dbBasedContentID. When the
content is first accessed, a file based input stream is created from the database content and
fileBasedContentID is set (fileBasedContentID = dbBasedContentID).
Field Summary | |
---|---|
protected String |
authorUserName
User name of the user who added the resource to the registry. |
protected Object |
content
Content of the resource. |
protected boolean |
contentModified
Used to detect whether the resource content is modified after it is retrieved from the Registry. |
protected long |
createdTime
Time at which the resource is first added to the registry. |
protected DataAccessManager |
dataAccessManager
The data access manager is to be used only by the resource implementation and users of the resource are not needed to use this. |
protected int |
dbBasedContentID
UUID of the content stored in the database. |
protected String |
description
Description about the resource. |
protected boolean |
directory
Specified whether the resource is a collection (directory) or a file. |
protected String |
id
UUID to identify the resource. |
protected long |
lastModified
Time at which the resource modified most recently. |
protected String |
lastUpdaterUserName
User name of the user who modified the resource most recently. |
protected long |
matchingSnapshotID
The matching snapshot identifier. |
protected String |
mediaType
Media type of the resource. |
protected String |
name
the name of the resource if collection - NULL non-collection - the name of the resource.. |
protected String |
parentPath
Path of the parent collection of the resource. |
protected String |
path
Unique path of the resource within the registry. |
protected int |
pathID
path id, if collection - id of the path of the collection if non-collection - id of the path of the non-collection |
protected String |
permanentPath
The permanent path of the resource. |
protected 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 int |
tenantId
tenant id resource belongs to |
protected String |
userName
Resources and collections can be accessed outside the user registry. |
protected org.wso2.carbon.user.core.UserRealm |
userRealm
Resources and collections can be accessed outside the user registry. |
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()
Default constructor for the resource. |
|
ResourceImpl(ResourceImpl resource)
A copy constructor used to create a shallow-copy of this resource. |
|
ResourceImpl(String path,
ResourceDO resourceDO)
Construct a resource with given path and resource data object. |
Method Summary | |
---|---|
void |
addAspect(String name)
Method to add an aspect. |
void |
addProperty(String key,
String value)
Add a property value for the provided key. |
void |
addPropertyWithNoUpdate(String key,
String value)
Add a property value for the provided key. |
protected void |
clearSessionInformation()
UnSet the session information. |
void |
discard()
Method to discard the resource |
void |
editPropertyValue(String key,
String oldValue,
String newValue)
Edit property value. |
protected ResourceImpl |
fillResourceCopy(ResourceImpl resource)
Fill the resource. |
List<String> |
getAspects()
Get the aspects associated with the resource. |
String |
getAuthorUserName()
Method to get the author user name. |
Object |
getContent()
Method to get the content of the resource. |
InputStream |
getContentStream()
Method to get the content stream. |
Date |
getCreatedTime()
Method to get the created time. |
int |
getDbBasedContentID()
Method to get the db id of the content |
String |
getDescription()
Method to get the description. |
String |
getId()
The Resource ID, In the default implementation this returns the path. |
Date |
getLastModified()
Method to get the created time. |
String |
getLastUpdaterUserName()
Method to get the last updated user name. |
long |
getMatchingSnapshotID()
Method to get the matching snapshot id. |
String |
getMediaType()
Method to get the media type. |
String |
getName()
Get the resource name. |
String |
getParentPath()
Method to get the parent path. |
String |
getPath()
Method to get the path. |
int |
getPathID()
Get the path id. |
String |
getPermanentPath()
Method to get the permanent path. |
Properties |
getProperties()
Returns all properties of the resource. |
String |
getProperty(String key)
Get the property value for the given key, if there are multiple value for that key, it will return the first value. |
List<String> |
getPropertyValues(String key)
Returns the list of values for the given property name. |
ResourceDO |
getResourceDO()
Method to get the resource data object. |
ResourceIDImpl |
getResourceIDImpl()
Get the resource id implementation instance. |
ResourceImpl |
getShallowCopy()
Create a shallow copy of the resource. |
long |
getSnapshotID()
Method to get the snapshot id. |
int |
getState()
Method to get the state. |
long |
getVersionNumber()
Method to get the version number. |
boolean |
isContentModified()
Method to check if the content is modified. |
boolean |
isPropertiesModified()
Method to check whether the properties are modified. |
boolean |
isVersionableChange()
Check whether there are any changes that need to make a version |
void |
prepareContentForPut()
Prepare the resource content to be put. |
void |
removeAspect(String name)
Method to remove an aspect. |
void |
removeProperty(String key)
Remove property. |
void |
removePropertyValue(String key,
String value)
Remove property value. |
void |
removePropertyWithNoUpdate(String key)
Remove property without modifiying the resource. |
void |
setAuthorUserName(String authorUserName)
Method to set the author user name. |
void |
setContent(Object content)
Set the content of the resource. |
void |
setContentModified(boolean contentModified)
This method is used to explicitly set the content modified state of the resource. |
void |
setContentStream(InputStream contentStream)
Invalidates the current file based content and creates a new file based content for the new content stream. |
void |
setContentStreamWithNoUpdate(InputStream contentStream)
Invalidates the current file based content and creates a new file based content for the new content stream. |
void |
setContentWithNoUpdate(Object content)
Set the content of the resource without setting the modified flag. |
void |
setCreatedTime(Date createdTime)
Method to set the created time. |
void |
setDataAccessManager(DataAccessManager dataAccessManager)
Method to set the data access manager. |
void |
setDbBasedContentID(int dbBasedContentID)
Method to set the db id of the content. |
void |
setDescription(String description)
Method to set the description. |
void |
setId(String id)
Method to set the resource id, currently it will just set the path. |
void |
setLastModified(Date lastModified)
Method to set the last modified date. |
void |
setLastUpdaterUserName(String lastUpdaterUserName)
Method to set the last updater user name. |
void |
setMatchingSnapshotID(long matchingSnapshotID)
Method to set the matching snapshot id. |
void |
setMediaType(String mediaType)
Method to set the media type. |
void |
setName(String name)
Method to set the name. |
void |
setParentPath(String parentPath)
Method to set the parent path. |
void |
setPath(String path)
Method to get the path. |
void |
setPathID(int pathID)
Set path id. |
void |
setProperties(Properties properties)
Set properties. |
void |
setPropertiesModified(boolean propertiesModified)
Method to set the whether properties are modified. |
void |
setPropertiesModifiedWithNoUpdate(boolean propertiesModified)
Make the properties modified flag true, without changing the last updated time. |
void |
setProperty(String key,
List<String> value)
Set a property with multiple value. |
void |
setProperty(String key,
String value)
Set a property with single value. |
protected void |
setSessionInformation()
Set the session information. |
void |
setSnapshotID(long snapshotID)
Method to set the snapshot id. |
void |
setState(int state)
Method to set the state. |
void |
setTenantId(int tenantId)
Method to set the tenant id associated with the resource. |
void |
setUserName(String userName)
Method to set the user name. |
void |
setUserRealm(org.wso2.carbon.user.core.UserRealm userRealm)
Method to set the user realm. |
void |
setVersionableChange(boolean versionableChange)
Method to set whether there are any changes that need to make a version |
void |
setVersionNumber(long versionNumber)
Method to set the version number. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected String id
protected long snapshotID
protected long versionNumber
protected String authorUserName
protected long createdTime
protected String lastUpdaterUserName
protected long lastModified
protected String description
protected String path
protected long matchingSnapshotID
protected String permanentPath
protected String mediaType
protected String parentPath
protected boolean contentModified
protected boolean propertiesModified
protected boolean versionableChange
protected int state
protected Properties properties
protected int dbBasedContentID
protected Object content
protected boolean directory
protected DataAccessManager dataAccessManager
protected String userName
protected org.wso2.carbon.user.core.UserRealm userRealm
protected int tenantId
protected ResourceDAO resourceDAO
protected int pathID
protected String name
Constructor Detail |
---|
public ResourceImpl()
public ResourceImpl(String path, ResourceDO resourceDO)
path
- the path of the resource.resourceDO
- the resource data object.public ResourceImpl(ResourceImpl resource)
resource
- the resource of which the copy is created.Method Detail |
---|
public void setDataAccessManager(DataAccessManager dataAccessManager)
dataAccessManager
- the data access manager.public void setUserName(String userName)
userName
- the user name.public void setUserRealm(org.wso2.carbon.user.core.UserRealm userRealm)
userRealm
- the user realm.public void setTenantId(int tenantId)
tenantId
- the tenant id.public String getId()
getId
in interface Resource
public void setId(String id)
id
- the pathpublic long getSnapshotID()
public void setSnapshotID(long snapshotID)
snapshotID
- the snapshot id.public long getVersionNumber()
public void setVersionNumber(long versionNumber)
versionNumber
- the version number.public String getAuthorUserName()
getAuthorUserName
in interface Resource
public void setAuthorUserName(String authorUserName)
authorUserName
- the author user name.public Date getCreatedTime()
getCreatedTime
in interface Resource
public void setCreatedTime(Date createdTime)
createdTime
- the created time.public Date getLastModified()
getLastModified
in interface Resource
public void setLastModified(Date lastModified)
lastModified
- the last modified date.public String getDescription()
getDescription
in interface Resource
public void setDescription(String description)
setDescription
in interface Resource
description
- the description.public String getPath()
getPath
in interface Resource
public void setPath(String path)
path
- the path.public long getMatchingSnapshotID()
public void setMatchingSnapshotID(long matchingSnapshotID)
matchingSnapshotID
- the snapshot id.public String getPermanentPath()
getPermanentPath
in interface Resource
public String getMediaType()
getMediaType
in interface Resource
public void setMediaType(String mediaType)
setMediaType
in interface Resource
mediaType
- the media type.public String getParentPath()
getParentPath
in interface Resource
public void setParentPath(String parentPath)
parentPath
- the parent path.public int getState()
getState
in interface Resource
public void setState(int state)
state
- the state.public String getProperty(String key)
getProperty
in interface Resource
key
- the property key.
public List<String> getPropertyValues(String key)
getPropertyValues
in interface Resource
key
- Key of the property.
public Properties getProperties()
getProperties
in interface Resource
public void removeProperty(String key)
removeProperty
in interface Resource
key
- the property key.public void removePropertyWithNoUpdate(String key)
key
- the property key.public void removePropertyValue(String key, String value)
removePropertyValue
in interface Resource
key
- the property key.value
- the property value.public void editPropertyValue(String key, String oldValue, String newValue)
editPropertyValue
in interface Resource
key
- the key.oldValue
- the old value.newValue
- the new value.public void setProperty(String key, String value)
setProperty
in interface Resource
key
- the property key.value
- the property value.public void setProperty(String key, List<String> value)
setProperty
in interface Resource
key
- the property key.value
- the property values.public void addProperty(String key, String value)
addProperty
in interface Resource
key
- the property key.value
- the property value.public void addPropertyWithNoUpdate(String key, String value)
key
- the property key.value
- the property value.public void setProperties(Properties properties)
setProperties
in interface Resource
properties
- the properties.public int getDbBasedContentID()
public void setDbBasedContentID(int dbBasedContentID)
dbBasedContentID
- the db id of the content.public InputStream getContentStream() throws RegistryException
getContentStream
in interface Resource
RegistryException
- throws if the operation fail.public void setContentStream(InputStream contentStream) throws RegistryException
setContentStream
in interface Resource
contentStream
- input stream containing the new content
RegistryException
- throws if the operation fail.public void setContentStreamWithNoUpdate(InputStream contentStream) throws RegistryException
contentStream
- input stream containing the new content
RegistryException
- throws if the operation fail.public Object getContent() throws RegistryException
getContent
in interface Resource
RegistryException
- throws if the operation fail.public void setContent(Object content) throws RegistryException
setContent
in interface Resource
content
- the resource.
RegistryException
- throws if the operation fail.public void setContentWithNoUpdate(Object content) throws RegistryException
content
- the resource.
RegistryException
- throws if the operation fail.public void prepareContentForPut() throws RegistryException
RegistryException
- throws if the operation fail.public String getLastUpdaterUserName()
getLastUpdaterUserName
in interface Resource
public void setLastUpdaterUserName(String lastUpdaterUserName)
lastUpdaterUserName
- the last updater user name.public boolean isContentModified()
public void setContentModified(boolean contentModified)
contentModified
- true if we want to add a new version upon putting this to the
registry. false otherwise.public boolean isPropertiesModified()
public void setPropertiesModified(boolean propertiesModified)
propertiesModified
- whether the properties modified or not.public void setPropertiesModifiedWithNoUpdate(boolean propertiesModified)
propertiesModified
- whether the properties modified or not.public boolean isVersionableChange()
public void setVersionableChange(boolean versionableChange)
versionableChange
- whether version-able change is made or not.public List<String> getAspects()
getAspects
in interface Resource
public void addAspect(String name)
addAspect
in interface Resource
name
- the name of the aspect.public void removeAspect(String name)
removeAspect
in interface Resource
name
- the name of the aspect to remove.public void discard()
discard
in interface Resource
protected void setSessionInformation()
protected void clearSessionInformation()
public int getPathID()
public void setPathID(int pathID)
pathID
- the path id.public String getName()
public void setName(String name)
name
- the name.public ResourceIDImpl getResourceIDImpl()
public ResourceDO getResourceDO()
public ResourceImpl getShallowCopy() throws RegistryException
RegistryException
- throws if the operation fail.protected ResourceImpl fillResourceCopy(ResourceImpl resource) throws RegistryException
resource
- the resource to be filled.
RegistryException
- throws if the operation fail.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |