001    /*
002     * Copyright 2002-2004 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.settings.xml;
017    
018    import java.io.IOException;
019    
020    import org.springframework.richclient.settings.SettingsException;
021    import org.springframework.util.Assert;
022    import org.w3c.dom.Document;
023    import org.w3c.dom.Element;
024    
025    /**
026     * @author Peter De Bruycker
027     */
028    public class RootXmlSettings extends XmlSettings {
029            private XmlSettingsReaderWriter readerWriter;
030    
031            private Document doc;
032    
033            public RootXmlSettings(Document doc, XmlSettingsReaderWriter readerWriter) {
034                    super(getSettingsElement(doc));
035    
036                    this.doc = doc;
037    
038                    Assert.notNull(readerWriter, "XmlSettingsReaderWriter cannot be null");
039                    this.readerWriter = readerWriter;
040            }
041    
042            private static Element getSettingsElement(Document doc) {
043                    Assert.notNull(doc, "Document cannot be null");
044                    return doc.getDocumentElement();
045            }
046    
047            public void save() throws IOException {
048                    try {
049                            readerWriter.write(this);
050                    } catch (SettingsException e) {
051                            e.printStackTrace();
052                    }
053            }
054    
055            public Document getDocument() {
056                    return doc;
057            }
058    }