public interface Settings4jInstance
Settings4j
Modifier and Type | Method and Description |
---|---|
void |
addConnector(Connector connector)
Add a
Connector . |
void |
addConnector(Connector connector,
ConnectorPosition position)
Add a custom
Connector to the right position in relation to the other connectors. |
Connector |
getConnector(String connectorName)
Return the
Connector for the given Name. |
List<Connector> |
getConnectors()
Return a List off
Connector who can be used with this Settings4jInstance instance. |
byte[] |
getContent(String key)
return the found byte[]-Value for the given key.
|
Map<String,String> |
getMapping()
The key mapping defined in settings4j.xml.
|
Object |
getObject(String key)
return the found Object-Value for the given key.
|
String |
getString(String key)
return the found String-Value for the given key.
|
void |
removeAllConnectors()
Remove all Settings.
|
void |
setMapping(Map<String,String> mapping)
Set the mapping for this Settings-Object without inheritance.
|
String getString(String key)
Settings4jInstance
Instance iterates all his Connector
s and return the first found Value.
Returns null if no connector found a Value for the given key
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"byte[] getContent(String key)
Settings4jInstance
Instance iterates all his Connector
s and return the first found Value.
Returns null if no connector found a Value for the given key
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"Object getObject(String key)
Settings4jInstance
iterates all his Connector
s and return the first found Value. key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"void addConnector(Connector connector)
Connector
.
This method will be call, if you create a connector-ref to a connector configuration in your settings4j.xml
Example configuration in settings4j.xml: -------------------------------------- <settings name="com.mycompany" > <connector-ref name="DBConnector" /> </settings> --------------------------------------
connector
- The connector to add.void addConnector(Connector connector, ConnectorPosition position)
Connector
to the right position in relation to the other connectors.
This method can be used to add custom connectors into the Settings4jInstance
--------------------------------------
Connector myConnector = ...
addConnector(myConnector, ConnectorPositions
.afterLast(SystemPropertyConnector.class));
--------------------------------------
will throw an exception if the ConnectorPositions
.afterLast(SystemPropertyConnector.class)Settings4jInstance
doesn't have a
SystemPropertyConnector.
To prevent an Exception you can provide multiple ConnectorPositions as fallback:
-------------------------------------- Connector myConnector = ... addConnector(myConnector, ConnectorPositions.firstValid(// ConnectorPositions.afterLast(SystemPropertyConnector.class), ConnectorPositions.atFirst() // fallback if no SystemPropertyConnector exists. ) ); --------------------------------------
addConnector(Connector)
will throw an exception if a connector with the same name already exists.
To prevent this Exception you should also check with getConnector(String)
if the Connector already exists:
-------------------------------------- Connector myConnector = ... if(getConnector(myConnector.getName()) == null) { addConnector(myConnector, ConnectorPositions.firstValid(// ConnectorPositions.afterLast(SystemPropertyConnector.class), ConnectorPositions.atFirst() // fallback if no SystemPropertyConnector exists. ) ); } --------------------------------------
connector
- The connector to add.position
- The position where the connector should be added.void removeAllConnectors()
Map<String,String> getMapping()
if some Sub-Modules of your App defines separated Keys for e.g. the DataSource, you can refer it to one unique Key:
Example: <mapping name="defaultMapping"> <entry key="com/mycompany/moduleX/datasource" ref-key="global/datasource"/> <entry key="com/mycompany/moduleY/datasource" ref-key="global/datasource"/> </mapping>
Settings4j.getXXX("com/mycompany/moduleX/datasource");
should return the configured value under "global/datasource"
void setMapping(Map<String,String> mapping)
This method will be call, if you create a mapping-ref to a mapping configuration in your settings4j.xml
Example: <root mapping-ref="defaultMapping" > ... </root> <mapping name="defaultMapping"> <entry key="com/mycompany/moduleX/datasource" ref-key="global/datasource"/> <entry key="com/mycompany/moduleY/datasource" ref-key="global/datasource"/> </mapping>
mapping
- The Mapping between available settings to used settings.List<Connector> getConnectors()
Connector
who can be used with this Settings4jInstance
instance.Settings4jInstance
instanceCopyright © 2008–2016 Brabenetz Harald, Austria. All rights reserved.