@ Override public synchronized void retain ( ) throws RepositoryException { try { if ( ! isRetainable ( ) ) throw new RepositoryException ( "Unsupported configuration place " + configurationService . getURL ( param . getValue ( ) ) + " If you want to save configuration, start repository from standalone file." + " Or persister-class-name not configured" ) ; OutputStream saveStream = null ; if ( configurationPersister != null ) { saveStream = new ByteArrayOutputStream ( ) ; } else { URL filePath = configurationService . getURL ( param . getValue ( ) ) ; final File sourceConfig = new File ( filePath . toURI ( ) ) ; final File backUp = new File ( sourceConfig . getAbsoluteFile ( ) + "." + indexBackupFile ++ ) ; if ( indexBackupFile > maxBackupFiles ) { indexBackupFile = 1 ; } try { SecurityHelper . doPrivilegedIOExceptionAction ( new PrivilegedExceptionAction < Void > ( ) { public Void run ( ) throws IOException { DirectoryHelper . deleteDstAndRename ( sourceConfig , backUp ) ; return null ; } } ) ; } catch ( IOException ioe ) { throw new RepositoryException ( "Can't back up configuration on path " + PrivilegedFileHelper . getAbsolutePath ( sourceConfig ) , ioe ) ; } saveStream = PrivilegedFileHelper . fileOutputStream ( sourceConfig ) ; } IBindingFactory bfact ; try { bfact = SecurityHelper . doPrivilegedExceptionAction ( new PrivilegedExceptionAction < IBindingFactory > ( ) { public IBindingFactory run ( ) throws Exception { return BindingDirectory . getFactory ( RepositoryServiceConfiguration . class ) ; } } ) ; } catch ( PrivilegedActionException pae ) { Throwable cause = pae . getCause ( ) ; if ( cause instanceof JiBXException ) { throw ( JiBXException ) cause ; } else if ( cause instanceof RuntimeException ) { throw ( RuntimeException ) cause ; } else { throw new RuntimeException ( cause ) ; } } IMarshallingContext mctx = bfact . createMarshallingContext ( ) ; mctx . marshalDocument ( this , "ISO-8859-1" , null , saveStream ) ; saveStream . close ( ) ; // writing configuration in to the persister if ( configurationPersister != null ) { configurationPersister . write ( new ByteArrayInputStream ( ( ( ByteArrayOutputStream ) saveStream ) . toByteArray ( ) ) ) ; } } catch ( JiBXException e ) { throw new RepositoryException ( e ) ; } catch ( FileNotFoundException e ) { throw new RepositoryException ( e ) ; } catch ( IOException e ) { throw new RepositoryException ( e ) ; } catch ( RepositoryConfigurationException e ) { throw new RepositoryException ( e ) ; } catch ( Exception e ) { throw new RepositoryException ( e ) ; } }
Retain configuration of JCR If configurationPersister is configured it write data in to the persister otherwise it try to save configuration in file