Fork me on GitHub

Overview

In Default Config you can see how do configure some of the existing Connectors from the Connector Package

On this page you will see how do write your own connector.

You can implement the Connector Interface directly, but it is recommended to extend one of the following two abstract classes:

  • AbstractPropertyConnector: The simplest way to implement your Connector. You only must implement the method String getString(final String key).
  • AbstractConnector: You can implement getString(), getContent() and getObject() separately.
Connector Package Graph

AbstractPropertyConnector

The AbstractPropertyConnector is the simplest way to implement your Connector.

The AbstractPropertyConnector extends the AbstractConnector by implementing the getContent() and getObject() method by resolving the found value from getString() with the given Content- and Object-Resolver.

The most important direct implementations are the PropertyFileConnector and the SystemPropertyConnector:

AbstractPropertyConnector Graph

You only must implement the method String getString(final String key).
Returning null means that no value for the given key where found and the next Connector in the settings4j-chain will be called.

public class MySimpleConnector extends AbstractPropertyConnector {
    public String getString(final String key) {
        return null;
    }
}

AbstractConnector

The AbstractConnector implements the basic features of the Connector Interface: name, contentResolver, objectResolver, and the reference to other connectors.

The most important direct implementations are the JNDIConnector and the ClasspathConnector:

AbstractConnector Graph

You can implement getString(), getContent() and getObject().
Returning null means that no value for the given key where found and the next Connector in the settings4j-chain will be called.

public class MyComplexConnector extends AbstractConnector {
    public String getString(final String key) {
        return null;
    }
    public byte[] getContent(final String key) {
        return null;
    }
    public Object getObject(final String key) {
        return null;
    }
}