|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatic
Factories
public final class Factories
Static methods relative to the factories. There are many aspects in the way Geotk manages factories on a system-wide basis:
Default settings: They are handled as the default hint values set on a system-wide
basis by Hints.get/put/removeSystemDefault methods. The default values can be provided
in application code.
Integration plugins: If hosting Geotk in a alternate plugin system such as
Spring or OSGi, application may needs to register additional "Factory Iterators" for Geotk
to search using the addFactoryIteratorProvider method.
| utility/geotk-utility (download) | View source code for this class |
| Method Summary | ||
|---|---|---|
static void |
addChangeListener(ChangeListener listener)
Adds the specified listener to the list of objects to inform when a system-wide configuration changed. |
|
static void |
addFactoryIteratorProvider(FactoryIteratorProvider provider)
Adds an alternative way to search for factory implementations. |
|
static void |
listProviders(Collection<FactoryRegistry> registries,
Writer out,
Locale locale)
Lists all available factory implementations in a tabular format. |
|
static
|
orderForClassLoader(ClassLoader classLoader,
Iterator<T> iterator)
Returns an iterator giving precedence to classes loaded by the given class loaderĀ or one of its parents/children. |
|
static void |
removeChangeListener(ChangeListener listener)
Removes the specified listener from the list of objects to inform when a system-wide configuration changed. |
|
static void |
removeFactoryIteratorProvider(FactoryIteratorProvider provider)
Removes a provider that was previously added. |
|
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void addChangeListener(ChangeListener listener)
Hints.putSystemDefault(RenderingHints.Key, Object)Hints.removeSystemDefault(RenderingHints.Key)addFactoryIteratorProvider(FactoryIteratorProvider)removeFactoryIteratorProvider(FactoryIteratorProvider)
listener - The listener to add.public static void removeChangeListener(ChangeListener listener)
listener - The listener to remove.@Configuration public static void addFactoryIteratorProvider(FactoryIteratorProvider provider)
FactoryRegistry has
a default mechanism bundled in it, which uses the content of all META-INF/services
directories found on the classpath. This addFactoryIteratorProvider 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.
If the given provider was not already registered, then this method notifies
every listeners registered with addChangeListener(ChangeListener).
provider - A new provider for factory iterators.@Configuration public static void removeFactoryIteratorProvider(FactoryIteratorProvider provider)
If the given provider was found, then this method notifies every listeners
registered with addChangeListener(ChangeListener).
provider - The provider to remove.
@Debug
public static void listProviders(Collection<FactoryRegistry> registries,
Writer out,
Locale locale)
throws IOException
registries - Where the factories are registered.out - The output stream where to format the list.locale - The locale for the list, or null.
IOException - if an error occurs while writing to out.FactoryFinder.listProviders(java.io.Writer, java.util.Locale)
public static <T> Iterator<T> orderForClassLoader(ClassLoader classLoader,
Iterator<T> iterator)
Example with Image I/O
The geotk-coverageio module defines new ImageReader
implementations, which are automatically discovered by the standard JDK through the
META-INF/services/ mechanism. If a web container contains two copies of the
Geotoolkit.org library - one for each web application - then all image formats like
NetcdfImageReader will be registered twice,
because the JVM will find two NetcdfImageReader.Spi classes loaded by two
different class loaders.
The service provider instance returned by IIORegistry may
be somewhat random in the above scenario. This leads to subtle and hard-to-identify
bugs. This method reduces the risk by giving precedence to SPI classes loaded by the
same class loader than the application. However users are still encouraged to load,
for each running JVM, only one copy of the Geotoolkit.org library to be shared by all
applications.
T - The type of elements in the iterator.classLoader - The desired class loader, or null for the bootstrap class loader.iterator - The iterator to wrap.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||