* @param schema the schema currently being built
* @param typeInfo the TypeInfo that owns the given Property
* @return
*/
private Element buildElement(Property property, boolean isAll, Schema schema, TypeInfo typeInfo) {
Element element = new Element();
// Set minOccurs based on the 'required' flag
element.setMinOccurs(property.isRequired() ? Occurs.ONE : Occurs.ZERO);
// handle nillable
if (property.shouldSetNillable()) {
element.setNillable(true);
}
// handle defaultValue
if (property.isSetDefaultValue()) {
element.setDefaultValue(property.getDefaultValue());
}
// handle mime-type
if (property.getMimeType() != null) {
element.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, property.getMimeType());
}
QName elementName = property.getSchemaName();
String elementNamespace = elementName.getNamespaceURI();
String lookupNamespace = schema.getTargetNamespace();
if (lookupNamespace == null) {
lookupNamespace = EMPTY_STRING;
}
NamespaceInfo namespaceInfo = getNamespaceInfoForNamespace(lookupNamespace);
boolean isElementFormQualified = false;
if (namespaceInfo != null) {
isElementFormQualified = namespaceInfo.isElementFormQualified();
}
// handle element reference
boolean addRef = shouldAddRefAndSetForm(element, elementNamespace, lookupNamespace, isElementFormQualified, true);
if(addRef){
schema = this.getSchemaForNamespace(elementNamespace);
}
JavaClass javaType = property.getActualType();
element.setName(elementName.getLocalPart());
String typeName = getTypeNameForComponent(property, schema, javaType, element, true);
if (property.getGenericType() != null) {
if (property.isXmlList()) {
SimpleType localSimpleType = new SimpleType();
org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
list.setItemType(typeName);
localSimpleType.setList(list);
element.setSimpleType(localSimpleType);
} else {
element.setMaxOccurs(Occurs.UNBOUNDED);
element.setType(typeName);
}
// handle map property
} else if (property.isMap()) {
addMapToSchema(property, element, schema, typeInfo);
} else {
element.setType(typeName);
}
return element;
}