JMadModelDefinitionExporter.java

  1. // @formatter:off
  2. /*******************************************************************************
  3. *
  4. * This file is part of JMad.
  5. *
  6. * Copyright (c) 2008-2011, CERN. All rights reserved.
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. *     http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. ******************************************************************************/
  21. // @formatter:on

  22. /**
  23.  *
  24.  */
  25. package cern.accsoft.steering.jmad.modeldefs.io;

  26. import static cern.accsoft.steering.jmad.modeldefs.io.JMadModelDefinitionExportRequest.allFrom;

  27. import java.io.File;

  28. import cern.accsoft.steering.jmad.modeldefs.domain.JMadModelDefinition;

  29. /**
  30.  * This is the interface of a class that can export jmad model-definitions to
  31.  * flat files or zip files.
  32.  *
  33.  * @author Kajetan Fuchsberger (kajetan.fuchsberger at cern.ch)
  34.  */
  35. public interface JMadModelDefinitionExporter {

  36.     /**
  37.      * exports the model definition to the given path. If the path is a directory
  38.      * then it is exported as separated local files, If is a filename then it is
  39.      * exported as a jmd.zip file.
  40.      *
  41.      * only the optics, sequences and ranges according to the export request are
  42.      * actually exported.
  43.      *
  44.      * @param exportRequest
  45.      *            the export request to select the scope of the export
  46.      * @param exportPath
  47.      *            the destination path
  48.      * @return either the xml file to which the model definition was written if the
  49.      *         export was to separate files or the zip file to which the whole model
  50.      *         definition and files were written.
  51.      */
  52.     File export(JMadModelDefinitionExportRequest exportRequest, File exportPath);

  53.     /**
  54.      * exports the model definition to separate files within the destination
  55.      * directory
  56.      *
  57.      * only the optics, sequences and ranges according to the export request are
  58.      * actually exported.
  59.      *
  60.      * @param destDir
  61.      *            the destination directory
  62.      * @return the xml file to which the model definition was written to
  63.      */
  64.     File exportAsFiles(JMadModelDefinitionExportRequest exportSpecification, File destDir);

  65.     /**
  66.      * exports the model definition to a zip file containing all the required files.
  67.      *
  68.      * only the optics, sequences and ranges according to the export request are
  69.      * actually exported.
  70.      *
  71.      * @param zipFile
  72.      *            the zip file which shall finally contain the model definitioin
  73.      * @return the zip file to which the data was written (can be different since
  74.      *         the default extension might have been added)
  75.      */
  76.     File exportAsZip(JMadModelDefinitionExportRequest exportSpecification, File zipFile);

  77.     /* -- default methods below for backwards compatibility & convenience -- */

  78.     /**
  79.      * exports the model definition to the given path. If the path is a directory
  80.      * then it is exported as separated local files, If is a filename then it is
  81.      * exported as a jmd.zip file.
  82.      *
  83.      * @param modelDefinition
  84.      *            the model definition to export.
  85.      * @param exportPath
  86.      *            the destination path
  87.      * @return either the xml file to which the model definition was written if the
  88.      *         export was to separate files or the zip file to which the whole model
  89.      *         definition and files were written.
  90.      */
  91.     default File export(JMadModelDefinition modelDefinition, File exportPath) {
  92.         return export(allFrom(modelDefinition), exportPath);
  93.     }

  94.     /**
  95.      * exports the model definition to separate files within the destination
  96.      * directory
  97.      *
  98.      * @param modelDefinition
  99.      *            the modelDefinition to export
  100.      * @param destDir
  101.      *            the destination directory
  102.      * @return the xml file to which the model definition was written to
  103.      */
  104.     default File exportAsFiles(JMadModelDefinition modelDefinition, File destDir) {
  105.         return exportAsFiles(allFrom(modelDefinition), destDir);
  106.     }

  107.     /**
  108.      * exports the model definition to a zip file containing all the required files.
  109.      *
  110.      * @param modelDefinition
  111.      *            the {@link JMadModelDefinition} to export
  112.      * @param zipFile
  113.      *            the zip file which shall finally contain the model definitioin
  114.      * @return the zip file to which the data was written (can be different since
  115.      *         the default extension might have been added)
  116.      */
  117.     default File exportAsZip(JMadModelDefinition modelDefinition, File zipFile) {
  118.         return exportAsZip(allFrom(modelDefinition), zipFile);
  119.     }
  120. }