entur / netex-java-model

Java JAXB binding classes for NeTEx xsd schema
European Union Public License 1.2
11 stars 13 forks source link

Navigation between related objects #21

Closed codeape2 closed 2 years ago

codeape2 commented 2 years ago

Using the Line->Route relation as example:

<routes>
  <Route version="0" id="MOR:Route:1150000011373077">
    <Name>33_E39 Vestnes</Name>
    <ShortName>33_E39 Vestnes</ShortName>
    <LineRef ref="MOR:Line:33" version="0"/>
    <DirectionType>outbound</DirectionType>
    <pointsInSequence>
      <PointOnRoute order="1" version="1" id="MOR:PointOnRoute:3460180">
        <RoutePointRef ref="MOR:RoutePoint:15028510_33"/>
      </PointOnRoute>
      <PointOnRoute order="2" version="1" id="MOR:PointOnRoute:3460181">
        <RoutePointRef ref="MOR:RoutePoint:15358311_33"/>
      </PointOnRoute>
    </pointsInSequence>
  </Route>
  <Route version="0" id="MOR:Route:1150000011373095">
    <Name>33_E39 Molde</Name>
    <ShortName>33_E39 Molde</ShortName>
    <LineRef ref="MOR:Line:33" version="0"/>
    <DirectionType>inbound</DirectionType>
    <pointsInSequence>
      <PointOnRoute order="1" version="1" id="MOR:PointOnRoute:3460182">
        <RoutePointRef ref="MOR:RoutePoint:15358311_33"/>
      </PointOnRoute>
      <PointOnRoute order="2" version="1" id="MOR:PointOnRoute:3460183">
        <RoutePointRef ref="MOR:RoutePoint:15028510_33"/>
      </PointOnRoute>
    </pointsInSequence>
  </Route>
</routes>
<lines>
  <Line version="0" id="MOR:Line:33">
    <Name>Molde - Vestnes</Name>
    <TransportMode>water</TransportMode>
    <TransportSubmode>
      <WaterSubmode>localCarFerry</WaterSubmode>
    </TransportSubmode>
    <PublicCode>15-33</PublicCode>
    <OperatorRef ref="MOR:Operator:BO232"/>
    <RepresentedByGroupRef ref="MOR:Network:FRAM"/>
  </Line>
</lines>
skinkie commented 2 years ago
  • disclaimer: I'm a JAXB noob
  • I use org.entur.netex.NetexParser and NetexEntitiesIndex

Using the Line->Route relation as example:

  • I can go from Route to Line using route.getLineRef()

This is under JAXB only possible under a very specify XSD-KeyRef contstraint, it will then work automatically, but this does not work for NeTEx due to id+version (or ref+version+nameOfRefClass) read: compound keys.

  • Question: Is there a simple way to go the other way. I.e. from a Line, getting all the routes for the line?
  • line.getRoutes() returns null

You mention NetexParser and NetexEntitiesIndex, I have never seen them. Typically under Java I am creating a HashMap<String, ...>.

  • Or do I have to iterate through routes using LineRef as predicate? Is using XPath queries a better way?

That works very well in Python (xsData). But with JAXB doing XPath integrated is "difficult".

codeape2 commented 2 years ago

You mention NetexParser and NetexEntitiesIndex, I have never seen them. Typically under Java I am creating a HashMap<String, ...>.

NetexParser etc. is defined in https://github.com/entur/netex-parser-java

That works very well in Python (xsData). But with JAXB doing XPath integrated is "difficult".

I guess then for my use case the I will simply skip using JAXB stuff and handle the NeTEx XML files directly using javax.xml.

Thanks!

skinkie commented 2 years ago

I guess then for my use case the I will simply skip using JAXB stuff and handle the NeTEx XML files directly using javax.xml.

I would advise strongly against that.