Package jadex.platform.service.settings
Class PlatformSettings
- java.lang.Object
-
- jadex.platform.service.settings.PlatformSettings
-
- All Implemented Interfaces:
IPlatformSettings
public class PlatformSettings extends java.lang.Object implements IPlatformSettings
-
-
Field Summary
Fields Modifier and Type Field Description protected RwAutoLock
lock
Locking mechanism.protected boolean
readonly
Read-only flag.protected java.io.File
settingsdir
The settings dir.
-
Constructor Summary
Constructors Constructor Description PlatformSettings(IComponentIdentifier id, boolean readonly)
Creates the settings manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Object
fromJson(java.lang.String json)
Converts JSON to object.byte[]
loadFile(java.lang.String filename)
Directly loads a file from the settings directory.java.lang.Object
loadState(java.lang.String id)
Loads arbitrary state form a persistent directory.void
saveFile(java.lang.String filename, byte[] content)
Directly saves a file in the settings directory.void
saveState(java.lang.String id, java.lang.Object state)
Saves arbitrary state to a persistent directory as JSON.static java.lang.String
toJson(java.lang.Object object)
Converts object to JSON.
-
-
-
Field Detail
-
settingsdir
protected java.io.File settingsdir
The settings dir.
-
readonly
protected boolean readonly
Read-only flag.
-
lock
protected RwAutoLock lock
Locking mechanism.
-
-
Constructor Detail
-
PlatformSettings
public PlatformSettings(IComponentIdentifier id, boolean readonly)
Creates the settings manager.
-
-
Method Detail
-
saveState
public void saveState(java.lang.String id, java.lang.Object state)
Saves arbitrary state to a persistent directory as JSON. Object must be serializable and the ID must be unique.- Specified by:
saveState
in interfaceIPlatformSettings
- Parameters:
id
- Unique ID for the saved state.state
- The state being saved.
-
loadState
public java.lang.Object loadState(java.lang.String id)
Loads arbitrary state form a persistent directory.- Specified by:
loadState
in interfaceIPlatformSettings
- Parameters:
id
- Unique ID for the saved state.- Returns:
- The state or null if none was found or corrupt.
-
saveFile
public void saveFile(java.lang.String filename, byte[] content)
Directly saves a file in the settings directory.- Specified by:
saveFile
in interfaceIPlatformSettings
- Parameters:
filename
- Name of the file.content
- The file content.
-
loadFile
public byte[] loadFile(java.lang.String filename)
Directly loads a file from the settings directory.- Specified by:
loadFile
in interfaceIPlatformSettings
- Parameters:
filename
- Name of the file.- Returns:
- Content of the file or null if not found.
-
toJson
public static final java.lang.String toJson(java.lang.Object object)
Converts object to JSON.- Parameters:
object
- Object.- Returns:
- JSON string.
-
fromJson
public static final java.lang.Object fromJson(java.lang.String json)
Converts JSON to object.- Parameters:
json
- JSON.- Returns:
- Object.
-
-