*/
private void addMapToSchema(Property property, Element element, Schema schema, TypeInfo typeInfo) {
ComplexType entryComplexType = new ComplexType();
Sequence entrySequence = new Sequence();
Element keyElement = new Element();
keyElement.setName(Property.DEFAULT_KEY_NAME);
keyElement.setMinOccurs(Occurs.ZERO);
JavaClass keyType = property.getKeyType();
JavaClass valueType = property.getValueType();
if (keyType == null) {
keyType = helper.getJavaClass(Object.class);
}
if (valueType == null) {
valueType = helper.getJavaClass(Object.class);
}
String typeName;
QName keySchemaType = getSchemaTypeFor(keyType);
if (keySchemaType != null) {
TypeInfo targetInfo = this.typeInfo.get(keyType.getQualifiedName());
if (targetInfo != null) {
Schema keyElementSchema = this.getSchemaForNamespace(keySchemaType.getNamespaceURI());
//add an import here
addImportIfRequired(schema, keyElementSchema, keySchemaType.getNamespaceURI());
}
String prefix;
if (keySchemaType.getNamespaceURI().equals(XMLConstants.SCHEMA_URL)) {
prefix = XMLConstants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, keySchemaType.getNamespaceURI());
}
if (prefix != null && !prefix.equals(EMPTY_STRING)) {
typeName = prefix + COLON + keySchemaType.getLocalPart();
} else {
typeName = keySchemaType.getLocalPart();
}
keyElement.setType(typeName);
}
entrySequence.addElement(keyElement);
Element valueElement = new Element();
valueElement.setName(Property.DEFAULT_VALUE_NAME);
valueElement.setMinOccurs(Occurs.ZERO);
QName valueSchemaType = getSchemaTypeFor(valueType);
if (valueSchemaType != null) {
TypeInfo targetInfo = this.typeInfo.get(valueType.getQualifiedName());
if (targetInfo != null) {
Schema valueElementSchema = this.getSchemaForNamespace(valueSchemaType.getNamespaceURI());
//add an import here
addImportIfRequired(schema, valueElementSchema, valueSchemaType.getNamespaceURI());
}
String prefix;
if (valueSchemaType.getNamespaceURI().equals(XMLConstants.SCHEMA_URL)) {
prefix = XMLConstants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, valueSchemaType.getNamespaceURI());
}
if (prefix != null && !prefix.equals(EMPTY_STRING)) {
typeName = prefix + COLON + valueSchemaType.getLocalPart();
} else {
typeName = valueSchemaType.getLocalPart();
}
valueElement.setType(typeName);
}
entrySequence.addElement(valueElement);
entryComplexType.setSequence(entrySequence);
JavaClass descriptorClass = helper.getJavaClass(typeInfo.getDescriptor().getJavaClassName());
JavaClass mapValueClass = helper.getJavaClass(MapValue.class);
if (mapValueClass.isAssignableFrom(descriptorClass)) {
element.setComplexType(entryComplexType);
element.setMaxOccurs(Occurs.UNBOUNDED);
} else {
ComplexType complexType = new ComplexType();
Sequence sequence = new Sequence();
complexType.setSequence(sequence);
Element entryElement = new Element();
entryElement.setName(ENTRY);
entryElement.setMinOccurs(Occurs.ZERO);
entryElement.setMaxOccurs(Occurs.UNBOUNDED);
sequence.addElement(entryElement);
entryElement.setComplexType(entryComplexType);
element.setComplexType(complexType);
}
}