use of org.drools.core.factmodel.MapCore in project drools by kiegroup.
the class AbstractTraitFactory method asTraitable.
public <K> TraitableBean<K, CoreWrapper<K>> asTraitable(K core, ClassDefinition coreDef) {
if (coreDef == null || coreDef.getDefinedClass() != core.getClass()) {
// ensure that a compatible interface cDef is not replaced for the missing actual definition
try {
coreDef = buildClassDefinition(core.getClass(), core.getClass());
} catch (IOException e) {
e.printStackTrace();
}
}
if (core instanceof Map) {
if (!coreDef.isTraitable()) {
throw new UnsupportedOperationException("Error: cannot apply a trait to non-traitable class " + core.getClass() + ". Was it declared as @Traitable? ");
}
return coreDef.isFullTraiting() ? new LogicalMapCore((Map) core) : new MapCore((Map) core);
}
CoreWrapper<K> wrapper = (CoreWrapper<K>) getCoreWrapper(core.getClass(), coreDef);
if (wrapper == null) {
throw new UnsupportedOperationException("Error: cannot apply a trait to non-traitable class " + core.getClass() + ". Was it declared as @Traitable? ");
}
wrapper.init(core);
return wrapper;
}
Aggregations