use of org.kie.api.definition.type.Duration in project drools by kiegroup.
the class TypeDeclarationUtil method createTypeDeclaration.
public static TypeDeclaration createTypeDeclaration(Class<?> cls) {
TypeDeclaration typeDeclaration = createTypeDeclarationForBean(cls);
Duration duration = cls.getAnnotation(Duration.class);
if (duration != null) {
wireDurationAccessor(duration.value(), typeDeclaration);
}
Timestamp timestamp = cls.getAnnotation(Timestamp.class);
if (timestamp != null) {
wireDurationAccessor(timestamp.value(), typeDeclaration);
}
return typeDeclaration;
}
use of org.kie.api.definition.type.Duration in project drools by kiegroup.
the class TypeDeclarationConfigurator method wireDurationAccessor.
private static void wireDurationAccessor(KnowledgeBuilderImpl kbuilder, Annotated annotated, TypeDeclaration type, PackageRegistry pkgRegistry) {
Duration duration = annotated.getTypedAnnotation(Duration.class);
if (duration != null) {
BaseDescr typeDescr = annotated instanceof BaseDescr ? ((BaseDescr) annotated) : new BaseDescr();
String durationField;
try {
durationField = duration.value();
} catch (Exception e) {
kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, e.getMessage()));
return;
}
type.setDurationAttribute(durationField);
InternalKnowledgePackage pkg = pkgRegistry.getPackage();
MVELAnalysisResult results = getMvelAnalysisResult(kbuilder, typeDescr, type, pkgRegistry, durationField, pkg);
if (results != null) {
type.setDurationExtractor(getFieldExtractor(type, durationField, pkg, results));
} else {
kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, "Error processing @duration for TypeDeclaration '" + type.getFullName() + "': cannot access the field '" + durationField + "'"));
}
}
}
Aggregations