📄 data.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 java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.logging.Level;
import javax.xml.namespace.QName;
import org.geotools.data.DataStore;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureSource;
import org.geotools.data.LockingManager;
import org.geotools.data.Transaction;
import org.geotools.feature.AttributeType;
import org.geotools.feature.FeatureType;
import org.geotools.styling.SLDParser;
import org.geotools.styling.Style;
import org.geotools.styling.StyleFactory;
import org.geotools.styling.StyleFactoryFinder;
import org.vfny.geoserver.global.dto.AttributeTypeInfoDTO;
import org.vfny.geoserver.global.dto.CoverageInfoDTO;
import org.vfny.geoserver.global.dto.CoverageStoreInfoDTO;
import org.vfny.geoserver.global.dto.DataDTO;
import org.vfny.geoserver.global.dto.DataStoreInfoDTO;
import org.vfny.geoserver.global.dto.DataTransferObjectFactory;
import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
import org.vfny.geoserver.global.dto.NameSpaceInfoDTO;
import org.vfny.geoserver.global.dto.StyleDTO;
/**
* This class stores all the information that a catalog would (and CatalogConfig
* used to).
* <p>
* All public methods besides constructors and stuff used for dependency injection
* setters is synchronized to avoid response failures during the Geoserver reconfiguration
* process (basically, each time you apply a new configuration set on the user interface).
* </p>
* <p>
* A quick benchar did not show significant scalability loss. If one is to be encountered,
* a more complex Reader/Write synchronization will be used, based on the java 5 concurrency
* classes or their backport for java 1.4
* </p>
*
* @author Gabriel Roldan, Axios Engineering
* @author Chris Holmes
* @author dzwiers
* @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
* modification)
* @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
* modification)
* @version $Id: Data.java 7731 2007-11-10 02:52:30Z groldan $
*/
public class Data extends GlobalLayerSupertype /* implements Repository */ {
public static final String WEB_CONTAINER_KEY = "DATA";
public static final Integer TYPE_VECTOR = new Integer(0);
public static final Integer TYPE_RASTER = new Integer(1);
/** Default name of feature type information */
private static final String INFO_FILE = "info.xml";
/** used to create styles */
private static StyleFactory styleFactory = StyleFactoryFinder.createStyleFactory();
/** used to cache layer names and types **/
private volatile Map layerNames = new HashMap();
/** holds the mappings between prefixes and NameSpaceInfo objects */
private Map nameSpaces;
/** NameSpaceInfo */
private NameSpaceInfo defaultNameSpace;
/** Mapping of DataStoreInfo by dataStoreId */
private Map dataStores;
/**
* Mapping of CoverageStoreInfo by formatId
*
* @uml.property name="formats"
* @uml.associationEnd elementType="org.vfny.geoserver.global.dto.FeatureTypeInfoDTO"
* qualifier="next:java.lang.String
* org.vfny.geoserver.global.CoverageStoreInfo"
* multiplicity= "(0 -1)" ordering="ordered"
*/
private Map formats;
/**
* holds the mapping of Styles and style names
*
* @uml.property name="styles"
* @uml.associationEnd elementType="org.vfny.geoserver.global.dto.FeatureTypeInfoDTO"
* qualifier="id:java.lang.String
* org.geotools.styling.Style" multiplicity="(0 -1) "
* ordering="ordered"
*/
private Map styles;
/**
*
* @uml.property name="stFiles"
* @uml.associationEnd qualifier="id:java.lang.String java.io.File"
* multiplicity="(0 1)"
*/
private Map stFiles;
/**
* Map of <code>FeatureTypeInfo</code>'s stored by full qualified name
* (NameSpaceInfo prefix + PREFIX_DELIMITER + typeName)
*
* @uml.property name="featureTypes"
* @uml.associationEnd inverse="data:org.vfny.geoserver.global.FeatureTypeInfo"
* qualifier= "name:java.lang.String
* org.vfny.geoserver.global.FeatureTypeInfo"
* multiplicity= "(0 1)"
*/
private Map featureTypes;
/**
*
* @uml.property name="coverages"
* @uml.associationEnd inverse="data:org.vfny.geoserver.global.CoverageInfo"
* qualifier= "next:java.lang.String
* org.vfny.geoserver.global.CoverageInfo"
* multiplicity="(0 1)"
*/
private Map coverages;
/**
* Base directory for use with file based relative paths
*
* @uml.property name="baseDir" multiplicity="(0 1)"
*/
private File baseDir;
/**
* Data constructor.
*
* <p>
* Creates a Data object from the data provided.
* </p>
*
* @uml.property name="gs"
* @uml.associationEnd multiplicity="(1 1)"
*/
private GeoServer gs;
/**
* map of all featureTypeDTO -> load status (Boolean.True, Boolean.False,
* Exception) Boolean.True when feature was loaded. Boolean.False when
* something was disabled. Exception the error.
*
* @uml.property name="errors"
* @uml.associationEnd qualifier="featureTypeDTO:org.vfny.geoserver.global.dto.FeatureTypeInfoDTO
* org.vfny.geoserver.global.ConfigurationException"
* multiplicity="(0 1)"
*/
private Map errors;
public Data(DataDTO config, File dir, GeoServer g)
throws ConfigurationException {
baseDir = dir;
load(config);
gs = g;
}
public Data(File dir, GeoServer g) throws ConfigurationException {
baseDir = dir;
gs = g;
}
public Data(Config config, GeoServer g) throws ConfigurationException {
this(config.getData(), config.dataDirectory(), g);
}
public GeoServer getGeoServer() {
return gs;
}
public void setDataDirectory(File dataDirectory) {
this.baseDir = dataDirectory;
}
public File getDataDirectory() {
return baseDir;
}
/*
* Places the data in this container and innitializes it. Complex tests are
* performed to detect existing datasources, while the remainder only
* include simplistic id checks.
*
* @param config
*
* @throws NullPointerException
*/
public synchronized void load(DataDTO config) {
if (config == null) {
throw new NullPointerException("Non null DataDTO required for load");
}
// Step 0: dispose datastore and readers as needed
if(dataStores != null)
for (Iterator it = dataStores.values().iterator(); it.hasNext();) {
DataStoreInfo ds = (DataStoreInfo) it.next();
ds.dispose();
}
// Step 1: load formats, dataStores and Namespaces
formats = loadFormats(config);
dataStores = loadDataStores(config);
nameSpaces = loadNamespaces(config);
defaultNameSpace = (NameSpaceInfo) nameSpaces.get(config.getDefaultNameSpacePrefix());
// Step 2: set up styles
styles = loadStyles(config);
// Step 3: load featureTypes
layerNames.clear();
featureTypes = loadFeatureTypes(config);
coverages = loadCoverages(config);
}
public synchronized Set getDataStores() {
return new HashSet(dataStores.values());
}
public synchronized Set getFormats() {
return new HashSet(formats.values());
}
private final Map loadFormats(DataDTO dto) {
if ((dto == null) || (dto.getFormats() == null)) {
return Collections.EMPTY_MAP; // we *are* allowed no datasets
}
Map map = new HashMap();
for (Iterator i = dto.getFormats().values().iterator(); i.hasNext();) {
CoverageStoreInfoDTO formatDTO = (CoverageStoreInfoDTO) i.next();
String id = formatDTO.getId();
CoverageStoreInfo formatInfo = new CoverageStoreInfo(formatDTO, this);
map.put(id, formatInfo);
if (formatDTO.isEnabled()) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(new StringBuffer("Register Format '").append(id).append("'")
.toString());
}
} else {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(new StringBuffer("Did not Register Format '").append(id)
.append("' as it was not enabled")
.toString());
}
}
}
return map;
}
/**
* Configure a map of DataStoreInfo by dataStoreId.
*
* <p>
* This method is order dependent and should be called by load( DataDTO ).
* This method may have to be smarter in the face of reloads.
* </p>
*
* <p>
* Note that any disabled DTO will not be added to the map.
* </p>
*
* <p>
* This method is just to make laod( DataDTO ) readable, making it private
* final will help
* </p>
*
* @param dto
*
* @return DOCUMENT ME!
*
* @throws NullPointerException
* DOCUMENT ME!
*/
private final Map loadDataStores(DataDTO dto) {
if ((dto == null) || (dto.getDataStores() == null)) {
return Collections.EMPTY_MAP; // we *are* allowed no datasets
}
Map map = new HashMap(dto.getDataStores().size());
DataStoreInfoDTO dataStoreDTO;
String id;
DataStoreInfo dataStoreInfo;
for (Iterator i = dto.getDataStores().values().iterator(); i.hasNext();) {
dataStoreDTO = (DataStoreInfoDTO) i.next();
id = dataStoreDTO.getId();
dataStoreInfo = new DataStoreInfo(dataStoreDTO, this);
map.put(id, dataStoreInfo);
if (dataStoreDTO.isEnabled()) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(new StringBuffer("Register DataStore '").append(id).append("'")
.toString());
}
} else {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(new StringBuffer("Did not Register DataStore '").append(id)
.append("' as it was not enabled")
.toString());
}
}
}
return map;
}
/**
* Configure a map of NamespaceInfo by prefix.
*
* <p>
* This method is order dependent and should be called by load( DataDTO ).
* This method may have to be smarter in the face of reloads.
* </p>
*
* <p>
* This method is just to make laod( DataDTO ) readable, making it private
* final will help
* </p>
*
* @param dto
*
* @return DOCUMENT ME!
*
* @throws NullPointerException
* DOCUMENT ME!
*/
private final Map loadNamespaces(DataDTO dto) {
if ((dto == null) || (dto.getNameSpaces() == null)) {
return Collections.EMPTY_MAP; // we *are* allowed no datasets
}
Map map = new HashMap(dto.getNameSpaces().size());
NameSpaceInfoDTO namespaceDto;
String prefix;
NameSpaceInfo namespaceInfo;
for (Iterator i = dto.getNameSpaces().values().iterator(); i.hasNext();) {
namespaceDto = (NameSpaceInfoDTO) i.next();
prefix = namespaceDto.getPrefix();
namespaceInfo = new NameSpaceInfo(this, namespaceDto);
map.put(prefix, namespaceInfo);
}
return map;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -