}
}
}
// Go on with the build
TypeDeclaration type = new TypeDeclaration( typeDescr.getTypeName() );
if ( resource != null ) {
type.setResource( this.resource );
}
// is it a regular fact or an event?
AnnotationDescr annotationDescr = typeDescr.getAnnotation( TypeDeclaration.Role.ID );
String role = (annotationDescr != null) ? annotationDescr.getSingleValue() : null;
if ( role != null ) {
type.setRole( TypeDeclaration.Role.parseRole( role ) );
}
annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_TYPESAFE );
String typesafe = (annotationDescr != null) ? annotationDescr.getSingleValue() : null;
if ( typesafe != null ) {
type.setTypesafe( Boolean.parseBoolean( typesafe ) );
}
// is it a POJO or a template?
annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_TEMPLATE );
String templateName = (annotationDescr != null) ? annotationDescr.getSingleValue() : null;
if ( templateName != null ) {
type.setFormat( TypeDeclaration.Format.TEMPLATE );
FactTemplate template = pkgRegistry.getPackage().getFactTemplate( templateName );
if ( template != null ) {
type.setTypeTemplate( template );
} else {
this.results.add( new TypeDeclarationError( "Template not found for TypeDeclaration '" + template + "' for type '" + type.getTypeName() + "'",
typeDescr.getLine() ) );
continue;
}
} else {
annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_CLASS );
String className = (annotationDescr != null) ? annotationDescr.getSingleValue() : null;
if ( StringUtils.isEmpty( className ) ) {
className = type.getTypeName();
}
type.setFormat( TypeDeclaration.Format.POJO );
Class clazz;
try {
// the type declaration is generated in any case (to be used by subclasses, if any)
// the actual class will be generated only if needed
generateDeclaredBean( typeDescr,
type,
pkgRegistry );
clazz = pkgRegistry.getTypeResolver().resolveType( className );
type.setTypeClass( clazz );
if ( type.getTypeClassDef() != null ) {
try {
buildFieldAccessors( type,
pkgRegistry );
} catch ( Exception e ) {
this.results.add( new TypeDeclarationError( "Error creating field accessors for TypeDeclaration '" + className + "' for type '" + type.getTypeName() + "'",
typeDescr.getLine() ) );
continue;
}
}
} catch ( final ClassNotFoundException e ) {
this.results.add( new TypeDeclarationError( "Class '" + className +
"' not found for type declaration of '" + type.getTypeName() + "'",
typeDescr.getLine() ) );
continue;
}
}
annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_TIMESTAMP );
String timestamp = (annotationDescr != null) ? annotationDescr.getSingleValue() : null;
if ( timestamp != null ) {
type.setTimestampAttribute( timestamp );
ClassDefinition cd = type.getTypeClassDef();
Package pkg = pkgRegistry.getPackage();
InternalReadAccessor reader = pkg.getClassFieldAccessorStore().getMVELReader( ClassUtils.getPackage( type.getTypeClass() ),
type.getTypeClass().getName(),
timestamp,
type.isTypesafe() );
MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( "mvel" );
data.addCompileable( (MVELCompileable) reader );
((MVELCompileable) reader).compile( data );
type.setTimestampExtractor( reader );
}
annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_DURATION );
String duration = (annotationDescr != null) ? annotationDescr.getSingleValue() : null;
if ( duration != null ) {
type.setDurationAttribute( duration );
ClassDefinition cd = type.getTypeClassDef();
Package pkg = pkgRegistry.getPackage();
InternalReadAccessor reader = pkg.getClassFieldAccessorStore().getMVELReader( ClassUtils.getPackage( type.getTypeClass() ),
type.getTypeClass().getName(),
duration,
type.isTypesafe() );
MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData( "mvel" );
data.addCompileable( (MVELCompileable) reader );
((MVELCompileable) reader).compile( data );
type.setDurationExtractor( reader );
}
annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_EXPIRE );
String expiration = (annotationDescr != null) ? annotationDescr.getSingleValue() : null;
if ( expiration != null ) {
if ( timeParser == null ) {
timeParser = new TimeIntervalParser();
}
type.setExpirationOffset( timeParser.parse( expiration )[0].longValue() );
}
boolean dynamic = typeDescr.getAnnotationNames().contains( TypeDeclaration.ATTR_PROP_CHANGE_SUPPORT );
type.setDynamic( dynamic );
pkgRegistry.getPackage().addTypeDeclaration( type );
}
}