Package org.geoforge.guillc.thread

Source Code of org.geoforge.guillc.thread.GfrPgsThrRdrHeadSheetAbs

/*
*  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.guillc.thread;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Logger;
import org.geoforge.io.util.eventobject.GfrEventObjectDoneReadFile;
import org.geoforge.io.reader.GfrIoRdrSheetHeadAbs;
import org.geoforge.lang.util.eventobject.GfrEventObjectAbs;
import org.geoforge.lang.handler.IGfrHandlerEventListenerThreadJobProgress;
import org.geoforge.lang.thread.GfrPgsThrAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;

/**
*
* @author bantchao
*/
abstract public class GfrPgsThrRdrHeadSheetAbs extends GfrPgsThrAbs
{
   // ----
   // begin: instantiate logger for this class
   final private static Logger _LOGGER_ = Logger.getLogger(GfrPgsThrRdrHeadSheetAbs.class.getName());

   static
   {
      GfrPgsThrRdrHeadSheetAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
  
  
   public ArrayList<Object[]> getResultList() { return this._alt_; }
   public int getResultNbColumn() { return this._intMaxColumn_; }
 
   private int _intMaxColumn_ = -1;
   private ArrayList<Object[]> _alt_ = null;
  
   protected String _strPathAbs = null;
  
   private int _intColumnMin_ = -1;
  
   protected GfrPgsThrRdrHeadSheetAbs(
           int intColumnMin,
           IGfrHandlerEventListenerThreadJobProgress lst,
           String strPathAbs)
           throws Exception
   {
      super(lst);
     
      this._intColumnMin_ = intColumnMin;
      this._strPathAbs = strPathAbs;
     
      super._thr.start();
   }
  
   @Override
   protected void _actionCancelled()
   {
      System.out.println("TODO: ThrProgressRdrHeadSheetAbs._actionCancelled()");
   }
 
   protected void _doJob(GfrIoRdrSheetHeadAbs rdr)
   {
      try
      {
         rdr.doJob();

        
         this._alt_ = rdr.getResultList();
         this._intMaxColumn_ = rdr.getResultNbColumn();
        
         if (this._intMaxColumn_ < this._intColumnMin_)
         {
            String strLog = "this._intMaxColumn_ < " + this._intColumnMin_;
            GfrPgsThrRdrHeadSheetAbs._LOGGER_.warning(strLog);
           
            super._strError =
                    "File should contain at least " +
                    this. _intColumnMin_ +
                    " columns, found: " +
                    this._intMaxColumn_;
           
            return;
         }
        
         if (this._alt_.size() < 2)
         {
            String strLog = "this._alt_.size() < 2";
            GfrPgsThrRdrHeadSheetAbs._LOGGER_.warning(strLog);
           
            super._strError = "File should contain at least 2 rows, found: " + this._alt_.size();
            return;
         }
       
      }
     
      catch(Exception exc)
      {
         exc.printStackTrace();
         String str = exc.getMessage();
        
         if (str == null)
            str = "Uncaught exception";
        
         GfrPgsThrRdrHeadSheetAbs._LOGGER_.warning(str);
         super._strError = str;
         return;
      }
   }
  
   @Override
  protected synchronized void _fireEvent() throws Exception
  {
     if (super._blnCanceled)
        return;
    
      GfrEventObjectAbs evt = new GfrEventObjectDoneReadFile(this, super._strError,
              this._strPathAbs);
     
      Iterator itr = super._listeners.iterator();
     
      while (itr.hasNext()) 
      {
         if (super._blnCanceled)
            return;
        
         ((IGfrHandlerEventListenerThreadJobProgress) itr.next()).handleEventThreadJobDone(evt);
      }
  }
}
TOP

Related Classes of org.geoforge.guillc.thread.GfrPgsThrRdrHeadSheetAbs

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.