Object valueToWrite = getValueToWrite(value, parent, record, field, includeField, session);
record.add(field, valueToWrite);
}
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery query, AbstractSession executionSession) {
ContainerPolicy cp = this.getContainerPolicy();
Object fieldValue = row.getValues(this.getField());
if (fieldValue == null) {
return cp.containerInstance();
}
Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue);
if (fieldValues == null) {
return cp.containerInstance();
}
Object 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;
record.setSession(executionSession);
if ((unmarshaller.getAttachmentUnmarshaller() != null) && unmarshaller.getAttachmentUnmarshaller().isXOPPackage() && !this.isSwaRef() && !this.shouldInlineBinaryData()) {
//look for the include element:
String xpath = "";
// 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 + ":" + INCLUDE + "/@href";
XMLField field = new XMLField(xpath);
field.setNamespaceResolver(tempResolver);
String includeValue = (String) record.get(field);
if (element != null) {
if ((getCollectionContentType() == ClassConstants.ABYTE) || (getCollectionContentType() == ClassConstants.APBYTE)) {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsByteArray(includeValue);
} else {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(includeValue);
}
}
} else if ((unmarshaller.getAttachmentUnmarshaller() != null) && isSwaRef()) {
String refValue = (String) record.get("text()");
if (refValue != null) {
fieldValue = unmarshaller.getAttachmentUnmarshaller().getAttachmentAsDataHandler(refValue);
}
} else {
fieldValue = record.get("text()");
//should be a base64 string
fieldValue = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(fieldValue);
}
}
Object attributeValue = fieldValue;
if (getValueConverter() != null) {
if (getValueConverter() instanceof XMLConverter) {
attributeValue = ((XMLConverter) getValueConverter()).convertDataValueToObjectValue(fieldValue, executionSession, unmarshaller);
} else {
attributeValue = getValueConverter().convertDataValueToObjectValue(fieldValue, executionSession);
}
}
if (collectionContentType != null) {
attributeValue = XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(attributeValue, collectionContentType, executionSession);
}
cp.addInto(attributeValue, result, query.getSession());
//return attributeValue;
}
return result;
}