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.IOException;
020: import java.util.List;
021: import java.util.logging.Logger;
022:
023: import org.geotools.util.ProgressListener;
024:
025: /**
026: * Abstract implementation of GeoResource.
027: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/catalog/AbstractGeoResource.java $
028: */
029: public abstract class AbstractGeoResource implements GeoResource {
030:
031: /**
032: * logger
033: */
034: protected static Logger logger = org.geotools.util.logging.Logging
035: .getLogger("org.geotools.catalog");
036:
037: /**
038: * Error message
039: */
040: private Throwable msg;
041:
042: /**
043: * This method is shorthand for
044: * <pre>
045: * <code>
046: * return (Service) resolve(Service.class, monitor);
047: * </code>
048: * </pre>
049: *
050: * @param monitor DOCUMENT ME!
051: *
052: * @return The service containg the resource, an object of type Service.
053: *
054: * @throws IOException DOCUMENT ME!
055: *
056: * @see AbstractGeoResource#resolve(Class, ProgressListener)
057: */
058: public Resolve parent(ProgressListener monitor) throws IOException {
059: return (Service) resolve(Service.class, monitor);
060: }
061:
062: /**
063: * return null ... almost always a leaf
064: *
065: * @see net.refractions.udig.catalog.IResolve#members(org.eclipse.core.runtime.ProgressListener)
066: */
067: public List members(ProgressListener monitor) {
068: return null;
069: }
070:
071: /**
072: * @return The cached error message.
073: */
074: public Throwable getMessage() {
075: return msg;
076: }
077:
078: /**
079: * Sets the cached error message.
080: *
081: * @param msg An exception which occured when connecting to the service.
082: */
083: protected void setMessage(Throwable msg) {
084: this .msg = msg;
085: }
086:
087: /**
088: * This should represent the identifier
089: *
090: * @param other
091: *
092: *
093: * @see Object#equals(java.lang.Object)
094: */
095: public boolean equals(Object other) {
096: if ((other != null) && other instanceof GeoResource) {
097: GeoResource resource = (GeoResource) other;
098:
099: if ((getIdentifier() != null)
100: && (resource.getIdentifier() != null)) {
101: return getIdentifier().equals(resource.getIdentifier());
102: }
103: }
104:
105: return false;
106: }
107:
108: /**
109: * This method does nothing. Sublcasses should override if events are
110: * supported.
111: *
112: * @param listener DOCUMENT ME!
113: */
114: public void addListener(ResolveChangeListener listener) {
115: // do nothing
116: }
117:
118: /**
119: * This method does nothing. Sublcasses should override if events are
120: * supported.
121: *
122: * @param listener DOCUMENT ME!
123: */
124: public void removeListener(ResolveChangeListener listener) {
125: // do nothing
126: }
127:
128: /**
129: * This method does nothing. Sublcasses should override if events are
130: * supported.
131: *
132: * @param event DOCUMENT ME!
133: */
134: public void fire(ResolveChangeEvent event) {
135: // do nothing
136: }
137:
138: /**
139: * This should represent the identified
140: *
141: *
142: * @see Object#hashCode()
143: */
144: public int hashCode() {
145: if (getIdentifier() != null) {
146: return getIdentifier().hashCode();
147: }
148:
149: return super .hashCode();
150: }
151:
152: /**
153: * Non blocking label used by LabelProvider. public static final String
154: * getGenericLabel(IGeoResource resource){ assert resource.getIdentifier()
155: * != null; return resource==null ||
156: * resource.getIdentifier()==null?"Resource":resource.getIdentifier().toString();
157: * }
158: *
159: * @return DOCUMENT ME!
160: */
161: /**
162: * Non blocking icon used by LabelProvider. public static final
163: * ImageDescriptor getGenericIcon(IGeoResource resource){ if(resource
164: * !=null){ assert resource.getIdentifier() != null;
165: * if(resource.canResolve(FeatureSource.class)){ // default feature return
166: * Images.getDescriptor(ISharedImages.FEATURE_OBJ); }
167: * if(resource.canResolve(GridCoverage.class)){ // default raster return
168: * Images.getDescriptor(ISharedImages.GRID_OBJ); }} return
169: * Images.getDescriptor(ISharedImages.RESOURCE_OBJ); }
170: *
171: * @return DOCUMENT ME!
172: */
173: /**
174: * Indicate class and id.
175: *
176: * @return string representing this IResolve
177: */
178: public String toString() {
179: StringBuffer buf = new StringBuffer();
180: String classname = getClass().getName();
181: String name = classname
182: .substring(classname.lastIndexOf('.') + 1);
183: buf.append(name);
184: buf.append("("); //$NON-NLS-1$
185: buf.append(getIdentifier());
186: buf.append(")"); //$NON-NLS-1$
187:
188: return buf.toString();
189: }
190: }
|