use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLObjectReferenceMapping.
/**
* Process a given XMLObjectReferenceMapping. In the case of an XMLCollectionReferenceMapping,
* i.e. the isCollection flag is set to true, maxOccurs will be set to 'unbounded' on any
* source elements
*/
protected void processXMLObjectReferenceMapping(ObjectReferenceMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) {
String tgtClassName = mapping.getReferenceClassName();
Descriptor tgtDesc = getDescriptorByName(tgtClassName, descriptors);
if (tgtDesc == null) {
throw DescriptorException.descriptorIsMissing(tgtClassName, (DatabaseMapping) mapping);
}
// get the target mapping(s) to determine the appropriate type(s)
String schemaTypeString = null;
Map<Field, Field> associations = mapping.getSourceToTargetKeyFieldAssociations();
for (Entry<Field, Field> entry : associations.entrySet()) {
Field tgtField = entry.getValue();
Vector mappings = tgtDesc.getMappings();
// schemaTypeString = Constants.SCHEMA_PREFIX + COLON + IDREF;
for (Enumeration mappingsNum = mappings.elements(); mappingsNum.hasMoreElements(); ) {
Mapping nextMapping = (Mapping) mappingsNum.nextElement();
if (nextMapping.getField() != null && nextMapping.getField() instanceof Field) {
Field xFld = (Field) nextMapping.getField();
if (xFld == tgtField) {
schemaTypeString = getSchemaTypeForElement(tgtField, nextMapping.getAttributeClassification(), workingSchema);
}
}
}
if (schemaTypeString == null) {
schemaTypeString = getSchemaTypeString(Constants.STRING_QNAME, workingSchema);
}
XPathFragment frag = entry.getKey().getXPathFragment();
if (frag.isAttribute()) {
Attribute attr = buildAttribute(frag, schemaTypeString);
ct.getOrderedAttributes().add(attr);
} else {
Element elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
if (isCollection) {
elem.setMaxOccurs(Occurs.UNBOUNDED);
}
seq.addElement(elem);
}
}
}
use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLCompositeDirectCollectionMapping.
/**
* Process a given XMLCompositeDirectCollectionMapping.
*/
protected void processXMLCompositeDirectCollectionMapping(DirectCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
Field xmlField = ((Field) (mapping).getField());
XPathFragment frag = xmlField.getXPathFragment();
seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
frag = getTargetXPathFragment(frag);
String schemaTypeString = getSchemaTypeForElement(xmlField, mapping.getAttributeElementClass(), workingSchema);
Element element = null;
if (xmlField.usesSingleNode()) {
SimpleType st = new SimpleType();
org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
if (schemaTypeString == null) {
schemaTypeString = getSchemaTypeString(Constants.ANY_SIMPLE_TYPE_QNAME, workingSchema);
}
list.setItemType(schemaTypeString);
st.setList(list);
element = buildElement(xmlField.getXPathFragment(), null, Occurs.ZERO, null);
element.setSimpleType(st);
} else {
if (frag.getNamespaceURI() != null) {
element = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, element, schemaTypeString);
element.setMaxOccurs(Occurs.UNBOUNDED);
} else {
element = buildElement(frag, schemaTypeString, Occurs.ZERO, Occurs.UNBOUNDED);
}
}
if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
element.setNillable(true);
}
if (xmlField.isRequired()) {
element.setMinOccurs("1");
}
seq.addElement(element);
}
use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method buildComplexTypeWithSimpleContent.
/**
* Create and return a ComplexType containing simple content for a given XMLDescriptor. Assumes
* that the descriptor has a schema context set.
*/
private ComplexType buildComplexTypeWithSimpleContent(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
ComplexType ct = new ComplexType();
SimpleContent sc = new SimpleContent();
Extension extension = new Extension();
sc.setExtension(extension);
ct.setSimpleContent(sc);
for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
Field xFld = (Field) mapping.getField();
if (xFld.getXPath().equals(TEXT)) {
extension.setBaseType(getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema));
} else if (xFld.getXPathFragment().isAttribute()) {
String schemaTypeString = getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema);
Attribute attr = buildAttribute((DirectMapping) mapping, schemaTypeString);
extension.getOrderedAttributes().add(attr);
}
}
return ct;
}
use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.
the class XMLVariableXPathMappingNodeValue method marshalSingleValue.
@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
if (null == value) {
return false;
}
Object originalValue = value;
VariableXPathObjectMapping mapping = this.getMapping();
Descriptor descriptor = (Descriptor) mapping.getReferenceDescriptor();
if (descriptor.hasInheritance()) {
Class<?> objectValueClass = value.getClass();
if (!(objectValueClass == descriptor.getJavaClass())) {
descriptor = (Descriptor) session.getDescriptor(objectValueClass);
}
}
Marshaller marshaller = marshalRecord.getMarshaller();
ObjectBuilder objectBuilder = (ObjectBuilder) descriptor.getObjectBuilder();
List extraNamespaces = objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor, marshalRecord, session, true, true);
// Change to get the value from the object
String defaultRootElementString = descriptor.getDefaultRootElement();
marshalRecord.beforeContainmentMarshal(value);
XPathFragment rootFragment = mapping.getXPathFragmentForValue(value, marshalRecord.getNamespaceResolver(), marshalRecord.isNamespaceAware(), marshalRecord.getNamespaceSeparator());
XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
if (mapping.isAttribute()) {
ObjectBuilder tob = (ObjectBuilder) mapping.getReferenceDescriptor().getObjectBuilder();
MappingNodeValue textMappingNodeValue = (MappingNodeValue) tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
Mapping textMapping = textMappingNodeValue.getMapping();
if (textMapping.isAbstractDirectMapping()) {
DirectMapping xmlDirectMapping = (DirectMapping) textMapping;
Object fieldValue = xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(value, xmlDirectMapping.getField(), session), session, marshalRecord);
QName schemaType = ((Field) xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue, session);
marshalRecord.attribute(rootFragment, namespaceResolver, fieldValue, schemaType);
// marshalRecord.closeStartGroupingElements(groupingFragment);
return true;
} else {
return textMappingNodeValue.marshalSingleValue(rootFragment, marshalRecord, value, textMapping.getAttributeValueFromObject(value), session, namespaceResolver, marshalContext);
}
} else {
marshalRecord.closeStartGroupingElements(groupingFragment);
getXPathNode().startElement(marshalRecord, rootFragment, object, session, marshalRecord.getNamespaceResolver(), objectBuilder, value);
writeExtraNamespaces(extraNamespaces, marshalRecord, session);
marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor, (Descriptor) mapping.getReferenceDescriptor(), (Field) mapping.getField(), originalValue, value, false, false);
objectBuilder.buildRow(marshalRecord, value, session, marshaller, null);
marshalRecord.afterContainmentMarshal(object, value);
marshalRecord.endElement(rootFragment, namespaceResolver);
marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces, session);
}
return true;
}
use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.
the class XMLVariableXPathMappingNodeValue method attribute.
@Override
public void attribute(UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) {
Descriptor referenceDescriptor = (Descriptor) getMapping().getReferenceDescriptor();
ObjectBuilder treeObjectBuilder = (ObjectBuilder) referenceDescriptor.getObjectBuilder();
MappingNodeValue textMappingNodeValue = (MappingNodeValue) treeObjectBuilder.getRootXPathNode().getTextNode().getNodeValue();
Mapping textMapping = textMappingNodeValue.getMapping();
Object childObject = referenceDescriptor.getInstantiationPolicy().buildNewInstance();
if (textMapping.isAbstractDirectMapping()) {
DirectMapping xmlDirectMapping = (DirectMapping) textMappingNodeValue.getMapping();
Field xmlField = (Field) xmlDirectMapping.getField();
Object realValue = unmarshalRecord.getXMLReader().convertValueBasedOnSchemaType(xmlField, value, (ConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(), unmarshalRecord);
Object convertedValue = xmlDirectMapping.getAttributeValue(realValue, unmarshalRecord.getSession(), unmarshalRecord);
xmlDirectMapping.setAttributeValueInObject(childObject, convertedValue);
} else {
Object oldChildObject = unmarshalRecord.getCurrentObject();
CompositeObjectMapping nestedXMLCompositeObjectMapping = (CompositeObjectMapping) textMappingNodeValue.getMapping();
unmarshalRecord.setCurrentObject(childObject);
textMappingNodeValue.attribute(unmarshalRecord, namespaceURI, localName, value);
unmarshalRecord.setCurrentObject(oldChildObject);
}
setXPathInObject(namespaceURI, localName, childObject);
setOrAddAttributeValue(unmarshalRecord, childObject, null, null);
}
Aggregations