private static final Environment prepareEnvironment (final ArgumentsProvider arguments, final ClassLoader classLoader_, final ThreadingContext threading_, final Transcript transcript_, final ExceptionTracer exceptions_)
throws Throwable
{
BasicThreadingSecurityManager.initialize ();
final Transcript transcript;
if (transcript_ == null)
transcript = Transcript.create (BasicComponentHarnessMain.class);
else
transcript = transcript_;
final ExceptionTracer exceptions;
if (exceptions_ == null)
exceptions = TranscriptExceptionTracer.create (transcript, AbortingExceptionTracer.defaultInstance);
else
exceptions = exceptions_;
final ComponentIdentifier identifier;
{
final String identifierData = arguments.getIdentifier ();
if (identifierData != null) {
transcript.traceDebugging ("parsing identifier `%s`...", identifierData);
identifier = ComponentIdentifier.resolve (identifierData);
} else {
transcript.traceWarning ("running a standalone component.");
identifier = ComponentIdentifier.standalone;
}
}
final Map<String, Object> options = new HashMap<String, Object> ();
{
final List<String> optionsDatas = arguments.getCallbacksOptions ();
if (optionsDatas != null) {
for (final String optionsData : optionsDatas) {
transcript.traceDebugging ("parsing configuration `%s`...", optionsData);
final Object optionsObject = DefaultJsonCoder.defaultInstance.decodeFromString (optionsData);
if (optionsObject != null) {
Preconditions.checkArgument (optionsObject instanceof Map, "invalid configuration `%s` (not a JSON map)", optionsObject);
for (final Map.Entry<String, Object> option : ((Map<String, Object>) optionsObject).entrySet ()) {
transcript.traceDebugging ("defining configuration `%s` = `%s`...", option.getKey (), option.getValue ());
options.put (option.getKey (), option.getValue ());
}
}
}
}
}
final ClassLoader classLoader;
if (classLoader_ == null)
classLoader = BasicComponentHarnessMain.prepareClassLoader (arguments, transcript, exceptions);
else
classLoader = classLoader_;
final ThreadingContext threading;
if (threading_ == null) {
transcript.traceDebugging ("creating threading context...");
final BasicThreadingContext threading1 = BasicThreadingContext.create (BasicComponentHarnessMain.class, exceptions, UncaughtExceptionHandler.create (exceptions), classLoader);
transcript.traceDebugging ("initializing threading context...");
threading1.initialize ();
threading = threading1;
} else
threading = threading_;
final BasicCallbackReactor reactor;
{
transcript.traceDebugging ("creating callbacks reactor...");
reactor = BasicCallbackReactor.create (threading, exceptions);
transcript.traceDebugging ("initializing callbacks reactor....");
reactor.initialize ();
}
final Environment environment = new Environment (identifier, classLoader, reactor, threading, transcript, exceptions, options);
return (environment);
}