use of org.drools.core.factmodel.traits.Thing in project drools by kiegroup.
the class StandaloneTest method testThing.
@Test
public void testThing() throws LogicalTypeInconsistencyException {
// Entity is @Traitable and implements TraitableBean natively
// Thing is a Trait
// --> just call getProxy
Entity core = new Entity("x");
Thing thing = factory.don(core, Thing.class);
assertNotNull(thing);
}
use of org.drools.core.factmodel.traits.Thing in project drools by kiegroup.
the class TraitHelper method reassignNodes.
private <K, X extends TraitableBean> void reassignNodes(TraitableBean<K, X> core, Collection<Thing<K>> removedTraits) {
if (!core.hasTraits()) {
return;
}
Collection<Thing<K>> mst = ((TraitTypeMap) core._getTraitMap()).getMostSpecificTraits();
for (Thing<K> shedded : removedTraits) {
for (BitSet bs : ((TraitProxy) shedded).listAssignedOtnTypeCodes()) {
boolean found = false;
for (Thing<K> tp : mst) {
TraitProxy candidate = (TraitProxy) tp;
if (HierarchyEncoderImpl.supersetOrEqualset(candidate._getTypeCode(), bs)) {
candidate.assignOtn(bs);
found = true;
break;
}
}
if (found) {
continue;
}
}
}
}
use of org.drools.core.factmodel.traits.Thing 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.Thing in project drools by kiegroup.
the class TraitHelper method getTraitBoundary.
protected <K> Collection<Thing> getTraitBoundary(TraitableBean<K, ?> inner, boolean needsProxy, boolean hasTrait, Class trait) {
boolean refresh = !needsProxy && !hasTrait && Thing.class != trait;
if (!refresh) {
return null;
}
if (inner._getTraitMap() == null || inner instanceof Thing)
return Collections.EMPTY_LIST;
if (inner._getTraitMap().isEmpty())
return null;
Collection<Thing> ts = new ArrayList<Thing>();
for (Thing t : inner._getTraitMap().values()) {
if (t instanceof TraitProxy) {
if (((TraitProxy) t).hasOtns()) {
ts.add(t);
}
}
}
return ts;
}
use of org.drools.core.factmodel.traits.Thing in project drools by kiegroup.
the class TraitHelper method updateManyTraits.
private void updateManyTraits(Object object, BitMask mask, Collection<Thing> originators, Class<?> modifiedClass, Collection<Thing> traits, Activation activation) {
for (Thing t : traits) {
if (!originators.contains(t)) {
InternalFactHandle h = (InternalFactHandle) lookupFactHandle(t);
if (h != null) {
NamedEntryPoint nep = (NamedEntryPoint) h.getEntryPoint();
PropagationContext propagationContext = nep.getPctxFactory().createPropagationContext(nep.getInternalWorkingMemory().getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, activation != null ? activation.getRule() : null, activation != null ? activation.getTuple().getTupleSink() : null, h, nep.getEntryPoint(), mask, modifiedClass, null);
nep.update(h, t, t, nep.getObjectTypeConfigurationRegistry().getObjectTypeConf(nep.getEntryPoint(), t), propagationContext);
}
}
}
}
Aggregations