public static void validateSchemasInPluginConfiguration ( final List < TransformSchema > configuredTransformSchemas ) throws MojoExecutionException { final List < String > uris = new ArrayList < String > ( ) ; final List < String > prefixes = new ArrayList < String > ( ) ; final List < String > fileNames = new ArrayList < String > ( ) ; for ( int i = 0 ; i < configuredTransformSchemas . size ( ) ; i ++ ) { final TransformSchema current = configuredTransformSchemas . get ( i ) ; final String currentURI = current . getUri ( ) ; final String currentPrefix = current . getToPrefix ( ) ; final String currentFile = current . getToFile ( ) ; // We cannot work with a null or empty uri if ( StringUtils . isEmpty ( currentURI ) ) { throw new MojoExecutionException ( MISCONFIG + "Null or empty property 'uri' found in " + "plugin configuration for schema element at index [" + i + "]: " + current ) ; } // No point in having *only* a namespace. if ( StringUtils . isEmpty ( currentPrefix ) && StringUtils . isEmpty ( currentFile ) ) { throw new MojoExecutionException ( MISCONFIG + "Null or empty properties 'prefix' " + "and 'file' found within plugin configuration for schema element at index [" + i + "]: " + current ) ; } // Validate that all given uris are unique. if ( uris . contains ( currentURI ) ) { throw new MojoExecutionException ( getDuplicationErrorMessage ( "uri" , currentURI , uris . indexOf ( currentURI ) , i ) ) ; } uris . add ( currentURI ) ; // Validate that all given prefixes are unique. if ( prefixes . contains ( currentPrefix ) && ! ( currentPrefix == null ) ) { throw new MojoExecutionException ( getDuplicationErrorMessage ( "prefix" , currentPrefix , prefixes . indexOf ( currentPrefix ) , i ) ) ; } prefixes . add ( currentPrefix ) ; // Validate that all given files are unique. if ( fileNames . contains ( currentFile ) ) { throw new MojoExecutionException ( getDuplicationErrorMessage ( "file" , currentFile , fileNames . indexOf ( currentFile ) , i ) ) ; } fileNames . add ( currentFile ) ; } }
Validates that the list of Schemas provided within the configuration all contain unique values . Should a MojoExecutionException be thrown it contains informative text about the exact nature of the configuration problem - we should simplify for all plugin users .