private void includeExtXSD(Type dataType)
{
//now we know there is a type for which the xsd must come from outside
//create a schema for the namespace of this type and add an include in it for
//the xsd that is defined externally
XSDSchema xmlSchema = getXmlSchema(dataType);
//ideally there could be more than one external schema defintions for a namespace
//and hence schemalocations will be a list of locations
//List schemaLocations = (List)schemaLocationMap.get(dataType.getURI());
//since as per the specs the input to XSDHelper is a map of <String, String> allowing
//only one schemalocation for a namespace. So for now this single location will be
//picked up and put into a list
List schemaLocations = new Vector();
if ( schemaLocationMap.get(dataType.getURI()) != null )
{
schemaLocations.add(schemaLocationMap.get(dataType.getURI()));
}
if ( schemaLocations.size() <= 0 )
{
schemaLocations.add(DEFAULT_SCHEMA_LOCATION);
}
Object schemaContent = null;
Iterator includesIterator = xmlSchema.getContents().iterator();
Iterator schemaLocIterator = schemaLocations.iterator();
String aSchemaLocation = null;
boolean includeExists = false;
//include all external schema locations
while ( schemaLocIterator.hasNext() )
{
aSchemaLocation = (String)schemaLocIterator.next();
while ( includesIterator.hasNext() )
{
schemaContent = includesIterator.next();
if ( schemaContent instanceof XSDInclude )
{
if ( !includeExists && aSchemaLocation.equals(
((XSDInclude)schemaContent).getSchemaLocation()
))
{
includeExists = true;
}
}
}
if ( !includeExists )
{
XSDInclude includeElement = xsdFactory.createXSDInclude();
includeElement.setSchemaLocation(aSchemaLocation);
xmlSchema.getContents().add(0, includeElement);
}
}
}