Instantiating nested class from MATLAB

I am trying to create an instance of the public nested class GPSPropagator$Builder but I have no experience using Java from MATLAB.
Although the outer class GPSPropagator and its functions are recognized by MATLAB, the inner class Builder is not. I have the following code that works:

rnxPath = './data/training/brdc/2020-08-06-US-MTV-2/BRDC00WRD_R_20202190000_01D_GN.rnx';
rnxFIS =;
nfParser = NavigationFileParser();
gpsNav = nfParser.parse(rnxFIS);
g17NavigationMessage = gpsNav.getGPSNavigationMessages('G17');

I have tried different options which I list below as well as the errors I get.

  1. Calling the constructor Builder with javaMethod (Call Java method - MATLAB javaMethod - MathWorks France):

    >> javaMethod('Builder', 'org.orekit.propagation.analytical.gnss.GPSPropagator$Builder', g17NavigationMessage)
    Error using javaMethod
    No method Builder exists in Java class org.orekit.propagation.analytical.gnss.GPSPropagator$Builder
  2. Calling the method build with javaMethod:

    >> javaMethod('build', 'org.orekit.propagation.analytical.gnss.GPSPropagator$Builder')
    Error using javaMethod
    No static build method with appropriate signature exists in Java class org.orekit.propagation.analytical.gnss.GPSPropagator$Builder
  3. Calling the function build with javaObject:

    >> javaObject('org.orekit.propagation.analytical.gnss.GPSPropagator$Builder', g17NavigationMessage)
    Error using javaObject
    No constructor with appropriate signature exists in Java class org.orekit.propagation.analytical.gnss.GPSPropagator$Builder
  4. Calling the Builder constructor and the build method at the same time

    >> GPSPropagator.Builder(g17NavigationMessage).build()
    Unrecognized function or variable 'Builder'.
  5. I also tried both the solutions proposed in How do I create an instance of a Java public static nested class from inside MATLAB 7.13 (R2011b)? - MATLAB Answers - MATLAB Central, but the structure of the outer and inner functions differ between the example and GPSPropagator.

You already tried a lot of Matlab tricks to solve the issue. Unfortunately, I don’t have more tricks to propose.

The only think I can propose is to change the current architecture of this Java class. We can for instance create a new class GNSSPropagatorBuilder, independant of GPSPropagator class. The GNSSPropagatorBuilder would be used to build the propagator. This architecture is already used for the Kalman estimator: KalmanEstimatorBuilder and KalmanEstimator classes.


1 Like

Anyway, for consistency between Builder classes in Orekit, I think this solution is a good one.

Could you open an issue on the Orekit issue tracker?

But I’m still interested to see if a Matlab trick exist :slight_smile:

Based on your option 5 it looks like you could do it now with reflection. It won’t be pretty though.

In your example g17NavigationMessage is a list of navigation messages. However, Builder constructor is expecting only one navigation message. So, you need to access the elements of the list using .get(index) method.



Your solution 3 should work. I did it this way for my own inner classes and it works well with Matlab.

builder = javaObject('com.thalesaleniaspace.fds.functions.propagate.DsstPropagator$Builder', PropagationType.MEAN, initialOrbit);
dsstPropagator = builder ...
    .withGravity(8, 8) ...
    .withSun() ...
    .withMoon() ...
    .withSRP(1.0, cpS) ...
    .withBiasWrtVVLH(Vector3D(bias)) ...

What I observed is that Matlab is not very good to handle hierarchy of class and/or interfaces during the calls, especially with the constructors. So sometimes a “cast” to the exact class required by the constructor helped Matlab to find and execute the correct method.