From: <jde...@sv...> - 2007-07-30 16:48:21
|
Author: jdeolive Date: 2007-07-30 09:46:48 -0700 (Mon, 30 Jul 2007) New Revision: 26370 Modified: geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/AbstractGenerator.java geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/BindingGeneratorMojo.java geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/ConfigurationGenerator.java geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaLocationResolverGenerator.java Log: checking schema lookup directories when copying over schema files Modified: geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/AbstractGenerator.java =================================================================== --- geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/AbstractGenerator.java 2007-07-30 16:46:43 UTC (rev 26369) +++ geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/AbstractGenerator.java 2007-07-30 16:46:48 UTC (rev 26370) @@ -58,6 +58,11 @@ boolean overwriting = false; /** + * lookup directories for schemas + */ + File[] schemaLookupDirectories; + + /** * Sets the base package for generated classes. * * @param packageBase Dot seperate package name, or <code>null</code> for @@ -99,6 +104,15 @@ this.overwriting = overwriting; } + /** + * Sets the directories to use when attempting to locate a schema via a + * relative reference. + * + * @param schemaLookupDirectories An array of directories. + */ + public void setSchemaLookupDirectories(File[] schemaLookupDirectories) { + this.schemaLookupDirectories = schemaLookupDirectories; + } /** * Writes out a string to a file. @@ -171,6 +185,32 @@ out.close(); in.close(); } + + /** + * Attempts to locate a schema file by name by iterating through + * {@link #schemaLookupDirectories}. + * + * @param path The path of the file. + * + */ + protected File findSchemaFile( String path ) throws IOException { + File file = new File( path ); + if ( file.isAbsolute() ) { + return file; + } + + if ( schemaLookupDirectories != null ) { + for ( int i = 0; i < schemaLookupDirectories.length; i++ ) { + File dir = schemaLookupDirectories[i]; + file = new File( dir, path ); + if ( file.exists() ) { + return file; + } + } + } + + return null; + } /** * Convenience method for generating the output location of generated files based on Modified: geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/BindingGeneratorMojo.java =================================================================== --- geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/BindingGeneratorMojo.java 2007-07-30 16:46:43 UTC (rev 26369) +++ geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/BindingGeneratorMojo.java 2007-07-30 16:46:48 UTC (rev 26370) @@ -194,7 +194,7 @@ slrg.setLocation( outputDirectory.getAbsolutePath() ); slrg.setOverwriting( overwriteExistingFiles ); slrg.setPackageBase( destinationPackage ); - + slrg.setSchemaLookupDirectories(schemaLookupDirectories); slrg.generate( xsdSchema ); } @@ -205,6 +205,7 @@ cg.setLocation( outputDirectory.getAbsolutePath() ); cg.setOverwriting( overwriteExistingFiles ); cg.setPackageBase( destinationPackage ); + cg.setSchemaLookupDirectories(schemaLookupDirectories); cg.generate( xsdSchema ); } } Modified: geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/ConfigurationGenerator.java =================================================================== --- geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/ConfigurationGenerator.java 2007-07-30 16:46:43 UTC (rev 26369) +++ geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/ConfigurationGenerator.java 2007-07-30 16:46:48 UTC (rev 26370) @@ -28,21 +28,39 @@ //copy over all included schemas ArrayList includes = new ArrayList(); - try { - includes.add(new File(new URI(schema.getSchemaLocation()))); + + File file = null; + try { + file = findSchemaFile( schema.getSchemaLocation() ); } - catch (URISyntaxException e) { - logger.log( Level.SEVERE, "Error generating resolver", e ); + catch (IOException e) { + logger.log(Level.SEVERE, "", e ); } + + if ( file != null ) { + includes.add( file ); + } + else { + logger.log( Level.SEVERE, "Could not find: " + schema.getSchemaLocation() + " to copy." ); + } + for (Iterator i = Schemas.getIncludes(schema).iterator(); i.hasNext();) { XSDInclude include = (XSDInclude) i.next(); - try { - includes.add(new File(new URI(include.getSchemaLocation()))); - } - catch (URISyntaxException e) { - logger.log( Level.SEVERE, "Error generating resolver", e ); - } + file = null; + try { + file = findSchemaFile( include.getSchemaLocation() ); + } + catch (IOException e) { + logger.log(Level.SEVERE, "", e ); + } + + if ( file != null ) { + includes.add( file ); + } + else { + logger.log( Level.SEVERE, "Could not find: " + include.getSchemaLocation() + " to copy." ); + } } for (Iterator i = includes.iterator(); i.hasNext();) { Modified: geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaLocationResolverGenerator.java =================================================================== --- geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaLocationResolverGenerator.java 2007-07-30 16:46:43 UTC (rev 26369) +++ geotools/branches/2.4.x/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaLocationResolverGenerator.java 2007-07-30 16:46:48 UTC (rev 26370) @@ -47,27 +47,48 @@ ArrayList includes = new ArrayList(); ArrayList namespaces = new ArrayList(); + File file = null; try { - includes.add(new File(new URI(schema.getSchemaLocation()))); - } - catch (URISyntaxException e1) { - throw new RuntimeException ( e1 ); - } - namespaces.add(schema.getTargetNamespace()); - + file = findSchemaFile( schema.getSchemaLocation() ); + } + catch( Exception e ) { + logger.log( Level.SEVERE, "", e ); + } + + if ( file != null ) { + includes.add(file); + namespaces.add(schema.getTargetNamespace()); + } + else { + logger.log( Level.SEVERE, "Could not find: " + schema.getSchemaLocation() + " to copy." ); + } + List included = Schemas.getIncludes(schema); for (Iterator i = included.iterator(); i.hasNext();) { XSDInclude include = (XSDInclude) i.next(); + file = null; try { - includes.add(new File(new URI(include.getSchemaLocation()))); - } - catch (URISyntaxException e) { - throw new RuntimeException( e ); + file = findSchemaFile( include.getSchemaLocation() ); + } + catch( Exception e ) { + logger.log( Level.SEVERE, "", e ); + } + + if ( file != null ) { + includes.add(file); + if( include.getSchema() != null ) { + namespaces.add(include.getSchema().getTargetNamespace()); + } + else { + namespaces.add( schema.getTargetNamespace() ); + } } - - namespaces.add(include.getSchema().getTargetNamespace()); + else { + logger.log( Level.SEVERE, "Could not find: " + include.getSchemaLocation() + " to copy." ); + } + } try { |