Package com.priint.pubserver.config
Class PluginConfigDataHandler
java.lang.Object
com.priint.pubserver.config.PluginConfigDataHandler
- All Implemented Interfaces:
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.
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 ClassesModifier and TypeClassDescriptionstatic enumType of data in the config handler. -
Constructor Summary
ConstructorsConstructorDescriptionPluginConfigDataHandler(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 TypeMethodDescriptionstatic ConfigFilePropertiescreateDefaultProperties(String user, String path) Factory method to create an empty default ConfigFileProperties.Class<?>[]Get the custom classes provided for this configurationGet internal debugging information for the data handler.Get properties.Get the source.Initialize (if required) and return the PluginConfig representation of this configuration.byte[]readData()Initialize (if required) and return the byte array representation of this configuration.readXml()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 callingwriteXml(String).
Example:voidsetCustomClass(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.voidsetProperties(ConfigFileProperties properties) Set properties.voidSet the source.toString()voidwriteConfig(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.voidwriteData(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.voidChange the source of this data handler to the XML string provided and invalidate all other representations (PluginConfig, byte array) of this configuration.
-
Constructor Details
-
PluginConfigDataHandler
Instantiates a new Plugin config data handler.- Parameters:
xml- the xmlcustomClazz- the custom clazz
-
PluginConfigDataHandler
Instantiates a new Plugin config data handler.- Parameters:
object- the objectcustomClazz- the custom clazz
-
PluginConfigDataHandler
Instantiates a new Plugin config data handler.- Parameters:
data- the datacustomClazz- the custom clazz
-
PluginConfigDataHandler
Instantiates a new Plugin config data handler.- Parameters:
customClazz- the custom clazz
-
-
Method Details
-
readConfig
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)
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
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
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 callingwriteXml(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
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.JAXBExceptionInitialize (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[])
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
Get the custom classes provided for this configuration- Returns:
- list of custom classes
-
setCustomClass
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
- Parameters:
customClazz- zero, one or several custom classes
-
getSource
Get the source.- Returns:
- source source
-
setSource
Set the source.- Parameters:
source- the source
-
getProperties
Get properties.- Returns:
- properties properties
-
setProperties
Set properties.- Parameters:
properties- the properties
-
createDefaultProperties
Factory method to create an empty default ConfigFileProperties.- Parameters:
user- the userpath- the path- Returns:
- new default properties object
-
toString
-
getDebugString
Get internal debugging information for the data handler.- Returns:
- debug information string
-