* @param property the Property used to build the Attribute
* @param schema the schema currently being generated
* @return
*/
private Attribute buildAttribute(Property property, Schema schema) {
Attribute attribute = new Attribute();
QName attributeName = property.getSchemaName();
attribute.setName(attributeName.getLocalPart());
if (property.isRequired()) {
attribute.setUse(Attribute.REQUIRED);
}
String fixedValue = property.getFixedValue();
if (fixedValue != null){
attribute.setFixed(fixedValue);
}
// Check to see if it's a collection
TypeInfo info = (TypeInfo) typeInfo.get(property.getActualType().getQualifiedName());
String typeName = null;
if (property.isXmlId()) {
typeName = XMLConstants.SCHEMA_PREFIX + COLON + ID;
} else if (property.isXmlIdRef()) {
typeName = XMLConstants.SCHEMA_PREFIX + COLON + IDREF;
} else if (info != null && !info.isComplexType()) {
typeName = info.getSimpleType().getName();
} else {
typeName = getTypeName(property, property.getActualType(), schema);
}
if (isCollectionType(property)) {
// assume XmlList for an attribute collection
SimpleType localType = new SimpleType();
org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
list.setItemType(typeName);
localType.setList(list);
attribute.setSimpleType(localType);
} else {
// may need to qualify the type
if (typeName != null && !typeName.contains(COLON)) {
if (info.getSchema() == schema) {
String prefix = getPrefixForNamespace(schema.getTargetNamespace(), schema.getNamespaceResolver());
if (prefix != null) {
typeName = prefix + COLON + typeName;
}
}
}
attribute.setType(typeName);
}
return attribute;
}