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 |
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 mapping)
Set the mapping for this Settings-Object without inheritance.
|
public List<Connector> getConnectors()
Connector
who can be used with this Settings4jInstance
instance.getConnectors
in interface Settings4jInstance
Settings4jInstance
instancepublic Connector getConnector(String connectorName)
Connector
for the given Name.getConnector
in interface Settings4jInstance
connectorName
- The Connector Name.Connector
for the given Name.public void addConnector(Connector connector)
Connector
.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)
Connector
to the right position in relation to the other connectors.Settings4jInstance
--------------------------------------
Connector myConnector = ...
addConnector(myConnector, ConnectorPositions
.afterLast(SystemPropertyConnector.class));
--------------------------------------
ConnectorPositions
.afterLast(SystemPropertyConnector.class)
will throw an exception if the
Settings4jInstance
doesn't have a SystemPropertyConnector. -------------------------------------- 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. 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()
removeAllConnectors
in interface Settings4jInstance
public 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
getContent
in interface Settings4jInstance
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public Object getObject(String key)
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
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 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");
getMapping
in interface Settings4jInstance
public void setMapping(Map mapping)
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–2014. All rights reserved.