Search in sources :

Example 16 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLAnyCollectionMapping method valueFromRow.

@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
    XMLRecord record = (XMLRecord) row;
    if (getField() != null) {
        // Get the nested row represented by this field to build the collection from
        Object nested = record.get(getField());
        if (nested instanceof Vector) {
            nested = ((Vector) nested).firstElement();
        }
        if (!(nested instanceof XMLRecord)) {
            return null;
        }
        record = (XMLRecord) nested;
    }
    return buildObjectValuesFromDOMRecord((DOMRecord) record, executionSession, sourceQuery, joinManager);
}
Also used : XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) Vector(java.util.Vector)

Example 17 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLAnyObjectMapping method buildCompositeRow.

protected AbstractRecord buildCompositeRow(Object attributeValue, AbstractSession session, XMLDescriptor referenceDescriptor, AbstractRecord parentRow, DatabaseField field, Object originalObject, boolean wasXMLRoot) {
    String defaultRootElementString = null;
    if (referenceDescriptor != null) {
        defaultRootElementString = referenceDescriptor.getDefaultRootElement();
        if (!wasXMLRoot && defaultRootElementString == null) {
            throw XMLMarshalException.defaultRootElementNotSpecified((XMLDescriptor) descriptor);
        }
    }
    if ((field == null) && (referenceDescriptor != null) && (defaultRootElementString != null)) {
        field = referenceDescriptor.buildField(defaultRootElementString);
    }
    if ((field != null) && (referenceDescriptor != null)) {
        ((XMLRecord) parentRow).setLeafElementType(referenceDescriptor.getDefaultRootElementType());
        XMLObjectBuilder objectBuilder = (XMLObjectBuilder) referenceDescriptor.getObjectBuilder();
        XMLRecord child = (XMLRecord) objectBuilder.createRecordFor(attributeValue, (XMLField) field, (XMLRecord) parentRow, this);
        child.setNamespaceResolver(((XMLRecord) parentRow).getNamespaceResolver());
        objectBuilder.buildIntoNestedRow(child, originalObject, attributeValue, session, referenceDescriptor, (XMLField) field, wasXMLRoot);
        return child;
    }
    return null;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLObjectBuilder(org.eclipse.persistence.internal.oxm.XMLObjectBuilder) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 18 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLAnyObjectMapping method valueFromRow.

@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
    XMLRecord record = (XMLRecord) row;
    if (getField() != null) {
        // Get the nested row represented by this field to build the Object from
        Object nested = record.get(getField());
        if (nested instanceof Vector) {
            nested = ((Vector) nested).firstElement();
        }
        if (!(nested instanceof XMLRecord)) {
            return null;
        }
        record = (XMLRecord) nested;
    }
    return buildObjectValuesFromDOMRecord((DOMRecord) record, executionSession, sourceQuery, joinManager);
}
Also used : XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) Vector(java.util.Vector)

Example 19 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLBinaryDataCollectionMapping method valueFromRow.

@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) {
    ContainerPolicy cp = this.getContainerPolicy();
    Object fieldValue = row.getValues(this.getField());
    if (fieldValue == null) {
        if (reuseContainer) {
            Object currentObject = ((XMLRecord) row).getCurrentObject();
            Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
            return container != null ? container : cp.containerInstance();
        } else {
            return cp.containerInstance();
        }
    }
    Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue);
    if (fieldValues == null) {
        if (reuseContainer) {
            Object currentObject = ((XMLRecord) row).getCurrentObject();
            Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
            return container != null ? container : cp.containerInstance();
        } else {
            return cp.containerInstance();
        }
    }
    Object result = null;
    if (reuseContainer) {
        Object currentObject = ((XMLRecord) row).getCurrentObject();
        Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
        result = container != null ? container : cp.containerInstance();
    } else {
        result = cp.containerInstance(fieldValues.size());
    }
    for (Enumeration stream = fieldValues.elements(); stream.hasMoreElements(); ) {
        Object element = stream.nextElement();
        // PERF: Direct variable access.
        // Object value = row.get(field);
        // Object fieldValue = null;
        XMLUnmarshaller unmarshaller = ((XMLRecord) row).getUnmarshaller();
        if (element instanceof String) {
            if (this.isSwaRef() && (unmarshaller.getAttachmentUnmarshaller() != null)) {
                fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler((String) element);
            } else if (!this.isSwaRef()) {
                // should be base64
                byte[] bytes = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(element);
                fieldValue = bytes;
            }
        } else {
            // this was an element, so do the XOP/SWAREF/Inline binary cases for an element
            XMLRecord record = (XMLRecord) element;
            if (getNullPolicy().valueIsNull((Element) record.getDOM())) {
                fieldValue = null;
            } else {
                record.setSession(executionSession);
                if ((unmarshaller.getAttachmentUnmarshaller() != null) && unmarshaller.getAttachmentUnmarshaller().isXOPPackage() && !this.isSwaRef() && !this.shouldInlineBinaryData()) {
                    // look for the include element:
                    String xpath = XMLConstants.EMPTY_STRING;
                    // need a prefix for XOP
                    String prefix = null;
                    NamespaceResolver descriptorResolver = ((XMLDescriptor) getDescriptor()).getNamespaceResolver();
                    if (descriptorResolver != null) {
                        prefix = descriptorResolver.resolveNamespaceURI(XMLConstants.XOP_URL);
                    }
                    if (prefix == null) {
                        prefix = XMLConstants.XOP_PREFIX;
                    }
                    NamespaceResolver tempResolver = new NamespaceResolver();
                    tempResolver.put(prefix, XMLConstants.XOP_URL);
                    xpath = prefix + XMLConstants.COLON + INCLUDE + "/@href";
                    XMLField field = new XMLField(xpath);
                    field.setNamespaceResolver(tempResolver);
                    String includeValue = (String) record.get(field);
                    if (element != null && includeValue != null) {
                        if ((getAttributeElementClass() == ClassConstants.ABYTE) || (getAttributeElementClass() == ClassConstants.APBYTE)) {
                            fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray(includeValue);
                        } else {
                            fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(includeValue);
                        }
                    } else {
                        // If we didn't find the Include element, check for inline
                        fieldValue = record.get(XMLConstants.TEXT);
                        // should be a base64 string
                        fieldValue = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(fieldValue);
                    }
                } else if ((unmarshaller.getAttachmentUnmarshaller() != null) && isSwaRef()) {
                    String refValue = (String) record.get(XMLConstants.TEXT);
                    if (refValue != null) {
                        fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(refValue);
                    }
                } else {
                    fieldValue = record.get(XMLConstants.TEXT);
                    // should be a base64 string
                    fieldValue = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(fieldValue);
                }
            }
        }
        Object attributeValue = convertDataValueToObjectValue(fieldValue, executionSession, unmarshaller);
        cp.addInto(attributeValue, result, query.getSession());
    }
    return result;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Enumeration(java.util.Enumeration) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) Vector(java.util.Vector) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 20 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLCompositeCollectionMapping method buildObjectFromNestedRow.

public Object buildObjectFromNestedRow(AbstractRecord nestedRow, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected) {
    Object objectToAdd = null;
    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) ((DOMRecord) nestedRow).getDOM());
            objectToAdd = ((DOMRecord) nestedRow).getDOM();
            convertDataValueToObjectValue(objectToAdd, executionSession, ((XMLRecord) nestedRow).getUnmarshaller());
            // simple case
            objectToAdd = convertToSimpleTypeIfPresent(objectToAdd, nestedRow, executionSession);
        } else {
            NodeList children = ((DOMRecord) nestedRow).getDOM().getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                Node nextNode = children.item(i);
                if (nextNode.getNodeType() == Node.ELEMENT_NODE) {
                    // complex child
                    String type = ((Element) ((DOMRecord) 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, (Mapping) this);
                    } else {
                        throw XMLMarshalException.noDescriptorFound((Mapping) this);
                    }
                }
            }
            // simple case
            objectToAdd = convertToSimpleTypeIfPresent(objectToAdd, nestedRow, executionSession);
        }
    } else {
        if (aDescriptor.hasInheritance()) {
            Class<?> newElementClass = aDescriptor.getInheritancePolicy().classFromRow(nestedRow, executionSession);
            if (newElementClass == 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, ((XMLRecord) nestedRow).isNamespaceAware());
                    Object indicator = aDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementXPathQName);
                    if (indicator != null) {
                        newElementClass = (Class) indicator;
                    }
                }
            }
            if (newElementClass != null) {
                aDescriptor = this.getReferenceDescriptor(newElementClass, executionSession);
            } else {
                // use the reference descriptor -  make sure it is non-abstract
                if (Modifier.isAbstract(aDescriptor.getJavaClass().getModifiers())) {
                    // throw an exception
                    throw DescriptorException.missingClassIndicatorField(nestedRow, aDescriptor.getInheritancePolicy().getDescriptor());
                }
            }
        }
        // Object element
        objectToAdd = buildCompositeObject(aDescriptor, nestedRow, sourceQuery, null, joinManager, executionSession);
        objectToAdd = convertDataValueToObjectValue(objectToAdd, executionSession, ((XMLRecord) nestedRow).getUnmarshaller());
    }
    return objectToAdd;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) XPathQName(org.eclipse.persistence.internal.oxm.XPathQName) QName(javax.xml.namespace.QName) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) XPathQName(org.eclipse.persistence.internal.oxm.XPathQName) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Aggregations

XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)50 XMLField (org.eclipse.persistence.oxm.XMLField)19 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)16 DOMRecord (org.eclipse.persistence.oxm.record.DOMRecord)14 Element (org.w3c.dom.Element)11 Vector (java.util.Vector)10 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)10 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)8 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)7 XMLObjectBuilder (org.eclipse.persistence.internal.oxm.XMLObjectBuilder)7 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)6 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)6 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)6 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)6 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)6 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)6 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)6 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)6 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)6 Field (org.eclipse.persistence.internal.oxm.mappings.Field)5