/* * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2012, Johann Sorel * * 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.geotoolkit.wmsc; import java.io.Serializable; import java.net.URL; import java.util.Collections; import java.util.Map; import org.apache.sis.metadata.iso.DefaultIdentifier; import org.apache.sis.metadata.iso.citation.DefaultCitation; import org.apache.sis.metadata.iso.identification.DefaultServiceIdentification; import org.apache.sis.parameter.ParameterBuilder; import org.apache.sis.storage.DataStoreException; import org.geotoolkit.client.AbstractClientFactory; import org.geotoolkit.client.map.CachedPyramidSet; import org.geotoolkit.internal.ClassLoaderInternationalString; import org.geotoolkit.parameter.Parameters; import org.geotoolkit.security.ClientSecurity; import org.geotoolkit.storage.DataType; import org.geotoolkit.storage.DefaultFactoryMetadata; import org.geotoolkit.storage.FactoryMetadata; import org.geotoolkit.storage.coverage.CoverageStoreFactory; import org.opengis.metadata.Identifier; import org.opengis.metadata.identification.Identification; import org.opengis.parameter.ParameterDescriptor; import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.parameter.ParameterNotFoundException; import org.opengis.parameter.ParameterValue; import org.opengis.parameter.ParameterValueGroup; /** * WMS-C Server factory. * * @author Johann Sorel (Puzzle-GIS) * @module */ public class WMSCClientFactory extends AbstractClientFactory implements CoverageStoreFactory { /** factory identification **/ public static final String NAME = "wmsc"; public static final DefaultServiceIdentification IDENTIFICATION; static { IDENTIFICATION = new DefaultServiceIdentification(); final Identifier id = new DefaultIdentifier(NAME); final DefaultCitation citation = new DefaultCitation(NAME); citation.setIdentifiers(Collections.singleton(id)); IDENTIFICATION.setCitation(citation); } public static final ParameterDescriptor<String> IDENTIFIER = createFixedIdentifier(NAME); public static final ParameterDescriptorGroup PARAMETERS = new ParameterBuilder().addName("WMSCParameters").createGroup(IDENTIFIER,URL,SECURITY,IMAGE_CACHE,NIO_QUERIES,TIMEOUT); @Override public Identification getIdentification() { return IDENTIFICATION; } @Override public ParameterDescriptorGroup getParametersDescriptor() { return PARAMETERS; } @Override public CharSequence getDescription() { return new ClassLoaderInternationalString(WMSCClientFactory.class,"org/geotoolkit/wmsc/bundle", "serverDescription"); } @Override public CharSequence getDisplayName() { return new ClassLoaderInternationalString(WMSCClientFactory.class,"org/geotoolkit/wmsc/bundle", "serverTitle"); } @Override public WebMapClientCached open(ParameterValueGroup params) throws DataStoreException { ensureCanProcess(params); final URL url = (URL)Parameters.getOrCreate(URL, params).getValue(); ClientSecurity security = null; try{ final ParameterValue val = params.parameter(SECURITY.getName().getCode()); security = (ClientSecurity) val.getValue(); }catch(ParameterNotFoundException ex){} boolean cacheImage = false; try{ final ParameterValue val = params.parameter(IMAGE_CACHE.getName().getCode()); cacheImage = Boolean.TRUE.equals(val.getValue()); }catch(ParameterNotFoundException ex){} final WebMapClientCached server = new WebMapClientCached(url,security,cacheImage); try{ final ParameterValue val = params.parameter(NIO_QUERIES.getName().getCode()); boolean useNIO = Boolean.TRUE.equals(val.getValue()); server.setUserProperty(CachedPyramidSet.PROPERTY_NIO, useNIO); }catch(ParameterNotFoundException ex){} return server; } @Override public WebMapClientCached open(Map<String, ? extends Serializable> params) throws DataStoreException { return (WebMapClientCached) super.open(params); } @Override public WebMapClientCached create(Map<String, ? extends Serializable> params) throws DataStoreException { throw new DataStoreException("Can not create new WMSC coverage store."); } @Override public WebMapClientCached create(ParameterValueGroup params) throws DataStoreException { throw new DataStoreException("Can not create new WMSC coverage store."); } @Override public FactoryMetadata getMetadata() { return new DefaultFactoryMetadata(DataType.GRID, true, false, false); } }