XmlSchemaComplexType complex = new XmlSchemaComplexType(root);
complex.setName(getSchemaType().getLocalPart());
root.addType(complex);
root.getItems().add(complex);
Type sooperType = getSuperType();
/*
* See Java Virtual Machine specification:
* http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
*/
if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0)
&& !inf.getTypeClass().isInterface()) {
complex.setAbstract(true);
}
XmlSchemaSequence sequence = new XmlSchemaSequence();
/*
* Decide if we're going to extend another type. If we are going to defer, then make sure that we
* extend the type for our superclass.
*/
boolean isExtension = inf.isExtension();
if (isExtension && sooperType != null) {
// if sooperType is null, things are confused.
XmlSchemaComplexContent content = new XmlSchemaComplexContent();
complex.setContentModel(content);
XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
content.setContent(extension);
extension.setBaseTypeName(sooperType.getSchemaType());
extension.setParticle(sequence);
} else {
complex.setParticle(sequence);
}
boolean needXmime = false;
boolean needUtilityTypes = false;
// Write out schema for elements
for (QName name : inf.getElements()) {
if (isExtension) {
PropertyDescriptor pd = inf.getPropertyDescriptorFromMappedName(name);
// assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
if (pd.getReadMethod().getDeclaringClass() != inf.getTypeClass()) {
continue;
}
}
XmlSchemaElement element = new XmlSchemaElement();
element.setName(name.getLocalPart());
sequence.getItems().add(element);
Type type = getType(inf, name);
if (AbstractTypeCreator.
HTTP_CXF_APACHE_ORG_ARRAYS.equals(type.getSchemaType().getNamespaceURI())) {
XmlSchemaUtils.addImportIfNeeded(root, AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS);
}
writeTypeReference(name, element, type, root);
needXmime |= type.usesXmime();
needUtilityTypes |= type.usesUtilityTypes();
}
if (needXmime) {
addXmimeToSchema(root);
}
if (needUtilityTypes) {
AegisContext.addUtilityTypesToSchema(root);
}
/**
* if future proof then add <xsd:any/> element
*/
if (inf.isExtensibleElements()) {
XmlSchemaAny any = new XmlSchemaAny();
any.setMinOccurs(0);
any.setMaxOccurs(Long.MAX_VALUE);
sequence.getItems().add(any);
}
// Write out schema for attributes
for (QName name : inf.getAttributes()) {
XmlSchemaAttribute attribute = new XmlSchemaAttribute();
complex.getAttributes().add(attribute);
attribute.setName(name.getLocalPart());
Type type = getType(inf, name);
attribute.setSchemaTypeName(type.getSchemaType());
String ns = name.getNamespaceURI();
if (!ns.equals(root.getTargetNamespace())) {
XmlSchemaUtils.addImportIfNeeded(root, ns);
}
}