comparison artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultSettings.java @ 359:f93edbfcf2bc

Improved the Settings and Section interfaces and added default implementations for both. artifacts/trunk@3416 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 14 Dec 2011 12:20:06 +0000
parents
children ab3900303f25
comparison
equal deleted inserted replaced
358:03a8f9796571 359:f93edbfcf2bc
1 package de.intevation.artifactdatabase.state;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.w3c.dom.Document;
7 import org.w3c.dom.Element;
8 import org.w3c.dom.Node;
9
10 import de.intevation.artifactdatabase.state.Section;
11 import de.intevation.artifactdatabase.state.Settings;
12
13
14 /**
15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
16 */
17 public class DefaultSettings implements Settings {
18
19 protected List<Section> sections;
20
21 public DefaultSettings() {
22 sections = new ArrayList<Section>();
23 }
24
25 @Override
26 public void addSection(Section section) {
27 if (section != null) {
28 sections.add(section);
29 }
30 }
31
32 @Override
33 public int getSectionCount() {
34 return sections.size();
35 }
36
37 @Override
38 public Section getSection(int pos) {
39 if (pos >= 0 && pos < getSectionCount()) {
40 return sections.get(pos);
41 }
42
43 return null;
44 }
45
46 @Override
47 public void removeSection(Section section) {
48 if (section != null) {
49 sections.remove(section);
50 }
51 }
52
53 @Override
54 public void toXML(Node parent) {
55 Document owner = parent.getOwnerDocument();
56 Element settings = owner.createElement("settings");
57
58 parent.appendChild(settings);
59
60 for (Section section: sections) {
61 section.toXML(settings);
62 }
63 }
64 }
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org