001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.geoserver.wfs;
006:
007: import net.opengis.wfs.DescribeFeatureTypeType;
008: import org.vfny.geoserver.global.Data;
009: import org.vfny.geoserver.global.FeatureTypeInfo;
010: import java.util.ArrayList;
011: import java.util.Collection;
012: import java.util.Iterator;
013: import java.util.List;
014: import javax.xml.namespace.QName;
015:
016: /**
017: * Web Feature Service DescribeFeatureType operation.
018: * <p>
019: * This operation returns an array of {@link org.geoserver.data.feature.FeatureTypeInfo} metadata
020: * objects corresponding to the feature type names specified in the request.
021: * </p>
022: *
023: * @author Rob Hranac, TOPP
024: * @author Chris Holmes, TOPP
025: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
026: *
027: * @version $Id: DescribeFeatureType.java 6326 2007-03-15 18:36:40Z jdeolive $
028: */
029: public class DescribeFeatureType {
030: /**
031: * Catalog reference
032: */
033: private Data catalog;
034:
035: /**
036: * WFS service
037: */
038: private WFS wfs;
039:
040: /**
041: * Creates a new wfs DescribeFeatureType operation.
042: *
043: * @param wfs The wfs configuration
044: * @param catalog The geoserver catalog.
045: */
046: public DescribeFeatureType(WFS wfs, Data catalog) {
047: this .catalog = catalog;
048: this .wfs = wfs;
049: }
050:
051: public WFS getWFS() {
052: return wfs;
053: }
054:
055: public void setWFS(WFS wfs) {
056: this .wfs = wfs;
057: }
058:
059: public Data getCatalog() {
060: return catalog;
061: }
062:
063: public void setCatalog(Data catalog) {
064: this .catalog = catalog;
065: }
066:
067: public FeatureTypeInfo[] run(DescribeFeatureTypeType request)
068: throws WFSException {
069: List names = new ArrayList(request.getTypeName());
070:
071: //list of catalog handles
072: Collection infos = catalog.getFeatureTypeInfos().values();
073: ArrayList requested = new ArrayList();
074:
075: if (!names.isEmpty()) {
076: O: for (Iterator t = names.iterator(); t.hasNext();) {
077: QName name = (QName) t.next();
078:
079: for (Iterator h = infos.iterator(); h.hasNext();) {
080: FeatureTypeInfo meta = (FeatureTypeInfo) h.next();
081: String namespace = meta.getNameSpace().getURI();
082: String local = meta.getTypeName();
083:
084: if (namespace.equals(name.getNamespaceURI())
085: && local.equals(name.getLocalPart())) {
086: //found, continue on and keep this handle in list
087: requested.add(meta);
088:
089: continue O;
090: }
091: }
092:
093: //not found
094: String msg = "Could not find type: " + name;
095: throw new WFSException(msg);
096: }
097: } else {
098: //if there are no specific requested types then get all.
099: requested.addAll(infos);
100: }
101:
102: return (FeatureTypeInfo[]) requested
103: .toArray(new FeatureTypeInfo[requested.size()]);
104: }
105: }
|