root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / gt2 / factory / Factory.java @ 10627
History | View | Annotate | Download (6.55 KB)
1 |
/*
|
---|---|
2 |
* Geotools2 - OpenSource mapping toolkit
|
3 |
* http://geotools.org
|
4 |
* (C) 2002, Geotools Project Managment Committee (PMC)
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation;
|
9 |
* version 2.1 of the License.
|
10 |
*
|
11 |
* This library is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*/
|
16 |
package com.iver.cit.gvsig.fmap.core.gt2.factory; |
17 |
|
18 |
// J2SE dependencies
|
19 |
import java.util.Map; |
20 |
|
21 |
import javax.imageio.spi.ServiceRegistry; |
22 |
|
23 |
import org.geotools.factory.FactoryUsingVolatileDependencies; |
24 |
|
25 |
|
26 |
|
27 |
/**
|
28 |
* Base interface for Geotools factories (i.e. service discovery).
|
29 |
*
|
30 |
* <p>This interfaces forms the core of the Geotools plug-in system, by which capabilities
|
31 |
* can be added to the library at runtime. Each sub-interface defines a <cite>service</cite>.
|
32 |
* Most services are set up with concrete implementation being registered for use in
|
33 |
* a <cite>service registry</cite>, which acts as a container for service implementations.</p>
|
34 |
*
|
35 |
* <p>Service registries don't need to be a Geotools implementation. They can be (but are not
|
36 |
* limited to) any {@link ServiceRegistry} subclass. If the standard {@code ServiceRegistry}
|
37 |
* (or its Geotools extension {@link FactoryRegistry}) is selected as a container for services,
|
38 |
* then factory implementations should be declared as below (select only one way):</p>
|
39 |
*
|
40 |
* <ul>
|
41 |
* <li><strong>Register for automatic discovery</strong></li>
|
42 |
* <ul>
|
43 |
* <li>Provide a public no-arguments constructor.</li>
|
44 |
* <li>Add the fully qualified name of the <u>implementation</u> class in the
|
45 |
* {@code META-INF/services/}<var>classname</var> file where <var>classname</var>
|
46 |
* is the fully qualified name of the service <u>interface</u>.</li>
|
47 |
* <li>The factory implementations will be discovered when
|
48 |
* {@link FactoryRegistry#scanForPlugins} will be invoked.</li>
|
49 |
* </ul>
|
50 |
* <li><strong><u>Or</u> register explicitly by application code</strong></li>
|
51 |
* <ul>
|
52 |
* <li>Invoke {@link ServiceRegistry#registerServiceProvider} in application code.</li>
|
53 |
* </ul>
|
54 |
* </ul>
|
55 |
*
|
56 |
* <p>In addition, it is recommended that implementations provide a constructor expecting
|
57 |
* a single {@link Hints} argument. This optional argument gives to the user some control
|
58 |
* of the factory's low-level details. The amount of control is factory specific. The geotools
|
59 |
* library defines a global class called {@link Hints} that is ment as API (i.e. you can assume
|
60 |
* these hints are supported). Factories may also provide information on their own custom hints
|
61 |
* as part of their javadoc class description.</p>
|
62 |
*
|
63 |
* <strong>Examples:</strong>
|
64 |
* <ul>
|
65 |
* <li><p>An application supplied a {@linkplain org.opengis.referencing.datum.DatumFactory datum
|
66 |
* factory} hint, being passed to a {@linkplain org.opengis.referencing.datum.DatumAuthorityFactory
|
67 |
* datum authority factory} so that all datum created from an authority code will come from the
|
68 |
* supplied datum factory.</p></li>
|
69 |
*
|
70 |
* <li><p>An application supplied a {@link org.geotools.feature.FeatureFactory} (ensuring all
|
71 |
* constructed features support the {@code IAdaptable} interface), being passed to a
|
72 |
* {@link org.geotools.feature.FeatureTypeFactory} so that all {@code FeatureTypes}
|
73 |
* constructed will produce features supporting the indicated interface.<p></li>
|
74 |
* </ul>
|
75 |
*
|
76 |
* <p>As seen in those examples this concept of a hint becomes more interesting when
|
77 |
* the opperation being controlled is discovery of other services used by the Factory.
|
78 |
* By supplying appropriate hints one can chain together several factories and retarget
|
79 |
* them to an application specific task.</p>
|
80 |
*
|
81 |
* @author Ian Schneider
|
82 |
* @author Martin Desruisseaux
|
83 |
* @author Jody Garnett
|
84 |
* @version $Id: Factory.java 10627 2007-03-06 17:10:21Z caballero $
|
85 |
*
|
86 |
* @see Hints
|
87 |
* @see FactoryRegistry
|
88 |
*/
|
89 |
public interface Factory { |
90 |
/**
|
91 |
* Map of hints (maybe {@linkplain java.util.Collections#unmodifiableMap unmodifiable})
|
92 |
* used by this factory to customize its use. This map is <strong>not</strong> guaranteed
|
93 |
* to contains all the hints supplied by the user; it may be only a subset. Consequently,
|
94 |
* hints provided here are usually not suitable for creating new factories, unless the
|
95 |
* implementation make some additional garantees (e.g.
|
96 |
* {@link FactoryUsingVolatileDependencies}).
|
97 |
*
|
98 |
* <p>The primary purpose of this method is to determine if an <strong>existing</strong>
|
99 |
* factory instance can be reused for a set of user-supplied hints. This method is invoked by
|
100 |
* {@link FactoryRegistry} in order to compare this factory's hints against user's hints.
|
101 |
* This is dependency introspection only; {@code FactoryRegistry} <strong>never</strong>
|
102 |
* invokes this method for creating new factories.</p>
|
103 |
*
|
104 |
* <p>Keys are usually static constants from the {@link Hints} class, while values are
|
105 |
* instances of some key-dependent class. The {@linkplain Map#keySet key set} must contains
|
106 |
* at least all hints impacting functionality. While the key set may contains all hints
|
107 |
* supplied by the user, it is recommended to limit the set to only the hints used by this
|
108 |
* particular factory instance. A minimal set will helps {@link FactoryRegistry} to compares
|
109 |
* only hints that matter and avoid the creation of unnecessary instances of this factory.</p>
|
110 |
*
|
111 |
* <p>The hint values may be different than the one supplied by the user. If a user supplied a
|
112 |
* hint as a {@link Class} object, this method shall replace it by the actual instance used, if
|
113 |
* possible.</p>
|
114 |
*
|
115 |
* <p>Implementations of this method are usually quite simple. For example if a
|
116 |
* {@linkplain org.opengis.referencing.datum.DatumAuthorityFactory datum authority factory}
|
117 |
* uses an ordinary {@linkplain org.opengis.referencing.datum.DatumFactory datum factory},
|
118 |
* its method could be implemented as below (note that we should not check if the datum
|
119 |
* factory is null, since key with null value is the expected behaviour in this case).
|
120 |
* Example:</p>
|
121 |
*
|
122 |
* <pre><code>
|
123 |
* Map hints = new HashMap();
|
124 |
* hints.put({@linkplain Hints#DATUM_FACTORY}, datumFactory);
|
125 |
* return hints;
|
126 |
* </code></pre>
|
127 |
*
|
128 |
* @return The map of hints, or an {@linkplain java.util.Collections#EMPTY_MAP empty map}
|
129 |
* if none.
|
130 |
*/
|
131 |
Map/*<RenderingHints.Key,Object>*/ getImplementationHints(); |
132 |
} |