use of org.eclipse.persistence.internal.oxm.XPathNode in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method getAttributeChildNodeValue.
@Override
public NodeValue getAttributeChildNodeValue(String namespace, String localName) {
Map<XPathFragment, XPathNode> attributeChildrenMap = xPathNode.getAttributeChildrenMap();
if (attributeChildrenMap != null) {
XPathNode resultNode;
xPathFragment.setLocalName(localName);
xPathFragment.setNamespaceURI(namespace);
if (unmarshaller.isCaseInsensitive()) {
resultNode = getNodeFromLookupTable(attributeChildrenMap, true);
} else {
resultNode = attributeChildrenMap.get(xPathFragment);
}
if (resultNode != null) {
return resultNode.getUnmarshalNodeValue();
}
}
return null;
}
use of org.eclipse.persistence.internal.oxm.XPathNode in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method endDocument.
@Override
public void endDocument() throws SAXException {
if (unmarshaller.getIDResolver() != null && parentRecord == null) {
unmarshaller.getIDResolver().endDocument();
}
if (null != selfRecords) {
for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
UnmarshalRecord selfRecord = selfRecords.get(x);
if (selfRecord != null) {
selfRecord.endDocument();
}
}
}
if (null != xPathNode.getSelfChildren()) {
int selfChildrenSize = xPathNode.getSelfChildren().size();
for (int x = 0; x < selfChildrenSize; x++) {
XPathNode selfNode = xPathNode.getSelfChildren().get(x);
if (null != selfNode.getNodeValue()) {
selfNode.getNodeValue().endSelfNodeValue(this, selfRecords.get(x), attributes);
}
}
}
CoreDescriptor xmlDescriptor = treeObjectBuilder.getDescriptor();
try {
// All populated containerValues need to be set on the object
if (null != populatedContainerValues) {
for (int populatedCVSize = populatedContainerValues.size(), i = populatedCVSize - 1; i >= 0; i--) {
ContainerValue cv = (populatedContainerValues.get(i));
cv.setContainerInstance(currentObject, getContainerInstance(cv, cv.isDefaultEmptyContainer()));
}
}
// Additionally if any containerValues are defaultEmptyContainerValues they need to be set to a new empty container
if (null != defaultEmptyContainerValues) {
for (int defaultEmptyCVSize = defaultEmptyContainerValues.size(), i = defaultEmptyCVSize - 1; i >= 0; i--) {
ContainerValue cv = (defaultEmptyContainerValues.get(i));
cv.setContainerInstance(currentObject, getContainerInstance(cv, cv.isDefaultEmptyContainer()));
}
}
// trigger the mapping.
if (null != nullCapableValues) {
for (int x = 0, nullValuesSize = nullCapableValues.size(); x < nullValuesSize; x++) {
nullCapableValues.get(x).setNullValue(currentObject, session);
}
}
// PROCESS TRANSFORMATION MAPPINGS
List<TransformationMapping> transformationMappings = treeObjectBuilder.getTransformationMappings();
if (null != transformationMappings) {
for (int x = 0, transformationMappingsSize = transformationMappings.size(); x < transformationMappingsSize; x++) {
TransformationMapping transformationMapping = transformationMappings.get(x);
transformationMapping.readFromRowIntoObject((XMLRecord) transformationRecord, currentObject, session, true);
}
}
Unmarshaller.Listener listener = unmarshaller.getUnmarshalListener();
if (listener != null) {
if (this.parentRecord != null) {
listener.afterUnmarshal(currentObject, parentRecord.getCurrentObject());
} else {
listener.afterUnmarshal(currentObject, null);
}
}
// HANDLE POST BUILD EVENTS
if (xmlDescriptor.hasEventManager()) {
CoreDescriptorEventManager eventManager = xmlDescriptor.getEventManager();
if (null != eventManager && eventManager.hasAnyEventListeners()) {
DescriptorEvent event = new DescriptorEvent(currentObject);
event.setSession((AbstractSession) session);
// this);
event.setRecord(null);
event.setEventCode(DescriptorEventManager.PostBuildEvent);
eventManager.executeEvent(event);
}
}
} catch (EclipseLinkException e) {
if (null == xmlReader.getErrorHandler()) {
throw e;
} else {
SAXParseException saxParseException = new SAXParseException(null, getDocumentLocator(), e);
xmlReader.getErrorHandler().error(saxParseException);
}
}
// if the object has any primary key fields set, add it to the cache
if (null != referenceResolver) {
if (null != xmlDescriptor) {
List primaryKeyFields = xmlDescriptor.getPrimaryKeyFields();
if (null != primaryKeyFields) {
int primaryKeyFieldsSize = primaryKeyFields.size();
if (primaryKeyFieldsSize > 0) {
CacheId pk = (CacheId) treeObjectBuilder.extractPrimaryKeyFromObject(currentObject, session);
for (int x = 0; x < primaryKeyFieldsSize; x++) {
Object value = pk.getPrimaryKey()[x];
if (null == value) {
Field pkField = (Field) xmlDescriptor.getPrimaryKeyFields().get(x);
pk.set(x, unmarshaller.getContext().getValueByXPath(currentObject, pkField.getXPath(), pkField.getNamespaceResolver(), Object.class));
}
}
referenceResolver.putValue(xmlDescriptor.getJavaClass(), pk, currentObject);
if (unmarshaller.getIDResolver() != null) {
try {
if (primaryKeyFieldsSize > 1) {
Map<String, Object> idWrapper = new HashMap<>();
for (int x = 0; x < primaryKeyFieldsSize; x++) {
String idName = (String) xmlDescriptor.getPrimaryKeyFieldNames().get(x);
Object idValue = pk.getPrimaryKey()[x];
idWrapper.put(idName, idValue);
}
unmarshaller.getIDResolver().bind(idWrapper, currentObject);
} else {
unmarshaller.getIDResolver().bind(pk.getPrimaryKey()[0], currentObject);
}
} catch (SAXException e) {
throw XMLMarshalException.unmarshalException(e);
}
}
}
}
}
}
if (null != parentRecord) {
reset();
}
// Set XML Location if applicable
if (xmlLocation != null && ((Descriptor) xmlDescriptor).getLocationAccessor() != null) {
((Descriptor) xmlDescriptor).getLocationAccessor().setAttributeValueInObject(getCurrentObject(), xmlLocation);
}
}
use of org.eclipse.persistence.internal.oxm.XPathNode in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method startUnmappedElement.
public void startUnmappedElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (xmlReader.getMediaType().isApplicationXML() && null == selfRecords && !isSelfRecord) {
ErrorHandler errorHandler = xmlReader.getErrorHandler();
// Bug 452584 - check if a warning exception should be generated when an unmapped element is encountered
if (null != errorHandler && unmarshaller.shouldWarnOnUnmappedElement()) {
StringBuilder messageBuilder = new StringBuilder("unexpected element (uri:\"");
if (null != namespaceURI) {
messageBuilder.append(namespaceURI);
}
messageBuilder.append("\", local:\"");
messageBuilder.append(localName);
messageBuilder.append("\"). Expected elements are ");
List<XPathNode> nonAttributeChildren = xPathNode.getNonAttributeChildren();
if (nonAttributeChildren == null || nonAttributeChildren.size() == 0) {
messageBuilder.append("(none)");
} else {
for (int x = 0, size = nonAttributeChildren.size(); x < size; x++) {
XPathFragment nonAttributeChildXPathFragment = nonAttributeChildren.get(x).getXPathFragment();
messageBuilder.append("<{");
String nonAttributeChildXPathFragmentNamespaceURI = nonAttributeChildXPathFragment.getNamespaceURI();
if (null != nonAttributeChildXPathFragmentNamespaceURI) {
messageBuilder.append(nonAttributeChildXPathFragmentNamespaceURI);
}
messageBuilder.append('}');
messageBuilder.append(nonAttributeChildXPathFragment.getLocalName());
messageBuilder.append('>');
if (x < size - 1) {
messageBuilder.append(',');
}
}
}
errorHandler.warning(new SAXParseException(messageBuilder.toString(), getDocumentLocator()));
}
}
if ((null != selfRecords) || (null == xmlReader) || isSelfRecord()) {
if (-1 == unmappedLevel) {
this.unmappedLevel = this.levelIndex;
}
return;
}
Class<?> unmappedContentHandlerClass = unmarshaller.getUnmappedContentHandlerClass();
UnmappedContentHandler unmappedContentHandler;
if (null == unmappedContentHandlerClass) {
unmappedContentHandler = DEFAULT_UNMAPPED_CONTENT_HANDLER;
} else {
try {
PrivilegedNewInstanceFromClass privilegedNewInstanceFromClass = new PrivilegedNewInstanceFromClass(unmappedContentHandlerClass);
unmappedContentHandler = (UnmappedContentHandler) privilegedNewInstanceFromClass.run();
} catch (ClassCastException e) {
throw XMLMarshalException.unmappedContentHandlerDoesntImplement(e, unmappedContentHandlerClass.getName());
} catch (IllegalAccessException e) {
throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e, unmappedContentHandlerClass.getName());
} catch (InstantiationException e) {
throw XMLMarshalException.errorInstantiatingUnmappedContentHandler(e, unmappedContentHandlerClass.getName());
}
}
UnmappedContentHandlerWrapper unmappedContentHandlerWrapper = new UnmappedContentHandlerWrapper(this, unmappedContentHandler);
unmappedContentHandlerWrapper.startElement(namespaceURI, localName, qName, atts);
xmlReader.setContentHandler(unmappedContentHandlerWrapper);
xmlReader.setLexicalHandler(unmappedContentHandlerWrapper);
}
use of org.eclipse.persistence.internal.oxm.XPathNode in project eclipselink by eclipse-ee4j.
the class MarshalRecord method openStartGroupingElements.
/**
* INTERNAL:
* Trigger that the grouping elements should be written. This is normally
* done when something like a mapping has a non-null value that is
* marshalled.
* @param namespaceResolver The NamespaceResolver can be used to resolve the
* namespace URI for the namespace prefix held by the XPathFragment (if
* required).
*/
@Override
public XPathFragment openStartGroupingElements(NamespaceResolver namespaceResolver) {
if (null == groupingElements) {
return null;
}
XPathFragment xPathFragment = null;
for (int x = 0, groupingElementsSize = groupingElements.size(); x < groupingElementsSize; x++) {
XPathNode xPathNode = groupingElements.get(x);
xPathFragment = xPathNode.getXPathFragment();
openStartElement(xPathFragment, namespaceResolver);
predicateAttribute(xPathFragment, namespaceResolver);
if (x != (groupingElementsSize - 1)) {
closeStartElement();
}
}
groupingElements = null;
return xPathFragment;
}
use of org.eclipse.persistence.internal.oxm.XPathNode in project eclipselink by eclipse-ee4j.
the class IsSetNullPolicy method xPathNode.
@Override
public void xPathNode(XPathNode xPathNode, NullCapableValue nullCapableValue) {
// isset optional only
if (!(isNullRepresentedByXsiNil() || marshalNullRepresentation == XMLNullRepresentationType.XSI_NIL)) {
if (xPathNode.getXPathFragment().isAttribute()) {
return;
}
}
// get the parent above the text() node
XPathNode parentNode = xPathNode.getParent();
parentNode.setNullCapableValue(nullCapableValue);
}
Aggregations