Package com.priint.pubserver.config
Class PluginConfigCollection
- java.lang.Object
-
- com.priint.pubserver.config.PluginConfigCollection
-
- All Implemented Interfaces:
java.io.Serializable
public class PluginConfigCollection extends java.lang.Object implements java.io.SerializableThe PluginConfigCollection class helps to manage a collection of configurations provided as plain XML Strings or PluginConfig objects. Properties are kept alongside the configurations and will be created on demand, if none are set explicitly.
Examples:
PluginConfigCollection myConfigSet = PluginConfigCollection.createEmptySet(myLogin, MyCustomClass.class); // add a configuration to this collection. MyCustomClass.class (as provided as the default for this collection) // will be used for marshaling and unmarshalling this configuration: myConfigs.addConfig(firstPath, firstObject); // this will actually be the same like the default properties, in real life you // probably would customize the properties: myConfigSet.addProperties(firstPath, new ConfigFileProperties(login, path)); // add another configuration. This object requires AnotherCustomClass for // marshaling and unmarshalling: myConfigSet.addConfig(secondPath, secondObject, AnotherCustomClass.class); // you can mix XML and Objects in a collection: myConfigSet.addXml(thirdPath, thirdConfig); // and get XML or Objects for any configuration managed in this collection at any time: PluginConfig object = myConfigSet.getObject(thirdPath); String xml = myConfigSet.getXml(firstPath); // configurations in this collection are stored as PluginConfigDataHandler objects, // in order to avoid unnecessary serialization / deserialization, you should work // with these objects whenever possible: PluginConfigDataHandler config = myConfigSet.getHandle(firstPath); String xml2 = config.getXml();
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConfig(java.lang.String path, PluginConfig object, java.lang.Class<?>... overrideClazz)Add a configuration object at the given path.voidaddConfigCollection(PluginConfigCollection collection)Add all configurations from the given collection to this collection.voidaddConfigDataHandler(java.lang.String path, PluginConfigDataHandler pluginConfigDataHandler)Add a configuration handler to this collection.voidaddData(java.lang.String path, byte[] data, java.lang.Class<?>... overrideClazz)Add byte[] data to this configuration collectionvoidaddDefaultProperties(java.lang.String path)Add the default ConfigFileProperties at the given pathvoidaddProperties(java.lang.String path, ConfigFileProperties properties)Add ConfigFileProperties at the given pathvoidaddXml(java.lang.String path, java.lang.String xml, java.lang.Class<?>... overrideClazz)Add a configuration provided as XML String at the given pathvoidaddXmlMap(java.util.Map<java.lang.String,java.lang.String> configs)Add configurations provided as XML Strings at the paths given by the key in the map.voidclear()Removes all of the configurations from this collection.booleancontainsConfiguration(java.lang.String path)Returns true if this internal list contains a configuration for the specified path.booleancontainsProperties(java.lang.String path)Returns true if this internal list contains a configuration for the specified path.static PluginConfigCollectioncreateCopy(PluginConfigCollection source)Create a shallow copy of a PluginConfigCollection.static PluginConfigCollectioncreateEmptySet(java.lang.Class<?>... customClazz)Create an empty configuration collection.static PluginConfigCollectioncreateEmptySet(java.lang.String login, java.lang.Class<?>... customClazz)Create an empty configuration collection.PluginConfiggetConfig(java.lang.String path)Get the Object representation of a particular configurationPluginConfigDataHandlergetConfigDataHandler(java.lang.String path)Get the data handler for a particular configuration.java.lang.Class<?>[]getCustomClass()Get the custom classes for this configuration collectionjava.lang.Class<?>[]getCustomClass(java.lang.String path)Get the custom classes for a particular configuration item in this configuration collectionjava.util.Collection<java.lang.String>getKeySet()Get the keys of all configurations managed in this collection.
The method returns getKeySetOfConfigurations.java.util.Collection<java.lang.String>getKeySetOfConfigurations()Get the keys of all configurations managed in this collection.java.util.Collection<java.lang.String>getMissingConfigKeys()Get the keys of all configurations missing in this collection, i.e.: properties have been provided for this key, but no configuration was added.java.util.Collection<java.lang.String>getMissingPropertiesKeys()Get the keys of all properties missing in this collection, i.e.: a configuration has been added for this key, but no properties have been provided.ConfigFilePropertiesgetProperties(java.lang.String path)Get the properties for a given path.java.lang.StringgetXml(java.lang.String path)Get the XML String representation of a particular configuration.java.util.Map<java.lang.String,java.lang.String>getXmlMap()Get a path / XML representation map for all configurations in this collection.java.util.Map<java.lang.String,java.lang.String>getXmlMapWithoutFullPath()Get a path / XML representation map for all configurations in this collection.booleanisEmpty()Is this configuration empty?voidremoveConfig(java.lang.String path)Remove a configuration and associated properties from this PluginConfig Setintsize()Number of items in the collection
-
-
-
Method Detail
-
createEmptySet
public static PluginConfigCollection createEmptySet(java.lang.Class<?>... customClazz)
Create an empty configuration collection.
If default properties are generated for this configuration collection, the anonymous login name from Constants.ANONYMOUS_LOGIN will be used.
Optionally a list of default custom classes can be provided, which will be used for marshalling / unmarshalling, if not overridden for a particular configuration.- Parameters:
customClazz-- Returns:
- empty configuration collection
-
createEmptySet
public static PluginConfigCollection createEmptySet(java.lang.String login, java.lang.Class<?>... customClazz)
Create an empty configuration collection.
"login" must be provided in order to process correct default properties for configurations managed by this collection. Optionally a list of default custom classes can be provided, which will be used for marshalling / unmarshalling, if not overridden for a particular configuration.- Parameters:
login-customClazz-- Returns:
- empty configuration collection
-
createCopy
public static PluginConfigCollection createCopy(PluginConfigCollection source)
Create a shallow copy of a PluginConfigCollection.- Parameters:
source-- Returns:
- new PluginConfigCollection
-
getKeySet
public java.util.Collection<java.lang.String> getKeySet()
Get the keys of all configurations managed in this collection.
The method returns getKeySetOfConfigurations.- Returns:
- collection of keys
-
getKeySetOfConfigurations
public java.util.Collection<java.lang.String> getKeySetOfConfigurations()
Get the keys of all configurations managed in this collection.- Returns:
- collection of keys
-
getMissingPropertiesKeys
public java.util.Collection<java.lang.String> getMissingPropertiesKeys()
Get the keys of all properties missing in this collection, i.e.: a configuration has been added for this key, but no properties have been provided.- Returns:
- collection of keys
-
getMissingConfigKeys
public java.util.Collection<java.lang.String> getMissingConfigKeys()
Get the keys of all configurations missing in this collection, i.e.: properties have been provided for this key, but no configuration was added.- Returns:
- collection of keys
-
addXml
public void addXml(java.lang.String path, java.lang.String xml, java.lang.Class<?>... overrideClazz)Add a configuration provided as XML String at the given path- Parameters:
path-xml-overrideClazz-
-
addData
public void addData(java.lang.String path, byte[] data, java.lang.Class<?>... overrideClazz)Add byte[] data to this configuration collection- Parameters:
path-data-overrideClazz-
-
addDefaultProperties
public void addDefaultProperties(java.lang.String path)
Add the default ConfigFileProperties at the given path- Parameters:
path-
-
addProperties
public void addProperties(java.lang.String path, ConfigFileProperties properties)Add ConfigFileProperties at the given path- Parameters:
path-properties-
-
addConfig
public void addConfig(java.lang.String path, PluginConfig object, java.lang.Class<?>... overrideClazz)Add a configuration object at the given path. Optionally a list of custom classes applicable for this particular PluginConfig can be provided.- Parameters:
path-object-overrideClazz-
-
addConfigDataHandler
public void addConfigDataHandler(java.lang.String path, PluginConfigDataHandler pluginConfigDataHandler)Add a configuration handler to this collection. In order to avoid unnecessary serialization / deserialization, you should work with PluginConfigDataHandler objects whenever possible- Parameters:
path-pluginConfigDataHandler-
-
addConfigCollection
public void addConfigCollection(PluginConfigCollection collection)
Add all configurations from the given collection to this collection.- Parameters:
collection-
-
addXmlMap
public void addXmlMap(java.util.Map<java.lang.String,java.lang.String> configs)
Add configurations provided as XML Strings at the paths given by the key in the map.- Parameters:
configs-
-
getConfig
public PluginConfig getConfig(java.lang.String path) throws javax.xml.bind.JAXBException
Get the Object representation of a particular configuration- Parameters:
path-- Returns:
- PluginConfig object of the configuration identified by path or null if it does not exist.
- Throws:
javax.xml.bind.JAXBException
-
getConfigDataHandler
public PluginConfigDataHandler getConfigDataHandler(java.lang.String path)
Get the data handler for a particular configuration. Whenever possible, you should use the PluginConfigDataHandler representation.- Parameters:
path-- Returns:
- PluginConfigDataHandler for the configuration identified by path
-
getXml
public java.lang.String getXml(java.lang.String path) throws javax.xml.bind.JAXBExceptionGet the XML String representation of a particular configuration.- Parameters:
path-- Returns:
- XML string for the configuration identified by path
- Throws:
javax.xml.bind.JAXBException
-
getXmlMap
public java.util.Map<java.lang.String,java.lang.String> getXmlMap() throws javax.xml.bind.JAXBExceptionGet a path / XML representation map for all configurations in this collection. The key represents full repository path inclusive file name.- Returns:
- map with (path, XML) for all configurations in this collection
- Throws:
javax.xml.bind.JAXBException
-
getXmlMapWithoutFullPath
public java.util.Map<java.lang.String,java.lang.String> getXmlMapWithoutFullPath() throws javax.xml.bind.JAXBExceptionGet a path / XML representation map for all configurations in this collection. The key represents only file name.- Returns:
- map with (path, XML) for all configurations in this collection
- Throws:
javax.xml.bind.JAXBException
-
getCustomClass
public java.lang.Class<?>[] getCustomClass()
Get the custom classes for this configuration collection- Returns:
- list of custom classes
-
getCustomClass
public java.lang.Class<?>[] getCustomClass(java.lang.String path)
Get the custom classes for a particular configuration item in this configuration collection- Parameters:
path-- Returns:
- list of custom classes
-
getProperties
public ConfigFileProperties getProperties(java.lang.String path)
Get the properties for a given path. The method will- return null, if no configuration exists at this path
- create and return default properties, if a configuration exists, but no properties have been provided
- return the properties collection for the given path, if available
- Parameters:
path-- Returns:
- properties or null, if no configuration is available for this path
-
removeConfig
public void removeConfig(java.lang.String path)
Remove a configuration and associated properties from this PluginConfig Set- Parameters:
path-
-
size
public int size()
Number of items in the collection- Returns:
- size of the collection
-
isEmpty
public boolean isEmpty()
Is this configuration empty?
- Returns:
- true, if empty, false otherwise
-
containsConfiguration
public boolean containsConfiguration(java.lang.String path)
Returns true if this internal list contains a configuration for the specified path.- Parameters:
path-- Returns:
- true if a configuration exist for the path
-
containsProperties
public boolean containsProperties(java.lang.String path)
Returns true if this internal list contains a configuration for the specified path.- Parameters:
path-- Returns:
- true if a configuration exist for the path
-
clear
public void clear()
Removes all of the configurations from this collection.
-
-