use of org.eclipse.persistence.core.queries.CoreAttributeItem in project eclipselink by eclipse-ee4j.
the class XMLRelationshipMappingNodeValue method processChild.
// Protected to public
public void processChild(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts, Descriptor xmlDescriptor, Mapping mapping) throws SAXException {
if (xmlDescriptor == null) {
// Use the DescriptorNotFoundContentHandler to "look ahead" and determine if this is a simple or complex element
// if it is complex the exception should be thrown
DescriptorNotFoundContentHandler handler = new DescriptorNotFoundContentHandler(unmarshalRecord, mapping);
String qnameString = xPathFragment.getLocalName();
if (xPathFragment.getPrefix() != null) {
qnameString = xPathFragment.getPrefix() + Constants.COLON + qnameString;
}
handler.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), qnameString, atts);
XMLReader xmlReader = unmarshalRecord.getXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.setLexicalHandler(handler);
return;
}
if (xmlDescriptor.hasInheritance()) {
unmarshalRecord.setAttributes(atts);
CoreAbstractSession session = unmarshalRecord.getSession();
Class<?> classValue = ((ObjectBuilder) xmlDescriptor.getObjectBuilder()).classFromRow(unmarshalRecord, session);
if (classValue == null) {
// no xsi:type attribute - look for type indicator on the default root element
XPathQName leafElementType = unmarshalRecord.getLeafElementType();
// if we have a user-set type, try to get the class from the inheritance policy
if (leafElementType != null) {
Object indicator = xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(leafElementType);
if (indicator != null) {
classValue = (Class) indicator;
}
}
// if xsi:type is overriden by JSON_TYPE_ATTRIBUTE_NAME unmarshall property
if (classValue == null && unmarshalRecord.getUnmarshaller().isApplicationJSON() && unmarshalRecord.getUnmarshaller().getJsonTypeConfiguration().getJsonTypeAttributeName() != null && atts.getValue(unmarshalRecord.getUnmarshaller().getJsonTypeConfiguration().getJsonTypeAttributeName()) != null) {
QName qname = new QName(xmlDescriptor.getSchemaReference().getSchemaContextAsQName().getNamespaceURI(), atts.getValue(unmarshalRecord.getUnmarshaller().getJsonTypeConfiguration().getJsonTypeAttributeName()));
classValue = (Class) xmlDescriptor.getInheritancePolicy().getClassIndicatorMapping().get(qname);
}
}
if (classValue != null) {
xmlDescriptor = (Descriptor) session.getDescriptor(classValue);
} else {
// on the mapping - make sure it is non-abstract
if (Modifier.isAbstract(xmlDescriptor.getJavaClass().getModifiers())) {
// need to throw an exception here
throw DescriptorException.missingClassIndicatorField(unmarshalRecord, (org.eclipse.persistence.oxm.XMLDescriptor) xmlDescriptor.getInheritancePolicy().getDescriptor());
}
}
}
ObjectBuilder targetObjectBuilder = (ObjectBuilder) xmlDescriptor.getObjectBuilder();
CoreAttributeGroup group = unmarshalRecord.getUnmarshalAttributeGroup();
CoreAttributeGroup nestedGroup = null;
if (group == XMLRecord.DEFAULT_ATTRIBUTE_GROUP) {
nestedGroup = group;
}
if (nestedGroup == null) {
CoreAttributeItem item = group.getItem(getMapping().getAttributeName());
nestedGroup = item.getGroup(xmlDescriptor.getJavaClass());
if (nestedGroup == null) {
if (item.getGroup() == null) {
nestedGroup = XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
} else {
nestedGroup = item.getGroup();
}
}
}
UnmarshalRecord childRecord = unmarshalRecord.getChildUnmarshalRecord(targetObjectBuilder);
childRecord.setAttributes(atts);
childRecord.startDocument();
childRecord.initializeRecord(null);
childRecord.setUnmarshalAttributeGroup(nestedGroup);
childRecord.startElement(xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), xPathFragment.getShortName(), atts);
XMLReader xmlReader = unmarshalRecord.getXMLReader();
xmlReader.setContentHandler(childRecord);
xmlReader.setLexicalHandler(childRecord);
}
use of org.eclipse.persistence.core.queries.CoreAttributeItem in project eclipselink by eclipse-ee4j.
the class XMLCompositeCollectionMappingNodeValue method marshalSingleValue.
@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
Marshaller marshaller = marshalRecord.getMarshaller();
// convert the value - if necessary
boolean isNil = false;
if (value instanceof Root) {
isNil = ((Root) value).nil;
value = ((Root) value).getObject();
}
value = xmlCompositeCollectionMapping.convertObjectValueToDataValue(value, session, marshaller);
if (null == value) {
return xmlCompositeCollectionMapping.getNullPolicy().compositeObjectMarshal(xPathFragment, marshalRecord, object, session, namespaceResolver);
}
Descriptor descriptor = (Descriptor) xmlCompositeCollectionMapping.getReferenceDescriptor();
if (descriptor == null) {
descriptor = (Descriptor) session.getDescriptor(value.getClass());
} else if (descriptor.hasInheritance()) {
Class<?> objectValueClass = value.getClass();
if (!(objectValueClass == descriptor.getJavaClass())) {
descriptor = (Descriptor) session.getDescriptor(objectValueClass);
}
}
UnmarshalKeepAsElementPolicy keepAsElementPolicy = xmlCompositeCollectionMapping.getKeepAsElementPolicy();
if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && value instanceof org.w3c.dom.Node) {
marshalRecord.node((org.w3c.dom.Node) value, marshalRecord.getNamespaceResolver());
return true;
}
if (descriptor != null) {
marshalRecord.beforeContainmentMarshal(value);
ObjectBuilder objectBuilder = (ObjectBuilder) descriptor.getObjectBuilder();
CoreAttributeGroup group = marshalRecord.getCurrentAttributeGroup();
CoreAttributeGroup nestedGroup = XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
CoreAttributeItem item = group.getItem(getMapping().getAttributeName());
if (item != null) {
if (item.getGroups() != null) {
nestedGroup = item.getGroup(descriptor.getJavaClass());
}
if (nestedGroup == null) {
nestedGroup = item.getGroup() == null ? XMLRecord.DEFAULT_ATTRIBUTE_GROUP : item.getGroup();
}
}
marshalRecord.pushAttributeGroup(nestedGroup);
xPathNode.startElement(marshalRecord, xPathFragment, object, session, namespaceResolver, objectBuilder, value);
if (isNil) {
marshalRecord.nilSimple(namespaceResolver);
}
List extraNamespaces = objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor, marshalRecord, session, true, false);
writeExtraNamespaces(extraNamespaces, marshalRecord, session);
marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor, (Descriptor) xmlCompositeCollectionMapping.getReferenceDescriptor(), (Field) xmlCompositeCollectionMapping.getField(), false);
objectBuilder.buildRow(marshalRecord, value, session, marshaller, xPathFragment);
marshalRecord.afterContainmentMarshal(object, value);
marshalRecord.popAttributeGroup();
marshalRecord.endElement(xPathFragment, namespaceResolver);
marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces, session);
} else {
if (Constants.UNKNOWN_OR_TRANSIENT_CLASS.equals(xmlCompositeCollectionMapping.getReferenceClassName())) {
throw XMLMarshalException.descriptorNotFoundInProject(value.getClass().getName());
}
xPathNode.startElement(marshalRecord, xPathFragment, object, session, namespaceResolver, null, value);
QName schemaType = ((Field) xmlCompositeCollectionMapping.getField()).getSchemaTypeForValue(value, session);
updateNamespaces(schemaType, marshalRecord, ((Field) xmlCompositeCollectionMapping.getField()));
marshalRecord.characters(schemaType, value, null, false);
marshalRecord.endElement(xPathFragment, namespaceResolver);
}
return true;
}
use of org.eclipse.persistence.core.queries.CoreAttributeItem in project eclipselink by eclipse-ee4j.
the class XMLAnyCollectionMappingNodeValue method pushAttributeGroup.
private void pushAttributeGroup(MarshalRecord marshalRecord, Descriptor descriptor, String attributeName) {
CoreAttributeGroup group = marshalRecord.getCurrentAttributeGroup();
CoreAttributeItem item = group.getItem(attributeName);
CoreAttributeGroup nestedGroup = XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
if (item != null) {
if (item.getGroups() != null) {
nestedGroup = item.getGroup(descriptor.getJavaClass());
}
if (nestedGroup == null) {
nestedGroup = item.getGroup() == null ? XMLRecord.DEFAULT_ATTRIBUTE_GROUP : item.getGroup();
}
}
marshalRecord.pushAttributeGroup(nestedGroup);
}
use of org.eclipse.persistence.core.queries.CoreAttributeItem in project eclipselink by eclipse-ee4j.
the class XMLCompositeObjectMappingNodeValue method marshalSingleValue.
@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object objectValue, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
boolean isNilFlag = isNil(objectValue);
objectValue = xmlCompositeObjectMapping.convertObjectValueToDataValue(objectValue, session, marshalRecord.getMarshaller());
if (null == objectValue) {
return xmlCompositeObjectMapping.getNullPolicy().compositeObjectMarshal(xPathFragment, marshalRecord, object, session, namespaceResolver);
}
XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
if (xPathFragment.hasAttribute) {
ObjectBuilder tob = (ObjectBuilder) xmlCompositeObjectMapping.getReferenceDescriptor().getObjectBuilder();
MappingNodeValue textMappingNodeValue = (MappingNodeValue) tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
Mapping textMapping = textMappingNodeValue.getMapping();
if (textMapping.isAbstractDirectMapping()) {
DirectMapping xmlDirectMapping = (DirectMapping) textMapping;
Object fieldValue = xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(objectValue, xmlDirectMapping.getField(), session), session, marshalRecord);
QName schemaType = ((Field) xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue, session);
if (fieldValue != null) {
marshalRecord.attribute(xPathFragment, namespaceResolver, fieldValue, schemaType);
} else {
XMLMarshalException ex = XMLMarshalException.nullValueNotAllowed(this.xmlCompositeObjectMapping.getAttributeName(), this.xmlCompositeObjectMapping.getDescriptor().getJavaClass().getName());
try {
marshalRecord.getMarshaller().getErrorHandler().warning(new SAXParseException(null, null, ex));
} catch (Exception saxException) {
throw ex;
}
}
marshalRecord.closeStartGroupingElements(groupingFragment);
return true;
} else {
return textMappingNodeValue.marshalSingleValue(xPathFragment, marshalRecord, objectValue, textMapping.getAttributeValueFromObject(objectValue), session, namespaceResolver, marshalContext);
}
}
boolean isSelfFragment = xPathFragment.isSelfFragment;
marshalRecord.closeStartGroupingElements(groupingFragment);
UnmarshalKeepAsElementPolicy keepAsElementPolicy = xmlCompositeObjectMapping.getKeepAsElementPolicy();
if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && objectValue instanceof Node) {
if (isSelfFragment) {
NodeList children = ((org.w3c.dom.Element) objectValue).getChildNodes();
for (int i = 0, childrenLength = children.getLength(); i < childrenLength; i++) {
Node next = children.item(i);
short nodeType = next.getNodeType();
if (nodeType == Node.ELEMENT_NODE) {
marshalRecord.node(next, marshalRecord.getNamespaceResolver());
return true;
} else if (nodeType == Node.TEXT_NODE) {
marshalRecord.characters(next.getNodeValue());
return true;
}
}
return false;
} else {
marshalRecord.node((Node) objectValue, marshalRecord.getNamespaceResolver());
return true;
}
}
Descriptor descriptor = (Descriptor) xmlCompositeObjectMapping.getReferenceDescriptor();
if (descriptor == null) {
descriptor = (Descriptor) session.getDescriptor(objectValue.getClass());
} else if (descriptor.hasInheritance()) {
Class<?> objectValueClass = objectValue.getClass();
if (!(objectValueClass == descriptor.getJavaClass())) {
descriptor = (Descriptor) session.getDescriptor(objectValueClass);
}
}
if (descriptor != null) {
marshalRecord.beforeContainmentMarshal(objectValue);
ObjectBuilder objectBuilder = (ObjectBuilder) descriptor.getObjectBuilder();
CoreAttributeGroup group = marshalRecord.getCurrentAttributeGroup();
CoreAttributeItem item = group.getItem(getMapping().getAttributeName());
CoreAttributeGroup nestedGroup = XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
if (item != null) {
if (item.getGroups() != null) {
nestedGroup = item.getGroup(descriptor.getJavaClass());
}
if (nestedGroup == null) {
nestedGroup = item.getGroup() == null ? XMLRecord.DEFAULT_ATTRIBUTE_GROUP : item.getGroup();
}
}
marshalRecord.pushAttributeGroup(nestedGroup);
if (!(isSelfFragment || xPathFragment.nameIsText)) {
xPathNode.startElement(marshalRecord, xPathFragment, object, session, namespaceResolver, objectBuilder, objectValue);
if (isNilFlag) {
marshalRecord.nilSimple(namespaceResolver);
}
}
List extraNamespaces = null;
if (marshalRecord.getNamespaceResolver() != null && descriptor.getNamespaceResolver() != null) {
for (String prefix : descriptor.getNamespaceResolver().getPrefixesToNamespaces().keySet()) {
if (!marshalRecord.getNamespaceResolver().hasPrefix(prefix)) {
marshalRecord.setEqualNamespaceResolvers(false);
break;
}
}
}
if (!marshalRecord.hasEqualNamespaceResolvers()) {
extraNamespaces = objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor, marshalRecord, session, true, false);
writeExtraNamespaces(extraNamespaces, marshalRecord, session);
}
if (!isSelfFragment) {
marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor, (Descriptor) xmlCompositeObjectMapping.getReferenceDescriptor(), (Field) xmlCompositeObjectMapping.getField(), false);
}
objectBuilder.buildRow(marshalRecord, objectValue, session, marshalRecord.getMarshaller(), xPathFragment);
marshalRecord.afterContainmentMarshal(object, objectValue);
marshalRecord.popAttributeGroup();
if (!(isSelfFragment || xPathFragment.nameIsText())) {
marshalRecord.endElement(xPathFragment, namespaceResolver);
}
marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces, session);
} else {
if (Constants.UNKNOWN_OR_TRANSIENT_CLASS.equals(xmlCompositeObjectMapping.getReferenceClassName())) {
throw XMLMarshalException.descriptorNotFoundInProject(objectValue.getClass().getName());
}
if (!(isSelfFragment || xPathFragment.nameIsText())) {
xPathNode.startElement(marshalRecord, xPathFragment, object, session, namespaceResolver, null, objectValue);
}
QName schemaType = ((Field) xmlCompositeObjectMapping.getField()).getSchemaTypeForValue(objectValue, session);
updateNamespaces(schemaType, marshalRecord, ((Field) xmlCompositeObjectMapping.getField()));
marshalRecord.characters(schemaType, objectValue, null, false);
if (!(isSelfFragment || xPathFragment.nameIsText())) {
marshalRecord.endElement(xPathFragment, namespaceResolver);
}
}
return true;
}
use of org.eclipse.persistence.core.queries.CoreAttributeItem in project eclipselink by eclipse-ee4j.
the class XMLAnyCollectionMappingNodeValue method marshalSimpleValue.
private void marshalSimpleValue(XPathFragment xmlRootFragment, MarshalRecord marshalRecord, Object originalValue, Object object, Object value, CoreAbstractSession session, NamespaceResolver namespaceResolver) {
QName qname = null;
if (xmlRootFragment != null) {
qname = ((Root) originalValue).getSchemaType();
setupFragment(((Root) originalValue), xmlRootFragment, marshalRecord);
CoreAttributeGroup group = marshalRecord.getCurrentAttributeGroup();
CoreAttributeItem item = group.getItem(getMapping().getAttributeName());
CoreAttributeGroup nestedGroup = XMLRecord.DEFAULT_ATTRIBUTE_GROUP;
if (item != null) {
if (item.getGroup() != null && null != xmlRootFragment.getLocalName()) {
CoreAttributeItem nestedItem = item.getGroup().getItem(xmlRootFragment.getLocalName());
if (null != nestedItem) {
nestedGroup = item.getGroup();
} else {
return;
}
}
}
getXPathNode().startElement(marshalRecord, xmlRootFragment, object, session, namespaceResolver, null, null);
updateNamespaces(qname, marshalRecord, null);
}
marshalRecord.characters(qname, value, null, false);
if (xmlRootFragment != null) {
marshalRecord.endElement(xmlRootFragment, namespaceResolver);
}
}
Aggregations