Package org.geoforge.wrpbasprsdatecl

Source Code of org.geoforge.wrpbasprsdatecl.GfrWrpBasTopDatEclScts

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

import java.awt.geom.Point2D;
import java.util.ArrayList;
import org.geoforge.basprjdat.table.object.GfrBasTblDatObjAbs;
import org.geoforge.basprjdat.table.object.GfrBasTblDatTloAbs;
import org.geoforge.basprjdat.table.object.GfrBasTblDatXloAbs;
import org.geoforge.basprjdatecl.table.objects.GfrBasTblDatChildNameImgSct;
import org.geoforge.basprjdatecl.table.objects.GfrBasTblDatTloEclSct;
import org.geoforge.lang.util.arraylist.GfrAltPointDouble;
import org.geoforge.java.lang.string.GfrUtlString;
import org.geoforge.sql.field.GfrFldAbs;

/**
*
* @author bantchao@gmail.com
*/
abstract public class GfrWrpBasTopDatEclScts extends GfrWrpBasTopDatEclAbs
{
   protected String[] _getSortedNames(String strPathAbsDbDtaProject) throws Exception
   {
      return super._getSortedNames(
              strPathAbsDbDtaProject,
              GfrBasTblDatTloEclSct.s_getInstance());
   }

   /*
    * returns unique ID
    */
   protected String _save(
           String strPathAbsDbDtaProject,
           String strName, String strDescShort, String strUrl,
           ArrayList<Point2D.Double> altPoint2d)
           throws Exception
   {
      GfrBasTblDatObjAbs tblObject = GfrBasTblDatTloEclSct.s_getInstance();
     
      String strIdObj = GfrUtlString.s_getUniqueId(tblObject.getName());

      GfrFldAbs[] flds =
      {
         GfrBasTblDatObjAbs.FLD_VAR_CHAR_ID_OBJ,
         GfrBasTblDatTloAbs.FLD_VAR_CHAR_NAME,
         GfrBasTblDatXloAbs.FLD_VAR_CHAR_DESCRIPTION,
         GfrBasTblDatTloAbs.FLD_VAR_CHAR_URL,
         GfrBasTblDatTloEclSct.FLD_VAR_CHAR_GEOMETRY
      };

      String[] strs =
      {
         strIdObj,
         strName,
         strDescShort,
         strUrl,
         GfrAltPointDouble.s_toString(altPoint2d)
      };
     
      super._save(
              strPathAbsDbDtaProject,
              tblObject,
              flds,
              strs,
              strIdObj);

      return strIdObj;
   }
  
  
   protected String[] _save(
           String strPathAbsDbDtaThis,
           String[] strsName,
           String[] strsDescShort,
           String[] strsUrl,
           Point2D.Double[][] p2dss)
           throws Exception
   {
     
      if (strsName == null || strsName.length < 1)
         throw new Exception("Inserting corrupted data in db :\n strsName == null || strsName.length <1");

      if (strsDescShort == null || strsDescShort.length < 1)
         throw new Exception("Inserting corrupted data in db :\n strsDescShort == null || strsDescShort.length <1");

      if (strsUrl == null || strsUrl.length < 1)
         throw new Exception("Inserting corrupted data in db :\n strsUrl == null || strsUrl.length <1");

      if (p2dss == null || p2dss.length < 1)
         throw new Exception("Inserting corrupted data in db :\n p2ds == null || p2ds.length <1");

         if (strsName.length != strsDescShort.length
              || strsDescShort.length != strsUrl.length
              || strsUrl.length != p2dss.length)
         throw new Exception("Trying to insert corrupted dataset in db");

      GfrBasTblDatObjAbs tblObject = GfrBasTblDatTloEclSct.s_getInstance();

      GfrFldAbs[] flds =
      {
         GfrBasTblDatObjAbs.FLD_VAR_CHAR_ID_OBJ,
         GfrBasTblDatTloAbs.FLD_VAR_CHAR_NAME,
         GfrBasTblDatXloAbs.FLD_VAR_CHAR_DESCRIPTION,
         GfrBasTblDatTloAbs.FLD_VAR_CHAR_URL,
         GfrBasTblDatTloEclSct.FLD_VAR_CHAR_GEOMETRY
      };


      int intSize = strsUrl.length;

      String[] strsIds = new String[intSize];
      ArrayList<String[]> altStrs = new  ArrayList<String[]>();
     
     
      for (int i = 0; i < intSize; i++)
      {
         String strIdObj = GfrUtlString.s_getUniqueId(tblObject.getName());

         strsIds[i] = strIdObj;
       
        
         ArrayList<Point2D.Double> altPoint2d = new ArrayList<Point2D.Double>();
        
        
         for(int j= 0; j < p2dss[i].length; j++)
         {
            altPoint2d.add(p2dss[i][j]);
         }
         String strGeometry =  GfrAltPointDouble.s_toString(altPoint2d);

         String[] strsCur =
         {
            strIdObj,
            strsName[i],
            strsDescShort[i],
            strsUrl[i],
            strGeometry
         };
        
         altStrs.add(strsCur);

      }

      super._save(
              strPathAbsDbDtaThis,
              tblObject,
              flds,
              altStrs,
              strsIds);

      return strsIds;
   }


   @Override
   public void deleteAllTlos() throws Exception
   {
      super._deleteAll(GfrBasTblDatChildNameImgSct.s_getInstance()); // !!! TO BE CHECKED
     
      GfrBasTblDatObjAbs tblObject = GfrBasTblDatTloEclSct.s_getInstance();

      if (!super.isNotEmpty())
         return;

      super._deleteAll(tblObject);
   }

   // avoid instantiation
   protected GfrWrpBasTopDatEclScts()
   {
   }
}
TOP

Related Classes of org.geoforge.wrpbasprsdatecl.GfrWrpBasTopDatEclScts

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.