public SchemaBinding resolve(String nsURI, String baseURI, String schemaLocation)
{
boolean trace = log.isTraceEnabled();
// Was the schema binding based on the nsURI
boolean foundByNS = false;
SchemaBinding schema = schemasByUri.get(nsURI);
if(schema != null)
{
if(trace)
log.trace("resolved cached schema, nsURI="+nsURI+", schema: " + schema);
return schema;
}
// Look for a class binding by schemaLocation
Class<?>[] classes = resolveClassFromSchemaLocation(schemaLocation, trace);
if (classes == null)
{
// Next look by namespace
classes = getClassesForURI(nsURI);
if(classes != null)
foundByNS = true;
}
if (classes != null)
{
if( trace )
{
log.trace("found bindingClass, nsURI=" + nsURI +
", baseURI=" + baseURI +
", schemaLocation=" + schemaLocation +
", classes=" + Arrays.asList(classes));
}
schema = JBossXBBuilder.build(classes);
}
else
{
// Parse the schema
InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
if( trace )
{
String msg = (is == null ? "couldn't find" : "found") +
" schema InputSource, nsURI=" + nsURI +
", baseURI=" + baseURI + ", schemaLocation=" +
schemaLocation;
log.trace(msg);
}
if (is != null)
{
if( baseURI == null )
baseURI = this.baseURI;
Boolean processAnnotationsBoolean = schemaParseAnnotationsByUri.get(nsURI);
boolean processAnnotations = (processAnnotationsBoolean == null) ? true : processAnnotationsBoolean.booleanValue();
try
{
schema = XsdBinder.bind(is.getByteStream(), null, baseURI, processAnnotations);
foundByNS = true;
}
catch(RuntimeException e)
{
String msg = "Failed to parse schema for nsURI="+nsURI
+", baseURI="+baseURI
+", schemaLocation="+schemaLocation;
throw new JBossXBRuntimeException(msg, e);
}
}
}
if(schema != null)
{
schema.setSchemaResolver(this);
SchemaBindingInitializer sbi = schemaInitByUri.get(nsURI);
if(sbi != null)
schema = sbi.init(schema);
if(schema != null && nsURI.length() > 0 && cacheResolvedSchemas && foundByNS)