use of org.eclipse.persistence.oxm.mappings.converters.XMLConverter in project eclipselink by eclipse-ee4j.
the class XMLCompositeObjectMapping method valueFromRow.
public Object valueFromRow(Object fieldValue, XMLRecord nestedRow, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException {
// pretty sure we can ignore inheritance here:
Object toReturn = null;
// Use local descriptor - not the instance variable on DatabaseMapping
ClassDescriptor aDescriptor = getReferenceDescriptor((DOMRecord) nestedRow);
if (aDescriptor == null) {
if ((getKeepAsElementPolicy() == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (getKeepAsElementPolicy() == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
XMLPlatformFactory.getInstance().getXMLPlatform().namespaceQualifyFragment((Element) nestedRow.getDOM());
toReturn = nestedRow.getDOM();
toReturn = convertDataValueToObjectValue(toReturn, executionSession, nestedRow.getUnmarshaller());
// try simple case
toReturn = convertToSimpleTypeIfPresent(toReturn, nestedRow, executionSession);
return toReturn;
} else {
NodeList children = nestedRow.getDOM().getChildNodes();
for (int i = 0, childrenLength = children.getLength(); i < childrenLength; i++) {
Node nextNode = children.item(i);
if (nextNode.getNodeType() == Node.ELEMENT_NODE) {
// complex child
String type = ((Element) nestedRow.getDOM()).getAttributeNS(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
if (type != null && type.length() > 0) {
throw XMLMarshalException.unknownXsiTypeValue(type, (CompositeObjectMapping) this);
} else {
throw XMLMarshalException.noDescriptorFound((CompositeObjectMapping) this);
}
}
}
// simple case
toReturn = convertToSimpleTypeIfPresent(toReturn, nestedRow, executionSession);
}
} else {
if (aDescriptor.hasInheritance()) {
Class<?> classValue = aDescriptor.getInheritancePolicy().classFromRow(nestedRow, executionSession);
if (classValue == null) {
// no xsi:type attribute - look for type indicator on the field
QName leafElementType = ((XMLField) getField()).getLeafElementType();
if (leafElementType != null) {
XPathQName leafElementXPathQName = new XPathQName(leafElementType, nestedRow.isNamespaceAware());
Object indicator = aDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementXPathQName);
if (indicator != null) {
classValue = (Class) indicator;
}
}
}
if (classValue != null) {
aDescriptor = this.getReferenceDescriptor(classValue, executionSession);
} else {
// use the reference descriptor - make sure it is non-abstract
if (Modifier.isAbstract(aDescriptor.getJavaClass().getModifiers())) {
// throw an exception
throw DescriptorException.missingClassIndicatorField((org.eclipse.persistence.internal.oxm.record.XMLRecord) nestedRow, aDescriptor.getInheritancePolicy().getDescriptor());
}
}
}
ObjectBuilder objectBuilder = aDescriptor.getObjectBuilder();
toReturn = buildCompositeObject(objectBuilder, nestedRow, sourceQuery, null, joinManager, executionSession);
}
if (getConverter() != null) {
if (getConverter() instanceof XMLConverter) {
toReturn = ((XMLConverter) getConverter()).convertDataValueToObjectValue(toReturn, executionSession, nestedRow.getUnmarshaller());
} else {
toReturn = getConverter().convertDataValueToObjectValue(toReturn, executionSession);
}
}
return toReturn;
}
use of org.eclipse.persistence.oxm.mappings.converters.XMLConverter in project eclipselink by eclipse-ee4j.
the class XMLChoiceCollectionMapping method initialize.
@Override
public void initialize(AbstractSession session) throws DescriptorException {
super.initialize(session);
if (this.converter != null) {
this.converter.initialize(this, session);
}
ArrayList<XMLMapping> mappingsList = new ArrayList<>();
mappingsList.addAll(getChoiceElementMappings().values());
for (XMLMapping next : getChoiceElementMappingsByClass().values()) {
if (!(mappingsList.contains(next))) {
mappingsList.add(next);
}
}
if (isAny) {
// anyMapping = new XMLAnyCollectionMapping();
mappingsList.add(anyMapping);
}
Iterator<XMLMapping> mappings = mappingsList.iterator();
while (mappings.hasNext()) {
DatabaseMapping nextMapping = (DatabaseMapping) mappings.next();
Converter converter = null;
if (fieldsToConverters != null) {
converter = fieldsToConverters.get(nextMapping.getField());
}
if (nextMapping.isAbstractCompositeDirectCollectionMapping()) {
XMLConversionManager xmlConversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager();
QName schemaType = xmlConversionManager.schemaType(((AbstractCompositeDirectCollectionMapping) nextMapping).getAttributeElementClass());
if (schemaType != null) {
((XMLField) nextMapping.getField()).setSchemaType(schemaType);
}
if (converter != null) {
((AbstractCompositeDirectCollectionMapping) nextMapping).setValueConverter(converter);
}
((AbstractCompositeDirectCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
} else if (nextMapping.isAbstractCompositeCollectionMapping()) {
if (converter != null) {
((AbstractCompositeCollectionMapping) nextMapping).setConverter(converter);
}
((AbstractCompositeCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
} else if (nextMapping instanceof XMLBinaryDataCollectionMapping) {
((XMLBinaryDataCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
if (converter != null) {
((XMLBinaryDataCollectionMapping) nextMapping).setValueConverter(converter);
}
} else if (nextMapping instanceof XMLAnyCollectionMapping) {
((XMLAnyCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
if (converter != null && converter instanceof XMLConverter) {
((XMLAnyCollectionMapping) nextMapping).setConverter((XMLConverter) converter);
}
} else {
((XMLCollectionReferenceMapping) nextMapping).setContainerPolicy(getContainerPolicy());
((XMLCollectionReferenceMapping) nextMapping).setReuseContainer(true);
}
nextMapping.initialize(session);
}
}
use of org.eclipse.persistence.oxm.mappings.converters.XMLConverter in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateAnyObjectMapping.
public AnyObjectMapping generateAnyObjectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
AnyObjectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, XMLConverter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, UnmarshalKeepAsElementPolicy, XMLUnmarshaller, XMLRecord> mapping = new XMLAnyObjectMapping();
initializeXMLMapping((XMLMapping) mapping, property);
// if the XPath is set (via xml-path) use it
if (property.getXmlPath() != null) {
mapping.setField(new XMLField(property.getXmlPath()));
}
Class<?> declaredType = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(property.getActualType().getQualifiedName(), helper.getClassLoader());
JAXBElementRootConverter jaxbElementRootConverter = new JAXBElementRootConverter(declaredType);
mapping.setConverter(jaxbElementRootConverter);
if (property.getDomHandlerClassName() != null) {
jaxbElementRootConverter.setNestedConverter(new DomHandlerConverter(property.getDomHandlerClassName()));
}
if (property.isLax()) {
mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
} else {
mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT);
}
if (property.isMixedContent()) {
mapping.setMixedContent(true);
} else {
mapping.setUseXMLRoot(true);
}
return mapping;
}
Aggregations