DataProvider.java

  1. /* Copyright 2002-2020 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.data;

  18. import java.util.regex.Pattern;

  19. import org.orekit.annotation.DefaultDataContext;

  20. /** Interface for providing data files to {@link DataLoader file loaders}.
  21.  * <p>
  22.  * This interface defines a generic way to explore some collection holding
  23.  * data files and load some of them. The collection may be a list of resources
  24.  * in the classpath, a directories tree in filesystem, a zip or jar archive,
  25.  * a database, a connexion to a remote server ...
  26.  * </p>
  27.  * <p>
  28.  * The proper way to use this interface is to configure one or more
  29.  * implementations and register them in the {@link DataProvidersManager data
  30.  * providers manager singleton}, or to let this manager use its default
  31.  * configuration. Once registered, they will be used automatically whenever
  32.  * some data needs to be loaded. This allow high level applications developers
  33.  * to customize Orekit data loading mechanism and get a tighter integration of
  34.  * the library within their application.
  35.  * </p>
  36.  * @see DataLoader
  37.  * @see DataProvidersManager
  38.  * @author Luc Maisonobe
  39.  */
  40. public interface DataProvider {

  41.     /** Pattern for name of zip/jar archives. */
  42.     Pattern ZIP_ARCHIVE_PATTERN = Pattern.compile("(.*)(?:(?:\\.zip)|(?:\\.jar))$");

  43.     /** Feed a data file loader by browsing the data collection.
  44.      * <p>
  45.      * The method crawls all files referenced in the instance (for example
  46.      * all files in a directories tree) and for each file supported by the
  47.      * file loader it asks the file loader to load it.
  48.      * </p>
  49.      * <p>
  50.      * If the method completes without exception, then the data loader
  51.      * is considered to have been fed successfully and the top level
  52.      * {@link DataProvidersManager data providers manager} will return
  53.      * immediately without attempting to use the next configured providers.
  54.      * </p>
  55.      * <p>
  56.      * If the method completes abruptly with an exception, then the top level
  57.      * {@link DataProvidersManager data providers manager} will try to use
  58.      * the next configured providers, in case another one can feed the
  59.      * {@link DataLoader data loader}.
  60.      * </p>
  61.      * @param supported pattern for file names supported by the visitor
  62.      * @param visitor data file visitor to use
  63.      * @return true if some data has been loaded
  64.      * @deprecated Use {@link #feed(Pattern, DataLoader, DataProvidersManager)} instead
  65.      * which allows specifying the {@link DataProvidersManager} to use for filtering
  66.      * resources. This method uses the default instance:
  67.      * {@link DataProvidersManager#getInstance()}.
  68.      */
  69.     @Deprecated
  70.     @DefaultDataContext
  71.     boolean feed(Pattern supported, DataLoader visitor);

  72.     /** Feed a data file loader by browsing the data collection.
  73.      * <p>
  74.      * The method crawls all files referenced in the instance (for example
  75.      * all files in a directories tree) and for each file supported by the
  76.      * file loader it asks the file loader to load it.
  77.      * </p>
  78.      * <p>
  79.      * If the method completes without exception, then the data loader
  80.      * is considered to have been fed successfully and the top level
  81.      * {@link DataProvidersManager data providers manager} will return
  82.      * immediately without attempting to use the next configured providers.
  83.      * </p>
  84.      * <p>
  85.      * If the method completes abruptly with an exception, then the top level
  86.      * {@link DataProvidersManager data providers manager} will try to use
  87.      * the next configured providers, in case another one can feed the
  88.      * {@link DataLoader data loader}.
  89.      * </p>
  90.      *
  91.      * <p> The default implementation will be removed in 11.0. It calls {@link
  92.      * #feed(Pattern, DataLoader)}.
  93.      *
  94.      * @param supported pattern for file names supported by the visitor
  95.      * @param visitor data file visitor to use
  96.      * @param manager with the filters to apply to the resources.
  97.      * @return true if some data has been loaded
  98.      */
  99.     default boolean feed(final Pattern supported,
  100.                          final DataLoader visitor,
  101.                          final DataProvidersManager manager) {
  102.         return feed(supported, visitor);
  103.     }

  104. }