1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.application.state.impl;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.util.Iterator;
26 import java.util.List;
27
28 import org.xml.sax.InputSource;
29
30 import com.cosylab.application.state.State;
31 import com.cosylab.application.state.StateStorage;
32
33
34
35
36
37
38
39
40
41
42 public class XMLStateStorage extends DefaultStateStorage {
43 private static final boolean USE_NEW="true".equalsIgnoreCase(System.getProperty("csl.XMLStateStorage.useNew"));
44
45
46
47
48
49
50
51
52
53
54 public static final State[] loadStates(InputSource is) throws IOException
55 {
56 if (USE_NEW) return NewXMLStateStorage.loadStates(is);
57 else return OldXMLStateStorage.loadStates(is);
58 }
59
60
61
62
63
64
65
66
67
68 public static final void storeStates(State[] outStates, OutputStream os)
69 throws IOException
70 {
71 if (USE_NEW) NewXMLStateStorage.storeStates(outStates, os);
72 else OldXMLStateStorage.storeStates(outStates, os);
73 }
74
75
76
77
78 private DefaultStateStorage ref=null;
79 public XMLStateStorage()
80 {
81 super();
82 ref=USE_NEW?new NewXMLStateStorage():new OldXMLStateStorage();
83 }
84
85
86
87
88
89
90 public XMLStateStorage(StateStorage ss)
91 {
92 super(ss);
93 ref=USE_NEW?new NewXMLStateStorage(ss):new OldXMLStateStorage(ss);
94 }
95
96 public void add(State state) {
97 ref.add(state);
98 }
99
100 public void addAll(List states) {
101 ref.addAll(states);
102 }
103
104 public boolean contains(State st) {
105 return ref.contains(st);
106 }
107
108 public boolean equals(Object obj) {
109 return ref.equals(obj);
110 }
111
112 public List getStates() {
113 return ref.getStates();
114 }
115
116 public int hashCode() {
117 return ref.hashCode();
118 }
119
120 public Iterator iterator() {
121 return ref.iterator();
122 }
123
124 public void load(InputStream stream) throws IOException {
125 ref.load(stream);
126 }
127
128 public void load(String filePath, String applicationName)
129 throws IOException {
130 ref.load(filePath, applicationName);
131 }
132
133 public void remove(State st) {
134 ref.remove(st);
135 }
136
137 public void store(OutputStream stream) throws IOException {
138 ref.store(stream);
139 }
140
141 public void store(String filePath, String applicationName)
142 throws IOException {
143 ref.store(filePath, applicationName);
144 }
145
146 public String toString() {
147 return ref.toString();
148 }
149 }