01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
05: * (C) 2005, Institut de Recherche pour le Développement
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.referencing.factory.epsg;
18:
19: // J2SE dependencies
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: // OpenGIS dependencies
24: import org.opengis.referencing.AuthorityFactory;
25: import org.opengis.referencing.FactoryException;
26: import org.opengis.referencing.IdentifiedObject;
27: import org.opengis.referencing.crs.CRSAuthorityFactory;
28: import org.opengis.referencing.operation.CoordinateOperation; // For javadoc
29: import org.opengis.referencing.operation.CoordinateOperationAuthorityFactory;
30:
31: // Geotools dependencies
32: import org.geotools.referencing.factory.IdentifiedObjectSet;
33:
34: /**
35: * A lazy set of {@link CoordinateOperation} objects to be returned by the
36: * {@link DirectEpsgFactory#createFromCoordinateReferenceSystemCodes
37: * createFromCoordinateReferenceSystemCodes} method.
38: *
39: * @since 2.2
40: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/factory/epsg/CoordinateOperationSet.java $
41: * @version $Id: CoordinateOperationSet.java 25972 2007-06-21 13:38:35Z desruisseaux $
42: * @author Martin Desruisseaux
43: */
44: final class CoordinateOperationSet extends IdentifiedObjectSet {
45: /**
46: * For compatibility with previous versions.
47: */
48: private static final long serialVersionUID = -2421669857023064667L;
49:
50: /**
51: * The codes of {@link ProjectedCRS} objects for the specified {@link Conversion} codes,
52: * or {@code null} if none.
53: */
54: private Map/*<String,String>*/projections;
55:
56: /**
57: * Creates a new instance of this lazy set.
58: */
59: public CoordinateOperationSet(final AuthorityFactory factory) {
60: super (factory);
61: }
62:
63: /**
64: * Add the specified authority code.
65: *
66: * @param code The code for the {@link CoordinateOperation} to add.
67: * @param crs The code for the CRS is create instead of the operation,
68: * or {@code null} if none.
69: */
70: public boolean addAuthorityCode(final String code, final String crs) {
71: if (crs != null) {
72: if (projections == null) {
73: projections = new HashMap();
74: }
75: projections.put(code, crs);
76: }
77: return super .addAuthorityCode(code);
78: }
79:
80: /**
81: * Creates an object for the specified code.
82: */
83: protected IdentifiedObject createObject(final String code)
84: throws FactoryException {
85: if (projections != null) {
86: final String crs = (String) projections.get(code);
87: if (crs != null) {
88: return ((CRSAuthorityFactory) factory)
89: .createProjectedCRS(crs)
90: .getConversionFromBase();
91: }
92: }
93: return ((CoordinateOperationAuthorityFactory) factory)
94: .createCoordinateOperation(code);
95: }
96: }
|