AbstractSelfFeedingLoader.java

  1. /* Contributed in the public domain.
  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. /**
  19.  * Abstract class that combines a {@link DataProvidersManager} with a supported names
  20.  * regular expression for {@link DataProvidersManager#feed(String, DataLoader)}.
  21.  *
  22.  * @author Evan Ward
  23.  * @since 10.1
  24.  */
  25. public abstract class AbstractSelfFeedingLoader {

  26.     /** Regular expression for supported files names. */
  27.     private String supportedNames;
  28.     /** Source for auxiliary data files. */
  29.     private final DataProvidersManager manager;

  30.     /**
  31.      * Create an abstract data loader that can feed itself.
  32.      *
  33.      * @param supportedNames regular expression. See {@link DataProvidersManager#feed(String,
  34.      *                       DataLoader)}.
  35.      * @param manager        the source of auxiliary data files.
  36.      */
  37.     public AbstractSelfFeedingLoader(final String supportedNames,
  38.                                      final DataProvidersManager manager) {
  39.         this.supportedNames = supportedNames;
  40.         this.manager = manager;
  41.     }

  42.     /**
  43.      * Feed the given loader with {@link #getDataProvidersManager()} and {@link
  44.      * #getSupportedNames()}.
  45.      *
  46.      * @param loader to feed.
  47.      * @return the value returned by {@link DataProvidersManager#feed(String,
  48.      * DataLoader)}.
  49.      */
  50.     protected boolean feed(final DataLoader loader) {
  51.         return getDataProvidersManager().feed(getSupportedNames(), loader);
  52.     }

  53.     /**
  54.      * Get the supported names regular expression.
  55.      *
  56.      * @return the supported names.
  57.      * @see DataProvidersManager#feed(String, DataLoader)
  58.      */
  59.     protected String getSupportedNames() {
  60.         return supportedNames;
  61.     }

  62.     /**
  63.      * Set the supported names regular expression. Using this method may create
  64.      * concurrency issues if multiple threads can call {@link #feed(DataLoader)} and it is
  65.      * not properly synchronized.
  66.      *
  67.      * @param supportedNames regular expression.
  68.      */
  69.     protected void setSupportedNames(final String supportedNames) {
  70.         this.supportedNames = supportedNames;
  71.     }

  72.     /**
  73.      * Get the data provider manager.
  74.      *
  75.      * @return the source of auxiliary data files.
  76.      */
  77.     protected DataProvidersManager getDataProvidersManager() {
  78.         return manager;
  79.     }

  80. }