use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class AbstractTerminalNode method initDeclaredMask.
public void initDeclaredMask(BuildContext context) {
if (!(unwrapTupleSource() instanceof LeftInputAdapterNode)) {
// RTN's not after LIANode are not relevant for property specific, so don't block anything.
setDeclaredMask(AllSetBitMask.get());
return;
}
Pattern pattern = context.getLastBuiltPatterns()[0];
ObjectType objectType = pattern.getObjectType();
if (!(objectType instanceof ClassObjectType)) {
// InitialFact has no type declaration and cannot be property specific
// Only ClassObjectType can use property specific
setDeclaredMask(AllSetBitMask.get());
return;
}
Class objectClass = ((ClassObjectType) objectType).getClassType();
TypeDeclaration typeDeclaration = context.getKnowledgeBase().getTypeDeclaration(objectClass);
if (typeDeclaration == null || !typeDeclaration.isPropertyReactive()) {
// if property specific is not on, then accept all modification propagations
setDeclaredMask(AllSetBitMask.get());
} else {
List<String> settableProperties = getAccessibleProperties(context.getKnowledgeBase(), objectClass);
Class modifiedClass = ((ClassObjectType) pattern.getObjectType()).getClassType();
setDeclaredMask(calculatePositiveMask(modifiedClass, pattern.getListenedProperties(), settableProperties));
setNegativeMask(calculateNegativeMask(modifiedClass, pattern.getListenedProperties(), settableProperties));
}
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class ModifyInterceptor method calculateModificationMask.
private void calculateModificationMask(KnowledgeHelper knowledgeHelper, WithNode node) {
Class<?> nodeClass = node.getEgressType();
TypeDeclaration typeDeclaration = knowledgeHelper.getWorkingMemory().getKnowledgeBase().getTypeDeclaration(nodeClass);
if (typeDeclaration == null || !typeDeclaration.isPropertyReactive()) {
modificationMask = allSetButTraitBitMask();
return;
}
List<String> settableProperties = typeDeclaration.getAccessibleProperties();
modificationMask = getEmptyPropertyReactiveMask(settableProperties.size());
// TODO: access parmValuePairs without reflection
WithNode.ParmValuePair[] parmValuePairs = getFieldValue(WithNode.class, "withExpressions", node);
for (WithNode.ParmValuePair parmValuePair : parmValuePairs) {
Method method = extractMethod(parmValuePair);
if (method == null) {
modificationMask = allSetButTraitBitMask();
return;
}
String propertyName = setter2property(method.getName());
if (propertyName != null) {
int index = settableProperties.indexOf(propertyName);
if (index >= 0) {
modificationMask = setPropertyOnMask(modificationMask, index);
}
}
List<String> modifiedProps = typeDeclaration.getTypeClassDef().getModifiedPropsByMethod(method);
if (modifiedProps != null) {
for (String modifiedProp : modifiedProps) {
int index = settableProperties.indexOf(modifiedProp);
if (index >= 0) {
modificationMask = setPropertyOnMask(modificationMask, index);
}
}
}
}
}
Aggregations