annotate artifact-database/src/main/java/org/dive4elements/artifactdatabase/state/DefaultSettings.java @ 502:09b5f7de8b6d 3.0.16

Added simple interface to convert an XML DOM element to something opaque.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 23 Sep 2013 10:49:01 +0200
parents 415df0fc4fa1
children
rev   line source
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
1 package org.dive4elements.artifactdatabase.state;
359
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.util.List;
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import org.w3c.dom.Document;
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import org.w3c.dom.Element;
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import org.w3c.dom.Node;
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 /**
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 */
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 public class DefaultSettings implements Settings {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 protected List<Section> sections;
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 public DefaultSettings() {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 sections = new ArrayList<Section>();
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 @Override
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 public void addSection(Section section) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 if (section != null) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 sections.add(section);
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 @Override
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 public int getSectionCount() {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 return sections.size();
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 @Override
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public Section getSection(int pos) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 if (pos >= 0 && pos < getSectionCount()) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 return sections.get(pos);
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 return null;
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 @Override
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 public void removeSection(Section section) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 if (section != null) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 sections.remove(section);
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 @Override
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 public void toXML(Node parent) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 Document owner = parent.getOwnerDocument();
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 Element settings = owner.createElement("settings");
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 for (Section section: sections) {
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 section.toXML(settings);
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 }
502
09b5f7de8b6d Added simple interface to convert an XML DOM element to something opaque.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 475
diff changeset
58
09b5f7de8b6d Added simple interface to convert an XML DOM element to something opaque.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 475
diff changeset
59 parent.appendChild(settings);
359
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 }
f93edbfcf2bc Improved the Settings and Section interfaces and added default implementations for both.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org