Class PluginConfigDataHandler

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

public class PluginConfigDataHandler extends Object implements Serializable
The PluginConfigDataHandler class wraps access to a Plugin configuration provided either as String (XML), Object (PluginConfig instance) ore byte array.
The class will translate to either representation on demand and cache the results.

Examples:

  PluginConfigDataHandler configuration = new PluginConfigDataHandler(xmlString, MyConfigClass.class);

  // triggers unmarshalling
  PluginConfig config = configuration.readConfig();
 
or vice versa
  config = new PluginConfigDataHandler(config, MyConfigClass.class);
  // triggers marshalling
  String xml = config.readXml();

  // returns the cached XML representation
  String xml2 = config.readXml();

  // this will invalidate the XML String representation
  handle.writeConfig(anotherConfig);

  // so next time we get an updated XML String representation
  xml = config.readXml();
 
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Type of data in the config handler.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PluginConfigDataHandler(byte[] data, Class<?>... customClazz)
    Instantiates a new Plugin config data handler.
    PluginConfigDataHandler(PluginConfig object, Class<?>... customClazz)
    Instantiates a new Plugin config data handler.
    PluginConfigDataHandler(Class<?>... customClazz)
    Instantiates a new Plugin config data handler.
    PluginConfigDataHandler(String xml, Class<?>... customClazz)
    Instantiates a new Plugin config data handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    Factory method to create an empty default ConfigFileProperties.
    Class<?>[]
    Get the custom classes provided for this configuration
    Get internal debugging information for the data handler.
    Get properties.
    Get the source.
    Initialize (if required) and return the PluginConfig representation of this configuration.
    byte[]
    Initialize (if required) and return the byte array representation of this configuration.
    Initialize (if required) and return the XML string representation of this configuration.
    Please note:
    Changing this string does not change the content of the data handler, unless you write the string back to the data handler by calling writeXml(String).
    Example:
    void
    setCustomClass(Class<?>... customClazz)
    Set the custom classes required for serialization / deserialization and invalidate all calculated representations of this configuration.
    Examples if the original source of this data handler is a PluginConfig object, the XML string and byte array representations are nulled, because different custom classes might affect marshalling of this object if the original source of this data handler is a XML string or byte array, the PluginConfig representation is nulled, because different custom classes might affect unmarshalling of this data Nothing will happen, if the classes provided are "superset" of the custom classed already defined for this data handler.
    void
    Set properties.
    void
    Set the source.
     
    void
    Change the source of this data handler to the PluginConfig object provided and invalidate all other representations (xml, byte array) of this configuration.
    void
    writeData(byte[] data)
    Change the source of this data handler to the byte array provided and invalidate all other representations (PluginConfig, XML string) of this configuration.
    void
    Change the source of this data handler to the XML string provided and invalidate all other representations (PluginConfig, byte array) of this configuration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PluginConfigDataHandler

      public PluginConfigDataHandler(String xml, Class<?>... customClazz)
      Instantiates a new Plugin config data handler.
      Parameters:
      xml - the xml
      customClazz - the custom clazz
    • PluginConfigDataHandler

      public PluginConfigDataHandler(PluginConfig object, Class<?>... customClazz)
      Instantiates a new Plugin config data handler.
      Parameters:
      object - the object
      customClazz - the custom clazz
    • PluginConfigDataHandler

      public PluginConfigDataHandler(byte[] data, Class<?>... customClazz)
      Instantiates a new Plugin config data handler.
      Parameters:
      data - the data
      customClazz - the custom clazz
    • PluginConfigDataHandler

      public PluginConfigDataHandler(Class<?>... customClazz)
      Instantiates a new Plugin config data handler.
      Parameters:
      customClazz - the custom clazz
  • Method Details

    • readConfig

      public PluginConfig readConfig() throws jakarta.xml.bind.JAXBException
      Initialize (if required) and return the PluginConfig representation of this configuration.
      • if the original source of this data handler is a PluginConfig object, the method just returns the object provided upon initialization. Be aware that changing this object does change the content of the data handler in this case.
      • if the original source of this data handler is a XML string or byte array, a newly unmarshalled or cached object is returned. Be aware that changing this object does not change the content of the data handler in this case, unless you write the changed object back by calling writeConfig(PluginConfig)
      Since this turned out to be a common pitfall, it's good practice to follow this pattern:
        try {
              PluginConfigDataHandler dataHandler;
              PluginConfig config = dataHandler.readConfig();
      
              // change common PluginConfig properties
              config.setName("A descriptive name");
      
              MyCustomType custom = config.getCustomConfig(myCustomType.class);
      
              // change whatever required and supported for your custom type
              custom.setCustomValue(12345);
      
              // to be on the very safe side: update the PluginConfig wrapper
              config.replaceCustomConfig(custom);
      
              // finally write back to data handler
              dataHandler.writeConfig(config);
        }
        catch (JAXBException e) {
              // because the object might have been unmarshalled / marshalled
              // in the code fragment above ...
        }
       
      Returns:
      PluginConfig object
      Throws:
      jakarta.xml.bind.JAXBException - the jaxb exception
    • writeConfig

      public void writeConfig(PluginConfig config)
      Change the source of this data handler to the PluginConfig object provided and invalidate all other representations (xml, byte array) of this configuration.
      Parameters:
      config - the new PluginConfig source
    • readXml

      public String readXml() throws jakarta.xml.bind.JAXBException
      Initialize (if required) and return the XML string representation of this configuration.
      Please note:
      Changing this string does not change the content of the data handler, unless you write the string back to the data handler by calling writeXml(String).
      Example:
              try {
                      PluginConfigDataHandler dataHandler;
                      String xml = dataHandler.readXml();
      
                      // enter the next level of digital publishing:
                      xml = xml.replace("print", "priint");
      
                      // finally update content fo the data handler
                      dataHandler.writeXml(xml);
          }
              catch (JAXBEception e) {
          }
       
      Returns:
      XML string
      Throws:
      jakarta.xml.bind.JAXBException - the jaxb exception
    • writeXml

      public void writeXml(String xml)
      Change the source of this data handler to the XML string provided and invalidate all other representations (PluginConfig, byte array) of this configuration.
      Parameters:
      xml - the xml
    • readData

      public byte[] readData() throws jakarta.xml.bind.JAXBException
      Initialize (if required) and return the byte array representation of this configuration.
      • if the original source of this data handler is a byte array, the method just returns the data provided upon initialization. Be aware that changing this array does change the content of the data handler in this case.
      • if the original source of this data handler is a XML string or PluginConfig object, a newly allocated or cached byte array is returned. Be aware that changing this array does not change the content of the data handler in this case, unless you write the changed data back by calling writeData(byte[])
      See the readConfig() method documentation for an example.
      Returns:
      binary data for the configuration
      Throws:
      jakarta.xml.bind.JAXBException - the jaxb exception
    • writeData

      public void writeData(byte[] data)
      Change the source of this data handler to the byte array provided and invalidate all other representations (PluginConfig, XML string) of this configuration.
      Parameters:
      data - the data
    • getCustomClass

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

      public void setCustomClass(Class<?>... customClazz)
      Set the custom classes required for serialization / deserialization and invalidate all calculated representations of this configuration.
      Examples
      • if the original source of this data handler is a PluginConfig object, the XML string and byte array representations are nulled, because different custom classes might affect marshalling of this object
      • if the original source of this data handler is a XML string or byte array, the PluginConfig representation is nulled, because different custom classes might affect unmarshalling of this data
      Nothing will happen, if the classes provided are "superset" of the custom classed already defined for this data handler. See the PubServerUtils documentation for more information.
      Parameters:
      customClazz - zero, one or several custom classes
    • getSource

      Get the source.
      Returns:
      source source
    • setSource

      public void setSource(PluginConfigDataHandler.SourceType source)
      Set the source.
      Parameters:
      source - the source
    • getProperties

      public ConfigFileProperties getProperties()
      Get properties.
      Returns:
      properties properties
    • setProperties

      public void setProperties(ConfigFileProperties properties)
      Set properties.
      Parameters:
      properties - the properties
    • createDefaultProperties

      public static ConfigFileProperties createDefaultProperties(String user, String path)
      Factory method to create an empty default ConfigFileProperties.
      Parameters:
      user - the user
      path - the path
      Returns:
      new default properties object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getDebugString

      public String getDebugString()
      Get internal debugging information for the data handler.
      Returns:
      debug information string