Package com.j_spaces.kernel
Class ResourceLoader
java.lang.Object
com.j_spaces.kernel.ResourceLoader
The class is responsible on loading the product resources such as space/container/cluster schema
xsl files, static cluster xml files, custom properties files, DCache config files etc.
It also provides the common methods to get the resource InputStream or URL using the current
thread context class loader. The useful methods for such purpose will be:
getResourceStream(String) getResourceURL(String)
TODO currently uses classpath for loading resources. We should provide later capability to load
resources from httpxx and other methods and protocols.- Since:
- 5.2
- Version:
- 1.0
- Author:
- Gershon Diner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class encapsulates schema file properties: InputStream, and full path ( including host IP or name ) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamfindClusterXML(String _clusterXML) Look for the requested cluster XML file in the ResourceBundle (classpath) under/config/ -cluster.xml. static InputStreamfindClusterXSLSchema(InputStream _clusterXMLInputStream) Using the _clusterMembersStream InputStream, we parse the DOM and fetch the value of the <cluster-schema-name> tag.static InputStreamfindClusterXSLSchema(String _clusterXSLSchema) Look for the requested cluster XSL schema file in the ResourceBundle (classpath) under/config/schemas/ -cluster-schema.xsl. static InputStreamfindConfigDCache(String fileName) static InputStreamfindContainerSchema(String schemaName) static InputStreamfindContainerSchema(String schemaName, boolean createIfNotExists) Look for the requested container schema file in the ResourceBundle (classpath) under/config/schemas/ -container-schema.xml. static URLfindContainerXML(String _containerName) Look for the requested container xml file in the classpath (resource) under/config/ .xml. static PropertiesfindCustomPropertiesObj(String schemaPropertiesFileName) Used to load xxx.properties file, parse it and create a Properties object out of it.findSpaceSchema(String _schemaName) Look for the requested space schema file in the ResourceBundle (classpath) under/config/schemas/ -space-schema.xml. static String[]Returns an array of strings naming the schemas in the default ${com.gs.home}/config/schemas directory.static String[]getClusterSchemas(File schemasDir) Returns an array of strings naming the schemas in the specified directory.static InputStreamgetResourceStream(String name) Several attempts to search for the requested resource as an input stream: 1.static InputStreamgetResourceStream(String name, String locatorBaseDir) static InputStreamgetResourceStream(String name, String locatorBaseDir, boolean createIfNotExists) Several attempts to search for the requested resource as an input stream: 1.static URLgetResourceURL(String name) Loads the requested resource and returns its URL.static URLgetResourceURL(String name, String locatorBaseDir) Loads the requested resource and returns its URL.static URLstatic InputStreamresolveClusterXSLSchema(String _clusterMembers) Resolving cluster schema XSL from cluster xml.
-
Constructor Details
-
ResourceLoader
public ResourceLoader()
-
-
Method Details
-
getServicesConfigUrl
-
getResourceStream
-
getResourceStream
public static InputStream getResourceStream(String name, String locatorBaseDir, boolean createIfNotExists) Several attempts to search for the requested resource as an input stream: 1. It calls the (current thread) contextClassLoader.getResource(config/schemas/yyy.xml). if not found --> 1.1 It calls the (current thread) contextClassLoader.getResource(yyy.xml). if not found --> 2. It calls this classLoader.getResource(config/schemas/yyy.xml) (e.g. if running in AppServer) if not found --> 2.1 It calls this classLoader.getResource(yyy.xml) (e.g. if running in AppServer) if not found AND useOnlyClasspath == false (expensive operation!) --> 2.2 if the resource was not found, instead of returning null, we attempt to load it as a File IF it was passed as file format e.g. D:/gigaspaces/GenericJDBCProperties/HSQLProperties/jdbc.properties 3. If Uses the com.gigaspaces.start.Locator.locate(yyy.xml) that searches recursively under the GS, using root file system. Not the default. Some notes: In some scenarios, the ResourceLoader does not use the right class loader and returns no resource. E.g. when running within application server the config and jar files loaded using the Thread.currentThread().getContextClassLoader().getResource() but since the lower level CL is used (of the APPServer) we should try also and use the getClass().getResource() in case the first attempt failed to find the resource. A third attempt, if the resource still was not found will be using the Locator facility that searches for the resource under a base directory in the file system.- Parameters:
name- name of resource to loadlocatorBaseDir- if not null we will try to search for the resource in the file system under the locatorBaseDir as the base search path- Returns:
- InputStream containing the resource
-
getResourceURL
Loads the requested resource and returns its URL. Several attempts to search for the requested resource: 1. It calls the (current thread) contextClassLoader.getResource(config/schemas/yyy.xml). if not found --> 1.1 It calls the (current thread) contextClassLoader.getResource(yyy.xml). if not found --> 2. It calls this classLoader.getResource(config/schemas/yyy.xml) (e.g. if running in AppServer) if not found --> 2.1 It calls this classLoader.getResource(yyy.xml) (e.g. if running in AppServer) if not found AND useOnlyClasspath == false (expensive operation!) --> 2.2 if the resource was not found, instead of returning null, we attempt to load it as a File IF it was passed as file format e.g. D:/gigaspaces/GenericJDBCProperties/HSQLProperties/jdbc.properties 3. Uses the com.gigaspaces.start.Locator.locate(yyy.xml) that searches recursively under the GS, using root file system. Not the default behavior Notes: In some scenarios, the ResourceLoader does not use the right class loader and returns no resource. E.g. when running within application server the config and jar files loaded using the Thread.currentThread().getContextClassLoader().getResource() but since the lower level CL is used (of the APPServer) we should try also and use the getClass().getResource() in case the first attempt failed to find the resource. A third attempt, if the resource still was not found, it will be using the Locator facility that searches for the resource (using only the resource name) under a base directory in the file system.- Parameters:
name- name of resource to loadlocatorBaseDir- if not null we will try to search for the resource in the file system- Returns:
- URL containing the resource
-
getResourceStream
Several attempts to search for the requested resource as an input stream: 1. It calls the (current thread) contextClassLoader.getResource(config/schemas/yyy.xml). if not found --> 1.1 It calls the (current thread) contextClassLoader.getResource(yyy.xml). if not found --> 2. It calls this classLoader.getResource(config/schemas/yyy.xml) (e.g. if running in AppServer) if not found --> 2.1 It calls this classLoader.getResource(yyy.xml) (e.g. if running in AppServer) Some notes: In some scenarios, the ResourceLoader does not use the right class loader and returns no resource. E.g. when running within application server the config and jar files loaded using the Thread.currentThread().getContextClassLoader().getResource() but since the lower level CL is used (of the APPServer) we should try also and use the getClass().getResource() in case the first attempt failed to find the resource.- Parameters:
name- name of resource to get- Returns:
- InputStream containing the resource
-
getResourceURL
Loads the requested resource and returns its URL. Several attempts to search for the requested resource: 1. It calls the (current thread) contextClassLoader.getResource(config/schemas/yyy.xml). if not found --> 1.1 It calls the (current thread) contextClassLoader.getResource(yyy.xml). if not found --> 2. It calls this classLoader.getResource(config/schemas/yyy.xml) (e.g. if running in AppServer) if not found --> 2.1 It calls this classLoader.getResource(yyy.xml) (e.g. if running in AppServer) Notes: In some scenarios, the ResourceLoader does not use the right class loader and returns no resource. E.g. when running within application server the config and jar files loaded using the Thread.currentThread().getContextClassLoader().getResource() but since the lower level CL is used (of the APPServer) we should try also and use the getClass().getResource() in case the first attempt failed to find the resource.- Parameters:
name- name of resource to get- Returns:
- URL containing the resource
-
findCustomPropertiesObj
public static Properties findCustomPropertiesObj(String schemaPropertiesFileName) throws IOException, ConfigurationException Used to load xxx.properties file, parse it and create a Properties object out of it. The system looks for the file using the Resource Bundle in the /config directory.- Returns:
- Properties object contains the xxx.properties values.
- Throws:
IOExceptionConfigurationException
-
findClusterXSLSchema
public static InputStream findClusterXSLSchema(InputStream _clusterXMLInputStream) throws ClusterConfigurationException Using the _clusterMembersStream InputStream, we parse the DOM and fetch the value of the <cluster-schema-name> tag. This name is the prefix of the requested cluster XSL schema file. Using this, we now go and find the Cluster XSL schema. Look for the requested cluster XSL schema file in the ResourceBundle (classpath) under/config/schemas/ -cluster-schema.xsl. If it does no find it in the disk (the default) it looks for it in the JSpaces.jar, in same path. if the requested schema file does not exist in the disk config/schemas dir.. In this case we load the default schema file which always exist in the resource under the path config/schemas/default-cluster-schema.xml. NOTE that the <com.gs.home> must be part of the classpath, in this case. - Returns:
- InputStream to the found schema file. Note that this is a read case, so we do not need to write the file to disk, just load it to the memory and return the InputStream.
- Throws:
ClusterConfigurationException- if the requested cluster schema was not found
-
resolveClusterXSLSchema
public static InputStream resolveClusterXSLSchema(String _clusterMembers) throws ClusterConfigurationException Resolving cluster schema XSL from cluster xml. Using the _clusterMembersStream InputStream, we parse the DOM and fetch the value of the <cluster-schema-name> tag. This name is the prefix of the requested cluster XSL schema file. Using this, we now go and find the Cluster XSL schema. Look for the requested cluster XSL schema file in the ResourceBundle (classpath) under/config/schemas/ -cluster-schema.xsl. If it does no find it in the disk (the default) it looks for it in the JSpaces.jar, in same path. if the requested schema file does not exist in the disk config/schemas dir.. In this case we throw exception (which does not interrupt the system load but acts as a warning) NOTE that the <com.gs.home> must be part of the classpath, in this case. - Returns:
- InputStream to the found schema file. Note that this is a read case, so we do not need to write the file to disk, just load it to the memory and return the InputStream.
- Throws:
ClusterConfigurationException- if the requested cluster schema was not found
-
findClusterXML
Look for the requested cluster XML file in the ResourceBundle (classpath) under/config/ -cluster.xml. If it does no find it in the disk (the default) it looks for it in the JSpaces.jar, in same path. if the requested schema file does not exist in the disk config/schemas dir.. In this case, DO we load the default schema file which always exist in the resource under the path config/default-cluster.xml. NOTE that the <com.gs.home> must be part of the classpath, in this case. - Returns:
- InputStream to the found schema file. Note that this is a read case, so we do not need to write the file to disk, just load it to the memory and return the InputStream.
-
findClusterXSLSchema
public static InputStream findClusterXSLSchema(String _clusterXSLSchema) throws ClusterConfigurationException Look for the requested cluster XSL schema file in the ResourceBundle (classpath) under/config/schemas/ -cluster-schema.xsl. If it does no find it in the disk (the default) it looks for it in the JSpaces.jar, in same path. if the requested schema file does not exist in the disk config/schemas dir.. In this case we throw exception (which does not interrupt the system load but acts as a warning) NOTE that the <com.gs.home> must be part of the classpath, in this case. - Returns:
- InputStream to the found schema file. Note that this is a read case, so we do not need to write the file to disk, just load it to the memory and return the InputStream.
- Throws:
ClusterConfigurationException- if the requested cluster schema was not found
-
findContainerSchema
-
findContainerSchema
Look for the requested container schema file in the ResourceBundle (classpath) under/config/schemas/ -container-schema.xml. If it does no find it in the disk (the default) it looks for it in the JSpaces.jar, in same path. if the requested schema file does not exist in the disk config/schemas dir.. In this case we load the default schema file which always exist in the resource under the path config/schemas/default-container-schema.xml. NOTE that the <com.gs.home> must be part of the classpath, in this case. - Returns:
- InputStream to the found schema file. Note that this is a read case, so we do not need to write the file to disk, just parse it in memory.
-
findConfigDCache
-
findSpaceSchema
public static ResourceLoader.SchemaProperties findSpaceSchema(String _schemaName) throws ConfigurationException Look for the requested space schema file in the ResourceBundle (classpath) under/config/schemas/ -space-schema.xml. If it does no find it in the disk (the default) it looks for it in the JSpaces.jar, in same path. if the requested schema file does not exist in the disk config/schemas dir.. In this we throw a ConfigurationExceptionNOTE that the <com.gs.home> must be part of the classpath, in this case.- Returns:
- SchemaProperties objects that encapsulates found schema properties file: InputStream and file path. Note that this is a read case, so we do not need to write the file to disk, just parse it in memory.
- Throws:
ConfigurationException- in case the requested resource could not be found
-
findContainerXML
Look for the requested container xml file in the classpath (resource) under/config/ .xml. If the classpath contains first in classpath, it will attempt to look for the container xml file first in the file system under /config/ .xml. Container xml file contains the list of the spaces which are part of this container. Fixed bug 26/06/06 Gershon - http://62.90.11.164:8080/browse/APP-90 Container.XML location mechanism must use getResource() and load the container xml from resource according to the classpath - Returns:
- URL to the found container xml file. Note that this is a read case, so we do not need to write the file to disk, just parse it in memory.
-
getClusterSchemas
Returns an array of strings naming the schemas in the default ${com.gs.home}/config/schemas directory.- Returns:
- result
-
getClusterSchemas
Returns an array of strings naming the schemas in the specified directory.- Parameters:
schemasDir- - directory that contains a schemas- Returns:
- result
-