inputSource = loc.getImportInputSource(
schema.getDocumentBaseURI(), schemaRef.getSchemaLocationURI());
if (inputSource == null)
{
throw new WSDLException(WSDLException.OTHER_ERROR,
"Unable to locate with a locator "
+ "the schema referenced at '"
+ schemaRef.getSchemaLocationURI()
+ "' relative to document base '"
+ schema.getDocumentBaseURI() + "'");
}
location = loc.getLatestImportURI();
//if a schema from this location has been read previously, use it.
referencedSchema = (Schema) this.allSchemas.get(location);
}
else
{
// We don't have a wsdl locator, so try to retrieve the schema by its URL
String contextURI = schema.getDocumentBaseURI();
URL contextURL = (contextURI != null) ? StringUtils.getURL(null, contextURI) : null;
URL url = StringUtils.getURL(contextURL, schemaRef.getSchemaLocationURI());
location = url.toExternalForm();
//if a schema from this location has been retrieved previously, use it.
referencedSchema = (Schema) this.allSchemas.get(location);
if (referencedSchema == null)
{
// We haven't read this schema in before so do it now
inputStream = StringUtils.getContentAsInputStream(url);
if (inputStream != null)
{
inputSource = new InputSource(inputStream);
}
if (inputSource == null)
{
throw new WSDLException(WSDLException.OTHER_ERROR,
"Unable to locate with a url "
+ "the document referenced at '"
+ schemaRef.getSchemaLocationURI()
+ "'"
+ (contextURI == null ? "." : ", relative to '"
+ contextURI + "'."));
}
}
} //end if loc
// If we have not previously read the schema, get its DOM element now.
if (referencedSchema == null)
{
inputSource.setSystemId(location);
Document doc = getDocument(inputSource, location);
if (inputStream != null)
{
inputStream.close();
}
Element documentElement = doc.getDocumentElement();
// If it's a schema doc process it, otherwise the schema reference remains null
QName docElementQName = QNameUtils.newQName(documentElement);
if (SchemaConstants.XSD_QNAME_LIST.contains(docElementQName))
{
//We now need to call parseSchema recursively to parse the referenced
//schema. The document base URI of the referenced schema will be set to
//the document base URI of the current schema plus the schemaLocation in
//the schemaRef. We cannot explicitly pass in a new document base URI
//to the schema deserializer, so instead we will create a dummy
//Definition and set its documentBaseURI to the new document base URI.
//We can leave the other definition fields empty because we know
//that the SchemaDeserializer.unmarshall method uses the definition
//parameter only to get its documentBaseURI. If the unmarshall method
//implementation changes (ie: its use of definition changes) we may need
//to rethink this approach.
WSDLFactory factory = getWSDLFactory();
Definition dummyDef = factory.newDefinition();
dummyDef.setDocumentBaseURI(location);
//By this point, we know we have a SchemaDeserializer registered
//so we can safely cast the ExtensibilityElement to a Schema.
referencedSchema = (Schema) parseSchema( parentType,
documentElement,
dummyDef,
extReg);
}
} //end if referencedSchema
schemaRef.setReferencedSchema(referencedSchema);
}
catch (WSDLException e)
{
throw e;
}
catch (RuntimeException e)
{
throw e;
}
catch (Exception e)
{
throw new WSDLException(WSDLException.OTHER_ERROR,
"An error occurred trying to resolve schema referenced at '"
+ schemaRef.getSchemaLocationURI()
+ "'"
+ (schema.getDocumentBaseURI() == null ? "." : ", relative to '"
+ schema.getDocumentBaseURI() + "'."),