use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.
the class XMLObjectReferenceMappingNodeValue method marshalSingleValue.
@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object targetObject, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
Object fieldValue = xmlObjectReferenceMapping.buildFieldValue(targetObject, xmlField, session);
if (fieldValue == null) {
if (null != targetObject) {
Field fkField = (Field) xmlObjectReferenceMapping.getSourceToTargetKeyFieldAssociations().get(xmlField);
if (null == fkField) {
Descriptor targetDescriptor = (Descriptor) session.getDescriptor(targetObject);
fieldValue = marshalRecord.getMarshaller().getContext().getValueByXPath(targetObject, ((CoreField) targetDescriptor.getPrimaryKeyFields().get(0)).getName(), targetDescriptor.getNamespaceResolver(), Object.class);
} else {
fieldValue = marshalRecord.getMarshaller().getContext().getValueByXPath(targetObject, fkField.getXPath(), fkField.getNamespaceResolver(), Object.class);
}
}
if (null == fieldValue) {
return false;
}
}
QName schemaType = xmlField.getSchemaTypeForValue(fieldValue, session);
XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
if (xPathFragment != null && xPathFragment.isAttribute()) {
marshalRecord.attribute(xPathFragment, namespaceResolver, fieldValue, schemaType);
marshalRecord.closeStartGroupingElements(groupingFragment);
} else {
marshalRecord.closeStartGroupingElements(groupingFragment);
marshalRecord.characters(schemaType, fieldValue, null, false);
}
return true;
}
use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.
the class QNameInheritancePolicy method addClassIndicatorFieldToRow.
/**
* INTERNAL:
* Add abstract class indicator information to the database row. This is
* required when building a row for an insert or an update of a concrete child
* descriptor.
*/
@Override
public void addClassIndicatorFieldToRow(AbstractRecord databaseRow) {
if (hasClassExtractor()) {
return;
}
CoreField field = getClassIndicatorField();
Object value = getClassIndicatorValue();
if (usesXsiType) {
boolean namespaceAware = ((XMLRecord) databaseRow).isNamespaceAware() || ((XMLRecord) databaseRow).hasCustomNamespaceMapper();
if (value instanceof String) {
if (namespaceAware) {
if (((XMLRecord) databaseRow).getNamespaceSeparator() != Constants.COLON) {
value = ((String) value).replace(Constants.COLON, ((XMLRecord) databaseRow).getNamespaceSeparator());
}
} else {
int colonIndex = ((String) value).indexOf(Constants.COLON);
if (colonIndex > -1) {
value = ((String) value).substring(colonIndex + 1);
}
}
}
}
databaseRow.put(field, value);
}
use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.
the class MarshalRecord method add.
/**
* INTERNAL:
* Add the field-value pair to the document.
*/
@Override
public void add(CoreField key, Object value) {
if (null == value) {
return;
}
Field xmlField = convertToXMLField(key);
XPathFragment lastFragment = xmlField.getLastXPathFragment();
if (lastFragment.nameIsText()) {
characters(xmlField.getSchemaType(), value, null, xmlField.isCDATA());
} else if (lastFragment.isAttribute()) {
attribute(lastFragment, xmlField.getNamespaceResolver(), value, xmlField.getSchemaType());
} else {
element(lastFragment);
}
}
use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.
the class XMLChoiceObjectMappingNodeValue method marshalSingleValue.
@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
Class<?> valueClass = null;
if (value instanceof Root) {
Root root = (Root) value;
for (CoreField next : (List<CoreField>) this.xmlChoiceMapping.getFields()) {
XPathFragment fragment = ((Field) next).getXPathFragment();
while (fragment != null && !fragment.nameIsText) {
if (fragment.getNextFragment() == null || fragment.getHasText()) {
if (fragment.getLocalName().equals(root.getLocalName())) {
String fragUri = fragment.getNamespaceURI();
String namespaceUri = root.getNamespaceURI();
if ((namespaceUri == null && fragUri == null) || (namespaceUri != null && fragUri != null && namespaceUri.equals(fragUri))) {
if (next == this.xmlField) {
return this.choiceElementNodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
} else {
// If this root is associated with another field, then return and let that NodeValue handle it
return false;
}
}
}
}
fragment = fragment.getNextFragment();
}
}
valueClass = root.getObject().getClass();
}
if (value != null) {
if (valueClass == null) {
valueClass = value.getClass();
}
Field fieldForClass = null;
Class<?> theClass = valueClass;
while (theClass != null) {
fieldForClass = (Field) xmlChoiceMapping.getClassToFieldMappings().get(valueClass);
if (fieldForClass != null) {
break;
}
theClass = theClass.getSuperclass();
}
if (fieldForClass != null && fieldForClass.equals(this.xmlField)) {
if (this.choiceElementNodeValues != null) {
NodeValue nodeValue = this.choiceElementNodeValues.get(theClass);
if (nodeValue != null) {
return nodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
}
}
return this.choiceElementNodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
}
List<Field> sourceFields = null;
theClass = valueClass;
while (theClass != null) {
sourceFields = (List<Field>) xmlChoiceMapping.getClassToSourceFieldsMappings().get(theClass);
if (sourceFields != null) {
break;
}
theClass = theClass.getSuperclass();
}
if (sourceFields != null && sourceFields.contains(this.xmlField)) {
return this.choiceElementNodeValue.marshalSingleValue(xPathFragment, marshalRecord, object, value, session, namespaceResolver, marshalContext);
}
}
return false;
}
use of org.eclipse.persistence.internal.core.helper.CoreField in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method get.
@Override
public Object get(CoreField key) {
Field xmlField = this.convertToXMLField(key);
XPathFragment lastFragment = xmlField.getLastXPathFragment();
String namespaceURI = lastFragment.getNamespaceURI();
if (namespaceURI == null) {
NamespaceResolver namespaceResolver = xmlField.getNamespaceResolver();
namespaceURI = Constants.EMPTY_STRING;
if (null != namespaceResolver && !(lastFragment.isAttribute() && lastFragment.getPrefix() == null)) {
namespaceURI = namespaceResolver.resolveNamespacePrefix(lastFragment.getPrefix());
if (null == namespaceURI) {
namespaceURI = Constants.EMPTY_STRING;
}
}
}
if (isNamespaceAware()) {
return attributes.getValue(namespaceURI, lastFragment.getLocalName());
}
return attributes.getValue(lastFragment.getLocalName());
}
Aggregations