BeanTypeInfo info = getTypeInfo();
Element complex = new Element("complexType", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
root.addContent(complex);
Type sooperType = getSuperType();
/*
* See Java Virtual Machine specification:
* http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
*/
if (((info.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0) &&
!info.getTypeClass().isInterface())
{
complex.setAttribute(new Attribute("abstract", "true"));
}
if (info.isExtension() && sooperType != null)
{
Element complexContent = new Element("complexContent", SoapConstants.XSD_PREFIX,
SoapConstants.XSD);
complex.addContent(complexContent);
complex = complexContent;
}
/*
* 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 = info.isExtension();
Element dummy = complex;
if (isExtension && sooperType != null)
{
Element extension = new Element("extension", SoapConstants.XSD_PREFIX,
SoapConstants.XSD);
complex.addContent(extension);
QName baseType = sooperType.getSchemaType();
extension.setAttribute(new Attribute("base", getNameWithPrefix2(root, baseType
.getNamespaceURI(), baseType.getLocalPart())));
dummy = extension;
}
Element seq = null;
// Write out schema for elements
for (Iterator itr = info.getElements(); itr.hasNext();)
{
QName name = (QName) itr.next();
if (isExtension)
{
PropertyDescriptor pd = info.getPropertyDescriptorFromMappedName(name);
assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
if (pd.getReadMethod().getDeclaringClass() != info.getTypeClass())
{
continue;
}
}
if (seq == null)
{
seq = new Element("sequence", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
dummy.addContent(seq);
}
Element element = new Element("element", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
seq.addContent(element);
Type type = getType(info, name);
String nameNS = name.getNamespaceURI();
String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());
String prefix = NamespaceHelper.getUniquePrefix((Element) root.getParent(), type
.getSchemaType().getNamespaceURI());
writeTypeReference(name, nameWithPrefix, element, type, prefix);
}
/**
* if future proof then add <xsd:any/> element
*/
if (info.isExtensibleElements())
{
if (seq == null)
{
seq = new Element("sequence", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
dummy.addContent(seq);
}
seq.addContent(createAnyElement());
}
// Write out schema for attributes
for (Iterator itr = info.getAttributes(); itr.hasNext();)
{
QName name = (QName) itr.next();
Element element = new Element("attribute", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
dummy.addContent(element);
Type type = getType(info, name);
String nameNS = name.getNamespaceURI();
String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());
String prefix = NamespaceHelper.getUniquePrefix((Element) root.getParent(), type
.getSchemaType().getNamespaceURI());
element.setAttribute(new Attribute("name", nameWithPrefix));
element.setAttribute(new Attribute("type", prefix + ':'
+ type.getSchemaType().getLocalPart()));
}
/**
* If extensible attributes then add <xsd:anyAttribute/>
*/