/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2003-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.data; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.geotools.data.DataAccessFactory.Param; import org.geotools.parameter.DefaultParameterDescriptor; import org.geotools.parameter.DefaultParameterDescriptorGroup; import org.geotools.parameter.FloatParameter; import org.geotools.parameter.Parameter; import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.parameter.ParameterValue; /** * A best of toolkit for DataStoreFactory implementors. *
* Will also allow me to mess with the interface API without breaking every * last DataStoreFactorySpi out there. *
** The default implementations often hinge around the use of * getParameterInfo and the correct use of Param by your subclass. *
** You still have to implement a few methods: *
*
* public DataSourceMetadataEnity createMetadata( Map params ) throws IOException {
* String host = (String) HOST.lookUp(params);
* String user = (String) USER.lookUp(params);
* Integer port = (Integer) PORT.lookUp(params);
* String database = (String) DATABASE.lookUp(params);
*
* String description = "Connection to "+getDisplayName()+" on "+host+" as "+user ;
* return new DataSourceMetadataEnity( host+":"+port, database, description );
* }
*
* @author Jody Garnett, Refractions Research
*
*
* @source $URL$
*/
public abstract class AbstractDataStoreFactory implements DataStoreFactorySpi {
/** Default Implementation abuses the naming convention.
*
* Will return Foo
for
* org.geotools.data.foo.FooFactory
.
*
* It will ensure that: *
*
* Why would you ever want to override this method? * If you want to check that a expected file exists and is a directory. *
* Overrride: *
* public boolean canProcess( Map params ) {
* if( !super.canProcess( params ) ){
* return false; // was not in agreement with getParametersInfo
* }
* // example check
* File file = (File) DIRECTORY.lookup( params ); // DIRECTORY is a param
* return file.exists() && file.isDirectory();
* }
*
* @param params
* @return true if params is in agreement with getParametersInfo, override for additional checks.
*/
public boolean canProcess( Map params ) {
if (params == null) {
return false;
}
Param arrayParameters[] = getParametersInfo();
for (int i = 0; i < arrayParameters.length; i++) {
Param param = arrayParameters[i];
Object value;
if( !params.containsKey( param.key ) ){
if( param.required ){
return false; // missing required key!
} else {
continue;
}
}
try {
value = param.lookUp( params );
} catch (IOException e) {
// could not upconvert/parse to expected type!
// even if this parameter is not required
// we are going to refuse to process
// these params
return false;
}
if( value == null ){
if (param.required) {
return (false);
}
} else {
if ( !param.type.isInstance( value )){
return false; // value was not of the required type
}
if( param.metadata != null ){
// check metadata
if( param.metadata.containsKey(Param.OPTIONS)){
List