/* ========================
* 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-2003, by :
* Corporate:
* Astrium SAS
* EADS CRC
* Individual:
* Nicolas Brodu
*
* $Id: RangeSourceProvider.java,v 1.1 2004/01/29 11:09:42 brodu Exp $
*
* Changes
* -------
* 27-Jan-2004 : Creation date (NB);
*
*/
package jsynoptic.builtin;
import simtools.data.DataSource;
import simtools.data.DataSourceCollection;
import simtools.data.DataSourcePool;
import simtools.data.DataSourceProvider;
/**
* Used in serializing/deserializing range data sources
*/
public class RangeSourceProvider implements DataSourceProvider {
/* (non-Javadoc)
* @see simtools.data.DataSourceProvider#getOptionalInformation(simtools.data.DataSource, simtools.data.DataSourceCollection)
*/
public Object getOptionalInformation(DataSource ds, DataSourceCollection dsc) {
if (!(ds instanceof RangeSource)) return null;
RangeSource r = (RangeSource)ds;
Object min = r.getMin();
Object max = r.getMax();
String name = r.getInformation().label;
Number step = r.getStep();
return new Object[] {name, min, max, step};
}
/* (non-Javadoc)
* @see simtools.data.DataSourceProvider#provide(java.lang.String, java.lang.String, java.lang.Object, simtools.data.DataSourcePool)
*/
public DataSource provide(String id, String dscId, Object optionalInformation, DataSourcePool pool) {
// mind this provider's own business
if (!id.startsWith(RangeSource.ID_PREFIX)) return null;
if (!(optionalInformation instanceof Object[])) return null;
Object[] info = (Object[])optionalInformation;
if (info.length!=4) return null;
DataSource ret = null;
if (info[1] instanceof Double) ret = new RangeSource((String)info[0], ((Double)info[1]).doubleValue(), ((Double)info[2]).doubleValue(), ((Double)info[3]).doubleValue());
else if (info[1] instanceof Long) ret = new RangeSource((String)info[0], ((Long)info[1]).longValue(), ((Long)info[2]).longValue(), ((Long)info[3]).longValue());
else return null; // error
if (pool!=null) pool.addDataSource(ret);
return ret;
}
}