protected final void closeContext ( GenerationContext context ) { boolean runPostElements = false ; GenerationContext selectedContext = null ; synchronized ( this ) { final Iterator < GenerationContext > iterator = this . bufferedContexes . iterator ( ) ; while ( selectedContext == null && iterator . hasNext ( ) ) { final GenerationContext candidate = iterator . next ( ) ; if ( Objects . equal ( candidate . getTypeIdentifier ( ) , context . getTypeIdentifier ( ) ) ) { runPostElements = candidate . getParentContext ( ) == null ; selectedContext = candidate ; } } } if ( selectedContext == null ) { throw new IllegalStateException ( "Not same contexts when closing" ) ; //$NON-NLS-1$ } if ( runPostElements ) { for ( final Runnable handler : selectedContext . getPostFinalizationElements ( ) ) { handler . run ( ) ; } } synchronized ( this ) { final Iterator < GenerationContext > iterator = this . bufferedContexes . iterator ( ) ; while ( iterator . hasNext ( ) ) { final GenerationContext candidate = iterator . next ( ) ; if ( selectedContext == candidate ) { candidate . setParentContext ( null ) ; iterator . remove ( ) ; return ; } } } }
Close a generation context .