📄 featuretypeinfo.java
字号:
/* 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.global;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import org.geoserver.feature.FeatureSourceUtils;
import org.geotools.data.DataSourceException;
import org.geotools.data.DataStore;
import org.geotools.data.FeatureSource;
import org.geotools.factory.FactoryConfigurationError;
import org.geotools.feature.AttributeType;
import org.geotools.feature.FeatureType;
import org.geotools.feature.FeatureTypeFactory;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.feature.SchemaException;
import org.geotools.feature.type.GeometricAttributeType;
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.geotools.styling.Style;
import org.opengis.filter.Filter;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.vfny.geoserver.global.dto.AttributeTypeInfoDTO;
import org.vfny.geoserver.global.dto.DataTransferObjectFactory;
import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
import org.vfny.geoserver.global.dto.LegendURLDTO;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Represents a FeatureTypeInfo, its user config and autodefined information.
* <p>
* This class implements {@link org.geotools.catalog.Service} interface as a
* link to a catalog.
* </p>
* @author Gabriel Rold?n
* @author Chris Holmes
* @author dzwiers
* @author Charles Kolbowicz
*
* @version $Id: FeatureTypeInfo.java 7443 2007-08-17 15:31:49Z aaime $
*/
public class FeatureTypeInfo extends GlobalLayerSupertype {
/** hash table that takes a epsg# to its definition**/
private static Hashtable SRSLookup = new Hashtable();
/**
* Force declared SRS
*/
public static int FORCE = 0;
/**
* Reproject to declared SRS
*/
public static int REPROJECT = 1;
/**
* Don't do anything, declared and actual are equal
*/
public static int LEAVE = 2;
/** Default constant */
private static final int DEFAULT_NUM_DECIMALS = 8;
/**
* Id used to locate parent DataStoreInfo using Data Catalog.
*/
private String dataStoreId;
/**
* Bounding box in Lat Long of the extent of this FeatureType.<p>Note
* reprojection may be required to derive this value.</p>
*/
private Envelope latLongBBox;
/**
* Bounding box in this FeatureType's native (or user declared) CRS.<p>Note
* reprojection may be required to derive this value.</p>
*/
private Envelope nativeBBox;
/**
* SRS number used to locate Coordidate Reference Systems
* <p>
* This will be used for reprojection and such like.
* </p>
*/
private int SRS;
/**
* List of AttributeTypeInfo representing the schema.xml information.
* <p>
* Used to define the order and manditoryness of FeatureType attributes
* during query (re)construction.
* </p>
*/
private List schema;
/** Name of elment that is an instance of schemaBase */
private String schemaName;
/** Base schema (usually NullType) defining manditory attribtues */
private String schemaBase;
/** typeName as defined by gt2 DataStore */
private String typeName;
/**
*
*/
private String wmsPath;
/**
* Directory where featureType is loaded from.
*
* This may contain metadata files.
*/
private String dirName;
/**
* Abstract used to describe FeatureType
*/
private String _abstract;
/**
* List of keywords for Web Register Services
*/
private List keywords;
/**
* List of keywords for Web Register Services
*/
private List metadataLinks;
/**
* Number of decimals used in GML output.
*/
private int numDecimals;
/**
* Magic query used to limit scope of this FeatureType.
*/
private Filter definitionQuery = null;
/**
* Default style used to render this FeatureType with WMS
*/
private String defaultStyle;
/**
* Other WMS Styles
*/
private ArrayList styles;
/**
* Title of this FeatureType as presented to End-Users.
* <p>
* Think of this as the display name on the off chance that typeName
* is considered ugly.
* </p>
*/
private String title;
/**
* ref to parent set of datastores.
* <p>
* This backpointer to our Catalog can be used to locate our DataStore
* using the dataStoreId.
* </p>
*/
private Data data;
/**
* MetaData used by apps to squirel information away for a rainy day.
*/
private Map meta;
/**
* AttributeTypeInfo by attribute name.
*
* <p>
* This will be null unless populated by schema or DTO.
* Even if the DTO provides one this list will be lazily
* created - so use the accessors.
* </p>
*/
private String xmlSchemaFrag;
/**
* The real geotools2 featureType cached for sanity checks.
* <p>
* This will be lazily created so use the accessors
* </p>
*/
private FeatureType ft;
// Modif C. Kolbowicz - 07/10/2004
/**
* Holds value of property legendURL.
*/
private LegendURL legendURL;
//-- Modif C. Kolbowicz - 07/10/2004
/** Holds the location of the file that contains schema information. */
private File schemaFile;
/**
* dont use this unless you know what you're doing. its for TemporaryFeatureTypeInfo.
*
*/
public FeatureTypeInfo() {
}
/**
* 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 "Cache-Control: max-age="
*/
private String cacheMaxAge;
/**
* Should we be adding the CacheControl: max-age header to outgoing maps which include this layer?
*/
private boolean cachingEnabled;
/**
* Either force or reproject (force is the only way if native data has no native SRS)
*/
private int srsHandling;
/**
* FeatureTypeInfo constructor.
*
* <p>
* Generates a new object from the data provided.
* </p>
*
* @param dto FeatureTypeInfoDTO The data to populate this class with.
* @param data Data a reference for future use to get at DataStoreInfo
* instances
*
* @throws ConfigurationException
*/
public FeatureTypeInfo(FeatureTypeInfoDTO dto, Data data)
throws ConfigurationException {
this.data = data;
_abstract = dto.getAbstract();
dataStoreId = dto.getDataStoreId();
defaultStyle = dto.getDefaultStyle();
styles = dto.getStyles();
// Modif C. Kolbowicz - 07/10/2004
if (dto.getLegendURL() != null) {
legendURL = new LegendURL(dto.getLegendURL());
} //-- Modif C. Kolbowicz - 07/10/2004
definitionQuery = dto.getDefinitionQuery();
dirName = dto.getDirName();
keywords = dto.getKeywords();
metadataLinks = dto.getMetadataLinks();
latLongBBox = dto.getLatLongBBox();
typeName = dto.getName();
wmsPath = dto.getWmsPath();
numDecimals = dto.getNumDecimals();
List tmp = dto.getSchemaAttributes();
schema = new LinkedList();
if ((tmp != null) && !tmp.isEmpty()) {
Iterator i = tmp.iterator();
while (i.hasNext())
schema.add(new AttributeTypeInfo((AttributeTypeInfoDTO) i.next()));
}
schemaBase = dto.getSchemaBase();
schemaName = dto.getSchemaName();
schemaFile = dto.getSchemaFile();
SRS = dto.getSRS();
srsHandling = dto.getSRSHandling();
nativeBBox = dto.getNativeBBox();
title = dto.getTitle();
cacheMaxAge = dto.getCacheMaxAge();
cachingEnabled = dto.isCachingEnabled();
}
/**
* toDTO purpose.
*
* <p>
* This method is package visible only, and returns a reference to the
* GeoServerDTO. This method is unsafe, and should only be used with
* extreme caution.
* </p>
*
* @return FeatureTypeInfoDTO the generated object
*/
public Object toDTO() {
FeatureTypeInfoDTO dto = new FeatureTypeInfoDTO();
dto.setAbstract(_abstract);
dto.setDataStoreId(dataStoreId);
dto.setDefaultStyle(defaultStyle);
dto.setStyles(styles);
// Modif C. Kolbowicz - 07/10/2004
if (legendURL != null) {
dto.setLegendURL((LegendURLDTO) legendURL.toDTO());
} //-- Modif C. Kolbowicz - 07/10/2004
dto.setDefinitionQuery(definitionQuery);
dto.setDirName(dirName);
dto.setKeywords(keywords);
dto.setMetadataLinks(metadataLinks);
dto.setLatLongBBox(latLongBBox);
dto.setNativeBBox(nativeBBox);
dto.setName(typeName);
dto.setWmsPath(wmsPath);
dto.setNumDecimals(numDecimals);
List tmp = new LinkedList();
Iterator i = schema.iterator();
while (i.hasNext()) {
tmp.add(((AttributeTypeInfo) i.next()).toDTO());
}
dto.setSchemaAttributes(tmp);
dto.setSchemaBase(schemaBase);
dto.setSchemaName(getSchemaName());
dto.setSRS(SRS);
dto.setTitle(title);
dto.setCacheMaxAge(cacheMaxAge);
dto.setCachingEnabled(cachingEnabled);
return dto;
}
/**
* getNumDecimals purpose.
*
* <p>
* The default number of decimals allowed in the data.
* </p>
*
* @return int the default number of decimals allowed in the data.
*/
public int getNumDecimals() {
return numDecimals;
}
/**
* getDataStore purpose.
*
* <p>
* gets the string of the path to the schema file. This is set during
* feature reading, the schema file should be in the same folder as the
* feature type info, with the name schema.xml. This function does not
* guarantee that the schema file actually exists, it just gives the
* location where it _should_ be located.
* </p>
*
* @return DataStoreInfo the requested DataStoreInfo if it was found.
*
* @see Data#getDataStoreInfo(String)
*/
public DataStoreInfo getDataStoreInfo() {
return data.getDataStoreInfo(dataStoreId);
}
/**
* By now just return the default style to be able to declare it in
* WMS capabilities, but all this stuff needs to be revisited since it seems
* currently there is no way of retrieving all the styles declared for
* a given FeatureType.
*
* @return the default Style for the FeatureType
*/
public Style getDefaultStyle() {
return data.getStyle(defaultStyle);
}
public ArrayList getStyles() {
final ArrayList realStyles = new ArrayList();
Iterator s_IT = styles.iterator();
while (s_IT.hasNext())
realStyles.add(data.getStyle((String) s_IT.next()));
return realStyles;
}
/**
* Indicates if this FeatureTypeInfo is enabled. For now just gets whether
* the backing datastore is enabled.
*
* @return <tt>true</tt> if this FeatureTypeInfo is enabled.
*
* @task REVISIT: Consider adding more fine grained control to config
* files, so users can indicate specifically if they want the
* featureTypes enabled, instead of just relying on if the datastore
* is. Jody here - this should be done on a service by service basis
* WMS and WFS will need to decide for themselves on this one
*/
public boolean isEnabled() {
return (getDataStoreInfo() != null) && (getDataStoreInfo().isEnabled());
}
/**
* Returns the XML prefix used for GML output of this FeatureType.
*
* <p>
* Returns the namespace prefix for this FeatureTypeInfo.
* </p>
*
* @return String the namespace prefix.
*/
public String getPrefix() {
return getDataStoreInfo().getNameSpace().getPrefix();
}
/**
* Gets the namespace for this featureType.
* <p>
* This isn't _really_ necessary,
* but I'm putting it in in case we change namespaces, letting
* FeatureTypes set their own namespaces instead of being dependant on
* datasources. This method will allow us to make that change more easily
* in the future.
*
* @return NameSpaceInfo the namespace specified for the specified
* DataStoreInfo (by ID)
*
* @throws IllegalStateException THrown when disabled.
*/
public NameSpaceInfo getNameSpace() {
if (!isEnabled()) {
throw new IllegalStateException("This featureType is not " + "enabled");
}
return getDataStoreInfo().getNameSpace();
}
/**
* Complete xml name (namespace:element> for this FeatureType.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -