Package org.geoforge.worldwindogc.factory

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

/*
*  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 2
*  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, write to the Free Software
*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

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 java.util.Set;
import java.util.logging.Logger;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.worldwindogc.capabilities.GfrWMSCapabilities;

/**
*
* @author bantchao
*/
abstract public class FactoryChildWms
{  
   static
    {
      if (Configuration.getStringValue(GfrBasicLayerFactory.GFR_KEY_LAYER) == null)
            Configuration.setValue(GfrBasicLayerFactory.GFR_KEY_LAYER,
                    GfrBasicLayerFactory.class.getName());
       
        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(FactoryChildWms.class.getName());

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

    // end: instantiate logger for this class
    // ----
  
   static public Object s_create(GfrWMSCapabilities capParent, AVList lstParamsChild)
    {
        AVList lstParamsChildClone = lstParamsChild.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.
        lstParamsChildClone.setValue(AVKey.URL_CONNECT_TIMEOUT, 30000);
        lstParamsChildClone.setValue(AVKey.URL_READ_TIMEOUT, 30000);
        lstParamsChildClone.setValue(AVKey.RETRIEVAL_QUEUE_STALE_REQUEST_LIMIT, 60000);

        try
        {
            String strKey = FactoryChildWms._s_getFactoryKeyForCapabilities_(capParent);
           
            // beg tempo code
           
            if (strKey.compareTo(GfrBasicElevationModelFactory.GFR_KEY_TERRAIN) == 0)
            {
               String str = "strKey.compareTo(GfrBasicElevationModelFactory.GFR_KEY_TERRAIN) == 0: by-passing";
               FactoryChildWms._LOGGER_.warning(str);
               return null;
           
            
           
            // end tempo code
           
            Factory factory = (Factory) WorldWind.createConfigurationComponent(strKey);
           
            Object obj = factory.createFromConfigSource(capParent, lstParamsChildClone);
           
            return obj;
        }
       
        catch (Exception exc)
        {
            // beg ori
            // Ignore the exception, and just return null.
            // end ori           
           
            exc.printStackTrace();
            String str = exc.getMessage() + "\nIgnoring ...";
            FactoryChildWms._LOGGER_.warning(str);
        }

        return null; // statement never reached !!!!!
    }
   
   /*
    * tempo by-passing elevation models
    * TODO: handle elevation models
    */
   static private String _s_getFactoryKeyForCapabilities_(GfrWMSCapabilities caps)
    {
        Set<String> setImageFormats = caps.getImageFormats();
       
        for (String strImageFormatCur: setImageFormats)
        {
            if (strImageFormatCur.contains("application/bil"))
            {
               String strWarning = "got elevation model, by-passing";
               FactoryChildWms._LOGGER_.warning(strWarning);
               return GfrBasicElevationModelFactory.GFR_KEY_TERRAIN;
            }
        }

        return GfrBasicLayerFactory.GFR_KEY_LAYER;
    }
  
   private FactoryChildWms() {}
}
TOP

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

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.