final SchemaUnmarshallerState state)
throws XMLException {
super(schemaContext);
if (schema == null) {
String err = SchemaNames.REDEFINE + " must be used with an existing parent XML Schema.";
throw new SchemaException(err);
}
setURIResolver(uriResolver);
URILocation uri = null;
//-- Get schemaLocation
String schemaLocation = atts.getValue(SchemaNames.SCHEMALOCATION_ATTR);
_schema = schema;
if (schemaLocation == null) {
//-- <redefine/> or <redefine> <annotation>(*) </redefine>
_redefineSchema = new RedefineSchema(schema);
_schema.addRedefineSchema(_redefineSchema);
return;
}
if (schemaLocation.indexOf("\\") != -1) {
String err = "'" + schemaLocation +
"' is not a valid URI as defined by IETF RFC 2396.";
err += "The URI mustn't contain '\\'.";
error(err);
}
try {
String documentBase = locator.getSystemId();
if (documentBase != null) {
if (!documentBase.endsWith("/"))
documentBase = documentBase.substring(0, documentBase.lastIndexOf('/') +1 );
}
uri = getURIResolver().resolve(schemaLocation, documentBase);
if (uri != null) {
schemaLocation = uri.getAbsoluteURI();
}
}
catch (URIException urix) {
throw new XMLException(urix);
}
//-- Schema object to hold import schema
boolean addSchema = false;
_redefineSchema = schema.getRedefineSchema(schemaLocation);
Schema importedSchema = null;
boolean alreadyLoaded = false;
//-- The schema is not yet loaded
if (_redefineSchema == null) {
if (uri instanceof SchemaLocation) {
importedSchema = ((SchemaLocation)uri).getSchema();
//-- set the main schema in order to handle
//-- redefinition at runtime
// importedSchema.addMainSchema(schema);
_redefineSchema = new RedefineSchema(schema, importedSchema);
schema.addRedefineSchema(_redefineSchema);
alreadyLoaded = true;
}
else {
importedSchema = new Schema();
addSchema = true;
}
}
else {
//-- check schema location, if different, allow merge
String tmpLocation = _redefineSchema.getOriginalSchema().getSchemaLocation();
alreadyLoaded = schemaLocation.equals(tmpLocation);
}
state.markAsProcessed(schemaLocation, importedSchema);
if (alreadyLoaded) return;
//-- Parser Schema
Parser parser = null;
try {
parser = getSchemaContext().getParser();
}
catch(RuntimeException rte) {}
if (parser == null) {
throw new SchemaException("Error failed to create parser for import");
}
//-- Create Schema object and setup unmarshaller
SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(getSchemaContext(), state);
schemaUnmarshaller.setURIResolver(getURIResolver());
schemaUnmarshaller.setSchema(importedSchema);
Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
parser.setDocumentHandler(handler);
parser.setErrorHandler(handler);
try {
InputSource source = new InputSource(uri.getReader());
source.setSystemId(uri.getAbsoluteURI());
parser.parse(source);
}
catch(java.io.IOException ioe) {
throw new SchemaException("Error reading import file '"+schemaLocation+"': "+ ioe);
}
catch(org.xml.sax.SAXException sx) {
throw new SchemaException(sx);
}
//-- namespace checking
String namespace = importedSchema.getTargetNamespace();
if ( namespace != null ) {