Search in sources :

Example 1 with BaseProcessorDefinition

use of org.openksavi.sponge.core.BaseProcessorDefinition in project sponge by softelnet.

the class DefaultProcessorManager method createProcessorInstance.

@Override
public <T extends Processor> T createProcessorInstance(ProcessorDefinition definition, Class<T> cls) {
    Validate.isInstanceOf(BaseProcessorDefinition.class, definition, "Processor definition must be or extend %s", BaseProcessorDefinition.class);
    BaseProcessorDefinition baseDefinition = (BaseProcessorDefinition) definition;
    if (baseDefinition.isJavaDefined()) {
        try {
            if (baseDefinition.getProcessorClass() == null) {
                throw new SpongeException("No corresponding Java class for processor: " + definition.getName());
            }
            return (T) baseDefinition.getProcessorClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw SpongeUtils.wrapException(e);
        }
    } else {
        return definition.getKnowledgeBase().getInterpreter().createProcessorInstance(definition.getName(), cls);
    }
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) BaseProcessorDefinition(org.openksavi.sponge.core.BaseProcessorDefinition)

Aggregations

SpongeException (org.openksavi.sponge.SpongeException)1 BaseProcessorDefinition (org.openksavi.sponge.core.BaseProcessorDefinition)1