QName qname = entry.getKey();
Type type = entry.getValue();
if (type instanceof Class) {
Class tClass = (Class) type;
String nsKey = qname.getNamespaceURI();
Schema schema = schemaForNamespace.get(nsKey);
QName typeAsQName = (QName) XMLConversionManager.getDefaultJavaTypes().get(tClass);
if (typeAsQName == null) {
// not a built in type - need to get the type via schema reference
XMLDescriptor desc = getDescriptorByClass(tClass, descriptorsToProcess);
if (desc == null) {
// at this point we can't determine the element type, so don't add anything
continue;
}
// if the schema is null generate a new one and create an import
if (schema == null) {
schema = buildNewSchema(nsKey, new NamespaceResolver(), schemaForNamespace.size(), properties);
schemaForNamespace.put(nsKey, schema);
typeAsQName = desc.getSchemaReference().getSchemaContextAsQName();
Schema schemaForUri = schemaForNamespace.get(typeAsQName.getNamespaceURI());
if (!importExists(schema, schemaForUri.getTargetNamespace())) {
Import newImport = new Import();
newImport.setNamespace(schemaForUri.getTargetNamespace());
newImport.setSchemaLocation(schemaForUri.getName());
schema.getImports().add(newImport);
}
} else {
typeAsQName = desc.getSchemaReference().getSchemaContextAsQName(schema.getNamespaceResolver());
}