Class DefaultPreferencesFactory
java.lang.Object
org.tentackle.prefs.DefaultPreferencesFactory
- All Implemented Interfaces:
PreferencesFactory, PersistedPreferencesFactory
Factory for
Use case is to map invocations of PersistedPreferences by the framework or applications back to the standard java util prefs. The preferences will then no more be persisted in the database.
To activate, extend this class and annotate with
You may also override the methods isSystemOnly, systemRoot, and systemNodeForPackage since system root is usually not writable by normal users.
Furthermore, consider overriding userRoot/systemRoot as well to prepend a sub node for non-class preferences such as table settings.
Preferences wrapped by PersistedPreferences.Use case is to map invocations of PersistedPreferences by the framework or applications back to the standard java util prefs. The preferences will then no more be persisted in the database.
To activate, extend this class and annotate with
@Service(PersistedPreferencesFactory.class).You may also override the methods isSystemOnly, systemRoot, and systemNodeForPackage since system root is usually not writable by normal users.
Furthermore, consider overriding userRoot/systemRoot as well to prepend a sub node for non-class preferences such as table settings.
Example:
@Service(PersistedPreferencesFactory.class)
public class JavaUtilPreferencesFactory extends DefaultPreferencesFactory {
@Override
public boolean isSystemOnly() {
return false;
}
@Override
public DefaultPreferences userRoot() {
return super.userRoot().node("MyApp");
}
@Override
public DefaultPreferences systemRoot() {
return userRoot();
}
@Override
public DefaultPreferences systemNodeForPackage(Class<?> c) {
return userNodeForPackage(c);
}
}
CAUTION: don't register this factory as a PreferencesFactory as this would
cause an endless loop!-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the system root preference node.
Multiple calls on this method will return the same object reference.Returns the user root preference node corresponding to the calling user.voidInvalidates all loaded and/or cached nodes.
The listeners remain registered.
Any modifications not flushed so far will be discarded as well.booleanReturns whether the preferences are automatically synchronized with the database backend.booleanReturns whether preferences are readonly.booleanReturns whether retrieving and storing preferences refers to the system scope only.protected StringReturns the absolute path name of the node corresponding to the package of the specified object.voidsetAutoSync(boolean autoSync) Sets the autosync feature.voidsetReadOnly(boolean readOnly) Sets the readonly feature.voidsetSystemOnly(boolean systemOnly) Sets the system-only feature.systemNodeForPackage(Class<?> c) Returns the preference node from the calling system's preference tree that is associated (by convention) with the specified class's package.userNodeForPackage(Class<?> c) Returns the preference node from the calling user's preference tree that is associated (by convention) with the specified class's package.userRoot()
-
Constructor Details
-
DefaultPreferencesFactory
public DefaultPreferencesFactory()Creates the preferences factory.
-
-
Method Details
-
invalidate
public void invalidate()Description copied from interface:PersistedPreferencesFactoryInvalidates all loaded and/or cached nodes.
The listeners remain registered.
Any modifications not flushed so far will be discarded as well.- Specified by:
invalidatein interfacePersistedPreferencesFactory
-
isAutoSync
public boolean isAutoSync()Description copied from interface:PersistedPreferencesFactoryReturns whether the preferences are automatically synchronized with the database backend.The default is autoSync enabled.
- Specified by:
isAutoSyncin interfacePersistedPreferencesFactory- Returns:
- true if auto sync, false if
PersistedPreferences.sync()must be invoked explicitly
-
setAutoSync
public void setAutoSync(boolean autoSync) Description copied from interface:PersistedPreferencesFactorySets the autosync feature.- Specified by:
setAutoSyncin interfacePersistedPreferencesFactory- Parameters:
autoSync- true if autosync
-
isReadOnly
public boolean isReadOnly()Description copied from interface:PersistedPreferencesFactoryReturns whether preferences are readonly.If readonly all modifications to the preferences will be silently ignored. The default is read-write.
- Specified by:
isReadOnlyin interfacePersistedPreferencesFactory- Returns:
- true readonly
-
setReadOnly
public void setReadOnly(boolean readOnly) Description copied from interface:PersistedPreferencesFactorySets the readonly feature.- Specified by:
setReadOnlyin interfacePersistedPreferencesFactory- Parameters:
readOnly- true if readonly
-
isSystemOnly
public boolean isSystemOnly()Description copied from interface:PersistedPreferencesFactoryReturns whether retrieving and storing preferences refers to the system scope only.This feature is nice to configure a system for all users. The default is user and system scope.
- Specified by:
isSystemOnlyin interfacePersistedPreferencesFactory- Returns:
- true if system-only
-
setSystemOnly
public void setSystemOnly(boolean systemOnly) Description copied from interface:PersistedPreferencesFactorySets the system-only feature.- Specified by:
setSystemOnlyin interfacePersistedPreferencesFactory- Parameters:
systemOnly- true if system scope
-
getSystemRoot
Description copied from interface:PersistedPreferencesFactoryReturns the system root preference node.
Multiple calls on this method will return the same object reference.- Specified by:
getSystemRootin interfacePersistedPreferencesFactory- Returns:
- the system root preference node
-
getUserRoot
Description copied from interface:PersistedPreferencesFactoryReturns the user root preference node corresponding to the calling user.- Specified by:
getUserRootin interfacePersistedPreferencesFactory- Returns:
- the user root preference node corresponding to the calling user, system root if isSystemOnly
- See Also:
-
userNodeForPackage
Description copied from interface:PersistedPreferencesFactoryReturns the preference node from the calling user's preference tree that is associated (by convention) with the specified class's package.- Specified by:
userNodeForPackagein interfacePersistedPreferencesFactory- Parameters:
c- the class for whose package a user preference node is desired.- Returns:
- the user preference node associated with the package of which
cis a member. - See Also:
-
systemNodeForPackage
Description copied from interface:PersistedPreferencesFactoryReturns the preference node from the calling system's preference tree that is associated (by convention) with the specified class's package.- Specified by:
systemNodeForPackagein interfacePersistedPreferencesFactory- Parameters:
c- the class for whose package a system preference node is desired.- Returns:
- the system preference node associated with the package of which
cis a member. - See Also:
-
systemRoot
- Specified by:
systemRootin interfacePreferencesFactory
-
userRoot
- Specified by:
userRootin interfacePreferencesFactory
-
nodeName
Returns the absolute path name of the node corresponding to the package of the specified object.- Parameters:
clazz- the class- Returns:
- the path name
- Throws:
IllegalArgumentException- if the package has no preference node associated with it
-