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: /*
017: * NOTICE OF RELEASE TO THE PUBLIC DOMAIN
018: *
019: * This work was created by employees of the USDA Forest Service's
020: * Fire Science Lab for internal use. It is therefore ineligible for
021: * copyright under title 17, section 105 of the United States Code. You
022: * may treat it as you would treat any public domain work: it may be used,
023: * changed, copied, or redistributed, with or without permission of the
024: * authors, for free or for compensation. You may not claim exclusive
025: * ownership of this code because it is already owned by everyone. Use this
026: * software entirely at your own risk. No warranty of any kind is given.
027: *
028: * A copy of 17-USC-105 should have accompanied this distribution in the file
029: * 17USC105.html. If not, you may access the law via the US Government's
030: * public websites:
031: * - http://www.copyright.gov/title17/92chap1.html#105
032: * - http://www.gpoaccess.gov/uscode/ (enter "17USC105" in the search box.)
033: */
034: package org.geotools.gce.geotiff;
035:
036: // Geotools dependencies
037: import java.util.Collections;
038: import java.util.Map;
039:
040: import org.geotools.coverage.grid.io.GridFormatFactorySpi;
041: import org.opengis.coverage.grid.Format;
042:
043: /**
044: * The <CODE>GeoTiffFormatFactorySpi</CODE> should never be instantiated
045: * directly by user code. It is discovered by the <CODE>GridFormatFinder</CODE>
046: * for automatic discovery. Use the standard Geotools method of discovering a
047: * factory in order to create a format.
048: *
049: * <p>
050: * This format will only report itself to be "available" if the JAI
051: * and JAI ImageI/O libraries are available. Otherwise it will be unavailable.
052: * If a user attempts to create a new instance of the format when the required
053: * libraries are unavailable, an <CODE>UnsupportedOperationException</CODE>
054: * will be thrown.
055: * </p>
056: *
057: * @author Bryce Nordgren / USDA Forest Service
058: * @author Simone Giannecchini
059: * @source $URL:
060: * http://svn.geotools.org/geotools/trunk/gt/plugin/geotiff/src/org/geotools/gce/geotiff/GeoTiffFormatFactorySpi.java $
061: */
062: public final class GeoTiffFormatFactorySpi implements
063: GridFormatFactorySpi {
064: /**
065: * Creates a new instance of GeoTiffFormatFactorySpi
066: */
067: public GeoTiffFormatFactorySpi() {
068: }
069:
070: /**
071: * Creates and returns a new instance of the <CODE>GeoTiffFormat</CODE>
072: * class if the required libraries are present. If JAI and JAI Image I/O are
073: * not present, will throw an <CODE>UnsupportedOperationException</CODE>.
074: *
075: * @return <CODE>GeoTiffFormat</CODE> object.
076: *
077: * @throws UnsupportedOperationException
078: * if this format is unavailable.
079: */
080: public Format createFormat() {
081: if (!isAvailable()) {
082: throw new UnsupportedOperationException(
083: "The GeoTiff plugin requires the JAI and JAI ImageI/O libraries!");
084: }
085:
086: return new GeoTiffFormat();
087: }
088:
089: /**
090: * Informs the caller whether the libraries required by the GeoTiff reader
091: * are installed or not.
092: *
093: * @return availability of the GeoTiff format.
094: */
095: public boolean isAvailable() {
096: boolean available = true;
097:
098: // if these classes are here, then the runtine environment has
099: // access to JAI and the JAI ImageI/O toolbox.
100: try {
101: Class.forName("javax.media.jai.JAI");
102: Class
103: .forName("com.sun.media.jai.operator.ImageReadDescriptor");
104: } catch (ClassNotFoundException cnf) {
105: available = false;
106: }
107:
108: return available;
109: }
110:
111: /**
112: * Returns the implementation hints. The default implementation returns en
113: * empty map.
114: *
115: * @return Empty Map.
116: */
117: public Map getImplementationHints() {
118: return Collections.EMPTY_MAP;
119: }
120: }
|