⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 featuretypeconfig.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */
package org.vfny.geoserver.config;

import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.geotools.feature.AttributeType;
import org.geotools.feature.AttributeType;
import org.geotools.feature.FeatureType;
import org.geotools.feature.FeatureType;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.referencing.CRS;
import org.opengis.filter.Filter;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.vfny.geoserver.global.FeatureTypeInfo;
import org.vfny.geoserver.global.dto.AttributeTypeInfoDTO;
import org.vfny.geoserver.global.dto.CloneLibrary;
import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;


/**
 * User interface FeatureType staging area.
 *
 * @author dzwiers, Refractions Research, Inc.
 * @version $Id: FeatureTypeConfig.java 7746 2007-11-13 15:38:35Z aaime $
 */
public class FeatureTypeConfig {
    protected static Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.vfny.geoserver.config");

    /** The Id of the datastore which should be used to get this featuretype. */
    private String dataStoreId;

    /** An EPSG:4326 bounding box for this featuretype */
    private Envelope latLongBBox;

    /** A native CRS bounding box for this featuretype */
    private Envelope nativeBBox;

    /** native wich EPGS code for the FeatureTypeInfo */
    private int SRS;
    
    /** 
     * Either force declared or reproject from native to declared, see {@link FeatureTypeInfo#FORCE}
     * and {@link FeatureTypeInfo#REPROJECT}
     */
    private int SRSHandling;

    /**
     * This is an ordered list of AttributeTypeInfoConfig.
     * <p>
     * These attribtue have been defined by the user (or schema.xml file).
     * Additional attribute may be assumed based on the schemaBase
     * </p>
     * <p>
     * If this is <code>null</code>, all Attribtue information
     * will be generated. An empty list is used to indicate that only
     * attribtues indicated by the schemaBase will be returned.
     * </p>
     */
    private List schemaAttributes;

    /** Name (must match DataStore typeName). */
    private String name;

    /**
     *
     */
    private String wmsPath;

    /**
    * The schema name.
    * <p>
    * Usually  name + "_Type"
    * </p>
    */
    private String schemaName;

    /**
     * The schema base.
     * <p>
     * The schema base is used to indicate additional attribtues, not defined
     * by the user. These attribute are fixed -not be edited by the user.
     * </p>
     * <p>
     * This easiest is "AbstractFeatureType"
     * </p>
     */
    private String schemaBase;

    /**
     * The featuretype directory name.
     * <p>
     * This is used to write to, and is  stored because it may be longer than
     * the name, as this often includes information about the source of the
     * featuretype.
     * </p>
     * <p>
     * A common naming convention is: <code>dataStoreId + "_" + name</code>
     * </p>
     */
    private String dirName;

    /**
     * The featuretype title.
     * <p>
     * Not sure what this is used for - usually name+"_Type"
     */
    private String title;

    /** The feature type abstract, short explanation of this featuretype. */
    private String _abstract;

    /**
     * A list of keywords to associate with this featuretype.
     * <p>
     * Keywords are destinct strings, often rendered surrounded by brackets
     * to aid search engines.
     * </p>
     */
    private Set keywords;

    /**
     * A list of metadata links to associate with this featuretype.
     * <p>
     * Metadata URLs are distinct URLs.
     * </p>
     */
    private Set metadataLinks;

    /** Configuration information used to specify numeric percision */
    private int numDecimals;

    /**
     * Filter used to limit query.
     * <p>
     * TODO: Check the following comment - I don't belive it.
     * The list of exposed attributes. If the list is empty or not present at
     * all, all the FeatureTypeInfo's attributes are exposed, if is present,
     * only those oattributes in this list will be exposed by the services
     * </p>
     */
    private Filter definitionQuery = null;

    /**
     * The default style name.
     */
    private String defaultStyle;

    /**
     * Other WMS Styles
     */
    private ArrayList styles;

    /**
     * A featureType-specific override for the defaultMaxAge defined in WMSConfig.  This value is added the
     * headers of generated maps, marking them as being both "cache-able" and designating the time for which
     * they are to remain valid.  The specific header added is "CacheControl: max-age="
     */
    private String cacheMaxAge;

    /**
     * Should we be adding the CacheControl: max-age header to outgoing maps which include this layer?
     */
    private boolean cachingEnabled;

    /**
     * Package visible constructor for test cases
     */
    FeatureTypeConfig() {
    }

    /**
     * Creates a FeatureTypeInfo to represent an instance with default data.
     *
     * @param dataStoreId ID for data store in catalog
     * @param schema Geotools2 FeatureType
     * @param generate True to generate entries for all attribtues
     */
    public FeatureTypeConfig(String dataStoreId, FeatureType schema, boolean generate) {
        if ((dataStoreId == null) || (dataStoreId.length() == 0)) {
            throw new IllegalArgumentException("dataStoreId is required for FeatureTypeConfig");
        }

        if (schema == null) {
            throw new IllegalArgumentException("FeatureType is required for FeatureTypeConfig");
        }

        this.dataStoreId = dataStoreId;
        latLongBBox = new Envelope();
        nativeBBox = new Envelope();
        SRS = lookupSRS(schema.getDefaultGeometry());

        if (generate) {
            this.schemaAttributes = new ArrayList();

            for (int i = 0; i < schema.getAttributeCount(); i++) {
                AttributeType attrib = schema.getAttributeType(i);
                this.schemaAttributes.add(new AttributeTypeInfoConfig(attrib));
            }
        } else {
            this.schemaAttributes = null;
        }

        defaultStyle = "";
        styles = new ArrayList();
        name = schema.getTypeName();
        wmsPath = "/";
        title = schema.getTypeName() + "_Type";
        _abstract = "Generated from " + dataStoreId;
        keywords = new HashSet();
        keywords.add(dataStoreId);
        keywords.add(name);
        metadataLinks = new HashSet();
        numDecimals = 8;
        definitionQuery = null;
        dirName = dataStoreId + "_" + name;
        schemaName = name + "_Type";
        schemaBase = "gml:AbstractFeatureType";

        cachingEnabled = false;
        cacheMaxAge = null;
    }

    /**
     * TODO: this method is duplicated with CoveragesEditorAction and should be replaced by
     * an equivalent method in CRS class. Once the methods is added, forward to the CRS class.
     * @param defaultGeometry
     * @return
     */
    private int lookupSRS(GeometryAttributeType defaultGeometry) {
        // NPE avoidance
        if (defaultGeometry == null) {
            return -1;
        }

        // try the (deprecated) geometry factory, we don't want to break data stores that
        // do correctly set it
        GeometryFactory geometryFactory = defaultGeometry.getGeometryFactory();

        if ((geometryFactory != null) && (geometryFactory.getSRID() != 0)) {
            return geometryFactory.getSRID();
        }

        return 0;

        //        // try to reverse engineer the SRID from the coordinate system
        //        CoordinateReferenceSystem ref = defaultGeometry.getCoordinateSystem();
        //        String code = CRS.lookupIdentifier(ref, Collections.singleton("EPSG"), true);
        //        if(code == null)
        //            return 0;
        //        if(code.startsWith("EPSG:")) {
        //            code = code.substring(5);
        //        }
        //        try {
        //            return Integer.parseInt(code);
        //        } catch(NumberFormatException e) {
        //            LOGGER.severe("Could not parse EPSG code: " + code);
        //            return 0;
        //        }
    }

    /**
     * FeatureTypeInfo constructor.
     *
     * <p>
     * Creates a copy of the FeatureTypeInfoDTO provided. All the data
     * structures are cloned.
     * </p>
     *
     * @param dto The FeatureTypeInfoDTO to copy.
     *
     * @throws NullPointerException DOCUMENT ME!
     */
    public FeatureTypeConfig(FeatureTypeInfoDTO dto) {
        if (dto == null) {
            throw new NullPointerException("Non null FeatureTypeInfoDTO required");
        }

        dataStoreId = dto.getDataStoreId();
        latLongBBox = new Envelope(dto.getLatLongBBox());
        nativeBBox = new Envelope(dto.getNativeBBox());
        SRS = dto.getSRS();
        SRSHandling = dto.getSRSHandling();

        if (dto.getSchemaAttributes() == null) {
            schemaAttributes = null;
        } else {
            schemaAttributes = new LinkedList();

            Iterator i = dto.getSchemaAttributes().iterator();

            while (i.hasNext()) {
                schemaAttributes.add(new AttributeTypeInfoConfig((AttributeTypeInfoDTO) i.next()));
            }
        }

        name = dto.getName();
        wmsPath = dto.getWmsPath();
        title = dto.getTitle();
        _abstract = dto.getAbstract();
        numDecimals = dto.getNumDecimals();
        definitionQuery = dto.getDefinitionQuery();

        try {
            keywords = new HashSet(dto.getKeywords());
        } catch (Exception e) {
            keywords = new HashSet();
        }

        try {
            metadataLinks = new HashSet(dto.getMetadataLinks());
        } catch (Exception e) {
            metadataLinks = new HashSet();
        }

        defaultStyle = dto.getDefaultStyle();
        styles = dto.getStyles();
        dirName = dto.getDirName();
        schemaName = dto.getSchemaName();
        schemaBase = dto.getSchemaBase();

        cachingEnabled = dto.isCachingEnabled();
        cacheMaxAge = dto.getCacheMaxAge();
    }

    /**
     * Implement toDTO.
     *
     * <p>
     * Creates a represetation of this object as a FeatureTypeInfoDTO
     * </p>
     *
     * @return a representation of this object as a FeatureTypeInfoDTO
     *
     * @see org.vfny.geoserver.config.DataStructure#toDTO()
     */
    public FeatureTypeInfoDTO toDTO() {
        FeatureTypeInfoDTO f = new FeatureTypeInfoDTO();
        f.setDataStoreId(dataStoreId);
        f.setLatLongBBox(CloneLibrary.clone(latLongBBox));
        f.setNativeBBox(CloneLibrary.clone(nativeBBox));
        f.setSRS(SRS);
        f.setSRSHandling(SRSHandling);

        if (schemaAttributes == null) {
            // Use generated default attributes
            f.setSchemaAttributes(null);
        } else {
            // Use user provided attribtue + schemaBase attribtues
            List s = new ArrayList();

            for (int i = 0; i < schemaAttributes.size(); i++) {
                s.add(((AttributeTypeInfoConfig) schemaAttributes.get(i)).toDTO());
            }

            f.setSchemaAttributes(s);
        }

        f.setName(name);
        f.setWmsPath(wmsPath);
        f.setTitle(title);
        f.setAbstract(_abstract);
        f.setNumDecimals(numDecimals);
        f.setDefinitionQuery(definitionQuery);

        try {
            f.setKeywords(new ArrayList(keywords));
        } catch (Exception e) {
            // do nothing, defaults already exist.
        }

        try {
            f.setMetadataLinks(new ArrayList(metadataLinks));
        } catch (Exception e) {
            // do nothing, defaults already exist.
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -