use of org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateMapping.
/**
* Generate a mapping for a given Property.
*
* @return newly created mapping
*/
public Mapping generateMapping(Property property, Descriptor descriptor, JavaClass descriptorJavaClass, NamespaceInfo namespaceInfo) {
if (property.isSetXmlJavaTypeAdapter()) {
// if we are dealing with a reference, generate mapping and return
if (property.isReference()) {
return generateMappingForReferenceProperty(property, descriptor, namespaceInfo);
}
XmlJavaTypeAdapter xja = property.getXmlJavaTypeAdapter();
JavaClass adapterClass = helper.getJavaClass(xja.getValue());
JavaClass valueType = null;
String sValType = xja.getValueType();
if (sValType.equals("jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT")) {
valueType = property.getActualType();
} else {
valueType = helper.getJavaClass(xja.getValueType());
}
Mapping mapping;
boolean isArray = property.getType().isArray() && !property.getType().getRawName().equals("byte[]");
// a composite mapping
if (property.isChoice()) {
if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
mapping = generateChoiceCollectionMapping(property, descriptor, namespaceInfo);
((ChoiceCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
} else {
mapping = generateChoiceMapping(property, descriptor, namespaceInfo);
((ChoiceObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
}
} else if (typeInfo.containsKey(valueType.getQualifiedName())) {
TypeInfo reference = typeInfo.get(valueType.getQualifiedName());
if (helper.isCollectionType(property.getType())) {
if (reference.isEnumerationType()) {
mapping = generateEnumCollectionMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
XMLJavaTypeConverter converter = new XMLJavaTypeConverter(adapterClass.getQualifiedName());
converter.setNestedConverter(((DirectCollectionMapping) mapping).getValueConverter());
((DirectCollectionMapping) mapping).setValueConverter(converter);
} else {
if (property.getVariableAttributeName() != null) {
mapping = generateVariableXPathCollectionMapping(property, descriptor, namespaceInfo, valueType);
((VariableXPathCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
} else {
mapping = generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, valueType.getQualifiedName());
((CompositeCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
}
}
} else {
if (reference.isEnumerationType()) {
mapping = generateDirectEnumerationMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
XMLJavaTypeConverter converter = new XMLJavaTypeConverter(adapterClass.getQualifiedName());
converter.setNestedConverter(((DirectMapping) mapping).getConverter());
((DirectMapping) mapping).setConverter(converter);
} else if (property.isInverseReference()) {
mapping = generateInverseReferenceMapping(property, descriptor, namespaceInfo);
} else {
if (property.getVariableAttributeName() != null) {
mapping = generateVariableXPathObjectMapping(property, descriptor, namespaceInfo, valueType);
((VariableXPathObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
} else {
mapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, valueType.getQualifiedName());
((CompositeObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
}
}
}
} else {
// no descriptor for value type
if (property.isAny()) {
if (helper.isCollectionType(property.getType())) {
mapping = generateAnyCollectionMapping(property, descriptor, namespaceInfo, property.isMixedContent());
((AnyCollectionMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
} else {
mapping = generateAnyObjectMapping(property, descriptor, namespaceInfo);
((AnyObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
}
} else if (helper.isCollectionType(property.getType()) || isArray) {
if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
mapping = generateBinaryDataCollectionMapping(property, descriptor, namespaceInfo);
((BinaryDataCollectionMapping) mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
} else {
mapping = generateDirectCollectionMapping(property, descriptor, namespaceInfo);
if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
((DirectCollectionMapping) mapping).setCollapsingStringValues(true);
} else if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
((DirectCollectionMapping) mapping).setNormalizingStringValues(true);
} else {
((DirectCollectionMapping) mapping).setValueConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
}
}
} else if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
mapping = generateBinaryMapping(property, descriptor, namespaceInfo);
((BinaryDataMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
} else {
if (!property.isAttribute() && areEquals(valueType, Object.class) || property.isTyped()) {
mapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, null);
((CompositeObjectMapping) mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
((CompositeObjectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
return mapping;
}
mapping = generateDirectMapping(property, descriptor, namespaceInfo);
if (adapterClass.getQualifiedName().equals(CollapsedStringAdapter.class.getName())) {
((DirectMapping) mapping).setCollapsingStringValues(true);
} else if (adapterClass.getQualifiedName().equals(NormalizedStringAdapter.class.getName())) {
((DirectMapping) mapping).setNormalizingStringValues(true);
} else {
((DirectMapping) mapping).setConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
}
}
}
return mapping;
}
if (property.getVariableAttributeName() != null) {
if (helper.isCollectionType(property.getType()) || property.getType().isArray() || property.isMap()) {
return generateVariableXPathCollectionMapping(property, descriptor, namespaceInfo, property.getActualType());
} else {
return generateVariableXPathObjectMapping(property, descriptor, namespaceInfo, property.getActualType());
}
}
if (property.isSetXmlJoinNodes()) {
if (helper.isCollectionType(property.getType())) {
return generateXMLCollectionReferenceMapping(property, descriptor, namespaceInfo, property.getActualType());
}
return generateXMLObjectReferenceMapping(property, descriptor, namespaceInfo, property.getType());
}
if (property.isXmlTransformation()) {
return generateTransformationMapping(property, descriptor, namespaceInfo);
}
if (property.isChoice()) {
if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
return generateChoiceCollectionMapping(property, descriptor, namespaceInfo);
}
return generateChoiceMapping(property, descriptor, namespaceInfo);
}
if (property.isInverseReference()) {
return generateInverseReferenceMapping(property, descriptor, namespaceInfo);
}
if (property.isReference()) {
return generateMappingForReferenceProperty(property, descriptor, namespaceInfo);
}
if (property.isAny()) {
if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
return generateAnyCollectionMapping(property, descriptor, namespaceInfo, property.isMixedContent());
}
return generateAnyObjectMapping(property, descriptor, namespaceInfo);
}
if (property.isMap()) {
if (property.isAnyAttribute()) {
return generateAnyAttributeMapping(property, descriptor, namespaceInfo);
}
return generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, null);
}
if (helper.isCollectionType(property.getType())) {
return generateCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo);
}
JavaClass referenceClass = property.getType();
String referenceClassName = referenceClass.getRawName();
if (referenceClass.isArray() && !referenceClassName.equals("byte[]")) {
JavaClass componentType = referenceClass.getComponentType();
TypeInfo reference = typeInfo.get(componentType.getName());
if (reference != null && reference.isEnumerationType()) {
return generateEnumCollectionMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
}
if (areEquals(componentType, Object.class)) {
CompositeCollectionMapping mapping = generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, null);
mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
return mapping;
}
if (reference != null || componentType.isArray()) {
if (property.isXmlIdRef() || property.isSetXmlJoinNodes()) {
return generateXMLCollectionReferenceMapping(property, descriptor, namespaceInfo, componentType);
}
return generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, componentType.getQualifiedName());
}
return generateDirectCollectionMapping(property, descriptor, namespaceInfo);
}
if (property.isXmlIdRef()) {
return generateXMLObjectReferenceMapping(property, descriptor, namespaceInfo, referenceClass);
}
TypeInfo reference = typeInfo.get(referenceClass.getQualifiedName());
if (reference != null) {
if (reference.isEnumerationType()) {
return generateDirectEnumerationMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) reference);
}
if (property.isXmlLocation()) {
CompositeObjectMapping locationMapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, referenceClass.getQualifiedName());
reference.getDescriptor().setInstantiationPolicy(new NullInstantiationPolicy());
descriptor.setLocationAccessor(locationMapping.getAttributeAccessor());
return locationMapping;
} else {
return generateCompositeObjectMapping(property, descriptor, namespaceInfo, referenceClass.getQualifiedName());
}
}
if (property.isSwaAttachmentRef() || property.isMtomAttachment()) {
return generateBinaryMapping(property, descriptor, namespaceInfo);
}
if (referenceClass.getQualifiedName().equals(OBJECT_CLASS_NAME) && !property.isAttribute() || property.isTyped()) {
CompositeObjectMapping coMapping = generateCompositeObjectMapping(property, descriptor, namespaceInfo, null);
coMapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
return coMapping;
}
if (property.isXmlLocation()) {
return null;
}
return generateDirectMapping(property, descriptor, namespaceInfo);
}
use of org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateMappingForType.
private Mapping generateMappingForType(JavaClass theType, String attributeName) {
Mapping mapping;
boolean typeIsObject = theType.getRawName().equals(OBJECT_CLASS_NAME);
TypeInfo info = typeInfo.get(theType.getQualifiedName());
if ((info != null && !(info.isEnumerationType())) || typeIsObject) {
mapping = new XMLCompositeObjectMapping();
mapping.setAttributeName(attributeName);
((CompositeObjectMapping) mapping).setXPath(attributeName);
if (typeIsObject) {
((CompositeObjectMapping) mapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
setTypedTextField((Field) mapping.getField());
} else {
((CompositeObjectMapping) mapping).setReferenceClassName(theType.getQualifiedName());
}
} else if (theType.isArray() || helper.isCollectionType(theType)) {
DirectCollectionMapping directCollectionMapping;
mapping = directCollectionMapping = new XMLCompositeDirectCollectionMapping();
initializeXMLContainerMapping(directCollectionMapping, theType.isArray());
directCollectionMapping.setAttributeName(attributeName);
if (theType.isArray()) {
JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(directCollectionMapping.getAttributeAccessor(), directCollectionMapping.getContainerPolicy(), helper.getClassLoader());
String componentClassName = theType.getComponentType().getQualifiedName();
if (theType.getComponentType().isPrimitive()) {
Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(componentClassName);
accessor.setComponentClass(primitiveClass);
directCollectionMapping.setAttributeAccessor(accessor);
Class<Object> declaredClass = XMLConversionManager.getObjectClass(primitiveClass);
directCollectionMapping.setAttributeElementClass(declaredClass);
} else {
accessor.setComponentClassName(componentClassName);
directCollectionMapping.setAttributeAccessor(accessor);
JavaClass componentType = theType.getComponentType();
Class<?> declaredClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> PrivilegedAccessHelper.getClassForName(componentType.getRawName(), false, helper.getClassLoader()), (ex) -> JAXBException.classNotFoundException(componentType.getRawName()));
directCollectionMapping.setAttributeElementClass(declaredClass);
}
} else if (helper.isCollectionType(theType)) {
Collection args = theType.getActualTypeArguments();
if (args.size() > 0) {
JavaClass itemType = (JavaClass) args.iterator().next();
Class<?> declaredClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> PrivilegedAccessHelper.getClassForName(itemType.getRawName(), false, helper.getClassLoader()), (ex) -> JAXBException.classNotFoundException(itemType.getRawName()));
if (declaredClass != String.class) {
directCollectionMapping.setAttributeElementClass(declaredClass);
}
}
}
theType = containerClassImpl(theType);
directCollectionMapping.useCollectionClassName(theType.getRawName());
directCollectionMapping.setXPath(attributeName + TXT);
} else {
mapping = new XMLDirectMapping();
mapping.setAttributeName(attributeName);
((DirectMapping) mapping).setNullValueMarshalled(true);
((DirectMapping) mapping).setXPath(attributeName + TXT);
QName schemaType = userDefinedSchemaTypes.get(theType.getQualifiedName());
if (schemaType == null) {
schemaType = helper.getXMLToJavaTypeMap().get(theType.getName());
}
((Field) mapping.getField()).setSchemaType(schemaType);
if (info != null && info.isEnumerationType()) {
((DirectMapping) mapping).setConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) info));
}
}
return mapping;
}
use of org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateCompositeObjectMapping.
public CompositeObjectMapping generateCompositeObjectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, String referenceClassName) {
CompositeObjectMapping mapping = new XMLCompositeObjectMapping();
initializeXMLMapping((XMLMapping) mapping, property);
// if the XPath is set (via xml-path) use it; otherwise figure it out
mapping.setField(getXPathForField(property, namespaceInfo, false, false));
// handle null policy set via xml metadata
if (property.isSetNullPolicy()) {
mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
} else {
NullPolicy nullPolicy = (NullPolicy) mapping.getNullPolicy();
nullPolicy.setSetPerformedForAbsentNode(false);
if (property.isNillable()) {
nullPolicy.setNullRepresentedByXsiNil(true);
nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
}
}
if (referenceClassName == null) {
setTypedTextField((Field) mapping.getField());
String defaultValue = property.getDefaultValue();
if (null != defaultValue) {
mapping.setConverter(new DefaultElementConverter(defaultValue));
}
} else {
mapping.setReferenceClassName(referenceClassName);
}
if (property.isTransientType()) {
mapping.setReferenceClassName(Constants.UNKNOWN_OR_TRANSIENT_CLASS);
}
if (property.isRequired()) {
((Field) mapping.getField()).setRequired(true);
}
return mapping;
}
use of org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping in project eclipselink by eclipse-ee4j.
the class XMLContext method applyORMMetadata.
/**
* ADVANCED:
* Adjust the OXM metadata to take into account ORM mapping metadata,
*/
public void applyORMMetadata(AbstractSession ormSession) {
// Iterate over the ORM descriptors and check for matching OXM descriptors
Iterator<ClassDescriptor> ormDescriptors = ormSession.getDescriptors().values().iterator();
while (ormDescriptors.hasNext()) {
ClassDescriptor ormDescriptor = ormDescriptors.next();
Class<?> javaClass = ormDescriptor.getJavaClass();
AbstractSession oxmSession = null;
try {
oxmSession = this.getSession(javaClass);
} catch (XMLMarshalException ex) {
// if we couldn't find a session for this class, we
// don't have an OX descriptor for it.
}
if (oxmSession != null) {
ClassDescriptor oxmDescriptor = oxmSession.getDescriptor(javaClass);
// If we have an oxmDescriptor for this ORM descriptor, iterate over
// mappings, and update the required OXM mappings attribute accessors
Iterator<DatabaseMapping> ormMappings = ormDescriptor.getMappings().iterator();
while (ormMappings.hasNext()) {
DatabaseMapping ormMapping = ormMappings.next();
Mapping oxmMapping = (Mapping) oxmDescriptor.getMappingForAttributeName(ormMapping.getAttributeName());
if (oxmMapping != null) {
CoreAttributeAccessor oxmAccessor = oxmMapping.getAttributeAccessor();
OrmAttributeAccessor newAccessor = new OrmAttributeAccessor(ormMapping.getAttributeAccessor(), oxmAccessor);
if (ormMapping.isOneToOneMapping() && ((OneToOneMapping) ormMapping).usesIndirection()) {
newAccessor.setValueHolderProperty(true);
}
newAccessor.setChangeTracking(ormDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
oxmMapping.setAttributeAccessor(newAccessor);
// check to see if we need to deal with containerAccessor
CoreAttributeAccessor containerAccessor = null;
Class<?> containerClass = null;
if (oxmMapping.isAbstractCompositeObjectMapping()) {
containerAccessor = ((CompositeObjectMapping) oxmMapping).getInverseReferenceMapping().getAttributeAccessor();
containerClass = ((CompositeObjectMapping) oxmMapping).getReferenceClass();
} else if (oxmMapping.isAbstractCompositeCollectionMapping()) {
containerAccessor = ((CompositeCollectionMapping) oxmMapping).getInverseReferenceMapping().getAttributeAccessor();
containerClass = ((CompositeCollectionMapping) oxmMapping).getReferenceClass();
}
if (containerAccessor != null) {
ClassDescriptor containerDescriptor = ormSession.getDescriptor(containerClass);
if (containerDescriptor != null) {
DatabaseMapping ormContainerMapping = containerDescriptor.getMappingForAttributeName(containerAccessor.getAttributeName());
if (ormContainerMapping != null) {
// Check for indirection on the container mapping
OrmAttributeAccessor ormAccessor = new OrmAttributeAccessor(ormContainerMapping.getAttributeAccessor(), containerAccessor);
ormAccessor.setChangeTracking(containerDescriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
ormAccessor.setValueHolderProperty(ormContainerMapping instanceof OneToOneMapping && ((OneToOneMapping) ormContainerMapping).usesIndirection());
if (oxmMapping.isAbstractCompositeObjectMapping()) {
((CompositeObjectMapping) oxmMapping).getInverseReferenceMapping().setAttributeAccessor(ormAccessor);
} else if (oxmMapping.isAbstractCompositeCollectionMapping()) {
((CompositeCollectionMapping) oxmMapping).getInverseReferenceMapping().setAttributeAccessor(ormAccessor);
}
}
}
}
}
}
Iterator<DatabaseMapping> oxmMappingsIterator = oxmDescriptor.getMappings().iterator();
while (oxmMappingsIterator.hasNext()) {
// iterate over the oxm mappings. Any ReferenceMappings that have a
// collection as a backpointer, check to see if the container policy
// needs to be matched with the ORM project
DatabaseMapping nextMapping = oxmMappingsIterator.next();
if (nextMapping instanceof ObjectReferenceMapping) {
ObjectReferenceMapping refMapping = (ObjectReferenceMapping) nextMapping;
if (refMapping.getInverseReferenceMapping().getAttributeAccessor() != null && refMapping.getInverseReferenceMapping().getContainerPolicy() != null) {
ClassDescriptor refDescriptor = ormSession.getClassDescriptor(refMapping.getReferenceClass());
if (refDescriptor != null) {
DatabaseMapping backpointerMapping = refDescriptor.getMappingForAttributeName(refMapping.getInverseReferenceMapping().getAttributeName());
if (backpointerMapping != null && backpointerMapping.isCollectionMapping()) {
refMapping.getInverseReferenceMapping().getContainerPolicy().setContainerClass(backpointerMapping.getContainerPolicy().getContainerClass());
}
}
}
}
}
}
}
}
use of org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping 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