org.wso2.carbon.registry.core.utils
Class RegistryUtils

java.lang.Object
  extended by org.wso2.carbon.registry.core.utils.RegistryUtils

public final class RegistryUtils
extends Object

This class contains a set of useful utility methods used by the Registry Kernel. These can also be used by third party components as well as the various clients written to access the registry via its remote APIs.


Method Summary
static void addBaseCollectionStructure(Registry registry, org.wso2.carbon.user.core.UserRealm userRealm)
          This method builds the base collection structure for the registry.
static void addCarbonRootCollection(Registry userRegistry, org.wso2.carbon.user.core.UserRealm userRealm)
          Deprecated. 
static void addMountCollection(Registry registry)
          Method to add the collection where the mount information is stored.
static void addMountEntry(Registry registry, RegistryContext registryContext, String path, String target, boolean remote, String author)
          Method to add a mount entry.
static void addMountEntry(Registry registry, RegistryContext registryContext, String path, String target, String targetSubPath, String author)
          Method to add a mount entry.
static void addRootCollectionAuthorization(org.wso2.carbon.user.core.UserRealm userRealm)
          Deprecated. 
static void addServiceConfigResources(Registry registry)
          Method to add the resources where the service configuration are stored.
static void addServiceStoreCollection(Registry registry, String servicePath)
          Method to add the collection where the services are stored.
static void addSystemCollection(Registry registry, org.wso2.carbon.user.core.UserRealm userRealm)
          Deprecated. 
static void addTenantsCollection(Registry registry, org.wso2.carbon.user.core.UserRealm userRealm)
          Deprecated. 
static void addUserProfileCollection(Registry registry, String profilesPath)
          Method to add the collection where the user profiles are stored.
static RegistryCacheKey buildRegistryCacheKey(String connectionId, int tenantId, String resourcePath)
          Builds the cache key for a resource path.
static String concatenateChroot(String chroot1, String chroot2)
          Method to concatenate two chroot paths.
static boolean containsAsSubString(String value, String[] array)
          Method to determine whether the given array of strings contains a string which has the given string as a portion (sub-string) of it.
static boolean containsString(String value, String[] array)
          Method to determine whether the given array of strings contains the given string.
static String decodeBytes(byte[] byteContent)
           
static byte[] encodeString(String content)
           
static String getAbsoluteAssociationPath(String path, String referencePath)
          Calculate the absolute associations path if a relative path is given to the reference path.
static String getAbsolutePath(RegistryContext context, String relativePath)
          Method to obtain the absolute path for the given relative path.
static String getAbsolutePathToOriginal(String relativePath, String originalPath)
          Method to obtain the path absolute to the given path.
static org.wso2.carbon.user.core.UserRealm getBootstrapRealm()
          Deprecated. 
static org.wso2.carbon.user.core.UserRealm getBootstrapRealm(org.wso2.carbon.user.core.service.RealmService realmService)
          This method returns the bootstrap (or initial) user realm from the realm service.
static byte[] getByteArray(InputStream inputStream)
          Convert an input stream into a byte array.
static String getConnectionId(Connection connection)
          Method to obtain a unique identifier for the database connection.
static String getExtensionLibDirectoryPath()
           
static InputStream getMemoryStream(InputStream inputStream)
          Create an in-memory input stream for the given input stream.
static URLMatcher getMountingMatcher(String path)
          Method to obtain the filter used with the mounting handler.
static String[] getMountingMethods()
          Utility method obtain the list of operations supported by the mount handler.
static String getParentPath(String resourcePath)
          Method to obtain the parent path of the given resource path.
static String getPureResourcePath(String resourcePath)
          All "valid" paths pure resources should be in the form /c1/c2/r1.
static String getRelativeAssociationPath(String path, String referencePath)
          Calculate the relative associations path to the reference path if an absolute path is given.
static String getRelativePath(RegistryContext context, String absolutePath)
          Method to obtain the relative path for the given absolute path.
static String getRelativePathToOriginal(String absolutePath, String originalPath)
          Method to obtain the path relative to the given path.
static javax.cache.Cache<RegistryCacheKey,org.wso2.carbon.registry.api.GhostResource> getResourceCache(String name)
          Method used to retrieve cache object for resources
static String getResourceName(String resourcePath)
          Returns resource name when full resource path is passed.
static javax.cache.Cache<RegistryCacheKey,RegistryCacheEntry> getResourcePathCache(String name)
          Method used to retrieve cache object for resource paths.
static ResourceImpl getResourceWithMinimumData(String path, ResourceDAO resourceDAO, boolean versioned)
          Gets the resource with sufficient data to differentiate it from another resource.
static Registry getSystemRegistry(Registry coreRegistry)
          this method can only be called if the registry context is initialized.
static String getUnChrootedPath(String path)
          Method to obtain the unchrooted path for the given relative path.
static javax.cache.Cache<String,String> getUUIDCache(String name)
          Method used to retrieve cache object for UUID, resource paths.
static VersionedPath getVersionedPath(ResourcePath resourcePath)
          Paths referring to a version of a resource are in the form /c1/c2/r1?v=2.
static boolean hasAdminAuthorizations(String userName, org.wso2.carbon.user.core.UserRealm userRealm)
          Method to determine whether the given user is in an admin role.
static void initializeTenant(RegistryService registryService, int tenantId)
           
static boolean isHiddenProperty(String propertyName)
          Method to determine whether a property is a hidden property or not.
static boolean isRegistryReadOnly(RegistryContext registryContext)
          Method to determine whether this registry is running in Read-Only mode.
static Class loadClass(String name)
          Load the class with the given name
static String prepareGeneralPath(String rawPath)
          Prepare the given path as a general resource path to be used in the registry.
static void recordStatistics(Object... parameters)
          Method to record statistics.
static void redirect(javax.servlet.http.HttpServletResponse response, String url)
          Method to redirect a given response to some URL.
static void registerHandlerForRemoteLinks(RegistryContext registryContext, String path, String target, String targetSubPath, String author)
          Method to register handlers for remote links for the tenant on the current registry session.
static void registerHandlerForRemoteLinks(RegistryContext registryContext, String path, String target, String targetSubPath, String author, boolean forAllTenants)
          Method to register handlers for remote links.
static void registerHandlerForSymbolicLinks(RegistryContext context, String path, String target, String author)
          Method to register handlers for symbolic links for the tenant on the current registry session.
static void registerMountPoints(Registry systemRegistry, int tenantId)
          Method to register mount points.
static org.apache.axiom.om.OMElement removeAuthorUpdaterFromDump(org.apache.axiom.om.OMElement root)
          Method to remove the author and updater from a dump.
static void setTrustStoreSystemProperties()
          Set-up the system properties required to access the trust-store in Carbon.
static void setupMediaTypes(RegistryService registryService, int tenantId)
           
static boolean systemResourceShouldBeAdded(Registry registry, String absolutePath)
          Method to determine whether a system resource (or collection) is existing or whether it should be created.
static boolean systemResourceShouldBeAdded(ResourceDAO dataAccessObject, String absolutePath)
          Method to determine whether a system resource (or collection) is existing or whether it should be created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getVersionedPath

public static VersionedPath getVersionedPath(ResourcePath resourcePath)
Paths referring to a version of a resource are in the form /c1/c2/r1?v=2. Give a such version path, this method extracts the valid pure path and the version number of the resource. Note that this method should only be used for pure resource paths.

Parameters:
resourcePath - versioned resource path.
Returns:
VersionPath object containing the valid resource path and the version number.

getByteArray

public static byte[] getByteArray(InputStream inputStream)
                           throws RegistryException
Convert an input stream into a byte array.

Parameters:
inputStream - the input stream.
Returns:
the byte array.
Throws:
RegistryException - if the operation failed.

getMemoryStream

public static InputStream getMemoryStream(InputStream inputStream)
                                   throws RegistryException
Create an in-memory input stream for the given input stream.

Parameters:
inputStream - the input stream.
Returns:
the in-memory input stream.
Throws:
RegistryException - if the operation failed.

getConnectionId

public static String getConnectionId(Connection connection)
Method to obtain a unique identifier for the database connection.

Parameters:
connection - the database connection.
Returns:
the unique identifier.

buildRegistryCacheKey

public static RegistryCacheKey buildRegistryCacheKey(String connectionId,
                                                     int tenantId,
                                                     String resourcePath)
Builds the cache key for a resource path.

Parameters:
connectionId - the database connection identifier
tenantId - the tenant identifier
resourcePath - the resource path
Returns:
the cache key.

getPureResourcePath

public static String getPureResourcePath(String resourcePath)
All "valid" paths pure resources should be in the form /c1/c2/r1. That is they should start with "/" and should not end with "/". Given a path of a pure resource, this method prepares the valid path for that path.

Parameters:
resourcePath - Path of a pure resource.
Returns:
Valid path of the pure resource.

getResourceCache

public static javax.cache.Cache<RegistryCacheKey,org.wso2.carbon.registry.api.GhostResource> getResourceCache(String name)
Method used to retrieve cache object for resources

Parameters:
name - the name of the cache
Returns:
the cache object for the given cache manger and cache name

getResourcePathCache

public static javax.cache.Cache<RegistryCacheKey,RegistryCacheEntry> getResourcePathCache(String name)
Method used to retrieve cache object for resource paths.

Parameters:
name - the name of the cache
Returns:
the cache object for the given cache manger and cache name

getUUIDCache

public static javax.cache.Cache<String,String> getUUIDCache(String name)
Method used to retrieve cache object for UUID, resource paths.

Parameters:
name - the name of the cache
Returns:
the cache object for the given cache manger and cache name

getParentPath

public static String getParentPath(String resourcePath)
Method to obtain the parent path of the given resource path.

Parameters:
resourcePath - the resource path.
Returns:
the parent path.

getResourceName

public static String getResourceName(String resourcePath)
Returns resource name when full resource path is passed.

Parameters:
resourcePath - full resource path.
Returns:
the resource name.

redirect

public static void redirect(javax.servlet.http.HttpServletResponse response,
                            String url)
Method to redirect a given response to some URL.

Parameters:
response - the HTTP Response.
url - The URL to redirect to.

prepareGeneralPath

public static String prepareGeneralPath(String rawPath)
Prepare the given path as a general resource path to be used in the registry. General resource paths may refer to pure resources or virtual resources.

Parameters:
rawPath - Raw path to be prepared
Returns:
Prepared general resource path

hasAdminAuthorizations

public static boolean hasAdminAuthorizations(String userName,
                                             org.wso2.carbon.user.core.UserRealm userRealm)
                                      throws RegistryException
Method to determine whether the given user is in an admin role.

Parameters:
userName - the user name.
userRealm - the user realm.
Returns:
true if the user is in the admin role, or false otherwise.
Throws:
RegistryException - if the operation failed.

containsString

public static boolean containsString(String value,
                                     String[] array)
Method to determine whether the given array of strings contains the given string.

Parameters:
value - the string to search.
array - the array of string.
Returns:
whether the given string was found.

containsAsSubString

public static boolean containsAsSubString(String value,
                                          String[] array)
Method to determine whether the given array of strings contains a string which has the given string as a portion (sub-string) of it.

Parameters:
value - the string to search.
array - the array of string.
Returns:
whether the given string was found.

removeAuthorUpdaterFromDump

public static org.apache.axiom.om.OMElement removeAuthorUpdaterFromDump(org.apache.axiom.om.OMElement root)
Method to remove the author and updater from a dump.

Parameters:
root - the input XML element.
Returns:
the output which contains the input XML element, but without details of the author and the updater.

addRootCollectionAuthorization

@Deprecated
public static void addRootCollectionAuthorization(org.wso2.carbon.user.core.UserRealm userRealm)
                                           throws RegistryException
Deprecated. 

Throws:
RegistryException

setTrustStoreSystemProperties

public static void setTrustStoreSystemProperties()
Set-up the system properties required to access the trust-store in Carbon. This is used in the atom-based Remote Registry implementation.


systemResourceShouldBeAdded

public static boolean systemResourceShouldBeAdded(Registry registry,
                                                  String absolutePath)
                                           throws RegistryException
Method to determine whether a system resource (or collection) is existing or whether it should be created. Once it has been identified that a system collection is existing, it will not be checked against a database until the server has been restarted.

Parameters:
registry - the base registry to use.
absolutePath - the absolute path of the system resource (or collection)
Returns:
whether the system resource (or collection) needs to be added.
Throws:
RegistryException - if an error occurred.

systemResourceShouldBeAdded

public static boolean systemResourceShouldBeAdded(ResourceDAO dataAccessObject,
                                                  String absolutePath)
                                           throws RegistryException
Method to determine whether a system resource (or collection) is existing or whether it should be created. Once it has been identified that a system collection is existing, it will not be checked against a database until the server has been restarted.

Parameters:
dataAccessObject - the resource data access object.
absolutePath - the absolute path of the system resource (or collection)
Returns:
whether the system resource (or collection) needs to be added.
Throws:
RegistryException - if an error occurred.

addBaseCollectionStructure

public static void addBaseCollectionStructure(Registry registry,
                                              org.wso2.carbon.user.core.UserRealm userRealm)
                                       throws RegistryException
This method builds the base collection structure for the registry. The base _system collection, and the remaining local, config and governance collections will be created as a result.

Parameters:
registry - the base registry to use.
userRealm - the user realm.
Throws:
RegistryException - if an error occurred.

addSystemCollection

@Deprecated
public static void addSystemCollection(Registry registry,
                                                  org.wso2.carbon.user.core.UserRealm userRealm)
                                throws RegistryException
Deprecated. 

Throws:
RegistryException

addCarbonRootCollection

@Deprecated
public static void addCarbonRootCollection(Registry userRegistry,
                                                      org.wso2.carbon.user.core.UserRealm userRealm)
                                    throws RegistryException
Deprecated. 

Throws:
RegistryException

addTenantsCollection

@Deprecated
public static void addTenantsCollection(Registry registry,
                                                   org.wso2.carbon.user.core.UserRealm userRealm)
                                 throws RegistryException
Deprecated. 

Throws:
RegistryException

addUserProfileCollection

public static void addUserProfileCollection(Registry registry,
                                            String profilesPath)
                                     throws RegistryException
Method to add the collection where the user profiles are stored.

Parameters:
registry - the registry to use.
profilesPath - the path at which user profiles are stored.
Throws:
RegistryException - if an error occurred.

addServiceStoreCollection

public static void addServiceStoreCollection(Registry registry,
                                             String servicePath)
                                      throws RegistryException
Method to add the collection where the services are stored.

Parameters:
registry - the registry to use.
servicePath - the path at which services are stored.
Throws:
RegistryException - if an error occurred.

addMountCollection

public static void addMountCollection(Registry registry)
                               throws RegistryException
Method to add the collection where the mount information is stored.

Parameters:
registry - the registry to use.
Throws:
RegistryException - if an error occurred.

registerMountPoints

public static void registerMountPoints(Registry systemRegistry,
                                       int tenantId)
                                throws RegistryException
Method to register mount points.

Parameters:
systemRegistry - the registry to use.
tenantId - the identifier of the tenant.
Throws:
RegistryException - if an error occurred.

getMountingMatcher

public static URLMatcher getMountingMatcher(String path)
Method to obtain the filter used with the mounting handler.

Parameters:
path - the path at which the mount was added.
Returns:
the built filter instance.

setupMediaTypes

public static void setupMediaTypes(RegistryService registryService,
                                   int tenantId)

initializeTenant

public static void initializeTenant(RegistryService registryService,
                                    int tenantId)
                             throws RegistryException
Throws:
RegistryException

getMountingMethods

public static String[] getMountingMethods()
Utility method obtain the list of operations supported by the mount handler.

Returns:
the list of operations.

addServiceConfigResources

public static void addServiceConfigResources(Registry registry)
                                      throws RegistryException
Method to add the resources where the service configuration are stored.

Parameters:
registry - the registry to use.
Throws:
RegistryException - if an error occurred.

concatenateChroot

public static String concatenateChroot(String chroot1,
                                       String chroot2)
Method to concatenate two chroot paths.

Parameters:
chroot1 - the base chroot path (or the registry root).
chroot2 - the the relative chroot path.
Returns:
the full chroot path.

isRegistryReadOnly

public static boolean isRegistryReadOnly(RegistryContext registryContext)
Method to determine whether this registry is running in Read-Only mode.

Parameters:
registryContext - the registry context.
Returns:
true if read-only or false otherwise.

getSystemRegistry

public static Registry getSystemRegistry(Registry coreRegistry)
                                  throws RegistryException
this method can only be called if the registry context is initialized.

Parameters:
coreRegistry - the core registry instance.
Returns:
the user registry instance for the special system user.
Throws:
RegistryException - if the operation failed.

getBootstrapRealm

@Deprecated
public static org.wso2.carbon.user.core.UserRealm getBootstrapRealm()
                                                             throws RegistryException
Deprecated. 

This method returns the bootstrap (or initial) user realm. You can call this function only if the registry context is initialized

Returns:
the bootstrap realm.
Throws:
RegistryException - if the operation failed.

recordStatistics

public static void recordStatistics(Object... parameters)
Method to record statistics.

Parameters:
parameters - The parameters to be passed to the statistics collector interface. Generally, it is expected that each method invoking this method will pass all relevant parameters such that the statistics collectors can examine them as required.

getBootstrapRealm

public static org.wso2.carbon.user.core.UserRealm getBootstrapRealm(org.wso2.carbon.user.core.service.RealmService realmService)
                                                             throws RegistryException
This method returns the bootstrap (or initial) user realm from the realm service.

Parameters:
realmService - the OSGi service which we can use to obtain the user realm.
Returns:
the bootstrap realm.
Throws:
RegistryException - if the operation failed.

getUnChrootedPath

public static String getUnChrootedPath(String path)
Method to obtain the unchrooted path for the given relative path.

Parameters:
path - the relative path.
Returns:
the unchrooted path.

getRelativePath

public static String getRelativePath(RegistryContext context,
                                     String absolutePath)
Method to obtain the relative path for the given absolute path.

Parameters:
context - the registry context.
absolutePath - the absolute path.
Returns:
the relative path.

getAbsolutePath

public static String getAbsolutePath(RegistryContext context,
                                     String relativePath)
Method to obtain the absolute path for the given relative path.

Parameters:
context - the registry context.
relativePath - the relative path.
Returns:
the absolute path.

getRelativePathToOriginal

public static String getRelativePathToOriginal(String absolutePath,
                                               String originalPath)
Method to obtain the path relative to the given path.

Parameters:
absolutePath - the absolute path.
originalPath - the path to which we need to make the given absolute path a relative one.
Returns:
the relative path.

getAbsolutePathToOriginal

public static String getAbsolutePathToOriginal(String relativePath,
                                               String originalPath)
Method to obtain the path absolute to the given path.

Parameters:
relativePath - the relative path.
originalPath - the path to which we need to make the given relative path a absolute one.
Returns:
the absolute path.

registerHandlerForSymbolicLinks

public static void registerHandlerForSymbolicLinks(RegistryContext context,
                                                   String path,
                                                   String target,
                                                   String author)
                                            throws RegistryException
Method to register handlers for symbolic links for the tenant on the current registry session.

Parameters:
context - the registry context.
path - the path at which the symbolic link is created.
target - the target path.
author - the creator of the symbolic link.
Throws:
RegistryException - if the operation failed.

registerHandlerForRemoteLinks

public static void registerHandlerForRemoteLinks(RegistryContext registryContext,
                                                 String path,
                                                 String target,
                                                 String targetSubPath,
                                                 String author)
                                          throws RegistryException
Method to register handlers for remote links for the tenant on the current registry session.

Parameters:
registryContext - the registry context.
path - the path at which the remote link is created.
target - the target path.
targetSubPath - the target sub-path.
author - the creator of the remote link.
Throws:
RegistryException - if the operation failed.

registerHandlerForRemoteLinks

public static void registerHandlerForRemoteLinks(RegistryContext registryContext,
                                                 String path,
                                                 String target,
                                                 String targetSubPath,
                                                 String author,
                                                 boolean forAllTenants)
                                          throws RegistryException
Method to register handlers for remote links.

Parameters:
registryContext - the registry context.
path - the path at which the remote link is created.
target - the target path.
targetSubPath - the target sub-path.
author - the creator of the remote link.
forAllTenants - whether the remote link should be added to the tenant on the current registry session or to all the tenants.
Throws:
RegistryException - if the operation failed.

addMountEntry

public static void addMountEntry(Registry registry,
                                 RegistryContext registryContext,
                                 String path,
                                 String target,
                                 String targetSubPath,
                                 String author)
                          throws RegistryException
Method to add a mount entry.

Parameters:
registry - the registry instance to use.
registryContext - the registry context.
path - the source path.
target - the target path or instance.
targetSubPath - the target sub-path.
author - the author
Throws:
RegistryException - if the operation failed.

addMountEntry

public static void addMountEntry(Registry registry,
                                 RegistryContext registryContext,
                                 String path,
                                 String target,
                                 boolean remote,
                                 String author)
                          throws RegistryException
Method to add a mount entry.

Parameters:
registry - the registry instance to use.
registryContext - the registry context.
path - the source path.
target - the target path or instance.
remote - whether local or remote link.
author - the author
Throws:
RegistryException - if the operation failed.

getResourceWithMinimumData

public static ResourceImpl getResourceWithMinimumData(String path,
                                                      ResourceDAO resourceDAO,
                                                      boolean versioned)
                                               throws RegistryException
Gets the resource with sufficient data to differentiate it from another resource. This would populate a ResourceImpl with the path, name and path identifier of a resource.

Parameters:
path - the path of the resource.
resourceDAO - the resource data access object to use.
versioned - whether version or not.
Returns:
the resource with minimum data.
Throws:
RegistryException - if an error occurs while retrieving resource data.

getRelativeAssociationPath

public static String getRelativeAssociationPath(String path,
                                                String referencePath)
Calculate the relative associations path to the reference path if an absolute path is given. This is used in dump.

Parameters:
path - absolute path value.
referencePath - the reference path
Returns:
the relative path

getAbsoluteAssociationPath

public static String getAbsoluteAssociationPath(String path,
                                                String referencePath)
Calculate the absolute associations path if a relative path is given to the reference path. This works only ".." components are there at the very start. This is used in restore.

Parameters:
path - relative path value.
referencePath - the reference path
Returns:
the absolute path

loadClass

public static Class loadClass(String name)
                       throws ClassNotFoundException
Load the class with the given name

Parameters:
name - name of the class
Returns:
java class
Throws:
ClassNotFoundException - if the class does not exists in the classpath

isHiddenProperty

public static boolean isHiddenProperty(String propertyName)
Method to determine whether a property is a hidden property or not.

Parameters:
propertyName - the name of property.
Returns:
true if the property is a hidden property or false if not.

getExtensionLibDirectoryPath

public static String getExtensionLibDirectoryPath()

decodeBytes

public static String decodeBytes(byte[] byteContent)
                          throws RegistryException
Throws:
RegistryException

encodeString

public static byte[] encodeString(String content)
                           throws RegistryException
Throws:
RegistryException


Copyright © 2014 WSO2 Inc. All Rights Reserved.