001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2005, Refractions Research Inc.
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.catalog;
018:
019: import java.io.File;
020: import java.io.IOException;
021: import java.net.URI;
022:
023: import org.geotools.util.ProgressListener;
024:
025: public abstract class AbstractFileGeoResource extends
026: AbstractGeoResource {
027:
028: /**
029: * The file
030: */
031: File file;
032:
033: /**
034: * Service containing the resource.
035: */
036: AbstractFileService service;
037:
038: public AbstractFileGeoResource(AbstractFileService service) {
039: this .service = service;
040: this .file = service.getFile();
041: }
042:
043: public AbstractFileGeoResource(AbstractFileService service,
044: File file) {
045: this .service = service;
046: this .file = file;
047: }
048:
049: public File getFile() {
050: return file;
051: }
052:
053: public Resolve parent(ProgressListener monitor) throws IOException {
054: return service;
055: }
056:
057: /**
058: * Supports default GeoResource resolves with an additional resolve to a
059: * {@link java.io.File}.
060: * <p>
061: * Subclasses may wish to extend, or override this method.
062: * </p>
063: */
064: public boolean canResolve(Class adaptee) {
065:
066: if (adaptee == null)
067: return false;
068:
069: return adaptee.isAssignableFrom(Service.class)
070: || adaptee.isAssignableFrom(GeoResourceInfo.class)
071: || adaptee.isAssignableFrom(File.class);
072: }
073:
074: /**
075: * Supports default GeoResource resolves with an additional resolve to a
076: * {@link java.io.File}.
077: * <p>
078: * Subclasses may wish to extend, or override this method.
079: * </p>
080: */
081: public Object resolve(Class adaptee, ProgressListener monitor)
082: throws IOException {
083:
084: if (adaptee == null)
085: return null;
086:
087: if (adaptee.isAssignableFrom(Service.class)) {
088: return parent(monitor);
089: }
090:
091: if (adaptee.isAssignableFrom(GeoResourceInfo.class)) {
092: return getInfo(monitor);
093: }
094:
095: if (adaptee.isAssignableFrom(File.class)) {
096: return service.getFile();
097: }
098:
099: return null;
100: }
101:
102: /**
103: * Returns {@link #service}#getStatus()
104: */
105: public Status getStatus() {
106: return service.getStatus();
107: }
108:
109: public URI getIdentifier() {
110: return file.toURI();
111: }
112:
113: }
|