]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/prefs/SystemRootPreferences.java
Improve init launch
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / prefs / SystemRootPreferences.java
1 package org.argeo.init.prefs;
2
3 import java.util.concurrent.CompletableFuture;
4 import java.util.concurrent.ExecutionException;
5 import java.util.function.Consumer;
6 import java.util.prefs.AbstractPreferences;
7 import java.util.prefs.BackingStoreException;
8
9 public class SystemRootPreferences extends AbstractPreferences implements Consumer<AbstractPreferences> {
10 private CompletableFuture<AbstractPreferences> singleChild;
11
12 protected SystemRootPreferences() {
13 super(null, "");
14 }
15
16 @Override
17 public void accept(AbstractPreferences t) {
18 this.singleChild.complete(t);
19 }
20
21 /*
22 * ABSTRACT PREFERENCES
23 */
24
25 @Override
26 protected void putSpi(String key, String value) {
27 throw new UnsupportedOperationException();
28 }
29
30 @Override
31 protected String getSpi(String key) {
32 throw new UnsupportedOperationException();
33 }
34
35 @Override
36 protected void removeSpi(String key) {
37 throw new UnsupportedOperationException();
38 }
39
40 @Override
41 protected void removeNodeSpi() throws BackingStoreException {
42 throw new UnsupportedOperationException();
43 }
44
45 @Override
46 protected String[] keysSpi() throws BackingStoreException {
47 return new String[0];
48 }
49
50 /** Will block. */
51 @Override
52 protected String[] childrenNamesSpi() throws BackingStoreException {
53 String childName;
54 try {
55 childName = singleChild.get().name();
56 } catch (InterruptedException | ExecutionException e) {
57 throw new IllegalStateException("Cannot get child preferences name", e);
58 }
59 return new String[] { childName };
60 }
61
62 @Override
63 protected AbstractPreferences childSpi(String name) {
64 String childName;
65 try {
66 childName = singleChild.get().name();
67 } catch (InterruptedException | ExecutionException e) {
68 throw new IllegalStateException("Cannot get child preferences name", e);
69 }
70 if (!childName.equals(name))
71 throw new IllegalArgumentException("Child name is " + childName + ", not " + name);
72 return null;
73 }
74
75 @Override
76 protected void syncSpi() throws BackingStoreException {
77 }
78
79 @Override
80 protected void flushSpi() throws BackingStoreException {
81 }
82
83 }