Search in sources :

Example 1 with MapCore

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;
}
Also used : IOException(java.io.IOException) MapCore(org.drools.core.factmodel.MapCore) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MapCore (org.drools.core.factmodel.MapCore)1