 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.preferences;
22 import java.util.Arrays;
23 import java.util.prefs.AbstractPreferences;
24 import java.util.prefs.BackingStoreException;
25 import java.util.prefs.Preferences;
26 import org.apache.log4j.Category;
27 import org.apache.log4j.Logger;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
76 final StringBuilder sb =
new StringBuilder(
name);
77 for (Preferences p = parent; p !=
null; p = p.parent()) {
78 sb.insert(0,
'_').insert(0, p.name());
98 if (
LOG.isDebugEnabled()) {
99 LOG.debug(
"childrenNamesSpi(" +
fullName +
")=" + Arrays.toString(result));
111 throw new InternalError();
118 public void flush() throws BackingStoreException {
119 if (
LOG.isDebugEnabled()) {
131 public String
get(@NotNull
final String key, @Nullable
final String def) {
134 throw new IllegalArgumentException(
"null key");
138 synchronized (lock) {
140 if (
LOG.isDebugEnabled()) {
141 LOG.debug(
"get(" +
fullName +
", " + key +
") called for removed node");
144 throw new IllegalStateException(
"removed node");
150 }
catch (
final Exception ignored) {
162 if (
LOG.isDebugEnabled()) {
163 LOG.debug(
"get(" +
fullName +
", " + key +
", " + def +
")=" + value);
169 public boolean getBoolean(@NotNull
final String key,
final boolean def) {
170 final boolean result = super.getBoolean(key, def);
171 putSpi(key, Boolean.toString(result));
176 public double getDouble(@NotNull
final String key,
final double def) {
177 final double result = super.getDouble(key, def);
178 putSpi(key, Double.toString(result));
183 public float getFloat(@NotNull
final String key,
final float def) {
184 final float result = super.getFloat(key, def);
185 putSpi(key, Float.toString(result));
190 public int getInt(@NotNull
final String key,
final int def) {
191 final int result = super.getInt(key, def);
192 putSpi(key, Integer.toString(result));
197 public long getLong(@NotNull
final String key,
final long def) {
198 final long result = super.getLong(key, def);
199 putSpi(key, Long.toString(result));
205 protected String
getSpi(@NotNull
final String key) {
206 if (
LOG.isDebugEnabled()) {
207 LOG.debug(
"getSpi(" +
fullName +
", key=" + key +
")");
216 if (
LOG.isDebugEnabled()) {
224 protected void putSpi(@NotNull
final String key, @NotNull
final String value) {
225 if (
LOG.isDebugEnabled()) {
226 LOG.debug(
"putSpi(" +
fullName +
", key=" + key +
", value=" + value +
")");
234 if (
LOG.isDebugEnabled()) {
243 if (
LOG.isDebugEnabled()) {
244 LOG.debug(
"removeSpi(" +
fullName +
", key=" + key +
")");
252 throw new InternalError();
259 public void sync() throws BackingStoreException {
260 if (
LOG.isDebugEnabled()) {
long getLong(@NotNull final String key, final long def)
FilePreferences(@Nullable final AbstractPreferences parent, @NotNull final String name, @NotNull final NodeType nodeType, @NotNull final Storage storage)
Creates a new instance.
final Storage storage
The Storage instance used for loading/saving values.
Storage getStorage()
Returns the storage instance used for loading/saving values.
boolean getBoolean(@NotNull final String key, final boolean def)
void flush()
@noinspection RefusedBequest
void removeValue(@NotNull final String path, @NotNull final String key)
Removes the association (if any) for the specified key at a node.
void newNode(@NotNull final String path)
Makes sure a node exists.
String getValue(@NotNull final String path, @NotNull final String key)
Returns the value associated with the specified key at a node, or.
String[] childrenNamesSpi()
double getDouble(@NotNull final String key, final double def)
Implements a Preferences that stores all values in a Storage instance.
String getSpi(@NotNull final String key)
void putValue(@NotNull final String path, @NotNull final String key, @NotNull final String value)
Puts the given key-value association into a node.
static final Category LOG
The Logger for printing log messages.
final NodeType nodeType
The node type of this node.
final String fullName
The full path name of this node.
float getFloat(@NotNull final String key, final float def)
void putSpi(@NotNull final String key, @NotNull final String value)
int getInt(@NotNull final String key, final int def)
String[] childrenNames(@NotNull final String path)
Returns the names of the children of a node.
void removeSpi(@NotNull final String key)
void sync(final boolean sync)
Saves changes to the underlying file.
void removeNode(@NotNull final String path)
Removes a preference node including all preferences that it contains.
An FilePreferences that represents an internal (non-root) node.
The type of a FilePreferences node.
Maintains a set of preference values.
AbstractPreferences childSpi(@NotNull final String name)
String[] getKeys(@NotNull final String path)
Returns all of the keys that have an associated value in a node.
void sync()
@noinspection RefusedBequest
String getPrefix()
Returns the prefix for building key names.