root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / gt2 / factory / OptionalFactory.java @ 10627
History | View | Annotate | Download (3.82 KB)
1 |
/*
|
---|---|
2 |
* Geotools 2 - OpenSource mapping toolkit
|
3 |
* (C) 2005, Geotools Project Managment Committee (PMC)
|
4 |
*
|
5 |
* This library is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
7 |
* License as published by the Free Software Foundation; either
|
8 |
* version 2.1 of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This library is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 |
* Lesser General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
16 |
* License along with this library; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
*/
|
19 |
package com.iver.cit.gvsig.fmap.core.gt2.factory; |
20 |
|
21 |
import javax.imageio.spi.ServiceRegistry; |
22 |
|
23 |
// J2SE dependencies
|
24 |
|
25 |
|
26 |
/**
|
27 |
* A factory that may not be available in all configurations.
|
28 |
*
|
29 |
* <p>Such factories often need some resources to download separatly, like a big file or a
|
30 |
* database. Those resources may not be installed in all configurations. The {@link #isReady}
|
31 |
* method tells if this factory has found every resources it needs in order to run.</p>
|
32 |
*
|
33 |
* <p>{@link FactoryRegistry#getServiceProvider} iterates over all registered factories. If an
|
34 |
* {@linkplain ServiceRegistry#setOrdering ordering is set}, it is taken in account. If no suitable
|
35 |
* factory was found before the iterator reachs this optional factory, then {@code FactoryRegistry}
|
36 |
* invokes {@link #isReady}. If the later returns {@code true}, then this optional factory is
|
37 |
* processed like any other factories. Otherwise it is ignored.</p>
|
38 |
*
|
39 |
* <p>Optional factories are useful when the preferred factory requires resources that are not
|
40 |
* guaranteed to be installed on the client machine (e.g. the <A HREF="http://www.epsg.org">EPSG
|
41 |
* database</A>) and some fallback exists (e.g. an EPSG factory based on a WKT file).</p>
|
42 |
*
|
43 |
* <p>Ignored factories are not deregistered; they will be queried again every time
|
44 |
* {@code getServiceProvider(...)} is invoked and the iterator reachs this optional factory.
|
45 |
* This means that if a resource was not available at startup time but become available later,
|
46 |
* it may be selected the next time {@code getServiceProvider(...)} is invoked. It will have no
|
47 |
* impact on previous results of {@code getServiceProvider(...)} however.</p>
|
48 |
*
|
49 |
* <p>{@code OptionalFactory} is not designed for factories with intermittent state (i.e. return
|
50 |
* value of {@link #isReady} varying in an unpredictable way). While {@code FactoryRegistry} can
|
51 |
* provides some deterministic behavior when the {@code isReady()} return value become {@code true}
|
52 |
* as explained in the previous paragraphe, the converse (when the value was {@code true} and become
|
53 |
* {@code false}) is unsafe. This is because factories returned by previous calls to
|
54 |
* {@code getServiceProvider(...)} would stop to work in an unexpected way for clients.</p>
|
55 |
*
|
56 |
* @todo This interface is like a tiny skeleton of external service API. To complete the picture
|
57 |
* we would need a callback mechanism. A listener that that client code can give to the
|
58 |
* factory, that it will call when ready. If it is ready it will be called immeditely.
|
59 |
* The above advice about alternatives could really be managed by such a factory (especially
|
60 |
* if it allowed to notify client code more then once.
|
61 |
*
|
62 |
* @author Martin Desruisseaux
|
63 |
* @version $Id: OptionalFactory.java 10627 2007-03-06 17:10:21Z caballero $
|
64 |
*/
|
65 |
public interface OptionalFactory extends Factory { |
66 |
/**
|
67 |
* Returns {@code true} if this factory is ready for use.
|
68 |
* An optional factory may returns {@code false} for now but returns {@code true} later.
|
69 |
* However, the converse is not recommended.
|
70 |
*/
|
71 |
public boolean isReady(); |
72 |
} |