/*
* Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.registry.ws.api;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Date;
import java.util.Map;
import javax.activation.DataHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.registry.common.services.RegistryAbstractAdmin;
import org.wso2.carbon.registry.core.Aspect;
import org.wso2.carbon.registry.core.Association;
import org.wso2.carbon.registry.core.Collection;
import org.wso2.carbon.registry.core.Comment;
import org.wso2.carbon.registry.core.LogEntry;
import org.wso2.carbon.registry.core.LogEntryCollection;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.Tag;
import org.wso2.carbon.registry.core.TaggedResourcePath;
import org.wso2.carbon.registry.core.config.RegistryContext;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.utils.UUIDGenerator;
import org.wso2.carbon.registry.ws.api.utils.CommonUtil;
import org.wso2.carbon.utils.ServerConstants;
@SuppressWarnings("unused")
public class WSRegistry extends RegistryAbstractAdmin implements Registry {
private Log log = LogFactory.getLog(WSRegistry.class);
private String workingDir = System.getProperty(ServerConstants.WORK_DIR);
private File tempFile;
/**
* Constructs a new Registry WS API instance. Only to be used by a web service client. This is used by
* the Registry Web Service client.
* @throws RegistryException
*/
public WSRegistry() throws RegistryException {
try {
tempFile = File.createTempFile("wsresource", ".tmp");
tempFile.deleteOnExit();
} catch (IOException e) {
throw new RegistryException("Not able to create temp files. Check permissions", e);
}
}
public Resource newResource() throws RegistryException{
return getRootRegistry().newResource();
}
public Collection newCollection() throws RegistryException{
return getRootRegistry().newCollection();
}
/**
* Returns a new WSResource instance. This method is not used by the Registry Web Service client to avoid an unnecessary network call. It
* is only there for completeness of the Registry interface. A new Resource instance can be created directly from the client side.
* @return WSResource instance
* @throws RegistryException
*/
public WSResource WSnewResource()throws RegistryException{
Resource resource = getRootRegistry().newResource();
return CommonUtil.newResourcetoWSResource(resource);
}
/**
* Returns a new WSCollection instance. This method is not used by the Registry Web Service client to avoid an unnecessary network call. It
* is only there for completeness of the Registry interface. A new Collection instance can be created directly from the client side.
*
* @return WSResource instance
* @throws RegistryException
*/
public WSCollection WSnewCollection()throws RegistryException{
Collection collection = getRootRegistry().newCollection();
return CommonUtil.newCollectiontoWSCollection(collection);
}
public Resource get(String path) throws RegistryException{
return getRootRegistry().get(path);
}
/**
* Returns the resource at the given path.
*
* @param path Path of the resource. e.g. /project1/server/deployment.xml
* @return WSResource instance
* @throws org.wso2.carbon.registry.core.exceptions.RegistryException
* is thrown if the resource is not in the registry
*/
public WSResource WSget(String path) throws RegistryException {
Resource resource = getRootRegistry().get(path);
DataHandler dataHandler = null;
if (resource instanceof Collection) {
return CommonUtil.transformCollectiontoWSCollection((Collection) resource, dataHandler);
}
return CommonUtil.transformResourceToWSResource(resource, dataHandler);
}
public Resource getMetaData(String path) throws RegistryException{
return getRootRegistry().getMetaData(path);
}
public String importResource(String s, String s1,
org.wso2.carbon.registry.api.Resource resource)
throws org.wso2.carbon.registry.api.RegistryException {
return importResource(s, s1, (Resource) resource);
}
/**
* Returns the meta data of the resource at the given path.
*
* @param path Path of the resource. e.g. /project1/server/deployment.xml
* @return WSResource instance
* @throws org.wso2.carbon.registry.core.exceptions.RegistryException
* is thrown if the resource is not in the registry
*/
public WSResource WSgetMetaData(String path) throws RegistryException{
Resource resource = getRootRegistry().getMetaData(path);
DataHandler dataHandler = null;
try {
dataHandler = CommonUtil.makeDataHandler(resource, tempFile);
} catch (IOException e) {
log.error("WSGet failed - Unable to generate temp file", e);
}
return CommonUtil.transformResourceToWSResource(resource, dataHandler);
}
public Collection get(String path, int start, int pageSize) throws RegistryException{
return getRootRegistry().get(path,start,pageSize);
}
public Collection getChildCollection(String path, int start, int pageSize) throws RegistryException{
return getRootRegistry().get(path,start,pageSize);
}
/**
* Returns the WSCollection according to the Collection at the given path, with the content paginated according to
* the arguments.
*
* @param path the path of the collection. MUST point to a collection!
* @param start the initial index of the child to return. If there are fewer children than
* the specified value, a RegistryException will be thrown.
* @param pageSize the maximum number of results to return
* @return a Collection containing the specified results in the content
* @throws RegistryException if the resource is not found, or if the path does not
* reference a Collection, or if the start index is greater than
* the number of children.
*/
public WSCollection WSgetWithPageSize(String path, int start, int pageSize) throws RegistryException{
Collection collection = getRootRegistry().get(path,start,pageSize);
DataHandler dataHandler = null;
// try {
// dataHandler = CommonUtil.makeDataHandler(collection, tempFile);
// } catch (IOException e) {
// log.error("WSGet failed - Unable to generate temp file", e);
// }
return CommonUtil.transformCollectiontoWSCollection(collection, dataHandler);
}
public WSCollection WSgetChildCollection(String path, int start, int pageSize) throws RegistryException{
Collection collection = getRootRegistry().get(path,start,pageSize);
DataHandler dataHandler = null;
// try {
// dataHandler = CommonUtil.makeDataHandler(collection, tempFile);
// } catch (IOException e) {
// log.error("WSGet failed - Unable to generate temp file", e);
// }
return CommonUtil.transformCollectiontoWSCollection(collection, dataHandler);
}
/**
* Check whether a resource exists at the given path
*
* @param path Path of the resource to be checked
* @return true if a resource exists at the given path, false otherwise.
* @throws org.wso2.carbon.registry.core.exceptions.RegistryException
* if an error occurs
*/
public boolean resourceExists(String path) throws RegistryException{
return getRootRegistry().resourceExists(path);
}
public String put(String s, org.wso2.carbon.registry.api.Resource resource)
throws org.wso2.carbon.registry.api.RegistryException {
return put(s, (Resource) resource);
}
public String put(String suggestedPath, Resource resource) throws RegistryException{
return getRootRegistry().put(suggestedPath,resource);
}
/**
* Adds or updates resources in the registry. If there is no resource at the given path,
* resource is added. If a resource already exist at the given path, it will be replaced with
* the new resource.
*
* @param suggestedPath the path which we'd like to use for the new resource.
* @param wsResource WSResource instance for the new resource. This will be converted to a Resource instance internally.
* @return the actual path that the server chose to use for our Resource
* @throws org.wso2.carbon.registry.core.exceptions.RegistryException
* @throws java.io.IOException
*/
public String WSput(String suggestedPath, WSResource wsResource) throws RegistryException, IOException{
Object content = CommonUtil.makeBytesFromDataHandler(wsResource);
Resource resource;
if (wsResource.isCollection()) {
resource = CommonUtil.transformWSCollectiontoCollection( wsResource, content);
}
else {
resource = CommonUtil.transformWSResourcetoResource(wsResource, content);
}
return getRootRegistry().put(suggestedPath,resource);
}
/**
* Deletes the resource at the given path. If the path refers to a directory, all child
* resources of the directory will also be deleted.
*
* @param path Path of the resource to be deleted.
* @throws RegistryException is thrown depending on the implementation.
*/
public void delete(String path) throws RegistryException{
getRootRegistry().delete(path);
}
public String importResource(String suggestedPath,
String sourceURL,
Resource metadata) throws RegistryException {
return getRootRegistry().importResource(suggestedPath,sourceURL,metadata);
}
/**
* Creates a resource by fetching the resource content from the given URL.
*
* @param suggestedPath path where we'd like to add the new resource. Although this path is
* specified by the caller of the method, resource may not be actually
* added at this path.
* @param sourceURL where to fetch the resource content
* @param metadata a WSResource instance containing meta data parameters
* @return actual path to the new resource
* @throws RegistryException if we couldn't get or store the new resource
*/
public String WSimportResource(String suggestedPath,
String sourceURL,
WSResource metadata) throws RegistryException {
return getRootRegistry().importResource(suggestedPath, sourceURL, CommonUtil.transformWSResourcetoResource(metadata, null));
}
/**
* Move or 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.
*
* @param currentPath current path of the resource
* @param newName where we'd like to move the reosurce
* @return the actual path for the new resource
* @throws RegistryException if something went wrong
*/
public String rename(String currentPath, String newName) throws RegistryException{
return getRootRegistry().rename(currentPath, newName);
}
/**
* Move or 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.
*
* @param currentPath current path of the resource
* @param newPath where we'd like to move the reosurce
* @return the actual path for the new resource
* @throws RegistryException if something went wrong
*/
public String move(String currentPath, String newPath) throws RegistryException{
return getRootRegistry().move(currentPath,newPath);
}
/**
* Copy a resource in the registry. The operation is atomic, so if the resource was a
* collection, all children and the collection would be copied in a single-go.
*
* @param sourcePath current path of the resource
* @param targetPath where we'd like to copy the resource
*
* @return the actual path for the new resource
* @throws RegistryException if something went wrong
*/
public String copy(String sourcePath, String targetPath) throws RegistryException{
return getRootRegistry().copy(sourcePath,targetPath);
}
/**
* Creates a new version of the resource.
*
* @param path the resource path.
*
* @throws RegistryException if something went wrong.
*/
public void createVersion(String path) throws RegistryException{
getRootRegistry().createVersion(path);
}
/**
* Get a list of all versions of the resource located at the given path. Version paths are
* returned in the form /projects/myresource?v=12
*
* @param path path of a current version of a resource
* @return a String array containing the individual paths of versions
* @throws RegistryException if there is an error
*/
public String[] getVersions(String path) throws RegistryException{
return getRootRegistry().getVersions(path);
}
/**
* Reverts a resource to a given version.
*
* @param versionPath path of the version to be reverted. It is not necessary to provide the
* path of the resource as it can be derived from the version path.
* @throws RegistryException if there is an error
*/
public void restoreVersion(String versionPath) throws RegistryException{
getRootRegistry().restoreVersion(versionPath);
}
////////////////////////////////////////////////////////
// Associations
////////////////////////////////////////////////////////
/**
* Adds an association stating that the resource at "associationPath" associate on the resource at
* "associationPath". Paths may be the resource paths of the current versions or paths of the old
* versions. If a path refers to the current version, it should contain the path in the form
* /c1/c2/r1. If it refers to an old version, it should be in the form /c1/c2/r1?v=2.
*
* @param sourcePath Path of the source resource
* @param targetPath Path of the target resource
* @param associationType Type of the association
* @throws RegistryException Depends on the implementation
*/
public void addAssociation(String sourcePath,
String targetPath,
String associationType) throws RegistryException{
getRootRegistry().addAssociation(sourcePath,targetPath,associationType);
}
/**
* To remove an association for a given resource
*
* @param sourcePath Path of the source resource
* @param targetPath Path of the target resource
* @param associationType Type of the association
* @throws RegistryException Depends on the implementation
*/
public void removeAssociation(String sourcePath,
String targetPath,
String associationType) throws RegistryException{
getRootRegistry().removeAssociation(sourcePath,targetPath,associationType);
}
/**
* Get all associations of the given resource. This is a chain of association starting from the
* given resource both upwards (source to destination) and downwards (destination to source). T
* his is useful to analyse how changes to other resources would affect the
* given resource.
*
* @param resourcePath Path of the resource to analyse associations.
* @return List of Association
* @throws RegistryException : If something went wrong
*/
public Association[] getAllAssociations(String resourcePath) throws RegistryException{
return getRootRegistry().getAllAssociations(resourcePath);
}
/**
* This is the web service friendly version of getAllAssociations(String resourcePath) method
* @param resoucePath path of resource
* @return WSAssociation
* @throws RegistryException
*/
public WSAssociation[] WSgetAllAssociations(String resoucePath) throws RegistryException {
Association[] associations = getRootRegistry().getAllAssociations(resoucePath);
WSAssociation[] wsAssociations = new WSAssociation[associations.length];
for (int i = 0; i < wsAssociations.length; i++) {
wsAssociations[i] = CommonUtil.transformAssociationToWSAssociation(associations[i]);
}
return wsAssociations;
}
/**
* Get all associations of the given resource for a give association type.
* This is a chain of association starting from the
* given resource both upwards (source to destination) and downwards (destination to source). T
* his is useful to analyse how changes to other resources would affect the
* given resource.
*
* @param resourcePath Path of the resource to analyse associations.
* @param associationType : Type of the association , that could be dependecy , or some other type
* @return List of Association
* @throws RegistryException : If something went wrong
*/
public Association[] getAssociations(String resourcePath, String associationType)
throws RegistryException {
return getRootRegistry().getAssociations(resourcePath, associationType);
}
/**
* This is the web service friendly version of getAssociations(resourcePath, associationType)
* method
* @param resourcePath
* @param associationType
* @return WSAssociation
* @throws RegistryException
*/
public WSAssociation[] WSgetAssociations(String resourcePath, String associationType)
throws RegistryException {
Association[] associations = getRootRegistry().getAssociations(resourcePath, associationType);
WSAssociation[] wsAssociations = new WSAssociation[associations.length];
for (int i = 0; i < wsAssociations.length; i++) {
wsAssociations[i] = CommonUtil.transformAssociationToWSAssociation(associations[i]);
}
return wsAssociations;
}
////////////////////////////////////////////////////////
// Tagging
////////////////////////////////////////////////////////
/**
* Applies the given tag to the resource in the given path. If the given tag is not defined in
* the registry, it will be defined.
*
* @param resourcePath Path of the resource to be tagged.
* @param tag Tag. Any string can be used for the tag.
* @throws RegistryException is thrown if a resource does not exist in the given path.
*/
public void applyTag(String resourcePath, String tag) throws RegistryException{
getRootRegistry().applyTag(resourcePath,tag);
}
public TaggedResourcePath[] getResourcePathsWithTag(String tag) throws RegistryException{
return getRootRegistry().getResourcePathsWithTag(tag);
}
/**
* Returns the paths of all Resources that are tagged with the given tag.
*
* @param tag the tag to search for
* @return an array of WSTaggedResourcePaths
* @throws RegistryException if an error occurs
*/
public WSTaggedResourcePath[] WSgetResourcePathsWithTag(String tag)throws RegistryException{
return CommonUtil.exchangeTaggedResourcepath(getRootRegistry().getResourcePathsWithTag(tag));
}
/**
* Returns all tags used for tagging the given resource.
*
* @param resourcePath Path of the resource
* @return Tags tag names
* @throws RegistryException is thrown if a resource does not exist in the given path.
*/
public Tag[] getTags(String resourcePath) throws RegistryException{
return getRootRegistry().getTags(resourcePath);
}
/**
* This is the web service friendly version of getTags(String resourcePath) method
* @param resourcePath
* @return WSTag
* @throws RegistryException
*/
public WSTag[] WSgetTags(String resourcePath) throws RegistryException {
Tag[] tags = getRootRegistry().getTags(resourcePath);
WSTag[] wsTags = new WSTag[tags.length];
for (int i = 0; i < wsTags.length; i++) {
wsTags[i] = CommonUtil.transformTagToWSTag(tags[i]);
}
return wsTags;
}
/**
* Removes a tag on a resource. If the resource at the path is owned by the current user, all
* taggings done using the given tag will be removed. If the resource is not owned by the
* current user, only the tagging done by the current user will be removed.
*
* @param path Resource path tagged with the given tag.
* @param tag Name of the tag to be removed.
* @throws RegistryException if there's a problem
*/
public void removeTag(String path, String tag) throws RegistryException{
getRootRegistry().removeTag(path,tag);
}
public String addComment(String s, org.wso2.carbon.registry.api.Comment comment)
throws org.wso2.carbon.registry.api.RegistryException {
return addComment(s, (Comment) comment);
}
////////////////////////////////////////////////////////
// Comments
////////////////////////////////////////////////////////
public String addComment(String resourcePath, Comment comment) throws RegistryException{
return getRootRegistry().addComment(resourcePath,comment);
}
/**
* Adds a comment to a resource.
*
* @param resourcePath Path of the resource to add the comment.
* @param comment WSComment instance for the new comment. This will be converted to a Comment instance internally.
* @return the path of the new comment.
* @throws RegistryException is thrown if a resource does not exist in the given path.
*/
public String WSaddComment(String resourcePath, WSComment comment) throws RegistryException{
return getRootRegistry().addComment(resourcePath,CommonUtil.WSCommenttoRegistryComment(comment));
}
/**
* Change the text of an existing comment.
*
* @param commentPath path to comment resource ("..foo/r1;comment:1")
* @param text new text for the comment.
* @throws RegistryException Registry implementations may handle exceptions and throw
* RegistryException if the exception has to be propagated to the
* client.
*/
public void editComment(String commentPath, String text) throws RegistryException{
getRootRegistry().editComment(commentPath,text);
}
public Comment[] getComments(String resourcePath) throws RegistryException{
return getRootRegistry().getComments(resourcePath);
}
/**
* Get all comments for the given resource.
*
* @param resourcePath path of the resource.
* @return an array of WSComment objects.
* @throws RegistryException Registry implementations may handle exceptions and throw
* RegistryException if the exception has to be propagated to the
* client.
*/
public WSComment[] WSgetComments(String resourcePath) throws RegistryException{
Comment[] rcomment = getRootRegistry().getComments(resourcePath);
WSComment[] wscomment = new WSComment[rcomment.length];
for(int i=0;i<rcomment.length;i++){
wscomment[i] = new WSComment();
wscomment[i] = CommonUtil.RegistryCommenttoWSComment(rcomment[i]);
}
return wscomment;
}
/**
* Get the comment for the given comment path.
*
* @param commentPath path of the resource.
* @return a WSComment.
* @throws RegistryException Registry implementations may handle exceptions and throw
* RegistryException if the exception has to be propagated to the
* client.
*/
public WSComment WSgetSingleComment(String commentPath) throws RegistryException {
Comment comment = (Comment) getRootRegistry().get(commentPath);
return CommonUtil.RegistryCommenttoWSComment(comment);
}
////////////////////////////////////////////////////////
// Ratings
////////////////////////////////////////////////////////
/**
* Rate the given resource.
*
* @param resourcePath Path of the resource.
* @param rating Rating value between 1 and 5.
* @throws RegistryException Registry implementations may handle exceptions and throw
* RegistryException if the exception has to be propagated to the
* client.
*/
public void rateResource(String resourcePath, int rating) throws RegistryException{
getRootRegistry().rateResource(resourcePath,rating);
}
/**
* Returns the average rating for the given resource. This is the average of all ratings done by
* all users for the given resource.
*
* @param resourcePath Path of the resource.
* @return Average rating between 1 and 5.
* @throws RegistryException if an error occurs
*/
public float getAverageRating(String resourcePath) throws RegistryException{
return getRootRegistry().getAverageRating(resourcePath);
}
/**
* Returns the rating given to the specified resource by the given user
*
* @param path Path of the resource
* @param userName username of the user
* @return rating given by the given user
* @throws RegistryException if there is a problem
*/
public int getRating(String path, String userName) throws RegistryException{
return getRootRegistry().getRating(path,userName);
}
public Collection executeQuery(String path, Map parameters) throws RegistryException{
return getRootRegistry().executeQuery(path,parameters);
}
/**
* Executes a custom query which lives at the given path in the Registry.
*
* @param path Path of the query to execute.
* @param key an array of String containing key parameters. These should correspond with the value parameters (key -> value)
* @param value an array of String containing value parameters to the corresponding key parameters (key -> value)
* @return a Collection containing any resource paths which match the query
* @throws RegistryException depends on the implementation.
*/
public WSCollection WSexecuteQuery(String path, String[] key,String[] value) throws RegistryException{
Collection collection = getRootRegistry().executeQuery(path, CommonUtil.createMap(key,value));
DataHandler dataHandler = null;
// try {
// dataHandler = CommonUtil.makeDataHandler(collection, tempFile);
// } catch (IOException e) {
// log.error("WSGet failed - Unable to generate temp file", e);
// }
WSCollection wsCollection =
CommonUtil.transformCollectiontoWSCollection(collection, dataHandler);
wsCollection.setChildCount(collection.getChildCount());
wsCollection.setChildren(collection.getChildren());
return wsCollection;
}
/**
* Returns the logs of the activities occurred in the Registry.
*
* @see LogEntry Accepted values for action parameter
*
* @param resourcePath If given, only the logs related to the resource path will be returned. If
* null, logs for all resources will be returned.
* @param action Only the logs pertaining to this action will be returned. For
* acceptable values, see LogEntry.
* @param userName If given, only the logs for activities done by the given user will be
* returned. If null, logs for all users will be returned.
* @param from If given, logs for activities occurred after the given date will be
* returned. If null, there will not be a bound for the starting date.
* @param to If given, logs for activities occurred before the given date will be
* returned. If null, there will not be a bound for the ending date.
* @param recentFirst If true, returned activities will be most-recent first. If false,
* returned activities will be oldest first.
* @return Array of LogEntry objects representing the logs
* @throws RegistryException if there is a problem
*/
public LogEntry[] getLogs(String resourcePath,
int action,
String userName,
Date from,
Date to,
boolean recentFirst) throws RegistryException{
return getRootRegistry().getLogs(resourcePath,action,userName,from,to,recentFirst);
}
/**
* This is the web service compatible version of getLogs() method
* @param resourcePath
* @param action
* @param userName
* @param from
* @param to
* @param recentFirst
* @return WSLogEntry
* @throws RegistryException
*/
public WSLogEntry[] WSgetLogs(String resourcePath,
int action,
String userName,
Date from,
Date to,
boolean recentFirst) throws RegistryException{
LogEntry[] entries =
getRootRegistry().getLogs(resourcePath,action,userName,from,to,recentFirst);
WSLogEntry[] wsEntries = new WSLogEntry[entries.length];
for (int i = 0; i < wsEntries.length; i++) {
wsEntries[i] = CommonUtil.transformLogEntryToWSLogEntry(entries[i]);
}
return wsEntries;
}
/**
* This method is not supported in WS-API
*/
public LogEntryCollection getLogCollection(String resourcePath,
int action,
String userName,
Date from,
Date to,
boolean recentFirst) throws RegistryException{
return getRootRegistry().getLogCollection(resourcePath,action,userName,from,to,recentFirst);
}
/**
* Get a list of the available Aspects for this Registry
* @return a String array containing available Aspect names
*/
public String [] getAvailableAspects(){
return getRootRegistry().getAvailableAspects();
}
/**
* Associate an Aspect with a resource.
*
* @param resourcePath Path of the resource
* @param aspect Name of the aspect
* @throws RegistryException : If some thing went wrong while doing associating the phase
*/
public void associateAspect(String resourcePath, String aspect) throws RegistryException{
getRootRegistry().associateAspect(resourcePath,aspect);
}
/**
* This invokes an action on a specified Aspect, which must be associated with the Resource
* at the given path.
*
* @param resourcePath Path of the resource
* @param aspectName Name of the aspect
* @param action Which action was selected - actions are aspect-specific
* @throws RegistryException if the Aspect isn't associated with the Resource, or the action
* isn't valid, or an Aspect-specific problem occurs.
*/
public void invokeAspectNoParam(String resourcePath, String aspectName, String action)
throws RegistryException{
invokeAspect(resourcePath,aspectName,action);
}
/**
* This invokes an action on a specified Aspect, which must be associated with the Resource
* at the given path.
*
* @param resourcePath Path of the resource
* @param aspectName Name of the aspect
* @param action Which action was selected - actions are aspect-specific
* @throws RegistryException if the Aspect isn't associated with the Resource, or the action
* isn't valid, or an Aspect-specific problem occurs.
*/
public void invokeAspect(String resourcePath, String aspectName, String action)
throws RegistryException{
getRootRegistry().invokeAspect(resourcePath,aspectName,action);
}
/**
* This invokes an action on a specified Aspect, which must be associated with the Resource
* at the given path.
*
* @param resourcePath Path of the resource
* @param aspectName Name of the aspect
* @param action Which action was selected - actions are aspect-specific
* @param parameters Parameters to be used for the operation
* @throws RegistryException if the Aspect isn't associated with the Resource, or the action
* isn't valid, or an Aspect-specific problem occurs.
*/
public void invokeAspect(String resourcePath, String aspectName, String action,
Map<String, String> parameters)
throws RegistryException{
getRootRegistry().invokeAspect(resourcePath,aspectName,action, parameters);
}
/**
* Obtain a list of the available actions on a given resource for a given Aspect. The
* Aspect must be associated with the Resource (@see associateAspect). The actions are
* determined by asking the Aspect itself, so they may change depending on the state of the
* Resource, the user who's asking, etc)
*
* @param resourcePath path of the Resource
* @param aspectName name of the Aspect to query for available actions
* @return a String[] of action names
* @throws RegistryException if the Aspect isn't associated or an Aspect-specific problem occurs
*/
public String[] getAspectActions(String resourcePath, String aspectName)
throws RegistryException{
return getRootRegistry().getAspectActions(resourcePath,aspectName);
}
public void beginTransaction() throws RegistryException{
getRootRegistry().beginTransaction();
}
public void commitTransaction() throws RegistryException{
getRootRegistry().commitTransaction();
}
public void rollbackTransaction() throws RegistryException{
getRootRegistry().rollbackTransaction();
}
public RegistryContext getRegistryContext(){
return getRootRegistry().getRegistryContext();
}
public Collection searchContent(String keywords) throws RegistryException{
return getRootRegistry().searchContent(keywords);
}
/**
* Search the content of resources
*
* @param keywords keywords to look for
* @return the result set as a WSCollection
* @throws org.wso2.carbon.registry.core.exceptions.RegistryException
*/
public WSCollection WSsearchContent(String keywords) throws RegistryException{
Collection collection = getRootRegistry().searchContent(keywords);
DataHandler dataHandler = null;
// try {
// dataHandler = CommonUtil.makeDataHandler(collection, tempFile);
// } catch (IOException e) {
// log.error("WSGet failed - Unable to generate temp file", e);
// }
WSCollection wsCollection =
CommonUtil.transformCollectiontoWSCollection(collection, dataHandler);
wsCollection.setChildCount(collection.getChildCount());
wsCollection.setChildren(collection.getChildren());
return wsCollection;
}
/**
* Create a symbolic link or mount a registry
*
* @param path the mount path
* @param target the point to be mounted
*/
public void createLink(String path, String target) throws RegistryException{
getRootRegistry().createLink(path, target);
}
public void createLink(String path, String target, String subTargetPath)
throws RegistryException{
getRootRegistry().createLink(path, target, subTargetPath);
}
/**
* Create a symbolic link or mount a registy
*
* @param path the mount path
* @param target the point to be mounted
* @param subTargetPath sub path in the remote instance to be mounted
* @throws org.wso2.carbon.registry.core.exceptions.RegistryException
*/
public void createLinkWithSubTarget(String path, String target, String subTargetPath)
throws RegistryException{
if (subTargetPath == null) {
getRootRegistry().createLink(path, target);
}
getRootRegistry().createLink(path, target, subTargetPath);
}
/**
* Remove a symbolic link or mount point created
*
* @param path the mount path
*/
public void removeLink(String path) throws RegistryException{
getRootRegistry().removeLink(path);
}
public void restore(String path, Reader reader) throws RegistryException {
getRootRegistry().restore(path, reader);
}
public void dump(String path, Writer writer) throws RegistryException {
getRootRegistry().dump(path, writer);
}
/**
* Gets the URL of the WS-Eventing Service.
*
* @param path the path to which the WS-Eventing Service URL is required
*
* @return the URL of the WS-Eventing Service
* @throws RegistryException throws if the operation fail
*/
public String getEventingServiceURL(String path) throws RegistryException {
return getRootRegistry().getEventingServiceURL(path);
}
/**
* Sets the URL of the WS-Eventing Service.
*
* @param path the path to which the WS-Eventing Service URL is associated
* @param eventingServiceURL the URL of the WS-Eventing Service
*
* @throws RegistryException throws if the operation fail
*/
public void setEventingServiceURL(String path, String eventingServiceURL) throws RegistryException {
getRootRegistry().setEventingServiceURL(path, eventingServiceURL);
}
/**
* Remove the given aspect from registry context.
*
* @param name the name of the aspect to be removed
*
* @return return true if the operation finished successful, false otherwise.
* @throws RegistryException throws if the operation fail
*/
public boolean removeAspect(String name)throws RegistryException{
return getRootRegistry().removeAspect(name);
}
public boolean addAspect(String name, Aspect aspect)throws RegistryException{
return getRootRegistry().removeAspect(name);
}
/**
* Delete an existing comment.
*
* @param commentPath path to comment resource ("..foo/r1;comment:1")
*
* @throws RegistryException Registry implementations may handle exceptions and throw
* RegistryException if the exception has to be propagated to the
* client.
*/
public void removeComment(String commentPath) throws RegistryException {
getRootRegistry().removeComment(commentPath);
}
/**
* Returns content of a Resource at the specified path. Used by the Registry Web Service client to fetch resource content only when requested.
* @param path Path of the resource
* @return data handler that is compatible with web services
* @throws RegistryException
*/
// Used to provide content on demand - for resources
public DataHandler getContent(String path) throws RegistryException {
DataHandler dataHandler = null;
try {
dataHandler = CommonUtil.makeDataHandler(getRootRegistry().get(path), tempFile);
} catch (IOException e) {
log.error("get Content failed - Unable to generate temp file", e);
}
return dataHandler;
}
/**
* Returns content of a specific Collection. Used by the Registry Web Service client to fetch collection content only when requested.
* @param path Path of the resource
* @return String array with the content
* @throws RegistryException
*/
// Used to provide content on demand - for Collection
public String[] getCollectionContent(String path) throws RegistryException {
Object collectionContent = getRootRegistry().get(path).getContent();
if (!(collectionContent instanceof String[])) {
throw new RegistryException("This method only provides content for a Collection. It has been accessed by a Resource");
}
return (String[])collectionContent;
}
/**
* @param path resource path
* @return child count inside the resource
* @throws RegistryException
*/
public int getChildCount(String path) throws RegistryException {
int count = 0;
Collection collection = (Collection) getRootRegistry().get(path);
if (collection != null) {
count = collection.getChildCount();
}
return count;
}
}