Skip to content

Commit fe5f0a4

Browse files
author
kaleidox
committed
introduce AccountLinkerService
1 parent 3cfb10b commit fe5f0a4

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/main/java/org/comroid/api/func/ext/Context.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -310,38 +310,37 @@ class Base implements Context {
310310
static {
311311
ROOT = Wrap.onDemand(() -> {
312312
try {
313-
return ServiceLoader.load(RootContextSource.class)
314-
.findFirst()
315-
.map(RootContextSource::getRootContext)
316-
.orElseGet(() -> {
317-
try {
318-
var rootContext = new Context.Base(null, "ROOT", new Object[0]);
319-
InputStream resource = ClassLoader.getSystemClassLoader()
320-
.getResourceAsStream("/org/comroid/api/context.properties");
321-
if (resource != null) {
322-
Properties props = new Properties();
323-
props.load(resource);
324-
325-
int c = 0;
326-
Object[] values = new Object[props.size()];
327-
for (Map.Entry<Object, Object> entry : props.entrySet()) {
328-
final int fc = c;
329-
Class<?> targetClass = Class.forName(String.valueOf(entry.getValue()));
330-
createInstance(targetClass).ifPresent(it -> values[fc] = it);
331-
c++;
332-
}
333-
Debug.logger.log(Level.FINE,
334-
"Initializing ContextualProvider Root with: {}",
335-
Arrays.toString(values));
336-
rootContext.addToContext(values);
337-
}
338-
return rootContext;
339-
} catch (IOException e) {
340-
throw new RuntimeException("Could not read context properties", e);
341-
} catch (ClassNotFoundException e) {
342-
throw new RuntimeException("Could not find Context Class", e);
313+
var serviceLoader = ServiceLoader.load(RootContextSource.class);
314+
var servicedContext = serviceLoader.findFirst().map(RootContextSource::getRootContext);
315+
return servicedContext.orElseGet(() -> {
316+
try {
317+
var rootContext = new Context.Base(null, "ROOT", new Object[0]);
318+
InputStream resource = ClassLoader.getSystemClassLoader()
319+
.getResourceAsStream("/org/comroid/api/context.properties");
320+
if (resource != null) {
321+
Properties props = new Properties();
322+
props.load(resource);
323+
324+
int c = 0;
325+
Object[] values = new Object[props.size()];
326+
for (Map.Entry<Object, Object> entry : props.entrySet()) {
327+
final int fc = c;
328+
Class<?> targetClass = Class.forName(String.valueOf(entry.getValue()));
329+
createInstance(targetClass).ifPresent(it -> values[fc] = it);
330+
c++;
343331
}
344-
});
332+
Debug.logger.log(Level.FINE,
333+
"Initializing ContextualProvider Root with: {}",
334+
Arrays.toString(values));
335+
rootContext.addToContext(values);
336+
}
337+
return rootContext;
338+
} catch (IOException e) {
339+
throw new RuntimeException("Could not read context properties", e);
340+
} catch (ClassNotFoundException e) {
341+
throw new RuntimeException("Could not find Context Class", e);
342+
}
343+
});
345344
} catch (Throwable t) {
346345
Log.at(Level.WARNING, "Unable to initialize Root Context", t);
347346
return null;

0 commit comments

Comments
 (0)