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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations