xsdComplexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
xsdComplexType.setBaseTypeDefinition(schema.resolveComplexTypeDefinition(gmlNamespace,
baseType));
XSDModelGroup group = factory.createXSDModelGroup();
group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
for (PropertyDescriptor pd : complexType.getDescriptors()) {
if (pd instanceof AttributeDescriptor) {
AttributeDescriptor attribute = (AttributeDescriptor) pd;
if ( filterAttributeType( attribute ) ) {
continue;
}
XSDElementDeclaration element = factory.createXSDElementDeclaration();
element.setName(attribute.getLocalName());
element.setNillable(attribute.isNillable());
Name typeName = attribute.getType().getName();
// skip if it's XS.AnyType. It's not added to XS.Profile, because
// a lot of types extend XS.AnyType causing it to be the returned
// binding.. I could make it so that it checks against all profiles
// but would that slow things down? At the moment, it returns the
// first matching one, so it doesn't go through all profiles.
if (!(typeName.getLocalPart().equals(XS.ANYTYPE.getLocalPart()) && typeName
.getNamespaceURI().equals(XS.NAMESPACE))) {
if (attribute.getType() instanceof ComplexType) {
// If non-simple complex property not in schema, recurse.
// Note that abstract types will of course not be resolved; these must be
// configured at global level, so they can be found by the
// encoder.
if (schema.resolveTypeDefinition(typeName.getNamespaceURI(), typeName
.getLocalPart()) == null) {
buildComplexSchemaContent((ComplexType) attribute.getType(), schema,
factory);
}
} else {
Class binding = attribute.getType().getBinding();
typeName = findTypeName(binding);
if (typeName == null) {
throw new NullPointerException("Could not find a type for property: "
+ attribute.getName() + " of type: " + binding.getName());
}
}
}
XSDTypeDefinition type = schema.resolveTypeDefinition(typeName.getNamespaceURI(),
typeName.getLocalPart());
element.setTypeDefinition(type);
XSDParticle particle = factory.createXSDParticle();
particle.setMinOccurs(attribute.getMinOccurs());
particle.setMaxOccurs(attribute.getMaxOccurs());
particle.setContent(element);
group.getContents().add(particle);
}
}
XSDParticle particle = factory.createXSDParticle();
particle.setContent(group);