@ SuppressWarnings ( "checkstyle:cyclomaticcomplexity" ) private static String initializePersistedSREs ( ) { // // FOR DEBUG // try { // clearSREConfiguration(); // } catch (CoreException e1) { // e1.printStackTrace(); // } final String rawXml = SARLEclipsePlugin . getDefault ( ) . getPreferences ( ) . get ( getCurrentPreferenceKey ( ) , "" ) ; //$NON-NLS-1$ try { Element config = null ; // If the preference was found, load SREs from it into memory if ( ! Strings . isNullOrEmpty ( rawXml ) ) { config = parseXML ( rawXml , true ) ; } else { // Otherwise, look for the old file that previously held the SRE definitions final SARLEclipsePlugin plugin = SARLEclipsePlugin . getDefault ( ) ; if ( plugin . getBundle ( ) != null ) { final IPath stateLocation = plugin . getStateLocation ( ) ; final IPath stateFile = stateLocation . append ( "sreConfiguration.xml" ) ; //$NON-NLS-1$ final File file = stateFile . toFile ( ) ; if ( file . exists ( ) ) { // If file exists, load SRE definitions from it into memory and // write the definitions to the preference store WITHOUT triggering // any processing of the new value try ( InputStream fileInputStream = new BufferedInputStream ( new FileInputStream ( file ) ) ) { config = parseXML ( fileInputStream , true ) ; } catch ( IOException e ) { SARLEclipsePlugin . getDefault ( ) . log ( e ) ; } } } } if ( config != null ) { final String defaultId = config . getAttribute ( "defaultSRE" ) ; //$NON-NLS-1$ final NodeList children = config . getChildNodes ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; ++ i ) { try { final Node child = children . item ( i ) ; if ( "SRE" . equalsIgnoreCase ( child . getNodeName ( ) ) //$NON-NLS-1$ && child instanceof Element ) { final Element element = ( Element ) child ; final boolean isPlatform = Boolean . parseBoolean ( element . getAttribute ( "platform" ) ) ; //$NON-NLS-1$ final String id = element . getAttribute ( "id" ) ; //$NON-NLS-1$ if ( ! isPlatform || ! ( ALL_SRE_INSTALLS . containsKey ( id ) ) ) { final ISREInstall sre = createSRE ( element . getAttribute ( "class" ) , //$NON-NLS-1$ id ) ; if ( sre == null ) { throw new IOException ( "Invalid XML format of the SRE preferences of " + id ) ; //$NON-NLS-1$ } try { sre . setFromXML ( element ) ; } catch ( IOException e ) { SARLEclipsePlugin . getDefault ( ) . log ( e ) ; } ALL_SRE_INSTALLS . put ( id , sre ) ; if ( isPlatform ) { platformSREInstalls . add ( id ) ; } } else { final ISREInstall sre = ALL_SRE_INSTALLS . get ( id ) ; if ( sre != null ) { try { sre . setFromXML ( element ) ; } catch ( IOException e ) { SARLEclipsePlugin . getDefault ( ) . log ( e ) ; } } } } } catch ( IOException e ) { SARLEclipsePlugin . getDefault ( ) . log ( e ) ; } } return defaultId ; } } catch ( IOException e ) { SARLEclipsePlugin . getDefault ( ) . log ( e ) ; } return null ; }
This method loads installed SREs based an existing user preference or old SRE configurations file .