Package org.geoforge.worldwindogc.factory

Source Code of org.geoforge.worldwindogc.factory.GfrBasicElevationModelFactory

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program 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, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program 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.
*
*  You should have received a copy of the GNU Lesser General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.geoforge.worldwindogc.factory;

import gov.nasa.worldwind.Configuration;
import gov.nasa.worldwind.Factory;
import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.avlist.AVListImpl;
import gov.nasa.worldwind.exception.WWRuntimeException;
import gov.nasa.worldwind.globes.ElevationModel;
import gov.nasa.worldwind.ogc.OGCConstants;

import gov.nasa.worldwind.ogc.wms.WMSLayerCapabilities;
import java.util.List;
import java.util.logging.Logger;

import org.geoforge.worldwindogc.terrain.GfrEmlWMSBasicElevationModel;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.worldwindogc.capabilities.GfrOGCCapabilities;
import org.geoforge.worldwindogc.capabilities.GfrWMSCapabilities;

/**
*
* @author bantchao
*/
public class GfrBasicElevationModelFactory extends GfrBasicFactory
{
   final static public String GFR_KEY_TERRAIN = "org.geoforge.worldwind.avkey.ElevationModelFactory";
  
   static
    {

       
        if (Configuration.getStringValue(GfrBasicElevationModelFactory.GFR_KEY_TERRAIN) == null)
            Configuration.setValue(GfrBasicElevationModelFactory.GFR_KEY_TERRAIN,
                    GfrBasicElevationModelFactory.class.getName());
    }
  
    // ----
    // begin: instantiate logger for this class
    final private static Logger _LOGGER_ = Logger.getLogger(GfrBasicElevationModelFactory.class.getName());

    static
    {
        GfrBasicElevationModelFactory._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
    }

    // end: instantiate logger for this class
    // ----
   
    static public Object s_createComponent(GfrWMSCapabilities caps, AVList params)
    {
        AVList configParams = params.copy(); // Copy to insulate changes from the caller.

        // Some wms servers are slow, so increase the timeouts and limits used by world wind's retrievers.
        configParams.setValue(AVKey.URL_CONNECT_TIMEOUT, 30000);
        configParams.setValue(AVKey.URL_READ_TIMEOUT, 30000);
        configParams.setValue(AVKey.RETRIEVAL_QUEUE_STALE_REQUEST_LIMIT, 60000);

        try
        {
            Factory factory = (Factory) WorldWind.createConfigurationComponent(GfrBasicElevationModelFactory.GFR_KEY_TERRAIN);
            Object obj = factory.createFromConfigSource(caps, configParams);
            return obj;
        }
       
        catch (Exception exc)
        {
            // beg ori
            // Ignore the exception, and just return null.
            // end ori           
           
            exc.printStackTrace();
            String str = exc.getMessage() + "\nIgnoring ...";
            GfrBasicElevationModelFactory._LOGGER_.warning(str);
        }

        return null; // statement never reached !!!!!
    }
   
   
    public GfrBasicElevationModelFactory()
    {
        super();
    }
   
    @Override
    protected ElevationModel doCreateFromCapabilities(GfrOGCCapabilities caps, AVList params)
    {
        String serviceName = caps.getServiceInformation().getServiceName();
       
        if (serviceName == null)
        {
            String str = "serviceName == null";
            GfrBasicElevationModelFactory._LOGGER_.severe(str);
            throw new IllegalArgumentException(str);
        }
       
        if (! serviceName.equalsIgnoreCase(OGCConstants.WMS_SERVICE_NAME))
        {
            String str = "! serviceName.equalsIgnoreCase(OGCConstants.WMS_SERVICE_NAME), serviceName=" + serviceName;
            GfrBasicElevationModelFactory._LOGGER_.severe(str);
            throw new IllegalArgumentException(str);
        }
       
        if (serviceName.equalsIgnoreCase("WMS"))
        {
            String str = "serviceName.equalsIgnoreCase(\"WMS\")";
            GfrBasicElevationModelFactory._LOGGER_.severe(str);
            throw new IllegalArgumentException(str);
        }
       

        if (params == null)
            params = new AVListImpl();

        if (params.getStringValue(AVKey.LAYER_NAMES) == null)
        {
            // Use the first named layer since no other guidance given
            List<WMSLayerCapabilities> namedLayers = ((GfrWMSCapabilities) caps).getNamedLayers();
           
            if (namedLayers == null)
            {
                String str = "namedLayers == null, serviceName=" + serviceName;
                GfrBasicElevationModelFactory._LOGGER_.severe(str);
                throw new IllegalStateException(str);
            }

            if (namedLayers.isEmpty())
            {
                String str = "namedLayers.isEmpty(), serviceName=" + serviceName;
                GfrBasicElevationModelFactory._LOGGER_.severe(str);
                throw new IllegalStateException(str);
            }

            if (namedLayers.get(0) == null)
            {
                String str = "namedLayers.get(0) == null, serviceName=" + serviceName;
                GfrBasicElevationModelFactory._LOGGER_.severe(str);
                throw new IllegalStateException(str);
            }

            params.setValue(AVKey.LAYER_NAMES, namedLayers.get(0).getName());
        }

        try
        {
           ElevationModel eml = new GfrEmlWMSBasicElevationModel((GfrWMSCapabilities) caps, params);
           return eml;
        }
       
        catch(IllegalArgumentException excIllegalArgument)
        {
           excIllegalArgument.printStackTrace();
           System.err.println("excIllegalArgument caught, returning nil");
           return null;
        }
       
        catch(WWRuntimeException excWWRuntime)
        {
           excWWRuntime.printStackTrace();
           System.err.println("excWWRuntime caught, returning nil");
           return null;
        }
       
        catch(Exception exc)
        {
           exc.printStackTrace();
           System.err.println("exc caught, returning nil");
           return null;
        }
      
    }
}
TOP

Related Classes of org.geoforge.worldwindogc.factory.GfrBasicElevationModelFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.