use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLBinaryDataMapping.
/**
* Process a given XMLBinaryDataMapping.
*/
protected void processXMLBinaryDataMapping(BinaryDataMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
Field xmlField = (Field) mapping.getField();
XPathFragment frag = xmlField.getXPathFragment();
String schemaTypeString;
if (mapping.isSwaRef()) {
schemaTypeString = getSchemaTypeString(Constants.SWA_REF_QNAME, workingSchema);
Import newImport = new Import();
newImport.setNamespace(Constants.REF_URL);
newImport.setSchemaLocation(SWAREF_LOCATION);
workingSchema.getImports().add(newImport);
} else {
schemaTypeString = getSchemaTypeString(Constants.BASE_64_BINARY_QNAME, workingSchema);
}
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");
}
if (mapping.getMimeType() != null) {
elem.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, mapping.getMimeType());
}
seq.addElement(elem);
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLBinaryDataCollectionMapping.
/**
* Process a given XMLBinaryDataCollectionMapping.
*/
protected void processXMLBinaryDataCollectionMapping(BinaryDataCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
Field xmlField = (Field) mapping.getField();
XPathFragment frag = xmlField.getXPathFragment();
String schemaTypeString;
if (mapping.isSwaRef()) {
schemaTypeString = getSchemaTypeString(Constants.SWA_REF_QNAME, workingSchema);
} else {
schemaTypeString = getSchemaTypeString(Constants.BASE_64_BINARY_QNAME, workingSchema);
}
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);
elem.setMaxOccurs(Occurs.UNBOUNDED);
} else {
elem = buildElement(frag, schemaTypeString, Occurs.ZERO, Occurs.UNBOUNDED);
}
if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
elem.setNillable(true);
}
if (xmlField.isRequired()) {
elem.setMinOccurs("1");
}
if (mapping.getMimeType() != null) {
elem.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, mapping.getMimeType());
}
seq.addElement(elem);
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processChoiceMapping.
/**
* Process a given XMLChoiceMapping.
*/
protected void processChoiceMapping(Map<Field, Class<?>> fieldToClassMap, List<XMLChoiceFieldToClassAssociation> choiceFieldToClassList, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) {
Choice theChoice = new Choice();
if (isCollection) {
theChoice.setMaxOccurs(Occurs.UNBOUNDED);
}
for (XMLChoiceFieldToClassAssociation next : choiceFieldToClassList) {
Field field = next.getXmlField();
Element element = buildElement(field.getXPathFragment().getShortName(), Occurs.ZERO, null);
QName schemaTypeQName = field.getSchemaType();
if (schemaTypeQName != null) {
element.setType(getSchemaTypeString(schemaTypeQName, workingSchema));
} else {
element = processReferenceDescriptor(element, getDescriptorByClass(fieldToClassMap.get(field), descriptors), schemaForNamespace, workingSchema, properties, descriptors, field, false);
}
theChoice.addElement(element);
}
seq.addChoice(theChoice);
}
use of org.eclipse.persistence.internal.oxm.schema.model.Element 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.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLCompositeMapping.
/**
* Process a given XML composite mapping - either an XMLCompositeObjectMapping, or an
* XMLCompositeCollectionMapping. For XMLCompositeDirectCollectionMappings the
* processXMLCompositeDirectCollectionMapping method should be used.
*/
protected void processXMLCompositeMapping(CompositeObjectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean collection) {
Field xmlField = (Field) mapping.getField();
String refClassName = mapping.getReferenceClassName();
Descriptor refDesc = getDescriptorByName(refClassName, descriptors);
if (refDesc == null) {
throw DescriptorException.descriptorIsMissing(refClassName, (DatabaseMapping) mapping);
}
XPathFragment frag = xmlField.getXPathFragment();
seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
frag = getTargetXPathFragment(frag);
Element element = buildElement(frag, null, Occurs.ZERO, (collection ? Occurs.UNBOUNDED : null));
ComplexType ctype = null;
// if the reference descriptor's schema context is null we need to generate an anonymous complex type
if (refDesc.getSchemaReference() == null) {
ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors);
} else {
element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
}
if (frag.getNamespaceURI() != null) {
// may need to add a global element
element = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, element, ctype, refDesc);
} else if (ctype != null) {
// set an anonymous complex type
element.setComplexType(ctype);
}
boolean isNillable = false;
if (!collection) {
isNillable = mapping.getNullPolicy().isNullRepresentedByXsiNil();
} else {
isNillable = mapping.getNullPolicy().isNullRepresentedByXsiNil();
}
element.setNillable(isNillable);
if (xmlField.isRequired()) {
element.setMinOccurs("1");
}
seq.addElement(element);
}
Aggregations