SourceInformationImpl.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.domain;

  26. import static java.util.Objects.requireNonNull;

  27. import java.io.File;

  28. /**
  29.  * The default implementation for the {@link SourceInformation} interface.
  30.  *
  31.  * @author Kajetan Fuchsberger (kajetan.fuchsberger at cern.ch)
  32.  */
  33. public class SourceInformationImpl implements SourceInformation {

  34.     /** The path to the jmd.xml or the name of the zip archive */
  35.     private final File rootPath;

  36.     /** The type of the model definition (like JAR, ZIP or LOCAL) */
  37.     private final SourceType sourceType;

  38.     /** The name of the xml file from which the model definition was loaded. */
  39.     private final String xmlFileName;

  40.     /**
  41.      * The path offset inside the archive, relative to which the files can be fond. This is usually the parent of the
  42.      * xmlFileName
  43.      */
  44.     private final String pathOffsetWithinArchive;

  45.     /**
  46.      * The constructor which requires both the {@link SourceInformation.SourceType} and the rootPath
  47.      *
  48.      * @param sourceType defines the method how the model-file paths will be treated.
  49.      * @param rootPath the path to the zip or base dir for the model definitions
  50.      * @param xmlFileName the name of the file from which the modelDefinition was loaded (usually fully qualified)
  51.      * @param pathOffsetWithinArchive the path offset within an archive to use, when querying files. This is usually the
  52.      *            parent path (within the offset) of the xml file.
  53.      */
  54.     public SourceInformationImpl(SourceType sourceType, File rootPath, String xmlFileName,
  55.             String pathOffsetWithinArchive) {
  56.         this.sourceType = sourceType;
  57.         this.rootPath = rootPath;
  58.         this.xmlFileName = xmlFileName;
  59.         this.pathOffsetWithinArchive = requireNonNull(pathOffsetWithinArchive,
  60.                 "pathWithinArchive must not be null");
  61.     }

  62.     @Override
  63.     public File getRootPath() {
  64.         return this.rootPath;
  65.     }

  66.     @Override
  67.     public SourceType getSourceType() {
  68.         return this.sourceType;
  69.     }

  70.     @Override
  71.     public String getFileName() {
  72.         return this.xmlFileName;
  73.     }

  74.     @Override
  75.     public String getPathOffsetWithinArchive() {
  76.         return this.pathOffsetWithinArchive;
  77.     }

  78. }