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  /**
20   * Abstract class that combines a {@link DataProvidersManager} with a supported names
21   * regular expression for {@link DataProvidersManager#feed(String, DataLoader)}.
22   *
23   * @author Evan Ward
24   * @since 10.1
25   */
26  public abstract class AbstractSelfFeedingLoader {
27  
28      /** Regular expression for supported files names. */
29      private String supportedNames;
30      /** Source for auxiliary data files. */
31      private final DataProvidersManager manager;
32  
33      /**
34       * Create an abstract data loader that can feed itself.
35       *
36       * @param supportedNames regular expression. See {@link DataProvidersManager#feed(String,
37       *                       DataLoader)}.
38       * @param manager        the source of auxiliary data files.
39       */
40      protected AbstractSelfFeedingLoader(final String supportedNames,
41                                          final DataProvidersManager manager) {
42          this.supportedNames = supportedNames;
43          this.manager = manager;
44      }
45  
46      /**
47       * Feed the given loader with {@link #getDataProvidersManager()} and {@link
48       * #getSupportedNames()}.
49       *
50       * @param loader to feed.
51       * @return the value returned by {@link DataProvidersManager#feed(String,
52       * DataLoader)}.
53       */
54      protected boolean feed(final DataLoader loader) {
55          return getDataProvidersManager().feed(getSupportedNames(), loader);
56      }
57  
58      /**
59       * Get the supported names regular expression.
60       *
61       * @return the supported names.
62       * @see DataProvidersManager#feed(String, DataLoader)
63       */
64      protected String getSupportedNames() {
65          return supportedNames;
66      }
67  
68      /**
69       * Set the supported names regular expression. Using this method may create
70       * concurrency issues if multiple threads can call {@link #feed(DataLoader)} and it is
71       * not properly synchronized.
72       *
73       * @param supportedNames regular expression.
74       */
75      protected void setSupportedNames(final String supportedNames) {
76          this.supportedNames = supportedNames;
77      }
78  
79      /**
80       * Get the data provider manager.
81       *
82       * @return the source of auxiliary data files.
83       */
84      protected DataProvidersManager getDataProvidersManager() {
85          return manager;
86      }
87  
88  }