use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLDirectMapping.
/**
* Process a given XMLDirectMapping.
*/
protected void processXMLDirectMapping(DirectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
Field xmlField = (Field) mapping.getField();
XPathFragment frag = xmlField.getXPathFragment();
if (frag.isSelfFragment()) {
// do nothing;
return;
}
// Handle ID
boolean isPk = isFragPrimaryKey(frag, mapping);
String schemaTypeString = null;
if (isPk) {
schemaTypeString = Constants.SCHEMA_PREFIX + Constants.COLON + ID;
} else {
schemaTypeString = getSchemaTypeForDirectMapping(mapping, workingSchema);
}
// Handle enumerations
Class<?> attributeClassification = mapping.getAttributeClassification();
if (attributeClassification != null && Enum.class.isAssignableFrom(attributeClassification)) {
CoreConverter converter = mapping.getConverter();
if (converter != null && converter instanceof EnumTypeConverter) {
processEnumeration(schemaTypeString, frag, mapping, seq, ct, workingSchema, converter);
return;
}
}
if (frag.isAttribute()) {
Attribute attr = buildAttribute(mapping, schemaTypeString);
if (xmlField.isRequired()) {
attr.setUse(Attribute.REQUIRED);
}
ct.getOrderedAttributes().add(attr);
} else {
seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
frag = getTargetXPathFragment(frag);
Element elem = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), seq);
if (elem == null) {
if (frag.getNamespaceURI() != null) {
elem = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, null, schemaTypeString);
} else {
elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
}
if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
elem.setNillable(true);
}
if (xmlField.isRequired()) {
elem.setMinOccurs("1");
}
seq.addElement(elem);
}
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method createGlobalAttribute.
/**
* Create a global attribute. An import is added if necessary. This method
* will typically be called when processing an XPath and a prefixed path
* element is encountered tha requires an attribute ref.
*/
public Attribute createGlobalAttribute(XPathFragment frag, Schema workingSchema, Schema fragSchema, Property prop) {
Attribute gAttribute = new Attribute();
gAttribute.setName(frag.getLocalName());
gAttribute.setType(getQualifiedTypeName(prop, fragSchema));
fragSchema.getTopLevelAttributes().put(gAttribute.getName(), gAttribute);
addImportIfRequired(workingSchema, fragSchema, frag.getNamespaceURI());
return gAttribute;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method processGlobalItem.
private void processGlobalItem(String targetNamespace, String defaultNamespace, String qualifiedName) {
if (rootSchema == null) {
return;
}
String localName = null;
int index = qualifiedName.indexOf(':');
if (index != -1) {
localName = qualifiedName.substring(index + 1, qualifiedName.length());
} else {
localName = qualifiedName;
}
SimpleType simpleType = rootSchema.getTopLevelSimpleTypes().get(localName);
if (simpleType == null) {
ComplexType complexType = rootSchema.getTopLevelComplexTypes().get(localName);
if (complexType == null) {
Element element = rootSchema.getTopLevelElements().get(localName);
if (element == null) {
Attribute attribute = rootSchema.getTopLevelAttributes().get(localName);
if (attribute != null) {
processGlobalAttribute(targetNamespace, defaultNamespace, attribute);
}
} else {
processGlobalElement(targetNamespace, defaultNamespace, element);
}
} else {
processGlobalComplexType(targetNamespace, defaultNamespace, complexType);
}
} else {
processGlobalSimpleType(targetNamespace, defaultNamespace, simpleType);
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method processGlobalAttribute.
private void processGlobalAttribute(String targetNamespace, String defaultNamespace, Attribute attribute) {
if (attribute.getName() != null) {
QName qname = new QName(targetNamespace, attribute.getName());
Attribute processed = processedAttributes.get(qname);
if (processed == null) {
SDOType attributeType = processAttribute(targetNamespace, defaultNamespace, null, attribute, true);
processedAttributes.put(qname, attribute);
if (null != attributeType && !getGeneratedTypes().containsKey(attributeType.getQName())) {
getGeneratedTypes().put(attributeType.getQName(), attributeType);
anonymousTypes.remove(attributeType);
}
}
} else {
processAttribute(targetNamespace, defaultNamespace, null, attribute, true);
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method processAttributes.
private void processAttributes(String targetNamespace, String defaultNamespace, SDOType owningType, java.util.List attributes) {
if (attributes == null) {
return;
}
for (int i = 0; i < attributes.size(); i++) {
Attribute nextAttribute = (Attribute) attributes.get(i);
processAttribute(targetNamespace, defaultNamespace, owningType, nextAttribute, false);
}
}
Aggregations