use of org.drools.core.factmodel.traits.TraitFactory in project drools by kiegroup.
the class TraitHelper method applyTrait.
protected <T, K> T applyTrait(Activation activation, K core, Class<T> trait, Object value, boolean logical, Mode... modes) throws LogicalTypeInconsistencyException {
TraitFactory builder = TraitFactory.getTraitBuilderForKnowledgeBase(entryPoint.getKnowledgeBase());
TraitableBean inner = makeTraitable(core, builder, logical, activation);
boolean needsProxy = trait.isAssignableFrom(inner.getClass());
boolean hasTrait = inner.hasTrait(trait.getName());
boolean needsUpdate = needsProxy || core != inner;
checkStaticTypeCode(inner);
Collection<Thing> mostSpecificTraits = getTraitBoundary(inner, needsProxy, hasTrait, trait);
T thing = asTrait(core, inner, trait, needsProxy, hasTrait, needsUpdate, builder, logical, activation);
configureTrait(thing, value);
thing = doInsertTrait(activation, thing, core, logical, modes);
refresh(thing, core, inner, trait, mostSpecificTraits, logical, activation);
if (trait != Thing.class && inner._getFieldTMS() != null) {
inner._getFieldTMS().resetModificationMask();
}
return thing;
}
use of org.drools.core.factmodel.traits.TraitFactory in project drools by kiegroup.
the class TraitHelper method applyManyTraits.
protected <T, K> T applyManyTraits(Activation activation, K core, Collection<Class<? extends Thing>> traits, Object value, boolean logical, Mode... modes) throws LogicalTypeInconsistencyException {
// Precondition : traits is not empty, checked by don
TraitFactory builder = TraitFactory.getTraitBuilderForKnowledgeBase(entryPoint.getKnowledgeBase());
TraitableBean inner = makeTraitable(core, builder, logical, activation);
Collection<Thing> mostSpecificTraits = inner.getMostSpecificTraits();
boolean newTraitsAdded = false;
T firstThing = null;
List<Thing> things = new ArrayList<Thing>(traits.size());
checkStaticTypeCode(inner);
for (Class<?> trait : traits) {
boolean needsProxy = trait.isAssignableFrom(inner.getClass());
boolean hasTrait = inner.hasTrait(trait.getName());
boolean needsUpdate = needsProxy || core != inner;
if (!hasTrait) {
T thing = (T) asTrait(core, inner, trait, needsProxy, hasTrait, needsUpdate, builder, logical, activation);
configureTrait(thing, value);
things.add((Thing) thing);
if (!newTraitsAdded && trait != Thing.class) {
firstThing = thing;
newTraitsAdded = true;
}
}
}
for (Thing t : things) {
doInsertTrait(activation, t, core, logical, modes);
}
if (newTraitsAdded) {
if (mostSpecificTraits != null) {
updateCore(inner, core, null, logical, activation);
if (!mostSpecificTraits.isEmpty()) {
updateManyTraits(inner, onlyTraitBitSetMask(), things, core.getClass(), mostSpecificTraits, activation);
}
}
}
return firstThing;
}
Aggregations