Package com.priint.pubserver.config
Class PluginConfigDataHandler
- java.lang.Object
-
- com.priint.pubserver.config.PluginConfigDataHandler
-
- All Implemented Interfaces:
java.io.Serializable
public class PluginConfigDataHandler extends java.lang.Object implements java.io.SerializableThe 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 versaconfig = 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPluginConfigDataHandler.SourceTypeType of data in the config handler.
-
Constructor Summary
Constructors Constructor Description PluginConfigDataHandler(byte[] data, java.lang.Class<?>... customClazz)Instantiates a new Plugin config data handler.PluginConfigDataHandler(PluginConfig object, java.lang.Class<?>... customClazz)Instantiates a new Plugin config data handler.PluginConfigDataHandler(java.lang.Class<?>... customClazz)Instantiates a new Plugin config data handler.PluginConfigDataHandler(java.lang.String xml, java.lang.Class<?>... customClazz)Instantiates a new Plugin config data handler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ConfigFilePropertiescreateDefaultProperties(java.lang.String user, java.lang.String path)Factory method to create an empty default ConfigFileProperties.java.lang.Class<?>[]getCustomClass()Get the custom classes provided for this configurationjava.lang.StringgetDebugString()Get internal debugging information for the data handler.ConfigFilePropertiesgetProperties()Get properties.PluginConfigDataHandler.SourceTypegetSource()Get the source.PluginConfigreadConfig()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.java.lang.StringreadXml()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(java.lang.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.voidsetSource(PluginConfigDataHandler.SourceType source)Set the source.java.lang.StringtoString()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.voidwriteXml(java.lang.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.
-
-
-
Constructor Detail
-
PluginConfigDataHandler
public PluginConfigDataHandler(java.lang.String xml, java.lang.Class<?>... customClazz)Instantiates a new Plugin config data handler.- Parameters:
xml- the xmlcustomClazz- the custom clazz
-
PluginConfigDataHandler
public PluginConfigDataHandler(PluginConfig object, java.lang.Class<?>... customClazz)
Instantiates a new Plugin config data handler.- Parameters:
object- the objectcustomClazz- the custom clazz
-
PluginConfigDataHandler
public PluginConfigDataHandler(byte[] data, java.lang.Class<?>... customClazz)Instantiates a new Plugin config data handler.- Parameters:
data- the datacustomClazz- the custom clazz
-
PluginConfigDataHandler
public PluginConfigDataHandler(java.lang.Class<?>... customClazz)
Instantiates a new Plugin config data handler.- Parameters:
customClazz- the custom clazz
-
-
Method Detail
-
readConfig
public PluginConfig readConfig() throws javax.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)
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:
javax.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 java.lang.String readXml() throws javax.xml.bind.JAXBExceptionInitialize (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:
javax.xml.bind.JAXBException- the jaxb exception
-
writeXml
public void writeXml(java.lang.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 javax.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:
javax.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 java.lang.Class<?>[] getCustomClass()
Get the custom classes provided for this configuration- Returns:
- list of custom classes
-
setCustomClass
public void setCustomClass(java.lang.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
- Parameters:
customClazz- zero, one or several custom classes
-
getSource
public PluginConfigDataHandler.SourceType 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(java.lang.String user, java.lang.String path)
Factory method to create an empty default ConfigFileProperties.- Parameters:
user- the userpath- the path- Returns:
- new default properties object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDebugString
public java.lang.String getDebugString()
Get internal debugging information for the data handler.- Returns:
- debug information string
-
-