use of org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class XMLCompositeObjectMappingNodeValue method endSelfNodeValue.
@Override
public void endSelfNodeValue(UnmarshalRecord unmarshalRecord, UnmarshalRecord selfRecord, Attributes attributes) {
if (xmlCompositeObjectMapping.getNullPolicy().valueIsNull(attributes)) {
xmlCompositeObjectMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), null);
return;
}
unmarshalRecord.removeNullCapableValue(this);
if (unmarshalRecord.getFragmentBuilder().getDocument() != null) {
UnmarshalKeepAsElementPolicy keepAsElementPolicy = xmlCompositeObjectMapping.getKeepAsElementPolicy();
SAXFragmentBuilder builder = unmarshalRecord.getFragmentBuilder();
if ((((keepAsElementPolicy.isKeepUnknownAsElement()) || (keepAsElementPolicy.isKeepAllAsElement()))) && (builder.getNodes().size() != 0)) {
if (unmarshalRecord.getTypeQName() != null) {
Class<Object> theClass = unmarshalRecord.getConversionManager().javaType(unmarshalRecord.getTypeQName());
if (theClass != null) {
// handle simple text
endElementProcessText(unmarshalRecord, xmlCompositeObjectMapping, null, null);
return;
}
}
Element element = (Element) builder.getNodes().remove(builder.getNodes().size() - 1);
String xsiType = null;
if (null != element) {
if (unmarshalRecord.isNamespaceAware()) {
xsiType = element.getAttributeNS(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.SCHEMA_TYPE_ATTRIBUTE);
} else {
xsiType = element.getAttribute(Constants.SCHEMA_TYPE_ATTRIBUTE);
}
}
if (null != xsiType) {
xsiType = xsiType.trim();
Object value = element;
String namespace = null;
int colonIndex = xsiType.indexOf(unmarshalRecord.getNamespaceSeparator());
if (colonIndex > -1) {
String prefix = xsiType.substring(0, colonIndex);
namespace = unmarshalRecord.resolveNamespacePrefix(prefix);
if (null == namespace) {
namespace = XMLPlatformFactory.getInstance().getXMLPlatform().resolveNamespacePrefix(element, prefix);
}
QName qName = new QName(namespace, xsiType.substring(colonIndex + 1));
ConversionManager conversionManager = unmarshalRecord.getConversionManager();
Class<Object> theClass = conversionManager.javaType(qName);
if (theClass != null) {
value = conversionManager.convertObject(element.getTextContent(), theClass, qName);
}
} else {
if (!unmarshalRecord.isNamespaceAware() || !unmarshalRecord.getUnmarshaller().getJsonTypeConfiguration().useXsdTypesWithPrefix()) {
QName qName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, xsiType);
ConversionManager conversionManager = unmarshalRecord.getConversionManager();
Class<Object> theClass = conversionManager.javaType(qName);
if (theClass != null) {
value = conversionManager.convertObject(element.getTextContent(), theClass, qName);
}
}
}
xmlCompositeObjectMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), value);
} else {
xmlCompositeObjectMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), element);
}
}
} else {
Object valueToSet = selfRecord.getCurrentObject();
valueToSet = xmlCompositeObjectMapping.convertDataValueToObjectValue(valueToSet, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
xmlCompositeObjectMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), valueToSet);
InverseReferenceMapping inverseReferenceMapping = xmlCompositeObjectMapping.getInverseReferenceMapping();
if (null != inverseReferenceMapping) {
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(valueToSet, unmarshalRecord.getCurrentObject());
}
}
}
use of org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class ReferenceResolver method perform.
/**
* Add java doc if you understand this code.
*/
private void perform(final CoreAbstractSession session, final IDResolver userSpecifiedResolver, final ErrorHandler handler, final Reference reference) {
final Object referenceSourceObject = reference.getSourceObject();
if (reference.getMapping() instanceof CollectionReferenceMapping) {
final CollectionReferenceMapping mapping = (CollectionReferenceMapping) reference.getMapping();
final CoreContainerPolicy cPolicy = mapping.getContainerPolicy();
// container should never be null
final Object container = reference.getContainer();
// create vectors of primary key values - one vector per reference instance
createPKVectorsFromMap(reference, mapping);
// if the we could not generate the primary key for the reference, it will not resolve - skip it
if (reference.getPrimaryKey() == null) {
return;
}
// loop over each pk vector and get object from cache - then add to collection and set on object
Object value = null;
if (!mapping.isWriteOnly()) {
for (Object o : ((Vector) reference.getPrimaryKey())) {
final CacheId primaryKey = (CacheId) o;
if (userSpecifiedResolver != null) {
final Callable c;
try {
if (primaryKey.getPrimaryKey().length > 1) {
final Map<String, Object> idWrapper = new HashMap<>();
for (int y = 0; y < primaryKey.getPrimaryKey().length; y++) {
final ObjectReferenceMapping refMapping = (ObjectReferenceMapping) reference.getMapping();
final String idName = (String) refMapping.getReferenceDescriptor().getPrimaryKeyFieldNames().get(y);
final Object idValue = primaryKey.getPrimaryKey()[y];
idWrapper.put(idName, idValue);
}
c = userSpecifiedResolver.resolve(idWrapper, reference.getTargetClass());
} else {
c = userSpecifiedResolver.resolve(primaryKey.getPrimaryKey()[0], reference.getTargetClass());
}
if (c != null) {
value = c.call();
}
} catch (Exception e) {
throw XMLMarshalException.unmarshalException(e);
}
} else {
value = getValue(session, reference, primaryKey, handler);
}
if (value != null) {
cPolicy.addInto(value, container, session);
}
}
}
// for each reference, get the source object and add it to the container policy
// when finished, set the policy on the mapping
mapping.setAttributeValueInObject(referenceSourceObject, container);
final InverseReferenceMapping inverseReferenceMapping = mapping.getInverseReferenceMapping();
if (inverseReferenceMapping != null && value != null) {
final CoreAttributeAccessor backpointerAccessor = inverseReferenceMapping.getAttributeAccessor();
final CoreContainerPolicy backpointerContainerPolicy = inverseReferenceMapping.getContainerPolicy();
if (backpointerContainerPolicy == null) {
backpointerAccessor.setAttributeValueInObject(value, referenceSourceObject);
} else {
Object backpointerContainer = backpointerAccessor.getAttributeValueFromObject(value);
if (backpointerContainer == null) {
backpointerContainer = backpointerContainerPolicy.containerInstance();
backpointerAccessor.setAttributeValueInObject(value, backpointerContainer);
}
backpointerContainerPolicy.addInto(referenceSourceObject, backpointerContainer, session);
}
}
} else if (reference.getMapping() instanceof ObjectReferenceMapping) {
final CacheId primaryKey = (CacheId) reference.getPrimaryKey();
Object value = null;
if (userSpecifiedResolver != null) {
final Callable c;
try {
if (primaryKey.getPrimaryKey().length > 1) {
final Map<String, Object> idWrapper = new HashMap<>();
for (int y = 0; y < primaryKey.getPrimaryKey().length; y++) {
final ObjectReferenceMapping refMapping = (ObjectReferenceMapping) reference.getMapping();
final String idName = (String) refMapping.getReferenceDescriptor().getPrimaryKeyFieldNames().get(y);
final Object idValue = primaryKey.getPrimaryKey()[y];
idWrapper.put(idName, idValue);
}
c = userSpecifiedResolver.resolve(idWrapper, reference.getTargetClass());
} else {
c = userSpecifiedResolver.resolve(primaryKey.getPrimaryKey()[0], reference.getTargetClass());
}
if (c != null) {
value = c.call();
}
} catch (Exception e) {
throw XMLMarshalException.unmarshalException(e);
}
} else {
value = getValue(session, reference, primaryKey, handler);
}
ObjectReferenceMapping mapping = (ObjectReferenceMapping) reference.getMapping();
if (value != null) {
mapping.setAttributeValueInObject(reference.getSourceObject(), value);
}
if (null != reference.getSetting()) {
reference.getSetting().setValue(value);
}
InverseReferenceMapping inverseReferenceMapping = mapping.getInverseReferenceMapping();
if (inverseReferenceMapping != null) {
CoreAttributeAccessor backpointerAccessor = inverseReferenceMapping.getAttributeAccessor();
CoreContainerPolicy backpointerContainerPolicy = inverseReferenceMapping.getContainerPolicy();
if (backpointerContainerPolicy == null) {
backpointerAccessor.setAttributeValueInObject(value, referenceSourceObject);
} else {
Object backpointerContainer = backpointerAccessor.getAttributeValueFromObject(value);
if (backpointerContainer == null) {
backpointerContainer = backpointerContainerPolicy.containerInstance();
backpointerAccessor.setAttributeValueInObject(value, backpointerContainer);
}
backpointerContainerPolicy.addInto(reference.getSourceObject(), backpointerContainer, session);
}
}
}
}
use of org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class XMLCompositeCollectionMappingNodeValue method endElement.
@Override
public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Object collection) {
if (unmarshalRecord.isNil() && unmarshalRecord.getXMLReader().isNullRepresentedByXsiNil(xmlCompositeCollectionMapping.getNullPolicy()) && (unmarshalRecord.getChildRecord() == null)) {
if (unmarshalRecord.getXMLReader().isInCollection()) {
unmarshalRecord.addAttributeValue(this, null);
} else {
unmarshalRecord.setAttributeValueNull(this);
}
unmarshalRecord.resetStringBuffer();
return;
}
if (null == unmarshalRecord.getChildRecord()) {
SAXFragmentBuilder builder = unmarshalRecord.getFragmentBuilder();
UnmarshalKeepAsElementPolicy keepAsElementPolicy = xmlCompositeCollectionMapping.getKeepAsElementPolicy();
if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && builder.getNodes().size() > 1) {
if (unmarshalRecord.getTypeQName() != null) {
Class<Object> theClass = unmarshalRecord.getConversionManager().javaType(unmarshalRecord.getTypeQName());
if (theClass != null) {
// handle simple text
endElementProcessText(unmarshalRecord, xmlCompositeCollectionMapping, xPathFragment, collection);
return;
}
}
if (builder.getNodes().size() > 1) {
setOrAddAttributeValueForKeepAsElement(builder, xmlCompositeCollectionMapping, xmlCompositeCollectionMapping, unmarshalRecord, true, collection);
return;
}
} else {
// handle simple text
endElementProcessText(unmarshalRecord, xmlCompositeCollectionMapping, xPathFragment, collection);
return;
}
return;
}
Object objectValue = unmarshalRecord.getChildRecord().getCurrentObject();
InverseReferenceMapping inverseReferenceMapping = xmlCompositeCollectionMapping.getInverseReferenceMapping();
if (null != inverseReferenceMapping) {
if (inverseReferenceMapping.getContainerPolicy() == null) {
Object currentValue = inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(objectValue);
if (!isInverseReference || (currentValue == null && isInverseReference)) {
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(objectValue, unmarshalRecord.getCurrentObject());
}
} else {
Object backpointerContainer = inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(objectValue);
if (backpointerContainer == null) {
backpointerContainer = inverseReferenceMapping.getContainerPolicy().containerInstance();
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(objectValue, backpointerContainer);
}
inverseReferenceMapping.getContainerPolicy().addInto(unmarshalRecord.getCurrentObject(), backpointerContainer, unmarshalRecord.getSession());
}
}
// convert the value - if necessary
objectValue = xmlCompositeCollectionMapping.convertDataValueToObjectValue(objectValue, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
unmarshalRecord.addAttributeValue(this, objectValue, collection);
unmarshalRecord.setChildRecord(null);
}
use of org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class XMLCompositeObjectMappingNodeValue method setAttributeValue.
private void setAttributeValue(Object object, UnmarshalRecord unmarshalRecord) {
InverseReferenceMapping inverseReferenceMapping = xmlCompositeObjectMapping.getInverseReferenceMapping();
// If isInverseReference then this mapping is an inlineMapping of an InverseReference
if (null != inverseReferenceMapping) {
if (inverseReferenceMapping.getContainerPolicy() == null) {
Object currentValue = inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(object);
if (!isInverseReference || (currentValue == null && isInverseReference)) {
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(object, unmarshalRecord.getCurrentObject());
}
} else {
Object backpointerContainer = inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(object);
if (backpointerContainer == null) {
backpointerContainer = inverseReferenceMapping.getContainerPolicy().containerInstance();
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(object, backpointerContainer);
}
inverseReferenceMapping.getContainerPolicy().addInto(unmarshalRecord.getCurrentObject(), backpointerContainer, unmarshalRecord.getSession());
}
}
object = xmlCompositeObjectMapping.convertDataValueToObjectValue(object, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller());
// Set the child object on the parent
unmarshalRecord.setAttributeValue(object, xmlCompositeObjectMapping);
}
use of org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class XPathObjectBuilder method lazyInitialize.
void lazyInitialize() {
if (initialized) {
return;
}
synchronized (this) {
if (initialized) {
return;
}
Descriptor xmlDescriptor = (Descriptor) descriptor;
// MAPPINGS
Iterator mappingIterator = xmlDescriptor.getMappings().iterator();
Iterator fieldTransformerIterator;
Mapping xmlMapping;
// Transformation Mapping
TransformationMapping transformationMapping;
FieldTransformerNodeValue fieldTransformerNodeValue;
Object[] nextFieldToTransformer;
// Simple Type Translator
TypeNodeValue typeNodeValue;
NodeValue mappingNodeValue = null;
Field xmlField;
while (mappingIterator.hasNext()) {
xmlMapping = (Mapping) mappingIterator.next();
xmlField = (Field) xmlMapping.getField();
if (xmlMapping.isTransformationMapping()) {
transformationMapping = (TransformationMapping) xmlMapping;
addTransformationMapping(transformationMapping);
fieldTransformerIterator = transformationMapping.getFieldToTransformers().iterator();
while (fieldTransformerIterator.hasNext()) {
fieldTransformerNodeValue = new FieldTransformerNodeValue(transformationMapping);
nextFieldToTransformer = (Object[]) fieldTransformerIterator.next();
xmlField = (Field) nextFieldToTransformer[0];
fieldTransformerNodeValue.setXMLField(xmlField);
fieldTransformerNodeValue.setFieldTransformer((CoreFieldTransformer) nextFieldToTransformer[1]);
addChild(xmlField.getXPathFragment(), fieldTransformerNodeValue, xmlDescriptor.getNamespaceResolver());
}
} else {
if (xmlMapping.isAbstractDirectMapping()) {
mappingNodeValue = new XMLDirectMappingNodeValue((DirectMapping) xmlMapping);
} else if (xmlMapping.isAbstractCompositeObjectMapping()) {
mappingNodeValue = new XMLCompositeObjectMappingNodeValue((CompositeObjectMapping) xmlMapping);
} else if (xmlMapping.isAbstractCompositeCollectionMapping()) {
CompositeCollectionMapping collectionMapping = (CompositeCollectionMapping) xmlMapping;
mappingNodeValue = new XMLCompositeCollectionMappingNodeValue(collectionMapping);
if (collectionMapping.getWrapperNullPolicy() != null) {
addChild(xmlField.getXPathFragment(), new CollectionGroupingElementNodeValue((ContainerValue) mappingNodeValue), xmlDescriptor.getNamespaceResolver());
}
} else if (xmlMapping.isAbstractCompositeDirectCollectionMapping()) {
DirectCollectionMapping collectionMapping = (DirectCollectionMapping) xmlMapping;
mappingNodeValue = new XMLCompositeDirectCollectionMappingNodeValue(collectionMapping);
if (collectionMapping.getWrapperNullPolicy() != null) {
addChild(xmlField.getXPathFragment(), new CollectionGroupingElementNodeValue((ContainerValue) mappingNodeValue), xmlDescriptor.getNamespaceResolver());
}
} else if (xmlMapping instanceof InverseReferenceMapping) {
xmlMapping = (Mapping) ((InverseReferenceMapping) xmlMapping).getInlineMapping();
if (xmlMapping == null) {
continue;
}
xmlField = (Field) xmlMapping.getField();
if (xmlMapping.isAbstractCompositeCollectionMapping()) {
mappingNodeValue = new XMLCompositeCollectionMappingNodeValue((CompositeCollectionMapping) xmlMapping, true);
}
if (xmlMapping.isAbstractCompositeObjectMapping()) {
mappingNodeValue = new XMLCompositeObjectMappingNodeValue((CompositeObjectMapping) xmlMapping, true);
}
} else if (xmlMapping instanceof VariableXPathCollectionMapping) {
mappingNodeValue = new XMLVariableXPathCollectionMappingNodeValue((VariableXPathCollectionMapping) xmlMapping);
} else if (xmlMapping instanceof VariableXPathObjectMapping) {
mappingNodeValue = new XMLVariableXPathObjectMappingNodeValue((VariableXPathObjectMapping) xmlMapping);
} else if (xmlMapping instanceof AnyObjectMapping) {
mappingNodeValue = new XMLAnyObjectMappingNodeValue((AnyObjectMapping) xmlMapping);
} else if (xmlMapping instanceof AnyCollectionMapping) {
mappingNodeValue = new XMLAnyCollectionMappingNodeValue((AnyCollectionMapping) xmlMapping);
} else if (xmlMapping instanceof AnyAttributeMapping) {
mappingNodeValue = new XMLAnyAttributeMappingNodeValue((AnyAttributeMapping) xmlMapping);
} else if (xmlMapping instanceof BinaryDataMapping) {
mappingNodeValue = new XMLBinaryDataMappingNodeValue((BinaryDataMapping) xmlMapping);
} else if (xmlMapping instanceof BinaryDataCollectionMapping) {
mappingNodeValue = new XMLBinaryDataCollectionMappingNodeValue((BinaryDataCollectionMapping) xmlMapping);
} else if (xmlMapping instanceof FragmentMapping) {
mappingNodeValue = new XMLFragmentMappingNodeValue((FragmentMapping) xmlMapping);
} else if (xmlMapping instanceof FragmentCollectionMapping) {
mappingNodeValue = new XMLFragmentCollectionMappingNodeValue((FragmentCollectionMapping) xmlMapping);
} else if (xmlMapping instanceof CollectionReferenceMapping) {
CollectionReferenceMapping xmlColMapping = (CollectionReferenceMapping) xmlMapping;
List fields = xmlColMapping.getFields();
Field xmlColMappingField = (Field) xmlColMapping.getField();
XPathNode branchNode;
if (null == xmlColMappingField) {
if (fields.size() > 1 && !xmlColMapping.usesSingleNode()) {
addChild(XPathFragment.SELF_FRAGMENT, new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver());
}
branchNode = rootXPathNode;
} else {
branchNode = addChild(((Field) xmlColMapping.getField()).getXPathFragment(), new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver());
}
int containerIndex = -1;
for (int i = 0, size = fields.size(); i < size; i++) {
Field xmlFld = (Field) fields.get(i);
mappingNodeValue = new XMLCollectionReferenceMappingNodeValue(xmlColMapping, xmlFld);
if (i == 0) {
addContainerValue((ContainerValue) mappingNodeValue);
containerIndex = ((ContainerValue) mappingNodeValue).getIndex();
} else {
((ContainerValue) mappingNodeValue).setIndex(containerIndex);
}
branchNode.addChild(xmlFld.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
}
continue;
} else if (xmlMapping instanceof ObjectReferenceMapping) {
ObjectReferenceMapping xmlORMapping = (ObjectReferenceMapping) xmlMapping;
Iterator fieldIt = xmlORMapping.getFields().iterator();
while (fieldIt.hasNext()) {
Field xmlFld = (Field) fieldIt.next();
mappingNodeValue = new XMLObjectReferenceMappingNodeValue(xmlORMapping, xmlFld);
addChild(xmlFld.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
}
continue;
} else if (xmlMapping instanceof ChoiceObjectMapping) {
ChoiceObjectMapping xmlChoiceMapping = (ChoiceObjectMapping) xmlMapping;
Iterator fields = xmlChoiceMapping.getChoiceElementMappings().keySet().iterator();
Field firstField = (Field) fields.next();
XMLChoiceObjectMappingNodeValue firstNodeValue = new XMLChoiceObjectMappingNodeValue(xmlChoiceMapping, firstField);
firstNodeValue.setNullCapableNodeValue(firstNodeValue);
addChild(firstField.getXPathFragment(), firstNodeValue, xmlDescriptor.getNamespaceResolver());
while (fields.hasNext()) {
Field next = (Field) fields.next();
XMLChoiceObjectMappingNodeValue nodeValue = new XMLChoiceObjectMappingNodeValue(xmlChoiceMapping, next);
nodeValue.setNullCapableNodeValue(firstNodeValue);
addChild(next.getXPathFragment(), nodeValue, xmlDescriptor.getNamespaceResolver());
}
continue;
} else if (xmlMapping instanceof ChoiceCollectionMapping) {
ChoiceCollectionMapping xmlChoiceMapping = (ChoiceCollectionMapping) xmlMapping;
Iterator<Entry<Field, Mapping>> fields = xmlChoiceMapping.getChoiceElementMappings().entrySet().iterator();
Entry<Field, Mapping> firstEntry = fields.next();
Field firstField = firstEntry.getKey();
XMLChoiceCollectionMappingUnmarshalNodeValue unmarshalValue = new XMLChoiceCollectionMappingUnmarshalNodeValue(xmlChoiceMapping, firstField);
XMLChoiceCollectionMappingMarshalNodeValue marshalValue = new XMLChoiceCollectionMappingMarshalNodeValue(xmlChoiceMapping, firstField);
// The reason behind LinkedHashMap is the order of items when for-cycling HashMap.getEntrySet() or HashMap.getKeySet().
// This change fixes non-determinism (implementation in JDK8 has changed so the order is different (sometimes) than in JDK6 and JDK7).
HashMap<Field, NodeValue> fieldToNodeValues = new LinkedHashMap<>();
unmarshalValue.setContainerNodeValue(unmarshalValue);
unmarshalValue.setFieldToNodeValues(fieldToNodeValues);
if (xmlChoiceMapping.isMixedContent() && (xmlChoiceMapping.getMixedContentMapping() == firstEntry.getValue())) {
unmarshalValue.setIsMixedNodeValue(true);
marshalValue.setIsMixedNodeValue(true);
}
this.addContainerValue(unmarshalValue);
((ContainerValue) unmarshalValue.getChoiceElementNodeValue()).setIndex(unmarshalValue.getIndex());
fieldToNodeValues.put(firstField, unmarshalValue);
addChild(firstField.getXPathFragment(), unmarshalValue, xmlDescriptor.getNamespaceResolver());
addChild(firstField.getXPathFragment(), marshalValue, xmlDescriptor.getNamespaceResolver());
while (fields.hasNext()) {
Entry<Field, Mapping> nextEntry = fields.next();
Field nextField = nextEntry.getKey();
XMLChoiceCollectionMappingUnmarshalNodeValue nodeValue = new XMLChoiceCollectionMappingUnmarshalNodeValue(xmlChoiceMapping, nextField);
nodeValue.setContainerNodeValue(unmarshalValue);
nodeValue.setIndex(unmarshalValue.getIndex());
((ContainerValue) nodeValue.getChoiceElementNodeValue()).setIndex(unmarshalValue.getIndex());
addChild(nextField.getXPathFragment(), nodeValue, xmlDescriptor.getNamespaceResolver());
fieldToNodeValues.put(nextField, nodeValue);
if (xmlChoiceMapping.isMixedContent() && (xmlChoiceMapping.getMixedContentMapping() == nextEntry.getValue())) {
nodeValue.setIsMixedNodeValue(true);
}
}
if (xmlChoiceMapping.isAny()) {
XMLChoiceCollectionMappingUnmarshalNodeValue nodeValue = new XMLChoiceCollectionMappingUnmarshalNodeValue(xmlChoiceMapping, null, xmlChoiceMapping.getAnyMapping());
nodeValue.setContainerNodeValue(unmarshalValue);
nodeValue.setIndex(unmarshalValue.getIndex());
((ContainerValue) nodeValue.getChoiceElementNodeValue()).setIndex(unmarshalValue.getIndex());
addChild(null, nodeValue, xmlDescriptor.getNamespaceResolver());
fieldToNodeValues.put(null, nodeValue);
if (xmlChoiceMapping.isMixedContent()) {
nodeValue.setIsMixedNodeValue(true);
}
}
marshalValue.setFieldToNodeValues(fieldToNodeValues);
continue;
}
if (mappingNodeValue.isContainerValue()) {
addContainerValue((ContainerValue) mappingNodeValue);
}
if (mappingNodeValue.isNullCapableValue()) {
addNullCapableValue((NullCapableValue) mappingNodeValue);
}
if (xmlField != null) {
addChild(xmlField.getXPathFragment(), mappingNodeValue, xmlDescriptor.getNamespaceResolver());
} else {
addChild(null, mappingNodeValue, xmlDescriptor.getNamespaceResolver());
}
}
}
if (descriptor.hasInheritance()) {
Field indicatorField = (Field) descriptor.getInheritancePolicy().getClassIndicatorField();
if (indicatorField != null) {
if (indicatorField.getLastXPathFragment().getNamespaceURI() != null && indicatorField.getLastXPathFragment().getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI) && indicatorField.getLastXPathFragment().getLocalName().equals(Constants.SCHEMA_TYPE_ATTRIBUTE)) {
xsiTypeIndicatorField = true;
}
}
}
initialized = true;
}
}
Aggregations