}
};
//add a location resolver which checks the schema source directory
XSDSchemaLocationResolver locationResolver = new XSDSchemaLocationResolver() {
public String resolveSchemaLocation(
XSDSchema schema, String namespaceURI, String schemaLocation
) {
if ( schemaLocation == null ) {
getLog().warn("Null location for " + namespaceURI );
return null;
}
//check location directlry
File file = new File( schemaLocation );
if ( file.exists() ) {
getLog().debug( "Resolving " + schemaLocation + " to " + schemaLocation );
return schemaLocation;
}
String fileName = new File( schemaLocation ).getName();
//check under teh schema source directory
file = new File( schemaSourceDirectory, fileName );
if ( file.exists() ) {
getLog().debug( "Resolving " + schemaLocation + " to " + file.getAbsolutePath() );
return file.getAbsolutePath();
}
//check hte lookup directories
if ( schemaLookupDirectories != null ) {
for ( int i = 0; i < schemaLookupDirectories.length; i++ ) {
File schemaLookupDirectory = schemaLookupDirectories[ i ];
file = new File( schemaLookupDirectory, fileName );
if ( file.exists() ) {
getLog().debug( "Resolving " + schemaLocation + " to " + file.getAbsolutePath() );
return file.getAbsolutePath();
}
}
}
getLog().warn( "Could not resolve location for: " + fileName );
return null;
}
};
//parse the schema
XSDSchema xsdSchema = null;
try {
getLog().info("Parsing schema: " + schemaLocation);
if (relativeSchemaReference) {
xsdSchema = Schemas.parse(schemaLocation.getAbsolutePath(), Collections.EMPTY_LIST,
Collections.singletonList(new XSDSchemaLocationResolver() {
public String resolveSchemaLocation(XSDSchema xsdSchema,
String namespaceURI, String schemaLocationURI) {
try {
URI contextUri = new URI(xsdSchema.getSchemaLocation());
if (contextUri.isOpaque()) {