1 /* Copyright 2002-2024 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.frames; 18 19 import java.io.Serializable; 20 21 import org.orekit.annotation.DefaultDataContext; 22 import org.orekit.data.DataContext; 23 import org.orekit.errors.OrekitException; 24 import org.orekit.errors.OrekitInternalError; 25 26 27 /** Base class for the predefined frames that are managed by {@link Frames}. 28 * @author Luc Maisonobe 29 */ 30 public class FactoryManagedFrame extends Frame { 31 32 /** Serializable UID. */ 33 private static final long serialVersionUID = -8176399341069422724L; 34 35 /** Key of the frame within the factory. */ 36 private final Predefined factoryKey; 37 38 /** Simple constructor. 39 * @param parent parent frame (must be non-null) 40 * @param transformProvider provider for transform from parent frame to instance 41 * @param pseudoInertial true if frame is considered pseudo-inertial 42 * (i.e. suitable for propagating orbit) 43 * @param factoryKey key of the frame within the factory 44 */ 45 public FactoryManagedFrame(final Frame parent, final TransformProvider transformProvider, 46 final boolean pseudoInertial, final Predefined factoryKey) { 47 super(parent, transformProvider, factoryKey.getName(), pseudoInertial); 48 this.factoryKey = factoryKey; 49 } 50 51 /** Get the key of the frame within the factory. 52 * @return key of the frame within the factory 53 */ 54 public Predefined getFactoryKey() { 55 return factoryKey; 56 } 57 58 /** Replace the instance with a data transfer object for serialization. 59 * <p> 60 * This intermediate class serializes only the frame key. 61 * </p> 62 * @return data transfer object that will be serialized 63 */ 64 @DefaultDataContext 65 private Object writeReplace() { 66 return new DataTransferObject(factoryKey); 67 } 68 69 /** Internal class used only for serialization. */ 70 @DefaultDataContext 71 private static class DataTransferObject implements Serializable { 72 73 /** Serializable UID. */ 74 private static final long serialVersionUID = 2970971575793609756L; 75 76 /** Name of the frame within the factory. */ 77 private final String name; 78 79 /** Simple constructor. 80 * @param factoryKey key of the frame within the factory 81 */ 82 private DataTransferObject(final Predefined factoryKey) { 83 this.name = factoryKey.name(); 84 } 85 86 /** Replace the deserialized data transfer object with a {@link FactoryManagedFrame}. 87 * @return replacement {@link FactoryManagedFrame} 88 */ 89 private Object readResolve() { 90 try { 91 // retrieve a managed frame 92 return DataContext.getDefault().getFrames() 93 .getFrame(Predefined.valueOf(name)); 94 } catch (OrekitException oe) { 95 throw new OrekitInternalError(oe); 96 } 97 } 98 99 } 100 101 }