use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class PatternBuilder method getExpirationForType.
private static ExpirationSpec getExpirationForType(BuildContext context, ObjectType objectType) {
long offset = NEVER_EXPIRES;
boolean hard = false;
for (TypeDeclaration type : context.getKnowledgeBase().getTypeDeclarations()) {
if (type.getObjectType().isAssignableFrom(objectType)) {
if (hard) {
if (type.getExpirationPolicy() == Policy.TIME_HARD && type.getExpirationOffset() > offset) {
offset = type.getExpirationOffset();
}
} else {
if (type.getExpirationPolicy() == Policy.TIME_HARD) {
offset = type.getExpirationOffset();
hard = true;
} else if (type.getExpirationOffset() > offset) {
offset = type.getExpirationOffset();
}
}
}
}
// the same timestamp
return new ExpirationSpec(offset == NEVER_EXPIRES ? NEVER_EXPIRES : offset + 1, hard);
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class ObjectSource method initDeclaredMask.
public void initDeclaredMask(BuildContext context) {
if (context == null || context.getLastBuiltPatterns() == null) {
// only happens during unit tests
declaredMask = AllSetBitMask.get();
return;
}
Pattern pattern = context.getLastBuiltPatterns()[0];
ObjectType objectType = pattern.getObjectType();
if (!(objectType instanceof ClassObjectType)) {
// Only ClassObjectType can use property specific
declaredMask = 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
declaredMask = AllSetBitMask.get();
} else {
List<String> settableProperties = getAccessibleProperties(context.getKnowledgeBase(), objectClass);
declaredMask = calculateDeclaredMask(objectClass, settableProperties);
}
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class ReteooFactHandleFactory method newFactHandle.
/* (non-Javadoc)
* @see org.kie.reteoo.FactHandleFactory#newFactHandle(long)
*/
public InternalFactHandle newFactHandle(final int id, final Object object, final long recency, final ObjectTypeConf conf, final InternalWorkingMemory workingMemory, final WorkingMemoryEntryPoint wmEntryPoint) {
if (conf != null && conf.isEvent()) {
TypeDeclaration type = conf.getTypeDeclaration();
long timestamp;
if (type != null && type.getTimestampExtractor() != null) {
timestamp = type.getTimestampExtractor().getLongValue(workingMemory, object);
} else {
timestamp = workingMemory.getTimerService().getCurrentTime();
}
long duration = 0;
if (type != null && type.getDurationExtractor() != null) {
duration = type.getDurationExtractor().getLongValue(workingMemory, object);
}
return new EventFactHandle(id, object, recency, timestamp, duration, wmEntryPoint != null ? wmEntryPoint : workingMemory, conf != null && conf.isTrait());
} else {
return new DefaultFactHandle(id, object, recency, wmEntryPoint != null ? wmEntryPoint : workingMemory, conf != null && conf.isTrait());
}
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class KiePackagesBuilder method getClassObjectType.
private ObjectType getClassObjectType(Class<?> patternClass) {
return objectTypeCache.computeIfAbsent(patternClass.getCanonicalName(), name -> {
boolean isEvent = false;
if (!name.startsWith("java.") && !patternClass.isPrimitive()) {
KnowledgePackageImpl pkg = (KnowledgePackageImpl) packages.computeIfAbsent(patternClass.getPackage().getName(), this::createKiePackage);
TypeDeclaration typeDeclaration = pkg.getTypeDeclaration(patternClass);
if (typeDeclaration == null) {
typeDeclaration = createTypeDeclaration(patternClass);
pkg.addTypeDeclaration(typeDeclaration);
}
isEvent = typeDeclaration.getRole() == Role.Type.EVENT;
}
return new ClassObjectType(patternClass, isEvent);
});
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class ModelBuilderImpl method registerTypeDeclarations.
private void registerTypeDeclarations(Collection<CompositePackageDescr> packages) {
for (CompositePackageDescr packageDescr : packages) {
InternalKnowledgePackage pkg = getOrCreatePackageRegistry(packageDescr).getPackage();
for (TypeDeclarationDescr typeDescr : packageDescr.getTypeDeclarations()) {
normalizeAnnotations(typeDescr, pkg.getTypeResolver(), false);
TypeDeclaration type = new TypeDeclaration(typeDescr.getTypeName());
type.setResource(typeDescr.getResource());
TypeDeclarationFactory.processAnnotations(typeDescr, type);
pkg.addTypeDeclaration(type);
}
}
}
Aggregations