use of org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping in project eclipselink by eclipse-ee4j.
the class JsonSchemaGenerator method generateProperty.
private Property generateProperty(Mapping next, XMLDescriptor descriptor, Map<String, Property> properties) {
Property prop = null;
if (next.isCollectionMapping()) {
if (next instanceof CollectionReferenceMapping) {
CollectionReferenceMapping mapping = (CollectionReferenceMapping) next;
Set<XMLField> sourceFields = mapping.getSourceToTargetKeyFieldAssociations().keySet();
XMLDescriptor reference = (XMLDescriptor) mapping.getReferenceDescriptor();
for (XMLField nextField : sourceFields) {
XPathFragment frag = nextField.getXPathFragment();
String propertyName = getNameForFragment(frag);
XMLField targetField = (XMLField) mapping.getSourceToTargetKeyFieldAssociations().get(nextField);
Class<?> type = CoreClassConstants.STRING;
if (reference != null) {
type = getTypeForTargetField(targetField, reference);
}
prop = properties.get(propertyName);
if (prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
nestedProperty.setType(JsonType.ARRAY);
nestedProperty.setItem(new Property());
nestedProperty.getItem().setType(getJsonTypeForJavaType(type));
if (!properties.containsKey(prop.getName())) {
properties.put(prop.getName(), prop);
}
}
return prop;
} else if (next.isAbstractCompositeCollectionMapping()) {
CompositeCollectionMapping mapping = (CompositeCollectionMapping) next;
XMLField field = (XMLField) mapping.getField();
XPathFragment frag = field.getXPathFragment();
String propName = getNameForFragment(frag);
// for paths, there may already be an existing property
prop = properties.get(propName);
if (prop == null) {
prop = new Property();
prop.setName(propName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
nestedProperty.setType(JsonType.ARRAY);
nestedProperty.setItem(new Property());
XMLDescriptor referenceDescriptor = (XMLDescriptor) mapping.getReferenceDescriptor();
if (referenceDescriptor != null && referenceDescriptor.hasInheritance()) {
// handle inheritence
// schema.setAnyOf(new Property[descriptor.getInheritancePolicy().getAllChildDescriptors().size()]);
List<ClassDescriptor> descriptors = getAllDescriptorsForInheritance(referenceDescriptor);
Property[] props = new Property[descriptors.size()];
for (int i = 0; i < props.length; i++) {
XMLDescriptor nextDescriptor = null;
nextDescriptor = (XMLDescriptor) descriptors.get(i);
Property ref = new Property();
ref.setRef(getReferenceForDescriptor(nextDescriptor, true));
props[i] = ref;
}
nestedProperty.getItem().setAnyOf(props);
} else {
nestedProperty.getItem().setRef(getReferenceForDescriptor(referenceDescriptor, false));
// populateProperties(nestedProperty.getItem().getProperties(), (XMLDescriptor)mapping.getReferenceDescriptor());
}
} else if (next.isAbstractCompositeDirectCollectionMapping()) {
DirectCollectionMapping mapping = (DirectCollectionMapping) next;
XMLField field = (XMLField) mapping.getField();
XPathFragment frag = field.getXPathFragment();
List<String> enumeration = null;
if (mapping.getValueConverter() instanceof JAXBEnumTypeConverter) {
enumeration = getEnumeration((DatabaseMapping) next);
}
String propertyName = getNameForFragment(frag);
if (frag.nameIsText()) {
propertyName = (String) this.contextProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER);
}
if (frag.isAttribute() && this.attributePrefix != null) {
propertyName = attributePrefix + propertyName;
}
prop = properties.get(propertyName);
if (prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
nestedProperty.setType(JsonType.ARRAY);
nestedProperty.setItem(new Property());
if (enumeration != null) {
nestedProperty.getItem().setEnumeration(enumeration);
}
Class<?> type = mapping.getAttributeElementClass();
if (type == null) {
type = CoreClassConstants.STRING;
}
nestedProperty.getItem().setType(getJsonTypeForJavaType(type));
return prop;
} else if (next instanceof BinaryDataCollectionMapping) {
BinaryDataCollectionMapping mapping = (BinaryDataCollectionMapping) next;
XMLField field = (XMLField) mapping.getField();
XPathFragment frag = field.getXPathFragment();
String propertyName = getNameForFragment(frag);
if (frag.isSelfFragment()) {
propertyName = Constants.VALUE_WRAPPER;
if (this.contextProperties != null) {
String valueWrapper = (String) this.contextProperties.get(JAXBContextProperties.JSON_VALUE_WRAPPER);
if (valueWrapper != null) {
propertyName = valueWrapper;
}
}
}
if (frag.isAttribute() && this.attributePrefix != null) {
propertyName = attributePrefix + propertyName;
}
prop = properties.get(propertyName);
if (prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
nestedProperty.setType(JsonType.ARRAY);
nestedProperty.setItem(new Property());
if (mapping.shouldInlineBinaryData()) {
nestedProperty.getItem().setType(JsonType.STRING);
} else {
nestedProperty.getItem().setAnyOf(getXopIncludeProperties());
}
return prop;
}
} else {
if (next.isAbstractDirectMapping()) {
// handle direct mapping
DirectMapping directMapping = (DirectMapping) next;
XMLField field = (XMLField) directMapping.getField();
XPathFragment frag = field.getXPathFragment();
List<String> enumeration = null;
if (directMapping.getConverter() instanceof JAXBEnumTypeConverter) {
enumeration = getEnumeration((DatabaseMapping) directMapping);
}
String propertyName = getNameForFragment(frag);
if (frag.nameIsText()) {
propertyName = Constants.VALUE_WRAPPER;
if (this.contextProperties != null) {
String valueWrapper = (String) this.contextProperties.get(JAXBContextProperties.JSON_VALUE_WRAPPER);
if (valueWrapper != null) {
propertyName = valueWrapper;
}
}
}
if (frag.isAttribute() && this.attributePrefix != null) {
propertyName = attributePrefix + propertyName;
}
prop = properties.get(propertyName);
if (prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
if (enumeration != null) {
nestedProperty.setEnumeration(enumeration);
}
if (directMapping instanceof BinaryDataMapping) {
BinaryDataMapping binaryMapping = (BinaryDataMapping) directMapping;
if (binaryMapping.shouldInlineBinaryData() || binaryMapping.isSwaRef()) {
nestedProperty.setType(JsonType.STRING);
} else {
if (this.xopIncludeProp == null) {
initXopIncludeProp();
}
nestedProperty.setAnyOf(this.xopIncludeProp);
}
} else {
nestedProperty.setType(getJsonTypeForJavaType(directMapping.getAttributeClassification()));
}
return prop;
} else if (next instanceof ObjectReferenceMapping) {
ObjectReferenceMapping mapping = (ObjectReferenceMapping) next;
Set<XMLField> sourceFields = mapping.getSourceToTargetKeyFieldAssociations().keySet();
XMLDescriptor reference = (XMLDescriptor) mapping.getReferenceDescriptor();
for (XMLField nextField : sourceFields) {
XPathFragment frag = nextField.getXPathFragment();
String propName = getNameForFragment(frag);
XMLField targetField = (XMLField) mapping.getSourceToTargetKeyFieldAssociations().get(nextField);
Class<?> type = CoreClassConstants.STRING;
if (reference != null) {
type = getTypeForTargetField(targetField, reference);
}
prop = properties.get(propName);
if (prop == null) {
prop = new Property();
prop.setName(propName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
// nestedProperty.setType(JsonType.ARRAY);
// nestedProperty.setItem(new Property());
nestedProperty.setType(getJsonTypeForJavaType(type));
if (!properties.containsKey(prop.getName())) {
properties.put(prop.getName(), prop);
}
}
return prop;
} else if (next.isAbstractCompositeObjectMapping()) {
CompositeObjectMapping mapping = (CompositeObjectMapping) next;
XMLDescriptor nextDescriptor = (XMLDescriptor) mapping.getReferenceDescriptor();
XMLField field = (XMLField) mapping.getField();
XPathFragment firstFragment = field.getXPathFragment();
if (firstFragment.isSelfFragment() || firstFragment.nameIsText()) {
if (nextDescriptor != null) {
populateProperties(properties, nextDescriptor);
}
} else {
String propName = getNameForFragment(firstFragment);
prop = properties.get(propName);
if (prop == null) {
prop = new Property();
prop.setName(propName);
}
// prop.setType(JsonType.OBJECT);
prop.setName(propName);
Property nestedProperty = getNestedPropertyForFragment(firstFragment, prop);
XMLDescriptor referenceDescriptor = (XMLDescriptor) mapping.getReferenceDescriptor();
if (referenceDescriptor != null && referenceDescriptor.hasInheritance()) {
// handle inheritence
// schema.setAnyOf(new Property[descriptor.getInheritancePolicy().getAllChildDescriptors().size()]);
List<ClassDescriptor> descriptors = getAllDescriptorsForInheritance(referenceDescriptor);
Property[] props = new Property[descriptors.size()];
for (int i = 0; i < props.length; i++) {
XMLDescriptor nextDesc = (XMLDescriptor) descriptors.get(i);
Property ref = new Property();
ref.setRef(getReferenceForDescriptor(nextDesc, true));
props[i] = ref;
}
nestedProperty.setAnyOf(props);
} else {
nestedProperty.setRef(getReferenceForDescriptor(referenceDescriptor, false));
// populateProperties(nestedProperty.getItem().getProperties(), (XMLDescriptor)mapping.getReferenceDescriptor());
}
// populateProperties(nestedProperty.getProperties(), nextDescriptor);
}
} else if (next instanceof BinaryDataMapping) {
BinaryDataMapping binaryMapping = (BinaryDataMapping) next;
XMLField field = (XMLField) binaryMapping.getField();
XPathFragment frag = field.getXPathFragment();
String propertyName = getNameForFragment(frag);
if (frag.isSelfFragment()) {
propertyName = Constants.VALUE_WRAPPER;
if (this.contextProperties != null) {
String valueWrapper = (String) this.contextProperties.get(MarshallerProperties.JSON_VALUE_WRAPPER);
if (valueWrapper != null) {
propertyName = valueWrapper;
}
}
}
if (frag.isAttribute() && this.attributePrefix != null) {
propertyName = attributePrefix + propertyName;
}
prop = properties.get(propertyName);
if (prop == null) {
prop = new Property();
prop.setName(propertyName);
}
Property nestedProperty = getNestedPropertyForFragment(frag, prop);
if (binaryMapping.shouldInlineBinaryData() || binaryMapping.isSwaRef()) {
nestedProperty.setType(JsonType.STRING);
} else {
if (this.xopIncludeProp == null) {
initXopIncludeProp();
}
nestedProperty.setAnyOf(this.xopIncludeProp);
}
return prop;
}
}
return prop;
}
use of org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processMapping.
/**
* Process a given mapping.
*/
protected void processMapping(CoreMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
if (mapping instanceof BinaryDataMapping) {
processXMLBinaryDataMapping((BinaryDataMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
} else if (mapping instanceof BinaryDataCollectionMapping) {
processXMLBinaryDataCollectionMapping((BinaryDataCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
} else if (mapping instanceof DirectMapping) {
processXMLDirectMapping((DirectMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
} else if (mapping instanceof DirectCollectionMapping) {
processXMLCompositeDirectCollectionMapping((DirectCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties);
} else if (mapping instanceof CompositeCollectionMapping) {
processXMLCompositeMapping((CompositeCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, true);
} else if (mapping instanceof CompositeObjectMapping) {
processXMLCompositeMapping((CompositeObjectMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, false);
} else if (mapping instanceof AnyAttributeMapping) {
AnyAttribute anyAttribute = new AnyAttribute();
anyAttribute.setProcessContents(AnyAttribute.LAX);
ct.setAnyAttribute(anyAttribute);
} else if (mapping instanceof AnyObjectMapping) {
processAnyMapping(seq, false);
} else if (mapping instanceof AnyCollectionMapping) {
processAnyMapping(seq, true);
} else if (mapping instanceof ChoiceObjectMapping) {
processXMLChoiceObjectMapping((ChoiceObjectMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors);
} else if (mapping instanceof ChoiceCollectionMapping) {
processXMLChoiceCollectionMapping((ChoiceCollectionMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors);
} else if (mapping instanceof CollectionReferenceMapping) {
processXMLObjectReferenceMapping((CollectionReferenceMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, true);
} else if (mapping instanceof ObjectReferenceMapping) {
processXMLObjectReferenceMapping((ObjectReferenceMapping) mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors, false);
}
}
use of org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping in project eclipselink by eclipse-ee4j.
the class XMLChoiceCollectionMappingUnmarshalNodeValue method initializeNodeValue.
private void initializeNodeValue() {
if (nestedMapping == null && isAny) {
nestedMapping = xmlChoiceCollectionMapping.getAnyMapping();
}
Mapping xmlMapping = this.nestedMapping;
if (xmlMapping instanceof BinaryDataCollectionMapping) {
choiceElementNodeValue = new XMLBinaryDataCollectionMappingNodeValue((BinaryDataCollectionMapping) xmlMapping);
choiceElementMarshalNodeValue = choiceElementNodeValue;
} else if (xmlMapping instanceof DirectCollectionMapping) {
choiceElementNodeValue = new XMLCompositeDirectCollectionMappingNodeValue((DirectCollectionMapping) xmlMapping);
choiceElementMarshalNodeValue = choiceElementNodeValue;
} else if (xmlMapping instanceof CompositeCollectionMapping) {
choiceElementNodeValue = new XMLCompositeCollectionMappingNodeValue((CompositeCollectionMapping) xmlMapping);
choiceElementMarshalNodeValue = choiceElementNodeValue;
} else if (xmlMapping instanceof AnyCollectionMapping) {
choiceElementNodeValue = new XMLAnyCollectionMappingNodeValue((AnyCollectionMapping) xmlMapping);
choiceElementMarshalNodeValue = choiceElementNodeValue;
} else {
choiceElementNodeValue = new XMLCollectionReferenceMappingNodeValue((CollectionReferenceMapping) xmlMapping, xmlField);
CollectionReferenceMapping refMapping = ((CollectionReferenceMapping) xmlMapping);
if (refMapping.usesSingleNode() || refMapping.getFields().size() == 1) {
choiceElementMarshalNodeValue = new XMLCollectionReferenceMappingNodeValue(refMapping, xmlField);
} else {
choiceElementMarshalNodeValue = new XMLCollectionReferenceMappingMarshalNodeValue((CollectionReferenceMapping) xmlMapping);
}
}
}
use of org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping 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.CollectionReferenceMapping 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