Class AbstractConnector.Configuration

java.lang.Object
com.priint.pubserver.plugin.AbstractConnector.Configuration
All Implemented Interfaces:
Serializable
Enclosing class:
AbstractConnector

public abstract static class AbstractConnector.Configuration extends Object implements Serializable
Base class for connector configurations.

This is a JAXB annotated class representing a rudimentary configuration containing only XML "version" as attribute.

Additionally the class uses another field to handle configurations for different connector instances: currentInstance.

Current instance will be set automatically when configurations are loaded. It should never be reassigned later.

For handling default instances see below.

Subclasses of AbstractConnector#Configuration will add further JAXB annotated data fields.

Example

Adding one string field for a jdbcResource as XML Element.
Using an optional default configuration named "default" which set the jdbcResource to the initial string "jdbc/MyConnector".

 @XmlRootElement(name = "my-config")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class MyConfig extends AbstractConnector.Configuration {

        @XmlElement(name = "jdbc-resource")
        private String jdbcResource = "jdbc/MyConnector";

        public final String getJdbcResource() {
                return this.jdbcResource;
        }

        public final void setJdbcResource(String jdbcResource) {
                this.jdbcResource = jdbcResource;
        }

        @Override
        public boolean allowDefaultInstance() {
                return true;
        }

 }
 

Resulting in XML Snippets like this where "version" comes from the super class and "jdbc-resource" comes from the subclass:

 <my-config version="1.0">
     <jdbc-resource>jdbc/MyConnector42</jdbc-resource>
 </my-config>
 

Default Instances

Default instances can be used if an entity configured by ison has no instance set, i.e. the "instance" field in ison is empty.

  • In these cases the default configuration will be used if (and only if) the allowDefaultInstance() method returns true.
  • if allowDefaultInstance() returns false a ConnectorException will be thrown if the connector instance is not set in ison.
  • If allowDefaultInstance() returns true the connector will create an instance of the Configuration class defined by AbstractConnector.getConfigurationClass() using the empty constructor. This AbstractConnector.Configuration object will then be used with its default values. This is the build-in default.
  • If a root configuration exists in the repository (i.e. as top level custom element in the plugin config XML) this will override the build-in default.

To allow default instance please add to following snippet to your AbstractConnector.Configuration class:

 @Override
 public boolean allowDefaultInstance() {
   return true;
 }
 

XML Configuration Example with Default Instance

If allowDefaultInstance() returns true the "root" configuration will be used if connector instance is empty.
If allowDefaultInstance() returns false a ConnectorException will be thrown if connector instance is empty.

 <con:PluginConfig xmlns:con="com.priint.pubserver.config.manager/20130620">
   <con:name>connectorConfig.xml</con:name>
   <con:type>ContentConnector</con:type>
   <con:custom>
     <MyConfig version="1.0"><!-- root configuration can be used as default --></MyConfig>
   </con:custom>
   <con:instances>
     <con:entry key="inst1">
       <con:PluginConfig>
         <con:name>inst1</con:name>
         <con:type>data</con:type>
         <con:custom>
           <MyConfig version="1.0"><!-- config for instance "inst1" --></MyConfig>
         </con:custom>
       </con:PluginConfig>
     </con:entry>
   </con:instances>
 </con:PluginConfig>
 
Since:
4.0.5
See Also:
  • Constructor Details

    • Configuration

      public Configuration()
  • Method Details

    • getVersion

      public String getVersion()
      Get the version of the class or XML definition.

      Version is NOT related the revision of the content but to the "schema".

      Default version is "1.0".

      To set a new version please override this in a concrete class.

      Returns:
    • getCurrentInstance

      public String getCurrentInstance()
      Get the current instance name for this configuration element.

      This will be the value of the "key" attribute in a plugin config XML, e.g. "inst1" in

      <con:instances><con:entry key="inst1">[...]</con:entry></con:instances>

      If default instances are allowed to may also equal an empty string.

    • allowDefaultInstance

      public boolean allowDefaultInstance()
      Return whether this configuration class supports default instances in situations where no connector instance is defined in entity model (or defined as empty string).

      If method returns true the default configuration is either

      • grabbed from the root level "custom" element in the configuration XML from the repository (if existing), or
      • created using the empty constructor of the configurations class, thus using the initial values from source code.

      Default value is false.

      Returns:
    • setCurrentInstance

      public void setCurrentInstance(String currentInstance)
      Sets the current instance name for this configuration element.

      This is done by the AbstractConnector. Please do not use this from outside.

      Parameters:
      currentInstance -
    • toString

      public String toString()
      Overrides:
      toString in class Object