Class PluginConfigCollection

java.lang.Object
com.priint.pubserver.config.PluginConfigCollection
All Implemented Interfaces:
Serializable

public class PluginConfigCollection extends Object implements Serializable
The 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:
  • Method Details

    • createEmptySet

      public static PluginConfigCollection createEmptySet(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(String login, 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 Collection<String> getKeySet()
      Get the keys of all configurations managed in this collection.
      The method returns getKeySetOfConfigurations.
      Returns:
      collection of keys
    • getKeySetOfConfigurations

      public Collection<String> getKeySetOfConfigurations()
      Get the keys of all configurations managed in this collection.
      Returns:
      collection of keys
    • getMissingPropertiesKeys

      public Collection<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 Collection<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(String path, String xml, Class<?>... overrideClazz)
      Add a configuration provided as XML String at the given path
      Parameters:
      path -
      xml -
      overrideClazz -
    • addData

      public void addData(String path, byte[] data, Class<?>... overrideClazz)
      Add byte[] data to this configuration collection
      Parameters:
      path -
      data -
      overrideClazz -
    • addDefaultProperties

      public void addDefaultProperties(String path)
      Add the default ConfigFileProperties at the given path
      Parameters:
      path -
    • addProperties

      public void addProperties(String path, ConfigFileProperties properties)
      Add ConfigFileProperties at the given path
      Parameters:
      path -
      properties -
    • addConfig

      public void addConfig(String path, PluginConfig object, 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(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(Map<String,String> configs)
      Add configurations provided as XML Strings at the paths given by the key in the map.
      Parameters:
      configs -
    • getConfig

      public PluginConfig getConfig(String path) throws jakarta.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:
      jakarta.xml.bind.JAXBException
    • getConfigDataHandler

      public PluginConfigDataHandler getConfigDataHandler(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 String getXml(String path) throws jakarta.xml.bind.JAXBException
      Get the XML String representation of a particular configuration.
      Parameters:
      path -
      Returns:
      XML string for the configuration identified by path
      Throws:
      jakarta.xml.bind.JAXBException
    • getXmlMap

      public Map<String,String> getXmlMap() throws jakarta.xml.bind.JAXBException
      Get 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:
      jakarta.xml.bind.JAXBException
    • getXmlMapWithoutFullPath

      public Map<String,String> getXmlMapWithoutFullPath() throws jakarta.xml.bind.JAXBException
      Get 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:
      jakarta.xml.bind.JAXBException
    • getCustomClass

      public Class<?>[] getCustomClass()
      Get the custom classes for this configuration collection
      Returns:
      list of custom classes
    • getCustomClass

      public Class<?>[] getCustomClass(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(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(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(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(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.