project.addDescriptor((CoreDescriptor)xmlDescriptor);
info.setDescriptor(xmlDescriptor);
}
private void setSchemaContext(Descriptor desc, TypeInfo info) {
XMLSchemaClassPathReference schemaRef = new XMLSchemaClassPathReference();
if (info.getClassNamespace() == null || info.getClassNamespace().equals("")) {
schemaRef.setSchemaContext("/" + info.getSchemaTypeName());
schemaRef.setSchemaContextAsQName(new QName(info.getSchemaTypeName()));
} else {
String prefix = desc.getNonNullNamespaceResolver().resolveNamespaceURI(info.getClassNamespace());
if (prefix != null && !prefix.equals("")) {
schemaRef.setSchemaContext("/" + prefix + ":" + info.getSchemaTypeName());
schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName(), prefix));
} else {
String generatedPrefix =getPrefixForNamespace(info.getClassNamespace(), desc.getNonNullNamespaceResolver(), false);
schemaRef.setSchemaContext("/" + getQualifiedString(generatedPrefix, info.getSchemaTypeName()));
if(generatedPrefix == null || generatedPrefix.equals(Constants.EMPTY_STRING)){
schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName()));
}else{
schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName(), generatedPrefix));
}
}
}
// the default type is complex; need to check for simple type case
if (info.isEnumerationType() || (info.getPropertyNames().size() == 1 && helper.isAnnotationPresent(info.getProperties().get(info.getPropertyNames().get(0)).getElement(), XmlValue.class))) {
schemaRef.setType(XMLSchemaReference.SIMPLE_TYPE);
}
desc.setSchemaReference(schemaRef);
}