All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.mpxj.asta.TextFileRow Maven / Gradle / Ivy

Go to download

Library that provides facilities to allow project information to be manipulated in Java and .Net. Supports a range of data formats: Microsoft Project Exchange (MPX), Microsoft Project (MPP,MPT), Microsoft Project Data Interchange (MSPDI XML), Microsoft Project Database (MPD), Planner (XML), Primavera (PM XML, XER, and database), Asta Powerproject (PP, MDB), Asta Easyplan (PP), Phoenix Project Manager (PPX), FastTrack Schedule (FTS), and the Standard Data Exchange Format (SDEF).

There is a newer version: 13.8.0
Show newest version
/*
 * file:       TextFileRow.java
 * author:     Jon Iles
 * copyright:  (c) Packwood Software 2012
 * date:       29/04/2012
 */

/*
 * This library 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.1 of the License, or (at your
 * option) any later version.
 *
 * This library 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 library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

package net.sf.mpxj.asta;

import java.sql.Types;
import java.util.HashMap;
import java.util.List;

import net.sf.mpxj.MPXJException;

/**
 * Extends the MapRow class to allow it to manage data read from an Asta file.
 */
class TextFileRow extends MapRow
{
   /**
    * Constructor.
    *
    * @param table table definition
    * @param data table data
    * @param epochDateFormat true if date is represented as an offset from an epoch
    * @throws MPXJException
    */
   public TextFileRow(TableDefinition table, List data, boolean epochDateFormat)
      throws MPXJException
   {
      super(new HashMap());

      ColumnDefinition[] columns = table.getColumns();
      for (int index = 0; index < columns.length; index++)
      {
         ColumnDefinition column = columns[index];
         if (index < data.size())
         {
            if (column != null)
            {
               m_map.put(column.getName(), getColumnValue(table.getName(), column.getName(), data.get(index), column.getType(), epochDateFormat));
            }
         }
      }
   }

   /**
    * Maps the text representation of column data to Java types.
    *
    * @param table table name
    * @param column column name
    * @param data text representation of column data
    * @param type column data type
    * @param epochDateFormat true if date is represented as an offset from an epoch
    * @return Java representation of column data
    * @throws MPXJException
    */
   private Object getColumnValue(String table, String column, String data, int type, boolean epochDateFormat) throws MPXJException
   {
      try
      {
         Object value = null;

         switch (type)
         {
            case Types.BIT:
            {
               value = AstaDataType.parseBoolean(data);
               break;
            }

            case Types.VARCHAR:
            case Types.LONGVARCHAR:
            {
               value = AstaDataType.parseString(data);
               break;
            }

            case Types.TIME:
            {
               value = AstaDataType.parseBasicTime(data);
               break;
            }

            case Types.TIMESTAMP:
            {
               if (epochDateFormat)
               {
                  value = AstaDataType.parseEpochTimestamp(data);
               }
               else
               {
                  value = AstaDataType.parseBasicTimestamp(data);
               }
               break;
            }

            case Types.DOUBLE:
            {
               value = AstaDataType.parseDouble(data);
               break;
            }

            case Types.INTEGER:
            {
               value = AstaDataType.parseInteger(data);
               break;
            }

            default:
            {
               throw new IllegalArgumentException("Unsupported SQL type: " + type);
            }
         }

         return value;
      }

      catch (Exception ex)
      {
         throw new MPXJException("Failed to parse " + table + "." + column + " (data=" + data + ", type=" + type + ")", ex);
      }
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy