01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2008, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * 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 org.geotools.factory;
17:
18: /**
19: * Base class for factory finders. {@code FactoryFinder}s are cover for {@link FactoryRegistry}
20: * adding type safety, default hints and synchronization for multi-thread environments.
21: *
22: * @since 2.4
23: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/factory/FactoryFinder.java $
24: * @version $Id: FactoryFinder.java 29058 2008-02-03 17:47:07Z desruisseaux $
25: * @author Martin Desruisseaux
26: */
27: public abstract class FactoryFinder {
28: /**
29: * A set of empty hints, which exclude any {@linkplain Geotools#getDefaultHints system hints}.
30: */
31: public static final Hints EMPTY_HINTS = new StrictHints.Empty();
32:
33: /**
34: * Creates a new factory finder.
35: */
36: protected FactoryFinder() {
37: }
38:
39: /**
40: * Returns new hints that combine user supplied hints with the
41: * {@linkplain GeoTools#getDefaultHints defaults hints}. If a hint is specified
42: * in both user and default hints, then user hints have precedence.
43: * <p>
44: * The returned hints should live only the time needed for invoking {@link FactoryRegistry}
45: * methods. No long-term reference should be held.
46: *
47: * @param hints The user hints, or {@code null} if none.
48: * @return New hints (never {@code null}).
49: */
50: public static Hints mergeSystemHints(final Hints hints) {
51: if (hints instanceof StrictHints) {
52: /*
53: * The hints have already been merged in a previous call to this method and we don't
54: * want to merge them again. This case happen typically in factory constructor fetching
55: * for dependencies. The constructor may have removed some hints. For example the
56: * "URN:OGC" factory may looks for the "EPSG" factory with FORCE_LONGITUDE_FIRST
57: * forced to FALSE.
58: */
59: return hints;
60: }
61: final Hints merged = Hints.getDefaults(true);
62: if (hints != null) {
63: merged.add(hints);
64: }
65: return merged;
66: }
67: }
|