private void handleEntityLinks ( EntityBuilder builder , EntityContext context ) throws Siren4JException { Class < ? > clazz = context . getCurrentObject ( ) . getClass ( ) ; Map < String , Link > links = new HashMap < String , Link > ( ) ; /* Caution!! Order matters when adding to the links map */ Siren4JEntity entity = clazz . getAnnotation ( Siren4JEntity . class ) ; if ( entity != null && ArrayUtils . isNotEmpty ( entity . links ( ) ) ) { for ( Siren4JLink l : entity . links ( ) ) { if ( evaluateConditional ( l . condition ( ) , context ) ) { links . put ( ArrayUtils . toString ( l . rel ( ) ) , annotationToLink ( l , context ) ) ; } } } if ( context . getParentField ( ) != null ) { Siren4JSubEntity subentity = context . getParentField ( ) . getAnnotation ( Siren4JSubEntity . class ) ; if ( subentity != null && ArrayUtils . isNotEmpty ( subentity . links ( ) ) ) { for ( Siren4JLink l : subentity . links ( ) ) { if ( evaluateConditional ( l . condition ( ) , context ) ) { links . put ( ArrayUtils . toString ( l . rel ( ) ) , annotationToLink ( l , context ) ) ; } } } } Collection < Link > resourceLinks = context . getCurrentObject ( ) instanceof Resource ? ( ( Resource ) context . getCurrentObject ( ) ) . getEntityLinks ( ) : null ; if ( resourceLinks != null ) { for ( Link l : resourceLinks ) { links . put ( ArrayUtils . toString ( l . getRel ( ) ) , l ) ; } } for ( Link l : links . values ( ) ) { l . setHref ( resolveUri ( l . getHref ( ) , context , false ) ) ; builder . addLink ( l ) ; } }
Handles getting all entity links both dynamically set and via annotations and merges them together overriding with the proper precedence order which is Dynamic > SubEntity > Entity . Href and uri s are resolved with the correct data bound in .