/*
 * Copyright (C) 2000 - 2013 Silverpeas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * As a special exception to the terms and conditions of version 3.0 of
 * the GPL, you may redistribute this Program in connection with Free/Libre
 * Open Source Software ("FLOSS") applications as described in Silverpeas's
 * FLOSS exception. You should have recieved a copy of the text describing
 * the FLOSS exception, and it is also available here:
 * "http://www.silverpeas.org/docs/core/legal/floss_exception.html"
 *
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.silverpeas.process.annotation;

import com.stratelia.webactiv.util.ActionType;
import com.stratelia.webactiv.util.WAPrimaryKey;
import org.silverpeas.process.io.file.DummyHandledFile;
import org.silverpeas.process.io.file.FileHandler;
import org.silverpeas.process.management.AbstractFileProcess;
import org.silverpeas.process.management.ProcessExecutionContext;
import org.silverpeas.process.session.ProcessSession;

import java.util.List;
import java.util.Map;

/**
 * User: Yohann Chastagnier
 * Date: 17/10/13
 */
public class SimulationElementConversionProcess extends AbstractFileProcess<ProcessExecutionContext> {

  private final Map<Class<SimulationElement>, List<SimulationElement>> elements;
  private final WAPrimaryKey targetPK;
  private final ActionType actionType;

  /**
   * Default constructor.
   * @param elements
   * @param targetPK
   * @param actionType
   */
  SimulationElementConversionProcess(
      final Map<Class<SimulationElement>, List<SimulationElement>> elements,
      final WAPrimaryKey targetPK, final ActionType actionType) {
    this.elements = elements;
    this.targetPK = targetPK;
    this.actionType = actionType;
  }

  @SuppressWarnings("unchecked")
  @Override
  public void processFiles(final ProcessExecutionContext processExecutionProcess,
      final ProcessSession session, final FileHandler fileHandler) throws Exception {

    // Converting each element
    for (Map.Entry<Class<SimulationElement>, List<SimulationElement>> typeElements : elements
        .entrySet()) {

      // Getting the right converter according to the type of elements
      DummyHandledFileConverter<? extends SimulationElement> converter =
          DummyHandledFileConverterRegistration.getConverter(typeElements.getKey());

      // Technical assertion
      if (converter == null) {
        throw new AssertionError(
            "SimulationElementConversionProcess.processFiles : converter is null " +
                "(converter must exist for a type of element)");
      }

      // Convert elements and add each one converted to the file handler
      for (DummyHandledFile dummyHandledFile : converter
          .convert((List) typeElements.getValue(), targetPK, actionType)) {
        fileHandler.addDummyHandledFile(dummyHandledFile);
      }
    }
  }
}

@@ -3237,21 +3237,21 @@
 r%0A      
-for (
+List%3C
 DummyHan
@@ -3262,15 +3262,11 @@
 File
- dummyH
+%3E h
 andl
@@ -3271,28 +3271,19 @@
 dledFile
- : converter
+s =
 %0A       
@@ -3285,16 +3285,25 @@
         
+converter
 .convert
@@ -3356,16 +3356,77 @@
 ionType)
+;%0A      for (DummyHandledFile dummyHandledFile : handledFiles
 ) %7B%0A    

Fix a compilation pb that comes with Java 8