Package org.geoforge.mdldatogc.worldwind.capabilities

Source Code of org.geoforge.mdldatogc.worldwind.capabilities.GfrCapWms

/*
*  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.mdldatogc.worldwind.capabilities;

import gov.nasa.worldwind.ogc.OGCAddress;
import gov.nasa.worldwind.ogc.OGCContactInformation;
import gov.nasa.worldwind.ogc.OGCServiceInformation;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.logging.Logger;
import javax.xml.stream.XMLStreamException;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldatogc.GfrMdlDatIdObjTloOgcWms;
import org.geoforge.worldwindogc.capabilities.GfrWMSCapabilities;
import org.geoforge.wrpbasprssynogc.GfrWrpBasSynObjNameTloWms;

/**
*
* @author bantchao
*/
public class GfrCapWms
{
   
    // ----
   // begin: instantiate logger for this class

   final private static Logger _LOGGER_ = Logger.getLogger(GfrCapWms.class.getName());

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

   // end: instantiate logger for this class
   // ----
   
   // beg static
   static private GfrCapWms _INSTANCE_ = null;
  
   static public GfrCapWms getInstance()
   {
      if (GfrCapWms._INSTANCE_ == null)
         GfrCapWms._INSTANCE_ = new GfrCapWms();
     
      return GfrCapWms._INSTANCE_;
   }
  
   // ---
   private boolean _blnIsOpen_ = false;
  
   public boolean isOpen() { return this._blnIsOpen_; }
  
   // beg public
  
   public GfrWMSCapabilities newObject(String strId, String strUrl) throws
           URISyntaxException,
           MalformedURLException,
           XMLStreamException,
           IOException,
           Exception
   {
      URI uri = new URI(strUrl);
      GfrWMSCapabilities cap = GfrWMSCapabilities.retrieve(uri);
      cap.parse();
     
      String strVersionService = cap.getVersion();
     
      OGCServiceInformation sin = cap.getServiceInformation();
     
      String strFeesService = sin.getFees();
      String strAbstractService = sin.getServiceAbstract();
      String strNameService = sin.getServiceName();
      String strTitleService = sin.getServiceTitle();
     
      // memo: strTitleService used to display node's userObject in JTree, allowed to be not unique
       if (strTitleService == null)
       {
           String strError = "strTitleService == null";
           GfrCapWms._LOGGER_.severe(strError);
           throw new Exception(strError);
       }
      
       strTitleService = strTitleService.trim();
      
       if (strTitleService.length() < 1)
       {
           String strError = "strTitleService.length() < 1";
           GfrCapWms._LOGGER_.severe(strError);
           throw new Exception(strError);
       }
     
     
     
     
      OGCContactInformation cin = sin.getContactInformation();
      String strPrimaryPersonContact = cin.getPersonPrimary();
      String strPositionContact = cin.getPosition();
      String strOrganisationContact = cin.getOrganization();
      String strTelephoneVoiceContact = cin.getVoiceTelephone();
      String strTelephoneFacsimileContact = cin.getFacsimileTelephone();
      String strEmailAddressContact = cin.getElectronicMailAddress();
    
     
    
      String strStreetContact = null;
      String strPostCodeContact = null;
      String strCityContact= null;
      String strStateOrProvinceContact = null;
      String strCountryContact = null;
     
      OGCAddress add = cin.getContactAddress();
     
      if (add != null)
      {
         strStreetContact = add.getAddress();
         strPostCodeContact = add.getPostCode();
         strCityContact = add.getCity();
         strStateOrProvinceContact = add.getStateOrProvince();
         strCountryContact = add.getCountry();
      }     
     
      String strTitleServicePrev = GfrWrpBasSynObjNameTloWms.getInstance().getTitleService(strId);
     
      GfrWrpBasSynObjNameTloWms.getInstance().updateInfos(
              strId,
              strNameService, strTitleService, strVersionService, strFeesService, strAbstractService,
              strPrimaryPersonContact, strPositionContact, strOrganisationContact, strTelephoneVoiceContact,
              strTelephoneFacsimileContact, strEmailAddressContact,
              strStreetContact, strPostCodeContact, strCityContact, strStateOrProvinceContact, strCountryContact);
     
      if (strTitleServicePrev!=null && strTitleServicePrev.compareTo(strTitleService)!=0)
         GfrMdlDatIdObjTloOgcWms.getInstance().rename(strId, strTitleService); // trick!!!!
     
      // ???
      if (this._blnIsOpen_)
         this._mapIdToCap_.put(strId, cap);
     
      return cap;
   }
  
   public void open() throws Exception
   {
      // memo: separate threads in secWin could cause not to be empty
      if (! this._mapIdToCap_.isEmpty())
         throw new Exception("Dev coding error: GfrCapWms.open(): ! this._mapIdToCap_.isEmpty()");
      
      this._blnIsOpen_ = true;
   }
  
   public void close()
   {
      this._blnIsOpen_ = false;
     
      this.deleteAll();
   }
  
   public void deleteAll()
   {
      this._mapIdToCap_.clear();
   }
  
   public GfrWMSCapabilities get(String strId)
   {
      return this._mapIdToCap_.get(strId);
   }
  
   /*public GfrWMSCapabilities load(String strId) throws
           URISyntaxException,
           MalformedURLException,
           XMLStreamException,
           Exception
   {
      String strUrl =  GfrWrpBasSynObjNameTloWms.getInstance().getName(strId);
      return this.newObject(strId, strUrl);
   }*/
  
   public void delete(String strId)
   {
      this._mapIdToCap_.remove(strId);
   }
  
  
   // beg private
  
   private HashMap<String, GfrWMSCapabilities> _mapIdToCap_ = null;
  
   private GfrCapWms()
   {
      this._mapIdToCap_ = new HashMap<String, GfrWMSCapabilities>();
   }
}
TOP

Related Classes of org.geoforge.mdldatogc.worldwind.capabilities.GfrCapWms

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.