@@ -0,0 +1,3220 @@
+/*%0A * JBoss, Home of Professional Open Source.%0A * Copyright 2011, Red Hat, Inc., and individual contributors%0A * as indicated by the @author tags. See the copyright.txt file in the%0A * distribution for a full listing of individual contributors.%0A *%0A * This is free software; you can redistribute it and/or modify it%0A * under the terms of the GNU Lesser General Public License as%0A * published by the Free Software Foundation; either version 2.1 of%0A * the License, or (at your option) any later version.%0A *%0A * This software is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU%0A * Lesser General Public License for more details.%0A *%0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this software; if not, write to the Free%0A * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA%0A * 02110-1301 USA, or see the FSF site: http://www.fsf.org.%0A */%0A%0Apackage org.jboss.as.controller;%0A%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport org.jboss.as.protocol.StreamUtils;%0Aimport org.jboss.dmr.ModelNode;%0Aimport org.jboss.staxmapper.XMLElementReader;%0Aimport org.jboss.staxmapper.XMLElementWriter;%0A%0Aimport javax.xml.namespace.QName;%0A%0A/**%0A * An XML configuration persister which backs up the old file before overwriting it.%0A *%0A * @author %3Ca href=%22mailto:david.lloyd@redhat.com%22%3EDavid M. Lloyd%3C/a%3E%0A */%0Apublic final class BackupXmlConfigurationPersister extends XmlConfigurationPersister %7B%0A%0A    /**%0A     * Construct a new instance.%0A     *%0A     * @param fileName the configuration base file name%0A     * @param rootElement the root element of the configuration file%0A     * @param rootParser the root model parser%0A     * @param rootDeparser the root model deparser%0A     */%0A    public BackupXmlConfigurationPersister(final File fileName, final QName rootElement, final XMLElementReader%3CModelNode%3E rootParser, final XMLElementWriter%3CModelNode%3E rootDeparser) %7B%0A        super(fileName, rootElement, rootParser, rootDeparser);%0A    %7D%0A%0A    /** %7B@inheritDoc%7D */%0A    protected void backup(final File fileName) throws ConfigurationPersistenceException %7B%0A        File backup = new File(fileName.getParent(), fileName.getName() + %22.last-known-good%22);%0A        try %7B%0A            moveFile(fileName, backup);%0A        %7D catch (IOException e) %7B%0A            throw new ConfigurationPersistenceException(%22Failed to back up %22 + fileName, e);%0A        %7D%0A    %7D%0A%0A    private void moveFile(File file, File backup) throws IOException %7B%0A%0A        if (backup.exists())%0A            backup.delete();%0A%0A        if (!file.renameTo(backup) && file.exists()) %7B%0A            final FileInputStream fis = new FileInputStream(file);%0A            try %7B%0A                final FileOutputStream fos = new FileOutputStream(backup);%0A                try %7B%0A                    StreamUtils.copyStream(fis, fos);%0A                    fos.close();%0A                %7D finally %7B%0A                    StreamUtils.safeClose(fos);%0A                %7D%0A            %7D finally %7B%0A                StreamUtils.safeClose(fis);%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add persister which backs up the original file