public FileDefinition buildFileDefinition ( Graphs graphs , File targetFile , boolean addComment ) { // Build the global structure FileDefinition result = new FileDefinition ( targetFile ) ; result . setFileType ( FileDefinition . GRAPH ) ; if ( addComment ) { String s = "# File created from an in-memory model,\n# without a binding to existing files." ; BlockComment initialComment = new BlockComment ( result , s ) ; result . getBlocks ( ) . add ( initialComment ) ; result . getBlocks ( ) . add ( new BlockBlank ( result , "\n" ) ) ; } // Process and serialize the components Set < String > alreadySerializedNames = new HashSet <> ( ) ; for ( Component c : ComponentHelpers . findAllComponents ( graphs ) ) { if ( alreadySerializedNames . contains ( c . getName ( ) ) ) continue ; alreadySerializedNames . add ( c . getName ( ) ) ; result . getBlocks ( ) . addAll ( buildComponent ( result , c , addComment ) ) ; for ( Facet f : ComponentHelpers . findAllFacets ( c ) ) { if ( alreadySerializedNames . contains ( f . getName ( ) ) ) continue ; alreadySerializedNames . add ( f . getName ( ) ) ; result . getBlocks ( ) . addAll ( buildFacet ( result , f , addComment ) ) ; } } // There may be orphan facets too for ( Facet f : graphs . getFacetNameToFacet ( ) . values ( ) ) { if ( alreadySerializedNames . contains ( f . getName ( ) ) ) continue ; alreadySerializedNames . add ( f . getName ( ) ) ; result . getBlocks ( ) . addAll ( buildFacet ( result , f , addComment ) ) ; } return result ; }
Builds a file definition from a graph .