public class JNDIConnector extends AbstractConnector
Connector
.
This JNDI connector is used in the default settings4j-config:
<connector name="JNDIConnector" class="org.settings4j.connector.JNDIConnector"> <contentResolver-ref ref="DefaultContentResolver" /> <objectResolver-ref ref="DefaultObjectResolver" /> </connector>
During the first use it will check if JNDI is accessible. If no JNDI context exists, The connector will deactivate itself. A INFO-Log message will print this information.
The default contextPathPrefix is "java:comp/env/". This JNDI Connector will first check if a value for "contextPathPrefix + key"
exists and
second if a value for the "key"
only exists.
You can also configure the JNDI Connector to connect to another JNDI Context as the default one.
<connector name="JNDIConnector" class="org.settings4j.connector.JNDIConnector"> <param name="initialContextFactory" value="org.apache.naming.java.javaURLContextFactory"/> <param name="providerUrl" value="localhost:1099"/> <param name="urlPkgPrefixes" value="org.apache.naming"/> </connector>
All three parameters must be set "initialContextFactory", "providerUrl", "urlPkgPrefixes" if you want use another JNDI Context.
If the getString() JNDI lookup returns an Object which isn't a String, a WARN-Log message will be printed.
If the getContent() JNDI lookup returns a String it will try to get a byte-Array Content from the ContentResolvers (assuming the String is as FileSystemPath
or ClassPath).
Else if the getContent() JNDI lookup returns an Object which isn't a byte[], a WARN-Log message will be printed.
If the getObject() JNDI lookup returns a String it will try to get an Object from the ObjectResolvers (assuming the String is as FileSystemPath or ClassPath which can be resolved to an Object).
Constructor and Description |
---|
JNDIConnector() |
Modifier and Type | Method and Description |
---|---|
protected void |
closeQuietly(InitialContext ctx)
Calls
InitialContext.close() with null-checks and Exception handling: log exception with log level info. |
byte[] |
getContent(String key)
return a byte[]-Value for the given key or
null if no file-content for the key where found. |
String |
getContextPathPrefix() |
protected Boolean |
getIsJNDIAvailable() |
Object |
getObject(String key)
return a Object-Value for the given key.
|
String |
getString(String key)
return a String-Value for the given key.
|
boolean |
isJNDIAvailable()
check if a JNDI context is available and sets the internal Flag setIsJNDIAvailable(Boolean).
|
protected void |
logInfoButExceptionDebug(String message,
Exception exc) |
int |
rebindToContext(String key,
Object value) |
void |
setContextPathPrefix(String contextPathPrefix) |
void |
setInitialContextFactory(String initialContextFactory) |
protected void |
setIsJNDIAvailable(Boolean isJNDIAvailable) |
int |
setObject(String key,
Object value)
Set or replace a new Value for the given key.
|
void |
setProviderUrl(String providerUrl) |
void |
setUrlPkgPrefixes(String urlPkgPrefixes) |
addConnector, getConnectors, getContentResolver, getName, getObjectResolver, init, setContentResolver, setName, setObjectResolver
public byte[] getContent(String key)
Connector
null
if no file-content for the key where found.
The concrete implementation can use the ContentResolver if required
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public Object getObject(String key)
Connector
The concrete implementation can use the ObjectResolver if required
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public String getString(String key)
Connector
key
- the Key for the configuration-property. e.g.: "com/mycompany/myapp/myParameterKey"public int setObject(String key, Object value)
Constants.SETTING_NOT_POSSIBLE
must be returned. If set or
replace was successful, then Constants.SETTING_SUCCESS
must be returned.key
- the Key for the configuration-property (will not be normalized: add contextPathPrefix, replace '\' with '/'). e.g.:
"com\mycompany\myapp\myParameterKey" => "java:comp/env/com/mycompany/myapp/myParameterKey"value
- the new Object-Value for the given keyConstants.SETTING_SUCCESS
or Constants.SETTING_NOT_POSSIBLE
public boolean isJNDIAvailable()
If the internal Flag IsJNDIAvailable is False
this Connector is disabled.
public void setProviderUrl(String providerUrl)
public void setInitialContextFactory(String initialContextFactory)
public void setUrlPkgPrefixes(String urlPkgPrefixes)
protected void closeQuietly(InitialContext ctx)
InitialContext.close()
with null-checks and Exception handling: log exception with log level info.ctx
- the InitialContextto close ( )public int rebindToContext(String key, Object value)
key
- the JNDI-Key (will NOT be normalized).value
- the JNDI-Value.public String getContextPathPrefix()
public void setContextPathPrefix(String contextPathPrefix)
protected Boolean getIsJNDIAvailable()
protected void setIsJNDIAvailable(Boolean isJNDIAvailable)
Copyright © 2008–2016 Brabenetz Harald, Austria. All rights reserved.