Package org.cishell.reference.app.service.fileloader

Source Code of org.cishell.reference.app.service.fileloader.FileValidator

package org.cishell.reference.app.service.fileloader;

import java.io.File;
import java.util.Hashtable;

import org.cishell.framework.CIShellContext;
import org.cishell.framework.algorithm.Algorithm;
import org.cishell.framework.algorithm.AlgorithmExecutionException;
import org.cishell.framework.algorithm.AlgorithmFactory;
import org.cishell.framework.algorithm.ProgressMonitor;
import org.cishell.framework.algorithm.ProgressTrackable;
import org.cishell.framework.data.BasicData;
import org.cishell.framework.data.Data;
import org.osgi.service.log.LogService;

public final class FileValidator {
  public static Data[] validateFile(
      File file,
      AlgorithmFactory validator,
      ProgressMonitor progressMonitor,
      CIShellContext ciShellContext,
      LogService logger) throws AlgorithmExecutionException {
    Data[] validationData =
      new Data[] { new BasicData(file.getPath(), String.class.getName()) };
    Algorithm algorithm = validator.createAlgorithm(
      validationData, new Hashtable<String, Object>(), ciShellContext);

    if ((progressMonitor != null) && (algorithm instanceof ProgressTrackable)) {
      ProgressTrackable progressTrackable = (ProgressTrackable)algorithm;
      progressTrackable.setProgressMonitor(progressMonitor);
    }

    Data[] validatedData = algorithm.execute();

    if (validatedData != null) {
      logger.log(LogService.LOG_INFO, "Loaded: " + file.getPath());
    }

    return validatedData;
  }
}
TOP

Related Classes of org.cishell.reference.app.service.fileloader.FileValidator

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.