@Test public void testValidateValidPersistableClasses( ) { assertTrue( validator.validate( PersistableClass1.class.getName( ), classLoader ).isEmpty( ) ); assertTrue( validator.validate( PersistableClass2.class.getName( ), classLoader ).isEmpty( ) ); assertTrue( validator.validate( PersistableClass3.class.getName( ), classLoader ).isEmpty( ) ); }
public List<ValidationMessage> validate( String className, ClassLoader classLoader ) { List<ValidationMessage> result = new ArrayList<>( ); Class< ? > clazz; try { if ( className == null || className.trim( ).isEmpty( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY ) ); return result; } clazz = classLoader.loadClass( className ); Annotation[] annotations = clazz.getAnnotations( ); Optional< Annotation > persistable = Arrays.stream( annotations ) .filter( annotation -> Entity.class.equals( annotation.annotationType( ) ) || Embeddable.class.equals( annotation.annotationType( ) ) || MappedSuperclass.class.equals( annotation.annotationType( ) ) ) .findFirst( ); if ( !persistable.isPresent( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE, className ), className ) ); } } catch ( ClassNotFoundException e ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND, className ), className ) ); } return result; }
PersistableClassValidator { public List<ValidationMessage> validate( String className, ClassLoader classLoader ) { List<ValidationMessage> result = new ArrayList<>( ); Class< ? > clazz; try { if ( className == null || className.trim( ).isEmpty( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY ) ); return result; } clazz = classLoader.loadClass( className ); Annotation[] annotations = clazz.getAnnotations( ); Optional< Annotation > persistable = Arrays.stream( annotations ) .filter( annotation -> Entity.class.equals( annotation.annotationType( ) ) || Embeddable.class.equals( annotation.annotationType( ) ) || MappedSuperclass.class.equals( annotation.annotationType( ) ) ) .findFirst( ); if ( !persistable.isPresent( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE, className ), className ) ); } } catch ( ClassNotFoundException e ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND, className ), className ) ); } return result; } }
PersistableClassValidator { public List<ValidationMessage> validate( String className, ClassLoader classLoader ) { List<ValidationMessage> result = new ArrayList<>( ); Class< ? > clazz; try { if ( className == null || className.trim( ).isEmpty( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY ) ); return result; } clazz = classLoader.loadClass( className ); Annotation[] annotations = clazz.getAnnotations( ); Optional< Annotation > persistable = Arrays.stream( annotations ) .filter( annotation -> Entity.class.equals( annotation.annotationType( ) ) || Embeddable.class.equals( annotation.annotationType( ) ) || MappedSuperclass.class.equals( annotation.annotationType( ) ) ) .findFirst( ); if ( !persistable.isPresent( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE, className ), className ) ); } } catch ( ClassNotFoundException e ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND, className ), className ) ); } return result; } PersistableClassValidator( ); }
PersistableClassValidator { public List<ValidationMessage> validate( String className, ClassLoader classLoader ) { List<ValidationMessage> result = new ArrayList<>( ); Class< ? > clazz; try { if ( className == null || className.trim( ).isEmpty( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY ) ); return result; } clazz = classLoader.loadClass( className ); Annotation[] annotations = clazz.getAnnotations( ); Optional< Annotation > persistable = Arrays.stream( annotations ) .filter( annotation -> Entity.class.equals( annotation.annotationType( ) ) || Embeddable.class.equals( annotation.annotationType( ) ) || MappedSuperclass.class.equals( annotation.annotationType( ) ) ) .findFirst( ); if ( !persistable.isPresent( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE, className ), className ) ); } } catch ( ClassNotFoundException e ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND, className ), className ) ); } return result; } PersistableClassValidator( ); List<ValidationMessage> validate( String className, ClassLoader classLoader ); }
PersistableClassValidator { public List<ValidationMessage> validate( String className, ClassLoader classLoader ) { List<ValidationMessage> result = new ArrayList<>( ); Class< ? > clazz; try { if ( className == null || className.trim( ).isEmpty( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY ) ); return result; } clazz = classLoader.loadClass( className ); Annotation[] annotations = clazz.getAnnotations( ); Optional< Annotation > persistable = Arrays.stream( annotations ) .filter( annotation -> Entity.class.equals( annotation.annotationType( ) ) || Embeddable.class.equals( annotation.annotationType( ) ) || MappedSuperclass.class.equals( annotation.annotationType( ) ) ) .findFirst( ); if ( !persistable.isPresent( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE, className ), className ) ); } } catch ( ClassNotFoundException e ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND, className ), className ) ); } return result; } PersistableClassValidator( ); List<ValidationMessage> validate( String className, ClassLoader classLoader );  }