001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.referencing.factory.epsg;
017:
018: /**
019: * Information about a specific table. This class also provides some utility methods
020: * for the creation of SQL queries. The MS-Access dialect of SQL is assumed (it will
021: * be translated into ANSI SQL later by {@link DirectEpsgFactory#adaptSQL} if needed).
022: *
023: * @since 2.2
024: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/factory/epsg/TableInfo.java $
025: * @version $Id: TableInfo.java 26090 2007-06-29 08:09:27Z desruisseaux $
026: * @author Martin Desruisseaux
027: */
028: final class TableInfo {
029: /**
030: * The class of object to be created.
031: */
032: public final Class type;
033:
034: /**
035: * The table name for SQL queries. May contains a {@code "JOIN"} clause.
036: */
037: public final String table;
038:
039: /**
040: * Column name for the code (usually with the {@code "_CODE"} suffix).
041: */
042: public final String codeColumn;
043:
044: /**
045: * Column name for the name (usually with the {@code "_NAME"} suffix), or {@code null}.
046: */
047: public final String nameColumn;
048:
049: /**
050: * Column type for the type (usually with the {@code "_TYPE"} suffix), or {@code null}.
051: */
052: public final String typeColumn;
053:
054: /**
055: * Sub-interfaces of {@link #type} to handle, or {@code null} if none.
056: */
057: public final Class[] subTypes;
058:
059: /**
060: * Names of {@link #subTypes} in the database, or {@code null} if none.
061: */
062: public final String[] typeNames;
063:
064: /**
065: * Stores information about a specific table.
066: */
067: TableInfo(final Class type, final String table,
068: final String codeColumn, final String nameColumn) {
069: this (type, table, codeColumn, nameColumn, null, null, null);
070: }
071:
072: /**
073: * Stores information about a specific table.
074: */
075: TableInfo(final Class type, final String table,
076: final String codeColumn, final String nameColumn,
077: final String typeColumn, final Class[] subTypes,
078: final String[] typeNames) {
079: this .type = type;
080: this .table = table;
081: this .codeColumn = codeColumn;
082: this .nameColumn = nameColumn;
083: this .typeColumn = typeColumn;
084: this .subTypes = subTypes;
085: this .typeNames = typeNames;
086: }
087:
088: /**
089: * Checks {@link Class#isAssignableFrom} both ways. It may seems strange but try
090: * to catch the following use cases:
091: *
092: * <ul>
093: * <li><p>{@code table.type.isAssignableFrom(kind)}<br>
094: * is for the case where a table is for {@code CoordinateReferenceSystem} while the user
095: * type is some subtype like {@code GeographicCRS}. The {@code GeographicCRS} need to be
096: * queried into the {@code CoordinateReferenceSystem} table. An additional filter will be
097: * applied inside the {@link AuthorityCodes} class implementation.</p></li>
098: *
099: * <li><p>{@code kind.isAssignableFrom(table.type)}<br>
100: * is for the case where the user type is {@code IdentifiedObject} or {@code Object},
101: * in which case we basically want to iterate through every tables.</p></li>
102: * </ul>
103: */
104: public boolean isTypeOf(final Class kind) {
105: return type.isAssignableFrom(kind)
106: || kind.isAssignableFrom(type);
107: }
108: }
|