Class Configuration
Object
Configuration
Provides system-wide configuration of the Apache SIS library.
Methods in this class can be used for overriding SIS default values.
Those methods can be used in final applications, but should not be used by libraries
in order to avoid interfering with user's settings.
Other system-wide configuration
The following methods have system-wide effects on Apache SIS configuration, but are not yet controlled through thisConfiguration class:
The following properties are defined by the standard Java environment.
Apache SIS reads those properties but does not modify them:
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Configurationcurrent()Returns the current configuration.Returns the data source for the SIS-wide "SpatialMetadata" database.booleanReturns whether to relax the default security settings.voidsetDatabase(Supplier<DataSource> source) Specifies the data source to use if no"jdbc/SpatialMetadata"source is binded to a JNDI environment.voidshutdown()Shutdowns the Apache SIS library.
-
Method Details
-
current
Returns the current configuration.- Returns:
- the current configuration.
-
isTrustedEnvironment
public boolean isTrustedEnvironment()Returns whether to relax the default security settings. By default, Apache SIS applies the following restrictions:- Disable all accesses to external DTDs and external Entity References when reading XML documents.
- Follow
xlink:hrefonly if it is an XML fragment or if the referenced file is in the same directory or in a sub-directory of the GML file containing the reference. - Open file referenced in coordinate operation only if the parameter is a datum shift grid file
and the file is in the
$SIS_DATA/DatumChangesdirectory, or (for any parameter) if the file is in the same directory or in a sub-directory of JSON, GML or WKT file containing the parameter value.
org.apache.sis.trustedEnvironmentis set totrue, the above listed restrictions are ignored.- Returns:
- whether the default security restrictions are relaxed.
- Since:
- 1.7
- See Also:
-
getDatabase
Returns the data source for the SIS-wide "SpatialMetadata" database. This method returns the first of the following steps that succeed:- If a JNDI context exists,
use the data source registered under the
"jdbc/SpatialMetadata"name. - Otherwise, if a default data source has been supplied, use that data source.
- Otherwise, if the
SIS_DATAenvironment variable is defined, use the following data sources if the corresponding database driver is found, in preference order:"jdbc:hsqldb:file:$SIS_DATA/Databases/SpatialMetadata"(HSQL),"jdbc:derby:$SIS_DATA/Databases/SpatialMetadata"(Derby).
- Otherwise, if the
org.apache.sis.referencing.databasemodule is present on the module path, use the embedded database. - Otherwise, if the Derby driver is present and the
"derby.system.home"property is defined, use the data source for"jdbc:derby:SpatialMetadata". This database will not be created if it does not exist. - Otherwise, (no JNDI, no environment variable, no Derby property set), empty.
- Returns:
- the data source for the
"SpatialMetadata"database. - Throws:
SQLException- if an error occurred while fetching the database source.
- If a JNDI context exists,
use the data source registered under the
-
setDatabase
Specifies the data source to use if no"jdbc/SpatialMetadata"source is binded to a JNDI environment. Data source specified by JNDI has precedence over data source specified by this method in order to let users control their data source. The following example shows how to setup a connection to a PostgreSQL database:This method can be invoked only before the first attempt to get the database. If theimport org.postgresql.ds.PGSimpleDataSource; class MyClass { private static DataSource createDataSource() { PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setDatabaseName("SpatialMetadata"); // Server default to "localhost". return ds; } static initialize() { if (WANT_TO_CONFIGURE_JNDI) { // Registration assuming that a JNDI implementation is available Context env = (Context) InitialContext.doLookup("java:comp/env"); env.bind("jdbc/SpatialMetadata", createDataSource()); } // Fallback if there is no JNDI or no "SpatialMetadata" entry. Configuration.current().setDatabase(MyClass::createDataSource); } }DataSourcehas already be obtained, then this method throwsIllegalStateException.- Parameters:
source- supplier of data source to set. The supplier may returnnull, in which case it will be ignored.- Throws:
IllegalStateException- ifDataSourcehas already be obtained before this method call.- See Also:
-
shutdown
public void shutdown()Shutdowns the Apache SIS library. This method closes database connections and stops the daemon threads that were started by SIS. The Apache SIS library shall not be used anymore after this method call. Any use of Apache SIS after this method call may have unexpected effects. In particular, it may cause memory leaks.When to use
This method should generally not be invoked, because Apache SIS registers itself a shutdown hook to the Java Virtual Machine. This method may be useful in embedded environments that do not allow the use of shutdown hooks, or when waiting for the JVM shutdown is overly conservative.Complete shutdown of Derby
This method shutdowns only the databases used by Apache SIS. If Apache Derby is used for the EPSG database, some Derby daemon threads may still be running. Those daemons can be ignored in standalone applications, but may need to be stopped in embedded environments. A complete Derby shutdown can be requested with the following code:Configuration.current().shutdown(); try { DriverManager.getConnection("jdbc:derby:;shutdown=true"); } catch (SQLException e) { // Expected exception as per Derby documentation. }- Since:
- 1.5
- See Also:
-