public abstract class ApplicationModel extends java.lang.Object implements LookAndFeelListener
C:/Dokumente und Einstellungen/user1/.digester
. All
registered resources are written to this directory which can easily be packaged as ZIP file
for storage in a database or on a configuration server. From the security point of view only
registered resources are stored, unknown files or directories are not recognized so that
illegal files like porn or hacked software cannot be stored by the model.
Normally resources are stored on the local computer and restored the next time the application
is started. If available the compressed or encrypted resource archive could be stored in a
JDBC database or on a public configuration server as well. This allows users to share their
settings with other users or with other application instances installed on different computers.
This is real "Configure once, use everywhere". Since application settings can be classified
into multiple categories like user specific, machine specific, shared, global, et cetera,
the resource handlers must reflect the different types of settings. Some kinds of settings
may be shared between different computers, some may not. Machine specific settings like paths
in the local file system cannot be shared with other computers while user specific settings
like an IMAP server can.
Modern applications normally use a more or less huge set of parameters and new application
versions should convert the settings of the older versions to run. So the model and the handlers
must provide a specific model version management which turns out to be quite application
specific but can be supported by some standardized methods. The local directory is necessary
as safe data store when the network connection breaks down. If the network is reachable again
the application can then save a copy for backup or sharing purposes on the server.
Some directories and files are reserved and cannot be used for normal registration:
/admin Administrative files like file maps, indexes etc., private access
/config Application configuration files
/temp Temporary files, deleted on application exit, not stored persistently
TODO: Deploy resource files in a later version, here we use hard-coded files and directories
TODO: since we only have two resource files at the moment (license and runtime configuration).
Modifier and Type | Field and Description |
---|---|
protected java.io.File |
adminDir
Local directory to use for storage of administrative files.
|
protected java.io.File |
baseDir
Local directory to use for storage of configuration.
|
protected java.util.Hashtable<java.lang.String,ConfigurableUnit> |
cacheConfigurablesByID
Shared cache for configurable units, key is unique identifier (application specific).
|
protected java.util.Hashtable<java.lang.String,OptionsUnit> |
cacheOptionUnitsByID
Shared cache for option units, key is unique identifier (application specific).
|
protected java.util.Hashtable<java.lang.String,ResourceFile> |
cacheResourceByID
Shared cache for model resources, key is unique identifier (package + name).
|
protected Configuration |
config
Runtime configuration to store units persistently.
|
protected java.io.File |
configDir
Local directory to use for storage of configuration files.
|
protected java.io.File |
configFile
Stores the application configuration.
|
protected java.io.File |
dataSourceDir
Local directory to use for storage of data source persistence files.
|
protected boolean |
firstStart
Is the application started the first time (no configuration found)?
|
protected java.lang.String |
format
The current file compression algorithm, default is
FORMAT_UNCOMPRESSED . |
static java.lang.String |
FORMAT_DEFLATED
Resource files shall be stored DEFLATED.
|
static java.lang.String |
FORMAT_GZIPPED
Resource files shall be stored GZIPped.
|
static java.lang.String |
FORMAT_UNCOMPRESSED
Resource files shall be stored with no compression.
|
static java.lang.String |
SUPPORT_ATTACHMENT
Represents a category for
SupportDataDialog . |
static java.lang.String |
SUPPORT_LICENSE
Represents a category for
SupportDataDialog . |
static java.lang.String |
SUPPORT_LOG
Represents a category for
SupportDataDialog . |
static java.lang.String |
SUPPORT_MESSAGE
Represents a category for
SupportDataDialog . |
static java.lang.String |
SUPPORT_SCREENSHOT
Represents a category for
SupportDataDialog . |
static java.lang.String |
SUPPORT_STATUS
Represents a category for
SupportDataDialog . |
protected java.io.File |
tempDir
Local directory to use for storage of temporary files.
|
Constructor and Description |
---|
ApplicationModel()
Constructor method for i18n purposes only.
|
ApplicationModel(java.io.File basedir,
java.lang.String configfile)
Constructor method receiving the local configuration directory.
|
Modifier and Type | Method and Description |
---|---|
ModelConfig |
checkZIP(java.io.File target)
Checks the given target archive and provides the configuration descriptor if available.
|
void |
clearTempDirectory(boolean onexit)
Removes all files and directories from the temporary directory.
|
java.lang.String |
exportToZIP(java.io.File target,
java.lang.String ignored,
DeployProps version,
boolean store)
Creates a compressed ZIP archive with the current configuration files and directories.
|
protected void |
finalize()
Cares for proper cleanup after releasing the object.
|
abstract SuffixFilter[] |
getAllSuffixFilters()
Convenience method to get all available file filters.
|
java.io.File |
getConfigFile()
Provides the configuration file for persistent storage.
|
ConfigurableUnit |
getConfigurable(java.lang.String id)
Gets the desired unit from the internal cache if available.
|
Configuration |
getConfiguration()
Provides the configuration instance for persistent storage.
|
java.io.File |
getDataSourceDirectory()
Provides the directory for data source persistence files.
|
abstract Configuration |
getDefaultValues()
Provides the default values for this model.
|
OptionsUnit |
getOptionsUnit(java.lang.String id)
Gets the desired options unit from the internal cache if available.
|
java.lang.String |
getOptionsUnitID(java.lang.Class clazz)
Gets the unique identifier of the desired options unit from the internal cache if available.
|
ResourceFile |
getResource(java.lang.String id)
Gets the desired resource from the internal cache if available.
|
abstract SuffixFilter |
getSuffixFilter(java.lang.String filterid)
Convenience method to get a certain file filter.
|
java.io.File |
getTempDirectory()
Provides the directory for temporary files.
|
boolean |
hasConfigurable(ConfigurableUnit unit)
Is the given unit identifier currently managed by the model?
|
boolean |
hasConfigurable(java.lang.String id)
Is the given unit identifier currently managed by the model?
|
boolean |
hasOptionsUnit(OptionsUnit unit)
Is the given options unit identifier currently managed by the model?
|
boolean |
hasOptionsUnit(java.lang.String id)
Is the given options unit identifier currently managed by the model?
|
boolean |
hasResource(ResourceFile resource)
Is the given resource currently managed by the model?
|
boolean |
hasResource(java.lang.String id)
Is the given resource identifier currently managed by the model?
|
boolean |
isFirstStart()
Checks if the application is started the first time (configuration does not exist).
|
protected abstract void |
loadDefaultValues()
Populates the internal cache with default values (overridden by subclasses).
|
protected void |
loadOverrideValues()
Populates the internal cache with override values after the file values have been loaded.
|
void |
lookAndFeelChanged(java.lang.String plaf,
java.lang.String theme)
Reacts on changes of the look & feel performed by the manager.
|
void |
registerConfigurable(java.lang.String id,
ConfigurableUnit unit)
Registers a configurable unit to be managed.
|
void |
registerOptionsUnit(java.lang.String id,
OptionsUnit unit)
Adds a new options unit to the internal cache.
|
void |
registerResource(ResourceFile resource)
Registers a resource to be managed.
|
int |
removeConfigurableVars(ConfigurableUnit unit)
Removes all variable/value pairs beginning with the id prefix from the configuration.
|
int |
removeConfigurableVars(java.lang.String id)
Removes all variable/value pairs beginning with the id prefix from the configuration.
|
boolean |
storeAll()
Stores all managed configuration units persistently.
|
void |
unregisterConfigurable(ConfigurableUnit unit)
Removes the unit from the internal cache if available.
|
void |
unregisterConfigurable(ConfigurableUnit unit,
boolean store)
Removes the unit from the internal cache if available.
|
void |
unregisterConfigurable(java.lang.String id)
Removes the unit from the internal cache if available.
|
void |
unregisterConfigurable(java.lang.String id,
boolean store)
Removes the unit from the internal cache if available.
|
void |
unregisterOptionsUnit(OptionsUnit unit)
Removes the options unit from the internal cache if available.
|
void |
unregisterOptionsUnit(OptionsUnit unit,
boolean store)
Removes the options unit from the internal cache if available.
|
void |
unregisterOptionsUnit(java.lang.String id)
Removes the options unit from the internal cache if available.
|
void |
unregisterOptionsUnit(java.lang.String id,
boolean store)
Removes the options unit from the internal cache if available.
|
void |
unregisterResource(ResourceFile resource)
Removes the resource from the internal cache if available.
|
void |
unregisterResource(java.lang.String id)
Removes the resource from the internal cache if available.
|
void |
updateComponentTreeUI()
The (hidden) components should be refreshed by
SwingUtilities.updateComponentTreeUI() . |
public static final java.lang.String FORMAT_UNCOMPRESSED
public static final java.lang.String FORMAT_GZIPPED
public static final java.lang.String FORMAT_DEFLATED
public static final java.lang.String SUPPORT_MESSAGE
SupportDataDialog
.public static final java.lang.String SUPPORT_ATTACHMENT
SupportDataDialog
.public static final java.lang.String SUPPORT_LICENSE
SupportDataDialog
.public static final java.lang.String SUPPORT_LOG
SupportDataDialog
.public static final java.lang.String SUPPORT_STATUS
SupportDataDialog
.public static final java.lang.String SUPPORT_SCREENSHOT
SupportDataDialog
.protected java.io.File baseDir
protected java.io.File adminDir
protected java.io.File configDir
protected java.io.File configFile
protected java.io.File tempDir
protected java.io.File dataSourceDir
protected java.lang.String format
FORMAT_UNCOMPRESSED
.protected java.util.Hashtable<java.lang.String,ResourceFile> cacheResourceByID
protected java.util.Hashtable<java.lang.String,ConfigurableUnit> cacheConfigurablesByID
protected java.util.Hashtable<java.lang.String,OptionsUnit> cacheOptionUnitsByID
protected Configuration config
protected boolean firstStart
public ApplicationModel() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic ApplicationModel(java.io.File basedir, java.lang.String configfile) throws java.lang.IllegalArgumentException
basedir
- The local directory to useconfigfile
- The short name of the configuration filejava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If parameters are invalid (e.g. id already in use)protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void registerResource(ResourceFile resource) throws java.lang.IllegalArgumentException
resource
- The resource to be addedjava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If parameters are invalid (e.g. id already in use)public ResourceFile getResource(java.lang.String id)
id
- The unique identifier (package + name)null
public boolean hasResource(java.lang.String id)
id
- The unique identifier (package + name)public boolean hasResource(ResourceFile resource)
resource
- The resource to be checkedpublic void unregisterResource(ResourceFile resource)
resource
- The resource to be removedjava.lang.NullPointerException
- If parameters are null
public void unregisterResource(java.lang.String id)
id
- The unique identifier (package + name)java.lang.NullPointerException
- If parameters are null
public void registerConfigurable(java.lang.String id, ConfigurableUnit unit)
configure()
method
is called immediately in order to load it with configuration data. If no values are
available (for instance if the application is started the first time) then the default
configuration should be used. So the unit must check whether there are valid values
available or not.
id
- The unique idunit
- The configurable unit to be addedjava.lang.NullPointerException
- If parameters are null
public ConfigurableUnit getConfigurable(java.lang.String id)
id
- The unique identifiernull
public boolean hasConfigurable(java.lang.String id)
id
- The unique identifierpublic boolean hasConfigurable(ConfigurableUnit unit)
unit
- The unit to be checkedpublic void unregisterConfigurable(ConfigurableUnit unit)
unit
- The unit to be removedjava.lang.NullPointerException
- If parameters are null
public void unregisterConfigurable(java.lang.String id)
id
- The unique identifierjava.lang.NullPointerException
- If parameters are null
public void unregisterConfigurable(ConfigurableUnit unit, boolean store)
unit
- The unit to be removedstore
- Store the unit after removal?java.lang.NullPointerException
- If parameters are null
public void unregisterConfigurable(java.lang.String id, boolean store)
id
- The unique identifierstore
- Store the unit after removal?java.lang.NullPointerException
- If parameters are null
public int removeConfigurableVars(ConfigurableUnit unit)
unit
- The unit to remove variablesjava.lang.NullPointerException
- If parameters are null
public int removeConfigurableVars(java.lang.String id)
id
- The unique identifierjava.lang.NullPointerException
- If parameters are null
public Configuration getConfiguration()
public java.io.File getConfigFile()
public java.io.File getTempDirectory()
public void clearTempDirectory(boolean onexit)
onexit
- Delete the files "on exit"?public java.io.File getDataSourceDirectory()
public boolean storeAll()
public java.lang.String exportToZIP(java.io.File target, java.lang.String ignored, DeployProps version, boolean store)
storeAll()
method is called first in order to get the current settings
on disk. The central descriptor holding the import information is the 'admin/config.xml'
file based on an XML format which is automatically added to the archive.
target
- The target archiveignored
- The regex filter for targets to be ignored, maybe null
version
- The application version infosstore
- Store units before export?null
on successpublic ModelConfig checkZIP(java.io.File target)
target
- The target archivenull
indicates errorpublic boolean isFirstStart()
public OptionsUnit getOptionsUnit(java.lang.String id)
id
- The unique identifiernull
public java.lang.String getOptionsUnitID(java.lang.Class clazz)
clazz
- The option unit classnull
public boolean hasOptionsUnit(java.lang.String id)
id
- The unique identifierpublic boolean hasOptionsUnit(OptionsUnit unit)
unit
- The unit to be checkedpublic void registerOptionsUnit(java.lang.String id, OptionsUnit unit)
id
- The unique identifierunit
- The unit to be addedjava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If parameters are invalid (e.g. id already in use)public void unregisterOptionsUnit(OptionsUnit unit)
unit
- The unit to be removedjava.lang.NullPointerException
- If parameters are null
public void unregisterOptionsUnit(java.lang.String id)
id
- The unique identifierjava.lang.NullPointerException
- If parameters are null
public void unregisterOptionsUnit(OptionsUnit unit, boolean store)
unit
- The unit to be removedstore
- Store the unit after removal?java.lang.NullPointerException
- If parameters are null
public void unregisterOptionsUnit(java.lang.String id, boolean store)
id
- The unique identifierstore
- Store the unit after removal?java.lang.NullPointerException
- If parameters are null
public void lookAndFeelChanged(java.lang.String plaf, java.lang.String theme)
lookAndFeelChanged
in interface LookAndFeelListener
plaf
- The current look & feel in fully qualified notationtheme
- The configuration of the specific look & feel, may be null
public void updateComponentTreeUI()
SwingUtilities.updateComponentTreeUI()
.
May be called by the manager if font sizes, colors etc. have been changed.
updateComponentTreeUI
in interface LookAndFeelListener
protected void loadOverrideValues()
protected abstract void loadDefaultValues()
public abstract Configuration getDefaultValues()
public abstract SuffixFilter getSuffixFilter(java.lang.String filterid)
filterid
- The filter identifiernull
public abstract SuffixFilter[] getAllSuffixFilters()
null
or have zero-lengthCopyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.