1 | package hozo.sparql;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 |
|
---|
5 | public class EndpointSettingsManager {
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 | private HashMap<String, EndpointSettings> settingMap;
|
---|
10 |
|
---|
11 | private boolean isChanged = false;
|
---|
12 |
|
---|
13 | public static final EndpointSettingsManager instance = new EndpointSettingsManager();
|
---|
14 |
|
---|
15 | private EndpointSettingsManager(){
|
---|
16 |
|
---|
17 | settingMap = new HashMap<String, EndpointSettings>();
|
---|
18 | }
|
---|
19 |
|
---|
20 | public EndpointSettings getSetting(String endpoint){
|
---|
21 | EndpointSettings setting = settingMap.get(endpoint);
|
---|
22 | if (setting == null){
|
---|
23 | isChanged = true;
|
---|
24 | setting = new EndpointSettings(endpoint);
|
---|
25 | settingMap.put(endpoint, setting);
|
---|
26 | }
|
---|
27 | return setting;
|
---|
28 |
|
---|
29 | }
|
---|
30 |
|
---|
31 | public EndpointSettings[] getSettings(){
|
---|
32 | return settingMap.values().toArray(new EndpointSettings[]{});
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void setSettings(EndpointSettings[] settings){
|
---|
36 | settingMap = new HashMap<String, EndpointSettings>();
|
---|
37 |
|
---|
38 | for (EndpointSettings setting : settings){
|
---|
39 | settingMap.put(setting.getEndpoint(), setting);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public boolean removeSetting(String endpoint){
|
---|
44 | EndpointSettings removed = settingMap.remove(endpoint);
|
---|
45 |
|
---|
46 | if (removed != null){
|
---|
47 | isChanged = true;
|
---|
48 | }
|
---|
49 |
|
---|
50 | return (removed != null);
|
---|
51 | }
|
---|
52 |
|
---|
53 | public boolean isChanged(){
|
---|
54 | if (isChanged){
|
---|
55 | return true;
|
---|
56 | }
|
---|
57 |
|
---|
58 | for (EndpointSettings setting : getSettings()){
|
---|
59 | if (setting.isChanged()){
|
---|
60 | isChanged = true;
|
---|
61 | break;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | return isChanged;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public void resetChanged(){
|
---|
69 | this.isChanged = false;
|
---|
70 |
|
---|
71 | for (EndpointSettings setting : getSettings()){
|
---|
72 | setting.resetChanged();
|
---|
73 | }
|
---|
74 |
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | }
|
---|