} else {
// get the schema to add the complex type
if (schemaMap.get(this.namespace) == null){
// create a new namespace for this schema
schemaMap.put(this.namespace, new XmlSchema(this.namespace));
}
XmlSchema xmlSchema = (XmlSchema) schemaMap.get(this.namespace);
// we have to generate a complex type for this
this.xmlType = new XmlTypeImpl(new QName(this.namespace,this.name));
this.xmlType.setSimpleType(false);
// set the parent type for this type
if (this.parentType != null){
Type parentType = this.parentType;
if (!parentType.isSchemaGenerated()){
parentType.generateSchema(configurator,schemaMap);
}
this.xmlType.setParentType(parentType.getXmlType());
// import the complex type namespace if needed.
if (!xmlSchema.containsNamespace(this.xmlType.getParentType().getQname().getNamespaceURI())){
// if the element namespace does not exists we have to add it
if (!this.xmlType.getParentType().getQname().getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
XmlImport xmlImport = new XmlImport(this.xmlType.getParentType().getQname().getNamespaceURI());
xmlSchema.addImport(xmlImport);
}
xmlSchema.addNamespace(this.xmlType.getParentType().getQname().getNamespaceURI());
}
}
// add elements of the elementFields
ElementField elementField;
for (Iterator iter = this.elementFields.iterator();iter.hasNext();){
elementField = (ElementField) iter.next();
if (!elementField.isSchemaGenerated()){
// if it is not already processed process it.
elementField.generateSchema(configurator,schemaMap);
}
this.xmlType.addElement(elementField.getElement());
// we have to set the namespaces of these element complex types properly
QName elementTypeQName = elementField.getElement().getType().getQname();
if (!xmlSchema.containsNamespace(elementTypeQName.getNamespaceURI())){
// if the element namespace does not exists we have to add it
if (!elementTypeQName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
XmlImport xmlImport = new XmlImport(elementTypeQName.getNamespaceURI());
xmlSchema.addImport(xmlImport);
}
xmlSchema.addNamespace(elementTypeQName.getNamespaceURI());
}
}
//add attribute fields
AttributeField attributeField;
for (Iterator iter = this.attributeFields.iterator(); iter.hasNext();){
attributeField = (AttributeField) iter.next();
if (!attributeField.isSchemaGenerated()){
// if it is not already processed process it.
attributeField.generateSchema(configurator,schemaMap);
}
this.xmlType.addAttribute(attributeField.getAttribute());
// we have to set the namespaces of these element complex types properly
QName attributeTypeQName = attributeField.getAttribute().getType().getQname();
if (!xmlSchema.containsNamespace(attributeTypeQName.getNamespaceURI())){
// if the element namespace does not exists we have to add it
if (!attributeTypeQName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
XmlImport xmlImport = new XmlImport(attributeTypeQName.getNamespaceURI());
xmlSchema.addImport(xmlImport);
}
xmlSchema.addNamespace(attributeTypeQName.getNamespaceURI());
}
}
// finally add this complex type to schema map
xmlSchema.addComplexType(this.xmlType);
}
}