001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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; either
009: * version 2.1 of the License, or (at your option) any later version.
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.catalog.wfs;
017:
018: import org.geotools.catalog.AbstractGeoResource;
019: import org.geotools.catalog.Catalog;
020: import org.geotools.catalog.GeoResource;
021: import org.geotools.catalog.GeoResourceInfo;
022: import org.geotools.catalog.ResolveChangeEvent;
023: import org.geotools.catalog.ResolveDelta;
024: import org.geotools.catalog.Service;
025: import org.geotools.catalog.defaults.DefaultGeoResourceInfo;
026: import org.geotools.catalog.defaults.DefaultResolveChangeEvent;
027: import org.geotools.catalog.defaults.DefaultResolveDelta;
028: import org.geotools.data.FeatureSource;
029: import org.geotools.data.FeatureStore;
030: import org.geotools.data.ows.FeatureSetDescription;
031: import org.geotools.data.wfs.WFSDataStore;
032: import org.geotools.feature.FeatureType;
033: import org.geotools.geometry.jts.ReferencedEnvelope;
034: import org.geotools.referencing.crs.DefaultGeographicCRS;
035: import org.geotools.util.ProgressListener;
036: import org.opengis.referencing.crs.CoordinateReferenceSystem;
037: import java.io.IOException;
038: import java.net.URI;
039: import java.net.URISyntaxException;
040: import java.util.Iterator;
041: import java.util.List;
042:
043: /**
044: * Access a feature type in a wfs.
045: *
046: * @since 0.6
047: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wfs/src/main/java/org/geotools/catalog/wfs/WFSGeoResource.java $
048: */
049: public class WFSGeoResource extends AbstractGeoResource {
050: WFSService parent;
051: String typename = null;
052: private GeoResourceInfo info;
053:
054: private WFSGeoResource() { /*not for use*/
055: }
056:
057: /**
058: * Construct <code>WFSGeoResourceImpl</code>.
059: *
060: * @param parent
061: * @param typename
062: */
063: public WFSGeoResource(WFSService parent, String typename) {
064: this .parent = parent;
065: this .typename = typename;
066: }
067:
068: public URI getIdentifier() {
069: try {
070: return new URI(parent.getIdentifier().toString() + "#"
071: + typename);
072: } catch (URISyntaxException e) {
073: return parent.getIdentifier();
074: }
075: }
076:
077: /*
078: * @see net.refractions.udig.catalog.IGeoResource#getStatus()
079: */
080: public Status getStatus() {
081: return parent.getStatus();
082: }
083:
084: /*
085: * @see net.refractions.udig.catalog.IGeoResource#getStatusMessage()
086: */
087: public Throwable getMessage() {
088: return parent.getMessage();
089: }
090:
091: /*
092: * Required adaptions:
093: * <ul>
094: * <li>IGeoResourceInfo.class
095: * <li>IService.class
096: * </ul>
097: */
098: public Object resolve(Class adaptee, ProgressListener monitor)
099: throws IOException {
100: if (adaptee == null) {
101: return null;
102: }
103:
104: if (adaptee.isAssignableFrom(Service.class)) {
105: return parent;
106: }
107:
108: if (adaptee.isAssignableFrom(WFSDataStore.class)) {
109: return parent.resolve(adaptee, monitor);
110: }
111:
112: if (adaptee.isAssignableFrom(GeoResource.class)) {
113: return this ;
114: }
115:
116: if (adaptee.isAssignableFrom(GeoResourceInfo.class)) {
117: return getInfo(monitor);
118: }
119:
120: if (adaptee.isAssignableFrom(FeatureStore.class)) {
121: FeatureSource fs = parent.getDS()
122: .getFeatureSource(typename);
123:
124: if (fs instanceof FeatureStore) {
125: return fs;
126: }
127:
128: if (adaptee.isAssignableFrom(FeatureSource.class)) {
129: return parent.getDS().getFeatureSource(typename);
130: }
131: }
132:
133: return null;
134: }
135:
136: /*
137: * @see net.refractions.udig.catalog.IResolve#canResolve(java.lang.Class)
138: */
139: public boolean canResolve(Class adaptee) {
140: if (adaptee == null) {
141: return false;
142: }
143:
144: return (adaptee.isAssignableFrom(GeoResourceInfo.class)
145: || adaptee.isAssignableFrom(FeatureStore.class)
146: || adaptee.isAssignableFrom(FeatureSource.class)
147: || adaptee.isAssignableFrom(WFSDataStore.class) || adaptee
148: .isAssignableFrom(Service.class));
149: }
150:
151: public GeoResourceInfo getInfo(ProgressListener monitor)
152: throws IOException {
153: if ((info == null) && (getStatus() != Status.BROKEN)) {
154: synchronized (parent.getDS()) {
155: if (info == null) {
156: info = new IGeoResourceWFSInfo();
157: }
158: }
159:
160: ResolveDelta delta = new DefaultResolveDelta(this ,
161: ResolveDelta.Kind.CHANGED);
162: ResolveChangeEvent event = new DefaultResolveChangeEvent(
163: this , ResolveChangeEvent.Type.POST_CHANGE, delta);
164:
165: ((Catalog) parent(monitor).parent(monitor)).fire(event);
166: }
167:
168: return info;
169: }
170:
171: class IGeoResourceWFSInfo extends DefaultGeoResourceInfo {
172: CoordinateReferenceSystem crs = null;
173:
174: IGeoResourceWFSInfo() throws IOException {
175: FeatureType ft = parent.getDS().getSchema(typename);
176:
177: List fts = parent.getDS().getCapabilities()
178: .getFeatureTypes();
179: FeatureSetDescription fsd = null;
180:
181: if (fts != null) {
182: Iterator i = fts.iterator();
183:
184: while (i.hasNext() && (fsd == null)) {
185: FeatureSetDescription t = (FeatureSetDescription) i
186: .next();
187:
188: if ((t != null) && typename.equals(t.getName())) {
189: fsd = t;
190: }
191: }
192: }
193:
194: bounds = new ReferencedEnvelope(
195: fsd.getLatLongBoundingBox(),
196: DefaultGeographicCRS.WGS84);
197: description = fsd.getAbstract();
198:
199: try {
200: crs = ft.getDefaultGeometry().getCoordinateSystem();
201: } catch (Exception e) {
202: crs = DefaultGeographicCRS.WGS84;
203: }
204:
205: name = typename;
206: schema = ft.getNamespace();
207: title = fsd.getTitle();
208:
209: keywords = new String[] { "wfs", //$NON-NLS-1$
210: typename, ft.getNamespace().toString() };
211: }
212:
213: /*
214: * @see net.refractions.udig.catalog.IGeoResourceInfo#getCRS()
215: */
216: public CoordinateReferenceSystem getCRS() {
217: if (crs != null) {
218: return crs;
219: }
220:
221: return super.getCRS();
222: }
223: }
224: }
|