*/
public Object processFinish() {
MergeDataException.mergeDataErrors.clear(); // clear merge errors list
MergeDSCollection ret=null;
String collectionName = (String)settings.get(COLLECTION_NAME);
boolean isAsynchronous = ((Boolean)settings.get(IS_ASYNCHRONOUS)).booleanValue();
if (isAsynchronous) {
try{
ret= new JSAsynchronousMergeDSCollection(collectionName);
} catch (IOException e) {
MergeDataException.mergeDataErrors.add(e.getMessage());
ret = null;
} catch (InvalidFormatException e) {
MergeDataException.mergeDataErrors.add(e.getMessage());
ret = null;
}
} else {
int interpolationOrder = ((Integer)settings.get(INTERPOLATION_ORDER)).intValue();
boolean collectionTimeReferenceIsRelative = ((Boolean)settings.get(COLLECTION_TIME_REFERENCE_IS_RELATIVE)).booleanValue();
// Get the data source the merged time is based on
Integer mergedTimeRefIndex = (Integer)settings.get(REFERENCE_FOR_MERGED_TIME);
int refTimeIndex = 0;
if (mergedTimeRefIndex != null){
refTimeIndex = mergedTimeRefIndex.intValue();
}
Object o = settings.get(DATA_TO_MERGE + "_" + refTimeIndex);
DataSource mergedTimeReferenceDs = null;
if (o instanceof TimeStampedDataSource){
mergedTimeReferenceDs = ((TimeStampedDataSource)o).getTime();
} else if (o instanceof TimeStampedDataSourceCollection){
// we take the fisrt TimeSource
mergedTimeReferenceDs = ((TimeStampedDataSource)((TimeStampedDataSourceCollection)o).get(0)).getTime();
} else {
mergedTimeReferenceDs = (DataSource)settings.get(TIME_REFERENCE + "_" + refTimeIndex);
}
double offset = ((Double)settings.get(TIME_REFERENCE_OFFSET + "_" + refTimeIndex)).doubleValue();
boolean refTimeIsRelative = false;
if ( settings.get(TIME_REFERENCE_IS_RELATIVE + "_" + refTimeIndex)!=null){
refTimeIsRelative = ((Boolean)settings.get(TIME_REFERENCE_IS_RELATIVE + "_" + refTimeIndex)).booleanValue();
}
long initialDate = 0;
if ( settings.get(TIME_REFERENCE_INITIAL_DATE + "_" + refTimeIndex)!=null) {
initialDate = ((Long)settings.get(TIME_REFERENCE_INITIAL_DATE + "_" + refTimeIndex)).longValue();
}
try {
ret= new JSSynchronousMergeDSCollection(
collectionName,
interpolationOrder,
collectionTimeReferenceIsRelative,
mergedTimeReferenceDs,
refTimeIsRelative,
offset,
initialDate);
} catch (MergeDataException e) {
ret = null;
}
}
if (ret != null) {
// Add data to merge collection
for(int i=0;i<numberOfAddedData;i++) {
try{
Object o = settings.get(DATA_TO_MERGE + "_" + i);
double offset = ((Double)settings.get(TIME_REFERENCE_OFFSET + "_" + i)).doubleValue();
boolean refTimeIsRelative = false;
if ( settings.get(TIME_REFERENCE_IS_RELATIVE + "_" + i)!=null)
refTimeIsRelative = ((Boolean)settings.get(TIME_REFERENCE_IS_RELATIVE + "_" + i)).booleanValue();
long initialDate = 0;
if ( settings.get(TIME_REFERENCE_INITIAL_DATE + "_" + i)!=null)
initialDate = ((Long)settings.get(TIME_REFERENCE_INITIAL_DATE + "_" + i)).longValue();
if (o instanceof DataSourceCollection){
if (o instanceof TimeStampedDataSourceCollection){
ret.add((TimeStampedDataSourceCollection)o, offset,initialDate);
}else{
// get synchronous parameters
DataSource refTime = (DataSource)settings.get(TIME_REFERENCE + "_" + i);
ret.add((DataSourceCollection)o, refTime, refTimeIsRelative,offset, initialDate);
}
} else{
if (o instanceof TimeStampedDataSource){
ret.add((TimeStampedDataSource)o, offset, initialDate);
}else{
// get synchronous parameters
DataSource refTime = (DataSource)settings.get(TIME_REFERENCE + "_" + i);
ret.add((DataSource)o, refTime, refTimeIsRelative, offset, initialDate);
}
}
} catch(MergeDataException e) {
}
}