use of org.openksavi.sponge.core.engine.GenericProcessorInstanceHolder in project sponge by softelnet.
the class NonScriptKotlinKnowledgeBaseInterpreter method createProcessorInstanceByProcessorClass.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ProcessorInstanceHolder createProcessorInstanceByProcessorClass(KnowledgeBase knowledgeBase, Object processorClass, Class<?> javaClass) {
if (processorClass instanceof KClass) {
// Kotlin-based processor.
KClass kclass = (KClass) processorClass;
Class<?> destJavaClass = JvmClassMappingKt.getJavaClass(kclass);
if (!javaClass.isAssignableFrom(destJavaClass)) {
throw new SpongeException("Unsupported processor specification: " + destJavaClass.getName() + " can't be used as " + javaClass.getName());
}
try {
return new GenericProcessorInstanceHolder((Processor) destJavaClass.newInstance(), KotlinUtils.createProcessorName(kclass), true);
} catch (Throwable e) {
throw SpongeUtils.wrapException(destJavaClass.getName(), e);
}
}
return null;
}
Aggregations