Class GeoTools
- Object
-
- GeoTools
-
public final class GeoTools extends Object
Static methods relative to the global GeoTools configuration. GeoTools can be configured in a system-wide basis through system properties, some of them are declared asString
constants in this class.There are many aspects to the configuration of GeoTools:
- Default Settings: Are handled as the Hints returned by
getDefaultHints()
, the default values can be provided in application code, or specified using system properties. - Integration JNDI: Telling the GeoTools library about the facilities of an application, or
application container takes several forms. This class provides the
init(InitialContext)
method allowing to tell GeoTools about the JNDI context to use. - Integration Plugins: If hosting GeoTools in a alternate plugin system such as Spring or
OSGi, application may needs to hunt down the
FactoryFinder
s and register additional "Factory Iterators" for GeoTools to search using theaddFactoryIteratorProvider(org.geotools.util.factory.FactoryIteratorProvider)
method.
- Since:
- 2.4
- Author:
- Jody Garnett, Martin Desruisseaux
- Default Settings: Are handled as the Hints returned by
-
-
Field Summary
Fields Modifier and Type Field Description static String
CRS_AUTHORITY_EXTRA_DIRECTORY
The system property key for the default value to be assigned to theCRS_AUTHORITY_EXTRA_DIRECTORY
hint.static String
DATE_TIME_FORMAT_HANDLING
The system property key for the default value to be assigned to theHints.DATE_TIME_FORMAT_HANDLING
hint.static Predicate<String>
DEFAULT_JNDI_VALIDATOR
Default JNDI name validator, allows lookups only on names without a scheme, or using thejava
scheme.static String
ENCODE_WKT
The system property key for the default value to be assigned to theHints.ENCODE_EWKT
hint.static String
ENTITY_RESOLVER
The system property key for the default value to be assigned to the {@link Hints# ENTITY_RESOLVER} hint.static String
EPSG_DATA_SOURCE
The system property key for the default value to be assigned to theEPSG_DATA_SOURCE
hint.static String
FORCE_LONGITUDE_FIRST_AXIS_ORDER
The system property key for the default value to be assigned to theFORCE_LONGITUDE_FIRST_AXIS_ORDER
hint.static String
FORCE_SRS_STYLE
The system property key for the default value to be assigned to the {@link Hints# FORCE_SRS_STYLE} hint.static String
HTTP_CLIENT
The system property key for the default value to be assigned to theHints.HTTP_CLIENT
hint.static String
HTTP_LOGGING
The system property key for the default value to be assigned to theHints.HTTP_LOGGING
hint.static String
LOCAL_DATE_TIME_HANDLING
The system property key for the default value to be assigned to theHints.LOCAL_DATE_TIME_HANDLING
hint.static String
RESAMPLE_TOLERANCE
The system property key for the default value to be assigned to the {@link Hints# RESAMPLE_TOLERANCE} hint.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addChangeListener(ChangeListener listener)
Adds the specified listener to the list of objects to inform when system-wide configuration changed.static void
addClassLoader(ClassLoader classLoader)
Adds a class loader to be included in the list of class loaders that are used to locate GeoTools plug-ins.static Hints
addDefaultHints(Hints hints)
Used to combine provided hints with global GeoTools defaults.static void
addFactoryIteratorProvider(FactoryIteratorProvider provider)
Adds an alternative way to search for factory implementations.static void
clearInitialContext()
Clears the initial context (closes it if not null)static void
fireConfigurationChanged()
Informs every listeners that system-wide configuration changed.static String
fixName(String name)
Deprecated.With no replacement, GeoTools now uses JNDI lookups as instructed injndiLookup(String)
, but does not put any object in the contex, the downstream application should do it if necessary instead.static String
fixName(Context context, String name)
Deprecated.With no replacement, GeoTools now uses JNDI lookups as instructed in {@link * #jndiLookup(String)}, but does not put any object in the contex, the downstream * application should do it if necessary instead.static String
getAboutInfo()
Returns summary information about GeoTools and the current environment.static Properties
getBuildProperties()
Returns the raw properties object containing all properties about this GeoTools build.static String
getBuildRevision()
Reports back the vcs revision at which the version of GeoTools was built.static String
getBuildTimestamp()
Reports back the timestamp at which the version of GeoTools of built.static Hints
getDefaultHints()
Returns the default set of hints used for the various utility classes.static EntityResolver
getEntityResolver(Hints hints)
Returns the default entity resolver, used to configureSAXParser
.static String
getEnvironmentInfo()
Returns summary information about the GeoTools version and the host environment.static String
getGeoToolsJarInfo()
Returns the names of the GeoTools jars on the classpath.static InitialContext
getInitialContext()
Deprecated.Please usejndiLookup(String)
instead, or provide anInitialContext
to theinit(InitialContext)
method and use it directly.static Manifest
getManifest(Class<?> type)
Lookup the MANIFEST.MF for the provided class.static Version
getVersion()
Reports back the version of GeoTools being used.static Version
getVersion(Class<?> type)
Lookup version for provided class.static void
init()
Initializes GeoTools for use.static void
init(InitialContext initialContext)
Provides GeoTools with the JNDI context for resource lookup.static void
init(Hints hints)
Initializes GeoTools for use.static boolean
isJNDIAvailable()
Checks if JNDI is available, either because it was initialized, or because it was possible to create one.static Object
jndiLookup(String name)
Looks up an object from the JNDIInitialContext
.static void
main(String... args)
Reports the GeoTools version number to the standard output stream.static void
removeChangeListener(ChangeListener listener)
Removes the specified listener from the list of objects to inform when system-wide configuration changed.static void
removeFactoryIteratorProvider(FactoryIteratorProvider provider)
Removes a provider that was previously added.static void
setJNDINameValidator(Predicate<String> validator)
Sets up a function that will be called to validate the JNDI lookups.static void
setLoggerFactory(LoggerFactory<?> factory)
Sets the global logger factory.
-
-
-
Field Detail
-
CRS_AUTHORITY_EXTRA_DIRECTORY
public static final String CRS_AUTHORITY_EXTRA_DIRECTORY
The system property key for the default value to be assigned to theCRS_AUTHORITY_EXTRA_DIRECTORY
hint.
-
EPSG_DATA_SOURCE
public static final String EPSG_DATA_SOURCE
The system property key for the default value to be assigned to theEPSG_DATA_SOURCE
hint.
-
FORCE_LONGITUDE_FIRST_AXIS_ORDER
public static final String FORCE_LONGITUDE_FIRST_AXIS_ORDER
The system property key for the default value to be assigned to theFORCE_LONGITUDE_FIRST_AXIS_ORDER
hint.This setting can provide a transition path for projects expecting a (longitude, latitude) axis order on a system-wide level. Application developpers can set the default value as below:
System.setProperty(FORCE_LONGITUDE_FIRST_AXIS_ORDER, "true");
"CRS"
,"AUTO"
, etc.) don't need this property since they use (longitude, latitude) axis order by design.
-
FORCE_SRS_STYLE
public static final String FORCE_SRS_STYLE
The system property key for the default value to be assigned to the {@link Hints# FORCE_SRS_STYLE} hint.GML Encoding in geotools forces http://www.opengis.net/gml/srs/epsg.xml# syntax on CRS that are East\North oriented or have no orientation (such as 1D CRS). This property prevents this behaviour.
System.setProperty(FORCE_SRS_STYLE, "true");
-
ENTITY_RESOLVER
public static final String ENTITY_RESOLVER
The system property key for the default value to be assigned to the {@link Hints# ENTITY_RESOLVER} hint.This setting specifies the XML Entity resolver to be used when configuring a SAXParser
-
RESAMPLE_TOLERANCE
public static final String RESAMPLE_TOLERANCE
The system property key for the default value to be assigned to the {@link Hints# RESAMPLE_TOLERANCE} hint.This setting specifies the tolerance used when linearizing warp transformation into piecewise linear ones, by default it is 0.333 pixels
-
LOCAL_DATE_TIME_HANDLING
public static final String LOCAL_DATE_TIME_HANDLING
The system property key for the default value to be assigned to theHints.LOCAL_DATE_TIME_HANDLING
hint.This setting specifies if dates shall be treated as local dates ignoring time zones.
- Since:
- 15.0
- See Also:
Hints.LOCAL_DATE_TIME_HANDLING
,getDefaultHints()
, Constant Field Values
-
DATE_TIME_FORMAT_HANDLING
public static final String DATE_TIME_FORMAT_HANDLING
The system property key for the default value to be assigned to theHints.DATE_TIME_FORMAT_HANDLING
hint.This setting specifies if GML 2 temporal data shall be formatted using same approach as GML 3+.
- Since:
- 21.0
- See Also:
Hints.DATE_TIME_FORMAT_HANDLING
,getDefaultHints()
, Constant Field Values
-
ENCODE_WKT
public static final String ENCODE_WKT
The system property key for the default value to be assigned to theHints.ENCODE_EWKT
hint.This setting specifies if geometries with
CoordinateReferenceSystem
in the user data shall be encoded as EWKT or not.- Since:
- 19.0
- See Also:
Hints.ENCODE_EWKT
,getDefaultHints()
, Constant Field Values
-
HTTP_CLIENT
public static final String HTTP_CLIENT
The system property key for the default value to be assigned to theHints.HTTP_CLIENT
hint.This setting specifies whether we wan't to use a special http client
- Since:
- 25.0
- See Also:
Hints.HTTP_CLIENT
,getDefaultHints()
, Constant Field Values
-
HTTP_LOGGING
public static final String HTTP_LOGGING
The system property key for the default value to be assigned to theHints.HTTP_LOGGING
hint.This setting specifies whether we want to log all http requests.
- Since:
- 25.0
- See Also:
Hints.HTTP_LOGGING
,getDefaultHints()
, Constant Field Values
-
-
Method Detail
-
getAboutInfo
public static String getAboutInfo()
Returns summary information about GeoTools and the current environment. Calls getEnvironmentInfo() followed by getGeoToolsJarInfo() and concatenates their results.- Returns:
- requested information as a string
-
getEnvironmentInfo
public static String getEnvironmentInfo()
Returns summary information about the GeoTools version and the host environment.- Returns:
- information as a String
-
getGeoToolsJarInfo
public static String getGeoToolsJarInfo()
Returns the names of the GeoTools jars on the classpath.- Returns:
- list of jars as a formatted string
-
getBuildRevision
public static String getBuildRevision()
Reports back the vcs revision at which the version of GeoTools was built.- Returns:
- The svn revision.
-
getBuildTimestamp
public static String getBuildTimestamp()
Reports back the timestamp at which the version of GeoTools of built.- Returns:
- The build timestamp.
-
getBuildProperties
public static Properties getBuildProperties()
Returns the raw properties object containing all properties about this GeoTools build.Example from the 14.3 release:
- version=14.3
- build.revision=2298d56000bef6f526b521a480316ea544c74571
- build.branch=rel_14.3
- build.timestamp=21-Mar-2016 21:30
-
getVersion
public static Version getVersion()
Reports back the version of GeoTools being used.- Returns:
- The current GeoTools version.
-
getVersion
public static Version getVersion(Class<?> type)
Lookup version for provided class.Version number is determined by either:
- Use of jar naming convention, matching jars such as jts-1.13.jar
- Use of MANIFEST.MF (to check Implementation-Version, Project-Version)
- To assist
- Returns:
- Version (or null if unavailable)
-
getManifest
public static Manifest getManifest(Class<?> type)
Lookup the MANIFEST.MF for the provided class.This can be used to quickly verify packaging information.
- Returns:
- MANIFEST.MF contents, please note contents may be empty when running from IDE
-
setLoggerFactory
public static void setLoggerFactory(LoggerFactory<?> factory)
Sets the global logger factory.This method is the same as calling
Logging#setLoggerFactory(factory)
to configure bothLogging.ALL
logger creation.GeoTools provides logback, log4j, reload4j, and commons-logging factories. This method exists to allow you supply your own implementation (when using a GeoTools library in an exotic environment like Eclipse, OC4J or your application).
If
null
is used, the Java logging formatter for console output is replaced by a monoline formatter.- Parameters:
factory
- The logger factory to use, or null for native java util logging.- Since:
- 2.4
- See Also:
Logging.setLoggerFactory(LoggerFactory)
-
init
public static void init(Hints hints)
Initializes GeoTools for use. This convenience method performs various tasks (more may be added in the future), including setting up the Java logging framework in one of the following states:- If Logback is available, then messages in
org.geotools
andjavax.media.jai
namespace sent to logger are redirected to SL4J API used by logback. - Otherwise if Log4J is available, then
messages in
org.geotools
andjavax.media.jai
namespace sent to Java logger are redirected to Log4J API. - Otherwise if Reload4J is available, then
messages in
org.geotools
andjavax.media.jai
namespace sent to Java logger are redirected to Log4J 1 API used by Reload4J. - finally if Commons-logging is
available, then messages in
org.geotools
andjavax.media.jai
namespaces sent to the Java logger are redirected to Commons-logging. - Otherwise, the Java logging formatter for console output is replaced by a monoline formatter.
In addition, the default hints are initialized to the specified
hints
.Invoking this method is not required for the GeoTools library to function. It is just a convenience method for overwriting select Java and GeoTools default settings. Supplying these defaults is not desirable in all settings, such as writing test cases.
Example of typical invocation in a GeoServer environment:
Hints hints = new Hints(); hints.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); hints.put(Hints.FORCE_AXIS_ORDER_HONORING, "http"); GeoTools.init(hints);
- Parameters:
hints
- The hints to use.- See Also:
Logging.setLoggerFactory(String)
,Logging.forceMonolineConsoleOutput()
,Hints.putSystemDefault(java.awt.RenderingHints)
,getDefaultHints()
- If Logback is available, then messages in
-
init
public static void init()
Initializes GeoTools for use. This convenience method performs various tasks (more may be added in the future)Primary task is setting up the Java logging framework with a logging factory (if it has not been done already):
- If Logging.ALL has already been configured no further work is required.
- Otherwise if Logback is available, then messages
in
org.geotools
andjavax.media.jai
namespace sent to logger are redirected to SL4J API used by logback. - Otherwise if Log4J is available, then
messages in
org.geotools
andjavax.media.jai
namespace sent to Java logger are redirected to Log4J API. - Otherwise if Reload4J is available, then
messages in
org.geotools
andjavax.media.jai
namespace sent to Java logger are redirected to Log4J 1 API used by Reload4J. - Otherwise if Commons-logging
is available, then messages in
org.geotools
andjavax.media.jai
namespaces sent to the Java logger are redirected to Commons-logging. - Otherwise, the Java logging formatter for console output is replaced by a monoline formatter.
Invoking this method is not required fpr the GeoTools library to function. It is just a convenience method for overwriting select Java and GeoTools default settings. Supplying these defaults is not always desirable, for example when quickly writing test cases.
- See Also:
Logging.setLoggerFactory(String)
,Logging.forceMonolineConsoleOutput()
,Hints.putSystemDefault(java.awt.RenderingHints)
,getDefaultHints()
-
init
public static void init(InitialContext initialContext)
Provides GeoTools with the JNDI context for resource lookup.- Parameters:
initialContext
- The initial context to use for JNDI lookup- Since:
- 2.4
- See Also:
jndiLookup(String)
-
getDefaultHints
public static Hints getDefaultHints()
Returns the default set of hints used for the various utility classes. This default set is determined by:- The available. Some property keys
are enumerated in the
GeoTools
class. - Any hints added by call to the
Hints.putSystemDefault(java.awt.RenderingHints)
orinit(org.geotools.util.factory.Hints)
method.
Long term plan: We would like to transition the utility classes to being injected with their required factories, either by taking Hints as part of their constructor, or otherwise. Making this change would be a three step process 1) create instance methods for each static final class method 2) create an singleton instance of the class 3) change each static final class method into a call to the singleton. With this in place we could then encourage client code to make use of utility class instances before eventually retiring the static final methods.
- Returns:
- A copy of the default hints. It is safe to add to it.
- The available. Some property keys
are enumerated in the
-
addDefaultHints
public static Hints addDefaultHints(Hints hints)
Used to combine provided hints with global GeoTools defaults.
-
getEntityResolver
public static EntityResolver getEntityResolver(Hints hints)
Returns the default entity resolver, used to configureSAXParser
.- Parameters:
hints
- An optional set of hints, ornull
if none, seeHints.ENTITY_RESOLVER
.- Returns:
- An entity resolver (never
null
)
-
getInitialContext
@Deprecated public static InitialContext getInitialContext() throws NamingException
Deprecated.Please usejndiLookup(String)
instead, or provide anInitialContext
to theinit(InitialContext)
method and use it directly.Returns the default initial context.- Returns:
- The initial context (never
null
). - Throws:
NamingException
- if the initial context can't be created.
-
isJNDIAvailable
public static boolean isJNDIAvailable()
Checks if JNDI is available, either because it was initialized, or because it was possible to create one.
-
setJNDINameValidator
public static void setJNDINameValidator(Predicate<String> validator)
Sets up a function that will be called to validate the JNDI lookups. If not set, the DEFAULT_JNDI_VALIDATOR is used. The function may want to log the reason why a given name was denied lookup.- Parameters:
validator
- A function returning true if the lookups are meant to be performed, false otherwise.
-
jndiLookup
public static Object jndiLookup(String name) throws NamingException
Looks up an object from the JNDIInitialContext
. By default, it only allows lookups with no scheme, or inside thejava
scheme. One can set up a custom name validation routine using- Parameters:
name
-- Returns:
- Throws:
NamingException
-
clearInitialContext
public static void clearInitialContext() throws NamingException
Clears the initial context (closes it if not null)- Throws:
NamingException
- Since:
- 15.0
-
fixName
@Deprecated public static String fixName(String name)
Deprecated.With no replacement, GeoTools now uses JNDI lookups as instructed injndiLookup(String)
, but does not put any object in the contex, the downstream application should do it if necessary instead.Converts a GeoTools name to the syntax used by the GeoTools JNDI context. Names may be constructed in a variety of ways depending on the implementation ofInitialContext
. GeoTools uses"jdbc:EPSG"
internally, but many implementaitons use the form"jdbc/EPSG"
. Calling this method before use will set the name right.- Parameters:
name
- Name of the form"jdbc:EPSG"
, ornull
.- Returns:
- Name fixed up with
Context.composeName(String,String)
, ornull
if the given name was null. - Since:
- 2.4
-
fixName
@Deprecated public static String fixName(Context context, String name)
Deprecated.With no replacement, GeoTools now uses JNDI lookups as instructed in {@link * #jndiLookup(String)}, but does not put any object in the contex, the downstream * application should do it if necessary instead.Converts a GeoTools name to the syntax used by the specified JNDI context. This method is similar tofixName(String)
, but uses the specified context instead of the GeoTools one.- Parameters:
context
- The context to use, ornull
if none.name
- Name of the form"jdbc:EPSG"
, ornull
.- Returns:
- Name fixed up with
Context.composeName(String,String)
, ornull
if the given name was null. - Since:
- 2.4
-
addFactoryIteratorProvider
public static void addFactoryIteratorProvider(FactoryIteratorProvider provider)
Adds an alternative way to search for factory implementations.FactoryRegistry
has a default mechanism bundled in it, which uses the content of allMETA-INF/services
directories found on the classpath. ThisaddFactoryIteratorProvider
method allows to specify additional discovery algorithms. It may be useful in the context of some frameworks that use the constructor injection pattern, like the Spring framework.- Parameters:
provider
- A new provider for factory iterators.
-
removeFactoryIteratorProvider
public static void removeFactoryIteratorProvider(FactoryIteratorProvider provider)
Removes a provider that was previously added. Note that factories already obtained from the specified provider will not be deregistered by this method.- Parameters:
provider
- The provider to remove.
-
addChangeListener
public static void addChangeListener(ChangeListener listener)
Adds the specified listener to the list of objects to inform when system-wide configuration changed.- Parameters:
listener
- The listener to add.
-
removeChangeListener
public static void removeChangeListener(ChangeListener listener)
Removes the specified listener from the list of objects to inform when system-wide configuration changed.- Parameters:
listener
- The listener to remove.
-
fireConfigurationChanged
public static void fireConfigurationChanged()
Informs every listeners that system-wide configuration changed.
-
addClassLoader
public static void addClassLoader(ClassLoader classLoader)
Adds a class loader to be included in the list of class loaders that are used to locate GeoTools plug-ins.Client code that calls this method may also need to call
FactoryRegistry.scanForPlugins()
on any existing registry to force it to clear its cache and use the added class loader to locate plugins.- Parameters:
classLoader
- The class loader.
-
main
public static void main(String... args)
Reports the GeoTools version number to the standard output stream.- Parameters:
args
- Command line arguments.
-
-