List<EntityResult> entityResults = new ArrayList<EntityResult>( elements.size() );
for ( Element entityResult : elements ) {
AnnotationDescriptor entityResultDescriptor = new AnnotationDescriptor( EntityResult.class );
String clazzName = entityResult.attributeValue( "entity-class" );
if ( clazzName == null ) {
throw new AnnotationException( "<entity-result> without entity-class. " + SCHEMA_VALIDATION );
}
Class clazz;
try {
clazz = ReflectHelper.classForName(
XMLContext.buildSafeClassName( clazzName, defaults ),
JPAOverridenAnnotationReader.class
);
}
catch ( ClassNotFoundException e ) {
throw new AnnotationException( "Unable to find entity-class: " + clazzName, e );
}
entityResultDescriptor.setValue( "entityClass", clazz );
copyStringAttribute( entityResultDescriptor, entityResult, "discriminator-column", false );
List<FieldResult> fieldResults = new ArrayList<FieldResult>();
for ( Element fieldResult : (List<Element>) entityResult.elements( "field-result" ) ) {
AnnotationDescriptor fieldResultDescriptor = new AnnotationDescriptor( FieldResult.class );
copyStringAttribute( fieldResultDescriptor, fieldResult, "name", true );
copyStringAttribute( fieldResultDescriptor, fieldResult, "column", true );
fieldResults.add( (FieldResult) AnnotationFactory.create( fieldResultDescriptor ) );
}
entityResultDescriptor.setValue(
"fields", fieldResults.toArray( new FieldResult[fieldResults.size()] )
);
entityResults.add( (EntityResult) AnnotationFactory.create( entityResultDescriptor ) );
}
ann.setValue( "entities", entityResults.toArray( new EntityResult[entityResults.size()] ) );
elements = subelement.elements( "column-result" );
List<ColumnResult> columnResults = new ArrayList<ColumnResult>( elements.size() );
for ( Element columnResult : elements ) {
AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor( ColumnResult.class );
copyStringAttribute( columnResultDescriptor, columnResult, "name", true );
columnResults.add( (ColumnResult) AnnotationFactory.create( columnResultDescriptor ) );
}
ann.setValue( "columns", columnResults.toArray( new ColumnResult[columnResults.size()] ) );
//FIXME there is never such a result-class, get rid of it?
String clazzName = subelement.attributeValue( "result-class" );
if ( StringHelper.isNotEmpty( clazzName ) ) {
Class clazz;
try {
clazz = ReflectHelper.classForName(
XMLContext.buildSafeClassName( clazzName, defaults ),
JPAOverridenAnnotationReader.class
);
}
catch ( ClassNotFoundException e ) {
throw new AnnotationException( "Unable to find entity-class: " + clazzName, e );
}
ann.setValue( "resultClass", clazz );
}
copyStringAttribute( ann, subelement, "result-set-mapping", false );
resultsets.add( (SqlResultSetMapping) AnnotationFactory.create( ann ) );