001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2006, Geomatys
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.referencing.factory;
018:
019: // OpenGIS dependencies
020: import org.opengis.referencing.AuthorityFactory;
021: import org.opengis.referencing.crs.CRSAuthorityFactory;
022: import org.opengis.referencing.cs.AxisDirection;
023: import org.opengis.referencing.cs.CSAuthorityFactory;
024: import org.opengis.referencing.cs.RangeMeaning;
025: import org.opengis.referencing.datum.DatumAuthorityFactory;
026: import org.opengis.referencing.datum.PixelInCell;
027: import org.opengis.referencing.datum.VerticalDatumType;
028: import org.opengis.referencing.operation.CoordinateOperationAuthorityFactory;
029:
030: /**
031: * An "object type" in a URN.
032: *
033: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/factory/URN_Type.java $
034: * @version $Id: URN_Type.java 23634 2007-01-01 02:38:54Z desruisseaux $
035: * @author Martin Desruisseaux
036: */
037: final class URN_Type {
038: /**
039: * List of object types. An object type is for example {@code "crs"} in
040: * <code>"urn:ogc:def:<b>crs</b>:EPSG:6.8"</code>.
041: */
042: private static final URN_Type[] TYPES = {
043: new URN_Type("crs", CRSAuthorityFactory.class),
044: new URN_Type("datum", DatumAuthorityFactory.class),
045: new URN_Type("meridian", DatumAuthorityFactory.class),
046: new URN_Type("ellipsoid", DatumAuthorityFactory.class),
047: new URN_Type("cs", CSAuthorityFactory.class),
048: new URN_Type("axis", CSAuthorityFactory.class),
049: new URN_Type("coordinateOperation",
050: CoordinateOperationAuthorityFactory.class),
051: new URN_Type("method",
052: CoordinateOperationAuthorityFactory.class),
053: new URN_Type("parameter",
054: CoordinateOperationAuthorityFactory.class),
055: new URN_Type("group",
056: CoordinateOperationAuthorityFactory.class),
057: // new URN_Type("derivedCRSType", ),
058: new URN_Type("verticalDatumType", VerticalDatumType.class),
059: new URN_Type("pixelInCell", PixelInCell.class),
060: new URN_Type("rangeMeaning", RangeMeaning.class),
061: new URN_Type("axisDirection", AxisDirection.class),
062: new URN_Type("uom", CSAuthorityFactory.class) };
063:
064: /**
065: * Subset of {@link #TYPES} for the main ones.
066: */
067: static final URN_Type[] MAIN = { TYPES[0], TYPES[1], TYPES[4],
068: TYPES[6] };
069:
070: /**
071: * The object type name.
072: */
073: public final String name;
074:
075: /**
076: * The factory for this type, either as a {@link AuthorityFactory} subinterface
077: * or a {@link CodeList}.
078: */
079: public final Class type;
080:
081: /**
082: * Creates a new instance of {@code URN_Type}.
083: */
084: private URN_Type(final String name, final Class type) {
085: this .name = name;
086: this .type = type;
087: }
088:
089: /**
090: * Returns an instance of the specified name (case-insensitive), or {@code null} if none.
091: */
092: public static URN_Type get(final String name) {
093: for (int i = 0; i < TYPES.length; i++) {
094: final URN_Type candidate = TYPES[i];
095: if (name.equalsIgnoreCase(candidate.name)) {
096: return candidate;
097: }
098: }
099: return null;
100: }
101:
102: /**
103: * Returns {@code true} if the specified factory is an instance of this type.
104: */
105: public boolean isInstance(final AuthorityFactory factory) {
106: return type.isInstance(factory);
107: }
108:
109: /**
110: * Returns the type name, for formatting and debugging purpose.
111: */
112: public String toString() {
113: return name;
114: }
115: }
|