}
return null;
}
});
XSDSchema ftSchema = null;
try {
ftSchema = Schemas.parse(schemaFile.getAbsolutePath(), locators, resolvers);
} catch (IOException e) {
logger.log(Level.WARNING,
"Unable to parse schema: " + schemaFile.getAbsolutePath(), e);
}
if (ftSchema != null) {
//respect the prefix (xs vs xsd) given by the underlying schema file
if ( ftSchema.getSchemaForSchemaQNamePrefix() != null ) {
schema.setSchemaForSchemaQNamePrefix(ftSchema.getSchemaForSchemaQNamePrefix());
}
//add the contents of this schema to the schema being built
//look up the complex type
List contents = ftSchema.getContents();
//ensure that an element for the feature is present
boolean hasElement = false;
for (Iterator i = contents.iterator(); i.hasNext();) {
XSDSchemaContent content = (XSDSchemaContent) i.next();
content.setElement(null);
//check for import of gml, skip over since we already imported it
if ( content instanceof XSDImport ) {
XSDImport imprt = (XSDImport) content;
if ( gmlNamespace.equals( imprt.getNamespace() ) ) {
i.remove();
}
}
//check for duplicated elements and types
if ( content instanceof XSDElementDeclaration ) {
if ( contains( (XSDNamedComponent) content, schema.getElementDeclarations() ) ) {
i.remove();
}
}
else if ( content instanceof XSDTypeDefinition ) {
if ( contains( (XSDNamedComponent) content, schema.getTypeDefinitions() ) ) {
i.remove();
}
}
// check for element
if ( !hasElement && content instanceof XSDElementDeclaration ) {
XSDElementDeclaration element = (XSDElementDeclaration) content;
if ( name.equals( element.getName() ) &&
featureTypeMeta.getNamespace().getURI().equals( element.getTargetNamespace() ) ) {
hasElement = true;
}
}
}
if ( !hasElement ) {
//need to create an element declaration in the schema
XSDElementDeclaration element = factory.createXSDElementDeclaration();
element.setName( featureTypeMeta.getName() );
element.setTargetNamespace( featureTypeMeta.getNamespace().getURI() );
element.setSubstitutionGroupAffiliation(
schema.resolveElementDeclaration(gmlNamespace, substitutionGroup));
//find the type of the element
List<XSDComplexTypeDefinition> candidates = new ArrayList<XSDComplexTypeDefinition>();
for ( Iterator t = ftSchema.getTypeDefinitions().iterator(); t.hasNext(); ) {
XSDTypeDefinition type = (XSDTypeDefinition) t.next();
if ( type instanceof XSDComplexTypeDefinition ) {
XSDTypeDefinition base = type.getBaseType();
while(base != null ) {
if ( baseType.equals(base.getName())