public class StdJndiLoader extends BaseLoader implements LookupLoader, StandardLoader
Property in the JNDI
environment and loads the value for any that are found.
org.foo.My_Prop:
java:comp/env/org/foo/My_Prop
java:comp/env/org.foo.My_Prop
java:org/foo/My_Prop
java:org.foo.My_Prop
org/foo/My_Prop
org.foo.My_Prop
java:comp/env/ is used by Tomcat and several other application servers,
java: is used by some non-container environments and at least one
application server (Glassfish) uses no root at all. In all, AndHow will
search for each property under six different names (2 X 3).
AndHow will throw an error at startup if it finds multiple names in the
JNDI context that refer to the same property.
<Context>
. . .
<Environment name="org/simple/GettingStarted/COUNT_DOWN_START" value="3" type="java.lang.Integer" override="false"/>
<Environment name="org/simple/GettingStarted/LAUNCH_CMD" value="GoGoGo!" type="java.lang.String" override="false"/>
. . .
</Context>
java:comp/env/
to the name it associates with each value. As the example shows, JNDI values
can be typed. If AndHow finds the value to already be the type it expects
(e.g. an Integer), great! If AndHow finds a String and needs a
different type, AndHow will do the conversion. Any other type of conversion
(e.g. from a Short to an Integer) will result in an exception.
java:xyz/ as a system property on command line:
java -Dorg.yarnandtail.andhow.load.std.StdJndiLoader.CONFIG.ADDED_JNDI_ROOTS=java:xyz/ -jar MyJarName.jar
StandardLoader's, this loader is intended to be auto-created
by AndHow. The set of standard loaders and their order can bet set
via the AndHowConfiguration.setStandardLoaders() methods.
Other loaders which don't implement the StandardLoader interface can
be inserted into the load order via the
AndHowConfiguration.insertLoaderBefore/After().| Modifier and Type | Class and Description |
|---|---|
static interface |
StdJndiLoader.CONFIG |
| Constructor and Description |
|---|
StdJndiLoader()
There is no reason to use the constructor in production application code
because AndHow creates a single instance on demand at runtime.
|
| Modifier and Type | Method and Description |
|---|---|
protected List<String> |
buildJndiNames(PropertyConfigurationInternal appConfigDef,
List<String> roots,
Property prop)
Builds a complete list of complete JNDI names to search for a parameter value.
|
protected List<String> |
buildJndiRoots(ValidatedValues values)
Combines the values of STANDARD_JNDI_ROOTS and ADDED_JNDI_ROOTS into one list of jndi root contexts to search.
|
protected LoaderValues |
doLoad(PropertyConfigurationInternal appConfigDef,
Context ctx,
ValidatedValuesWithContext existingValues)
The actual loading, called only when there is a non-null Jndi Context.
|
Class<?> |
getClassConfig()
Returns a PropertyGroup used to globally configure a class of Loader.
|
SamplePrinter |
getConfigSamplePrinter()
Returns a ConfigSamplePrinter, which can be used to print a configuration
sample for this Loader.
|
String |
getLoaderDialect()
The type dialect of the loader.
|
String |
getLoaderType()
The type of the loader, such as JNDI, PropertyFile, SystemProperty,
etc..
|
String |
getSpecificLoadDescription()
For this particular load, where was info loaded from?
This may vary from run to run based on config params.
|
boolean |
isFailedEnvironmentAProblem()
If true, then a failure to initiate or connect to the needed environment
or external system will result in a failure and it will register a
'Propblem' during load which will cause application initiation to stop.
|
boolean |
isFlaggable()
Returns true if this loader supports
FlaggableType's. |
boolean |
isTrimmingRequiredForStringValues()
If true, values for string properties are trimmed by the Trimmer of
the property they are associated with.
|
LoaderValues |
load(PropertyConfigurationInternal appConfigDef,
LoaderEnvironment environment,
ValidatedValuesWithContext existingValues)
Builds up a list of LoaderValues by loading property values from a configuration source.
|
void |
setFailedEnvironmentAProblem(boolean isAProblem)
If true, failing to initialize the environment needed to lookup values is
considered a problem/error.
|
protected List<String> |
split(String rootStr)
Spits a comma separate list of JNDI roots into individual root strings.
|
attemptToAdd, attemptToAdd, attemptToAdd, attemptToAddIfNotDuplicate, createValue, findDuplicateProperty, getInstanceConfig, mapNametoProperty, releaseResourcesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetInstanceConfig, releaseResourcesprotected static AndHowLog log
public StdJndiLoader()
public LoaderValues load(PropertyConfigurationInternal appConfigDef, LoaderEnvironment environment, ValidatedValuesWithContext existingValues)
LoaderLoaders find and load values and associate them with the correct Property. If there is a problem while doing that, they register one or more LoaderProblems in the returned LoaderValues.
Validation of Property values is not Loader's responsibility and will be handled outside this method.
load in interface LoaderappConfigDef - The definition of all known Properties and naming metadata.environment - The environment (System Props, Env vars, fixed values) as
known to the Loader.existingValues - The values already set by prior loaders, which may configure
the behavior of this loader.protected LoaderValues doLoad(PropertyConfigurationInternal appConfigDef, Context ctx, ValidatedValuesWithContext existingValues)
appConfigDef - The definition of all known Properties and naming metadata.ctx - The non-null Jndi ContextexistingValues - The values already set by prior loaders, which may configure
the behavior of this loader.public boolean isTrimmingRequiredForStringValues()
LoaderisTrimmingRequiredForStringValues in interface Loaderpublic boolean isFlaggable()
LoaderFlaggableType's.
Loaders that support FlaggableType give special 'is present' meaning to a property being
present without a value, similar to a 'nix command line flag. If a Loader supports
flags, it should call FlaggableType.parseFlag(String) instead of
ValueType.parse(String) when a Property's ValueType is a FlaggableType.
See FlagProp for an example type.
Note: Returning true from this method is only potentially applicable to Loaders that parse strings. Loaders that directly load from rich values do not parse, so the loader logic would ignore the value here.
Examples:
Loading a non-null value from the properties file entry 'name = ' would be unexpected,
so a properties file Loader should return 'false' here.
However, a command line loader would be expected to support flags, so should return 'true'.
isFlaggable in interface Loaderpublic String getSpecificLoadDescription()
LoadergetSpecificLoadDescription in interface Loaderpublic Class<?> getClassConfig()
LoadergetClassConfig in interface LoadergetClassConfig in class BaseLoaderpublic SamplePrinter getConfigSamplePrinter()
LoadergetConfigSamplePrinter in interface LoadergetConfigSamplePrinter in class BaseLoaderprotected List<String> buildJndiRoots(ValidatedValues values)
values - The configuration state.protected List<String> buildJndiNames(PropertyConfigurationInternal appConfigDef, List<String> roots, Property prop)
appConfigDef - roots - prop - protected List<String> split(String rootStr)
rootStr - public String getLoaderType()
LoadergetLoaderType in interface Loaderpublic String getLoaderDialect()
LoadergetLoaderDialect in interface Loaderpublic void setFailedEnvironmentAProblem(boolean isAProblem)
LookupLoadersetFailedEnvironmentAProblem in interface LookupLoaderpublic boolean isFailedEnvironmentAProblem()
LookupLoaderisFailedEnvironmentAProblem in interface LookupLoaderCopyright © 2022. All rights reserved.