public class DefaultSettings extends Object implements Settings4jInstance
Constructor and Description |
---|
DefaultSettings() |
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.
|
public List<Connector> getConnectors()
Settings4jInstance
Connector
who can be used with this Settings4jInstance
instance.getConnectors
in interface Settings4jInstance
Settings4jInstance
instancepublic Connector getConnector(String connectorName)
Settings4jInstance
Connector
for the given Name.getConnector
in interface Settings4jInstance
connectorName
- The Connector Name.Connector
for the given Name.public void addConnector(Connector connector)
Settings4jInstance
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> --------------------------------------
addConnector
in interface Settings4jInstance
connector
- The connector to add.public void addConnector(Connector connector, ConnectorPosition position)
Settings4jInstance
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. ) ); --------------------------------------
Settings4jInstance.addConnector(Connector)
will throw an exception if a connector with the same name already exists.
To prevent this Exception you should also check with Settings4jInstance.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. ) ); } --------------------------------------
addConnector
in interface Settings4jInstance
connector
- The connector to add.position
- The position where the connector should be added.public void removeAllConnectors()
Settings4jInstance
removeAllConnectors
in interface Settings4jInstance
public byte[] getContent(String key)
Settings4jInstance
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
getContent
in interface Settings4jInstance
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public Object getObject(String key)
Settings4jInstance
Settings4jInstance
iterates all his Connector
s and return the first found Value. getObject
in interface Settings4jInstance
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public String getString(String key)
Settings4jInstance
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
getString
in interface Settings4jInstance
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public Map<String,String> getMapping()
Settings4jInstance
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"
getMapping
in interface Settings4jInstance
public void setMapping(Map<String,String> mapping)
Settings4jInstance
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>
setMapping
in interface Settings4jInstance
mapping
- The Mapping between available settings to used settings.Copyright © 2008–2016 Brabenetz Harald, Austria. All rights reserved.