LazyLoadedDataContext.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. import org.orekit.bodies.LazyLoadedCelestialBodies;
  19. import org.orekit.forces.gravity.potential.LazyLoadedGravityFields;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.frames.LazyLoadedEop;
  22. import org.orekit.frames.LazyLoadedFrames;
  23. import org.orekit.models.earth.LazyLoadedGeoMagneticFields;
  24. import org.orekit.time.LazyLoadedTimeScales;

  25. /**
  26.  * A data context that aims to match the behavior of Orekit 10.0 regarding auxiliary data.
  27.  * This data context only loads auxiliary data when it is first accessed. It allows data
  28.  * loaders to be added before the data is loaded.
  29.  *
  30.  * @author Evan Ward
  31.  * @since 10.1
  32.  */
  33. public class LazyLoadedDataContext implements DataContext {

  34.     /** The data provider manager. */
  35.     private final DataProvidersManager dataProvidersManager;
  36.     /** EOP loader. */
  37.     private final LazyLoadedEop eop;
  38.     /** The time scales. */
  39.     private final LazyLoadedTimeScales timeScales;
  40.     /** The reference frames. */
  41.     private LazyLoadedFrames frames;
  42.     /** The celestial bodies. */
  43.     private LazyLoadedCelestialBodies bodies;
  44.     /** The gravity fields. */
  45.     private final LazyLoadedGravityFields gravityFields;
  46.     /** The magnetic fields. */
  47.     private final LazyLoadedGeoMagneticFields geoMagneticFields;

  48.     /**
  49.      * Create a new data context that only loads auxiliary data when it is first accessed
  50.      * and allows configuration of the auxiliary data sources until then.
  51.      */
  52.     public LazyLoadedDataContext() {
  53.         this.dataProvidersManager = new DataProvidersManager();
  54.         this.eop = new LazyLoadedEop(dataProvidersManager);
  55.         this.timeScales = new LazyLoadedTimeScales(eop);
  56.         this.gravityFields =
  57.                 new LazyLoadedGravityFields(dataProvidersManager, timeScales.getTT());
  58.         this.geoMagneticFields = new LazyLoadedGeoMagneticFields(dataProvidersManager);
  59.         // creating Frames and CelestialBodies here creates an initialization problem for
  60.         // DataContext.getDefault(). Delay creating them until they are used for the first
  61.         // time.
  62.     }

  63.     /**
  64.      * Get the provider of auxiliary data for this data context.
  65.      *
  66.      * @return the provider that supplies auxiliary data to all of the other methods of
  67.      * this data context.
  68.      */
  69.     public DataProvidersManager getDataProvidersManager() {
  70.         return dataProvidersManager;
  71.     }

  72.     @Override
  73.     public LazyLoadedTimeScales getTimeScales() {
  74.         return timeScales;
  75.     }

  76.     @Override
  77.     public LazyLoadedFrames getFrames() {
  78.         synchronized (this) {
  79.             if (this.frames == null) {
  80.                 this.frames = new LazyLoadedFrames(
  81.                                                    eop, getTimeScales(), getCelestialBodies());
  82.             }
  83.             return this.frames;
  84.         }
  85.     }

  86.     @Override
  87.     public LazyLoadedCelestialBodies getCelestialBodies() {
  88.         synchronized (this) {
  89.             if (this.bodies == null) {
  90.                 final Frame gcrf = Frame.getRoot();
  91.                 this.bodies = new LazyLoadedCelestialBodies(
  92.                                                             getDataProvidersManager(), getTimeScales(), gcrf);
  93.             }
  94.             return this.bodies;
  95.         }
  96.     }

  97.     @Override
  98.     public LazyLoadedGravityFields getGravityFields() {
  99.         return gravityFields;
  100.     }

  101.     @Override
  102.     public LazyLoadedGeoMagneticFields getGeoMagneticFields() {
  103.         return geoMagneticFields;
  104.     }

  105. }