Package jsynoptic.plugins.merge

Source Code of jsynoptic.plugins.merge.JSAsynchronousMergeDSCollection$AsynchronousMergeDSCollectionInformation

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* 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.1 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.
*
* (C) Copyright 2001-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: JSAsynchronousMergeDSCollection.java,v 1.2 2008/04/08 11:54:11 ogor Exp $
*
* Changes
* -------
* 18 mai 2006  : Initial public release (CC);
*
*/
package jsynoptic.plugins.merge;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.logging.Logger;

import simtools.data.CollectiveDataSource;
import simtools.data.DataInfo;
import simtools.data.DataSource;
import simtools.data.DataSourceCollection;
import simtools.data.DataSourcePool;
import simtools.data.DuplicateIdException;
import simtools.data.async.AsynchronousMergeDSCollection;
import simtools.data.async.TimeStampedDataSource;
import simtools.data.async.TimeStampedDataSourceCollection;
import simtools.data.buffer.BufferedDataSource;
import simtools.data.merge.MergeDataException;
import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;


/**
* A JSynoptic implementation of AsynchronousMergeDSCollection.
* Add action listener and posibility to serialize information
* @author zxpletran007
*
*/
public class JSAsynchronousMergeDSCollection extends AsynchronousMergeDSCollection {

  /**
   * A looger to dump error or warning messages in a soket, an output stream, a file...
   */
  protected static Logger _logger = simtools.util.LogConfigurator.getLogger(JSAsynchronousMergeDSCollection.class.getName());
 
  protected static MenuResourceBundle resources =  ResourceFinder.getMenu(JSMergeCollectionPlugin.class);
 
  /**
   * list of merged data information
   */
  protected AsynchronousMergeDSCollectionInformation information;
 
 
  public AsynchronousMergeDSCollectionInformation getMergeInformation(){
    return information;
  }
 
  public JSAsynchronousMergeDSCollection(String name) throws IOException, InvalidFormatException {
    super(name);
    information=new AsynchronousMergeDSCollectionInformation(name);
    JSMergeCollectionPlugin.numberOfMergeCollection++;
  }

 
  public JSAsynchronousMergeDSCollection(AsynchronousMergeDSCollectionInformation information) throws IOException, InvalidFormatException {
      this(information.collectionName);
      // Merge data
      for(int i=0; i<information.mergedData.size();i++){
          try {
              AsynchronousMergeDataSourceInformation dataInfo = (AsynchronousMergeDataSourceInformation)information.mergedData.get(i);

              DataSource ds = dataInfo.data;

              if (!dataInfo.mergeAllRelatedCollection){     // Merge just a data source
                  if (ds instanceof TimeStampedDataSource)
                      add((TimeStampedDataSource)ds,  dataInfo.offset, dataInfo.initialDate);
                  else{
                      add(ds, dataInfo.timeReference, dataInfo.isRelative, dataInfo.offset, dataInfo.initialDate);
                  }
              }else// merge all collection
                  DataSourceCollection dsc = AsynchronousMergeDataSourceInformation.creationCollectionFromDataSource(ds);
                  if (dsc instanceof TimeStampedDataSourceCollection){
                      add((TimeStampedDataSourceCollection)dsc, dataInfo.offset, dataInfo.initialDate);
                  }else{

                      add(dsc, dataInfo.timeReference,  dataInfo.isRelative, dataInfo.offset,  dataInfo.initialDate)
                  }
              }
          } catch (MergeDataException e){
              //continue
          }
      }
  }



  public void add(TimeStampedDataSourceCollection collection, double offset, double initialDate) throws MergeDataException{
      super.add(collection, offset, initialDate);
      information.mergedData.add(new AsynchronousMergeDataSourceInformation(collection, offset));
  }

  public void add(TimeStampedDataSource data, double offset,  double initialDatethrows MergeDataException
      super.add(data, offset, initialDate);
      information.mergedData.add(new AsynchronousMergeDataSourceInformation(data, offset));
  }

  public void add(DataSourceCollection collection, DataSource timeRef,boolean isRelative, double offset, double initialDatethrows MergeDataException{
      super.add(collection, timeRef, isRelative, offset, initialDate);
      information.mergedData.add(new AsynchronousMergeDataSourceInformation(collection, timeRef, isRelative, offset, initialDate));
  }

  public void add(DataSource data, DataSource timeRef, boolean isRelative,  double offset, double initialDatethrows MergeDataException{
      super.add(data, timeRef, isRelative, offset, initialDate);   
      information.mergedData.add(new AsynchronousMergeDataSourceInformation(data, timeRef, isRelative, offset, initialDate))
  }
 

  /**
   * A nested class dedicated to serialize all information about a merge collection
   * @author zxpletran007
   *
   */
  public static class AsynchronousMergeDSCollectionInformation implements Serializable{

    private static final long serialVersionUID = -5203730561945722547L;

    public String collectionName; 
    public ArrayList mergedData;
   
    public AsynchronousMergeDSCollectionInformation(String collectionName){
      this.collectionName = collectionName;
      mergedData = new ArrayList();
    }
  }


  /**
   * A nested class dedicated to serialize information about a merged data.
   * @author zxpletran007
   *
   */
  public static class AsynchronousMergeDataSourceInformation implements Serializable{

    private static final long serialVersionUID = 8618136056672191292L;
    /**
     * A data source to merge
     */
    public transient DataSource data;

    /**
     * If true, all collection that hold data source has to be merged
     */
    public boolean mergeAllRelatedCollection;

    /**
     * When data is synchronous: data sous related to time referenc
     */
    public transient DataSource timeReference;

    /**
     * Time reference is expressed in relative format (number of seconds)
     */
    public boolean isRelative;
   
    /**
     * Offset applied to time reference values
     */
    public double offset;
   
   
    /**
     * An optional initial date used in case a relative time to absolute time conversion has to be performed
     */
    public double initialDate;



    public AsynchronousMergeDataSourceInformation(TimeStampedDataSourceCollection collection, double offset){
      data = (DataSource)collection.get(0)//get the fisrt data for serialization
      mergeAllRelatedCollection=true;
      timeReference=null;
      this.offset = offset;
      isRelative = false;

    }
    public AsynchronousMergeDataSourceInformation(TimeStampedDataSource dataSource, double offset){
      data = dataSource;
      mergeAllRelatedCollection=false;
      timeReference=null;
      this.offset = offset;
      isRelative = false;
    }

    // synchronous  data
    public AsynchronousMergeDataSourceInformation(DataSourceCollection collection, DataSource refTime, boolean isRelative, double offset, double initialDate){
      data = (DataSource)collection.get(0)//get the fisrt data for serialization
      mergeAllRelatedCollection=true;
      timeReference=refTime;
      this.offset = offset;
      this.isRelative = isRelative;
      this.initialDate = initialDate;
   

    public AsynchronousMergeDataSourceInformation(DataSource dataSource, DataSource refTime, boolean isRelative, double offset, double initialDate){
      data = dataSource;
      mergeAllRelatedCollection=false;
      timeReference=refTime;
      this.offset = offset;
      this.isRelative = isRelative;
      this.initialDate = initialDate;
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
      out.defaultWriteObject();
      DataSourcePool.global.writeDataSource(out,data);
      DataSourcePool.global.writeDataSource(out,timeReference);
    }

    private void readObject(java.io.ObjectInputStream in) throws java.lang.ClassNotFoundException, java.io.IOException {
      in.defaultReadObject();
      data = (DataSource)DataSourcePool.global.readDataSource(in);
      timeReference = (DataSource)DataSourcePool.global.readDataSource(in);
    }
   
   
    public static DataSourceCollection creationCollectionFromDataSource(DataSource ds){
      if (ds instanceof TimeStampedDataSource)
        return ((TimeStampedDataSource)ds).getCollection();

      if (ds instanceof CollectiveDataSource)
        return((CollectiveDataSource)ds).getCollection();
     
      if (ds instanceof BufferedDataSource)
        return creationCollectionFromDataSource(((BufferedDataSource)ds).dataSource);
     
      try{
        return DataSourcePool.global.getCollectionForDataSourceId(DataInfo.getId(ds));
      }catch(DuplicateIdException e){
        _logger.fine("Cannot find collection related to " + DataInfo.getId(ds));

      }
      return null;
    }
  }


}
TOP

Related Classes of jsynoptic.plugins.merge.JSAsynchronousMergeDSCollection$AsynchronousMergeDSCollectionInformation

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.