use of org.eclipse.persistence.internal.oxm.NodeValue in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method initializeRecord.
@Override
public void initializeRecord(Mapping selfRecordMapping) throws SAXException {
try {
Descriptor xmlDescriptor = (Descriptor) treeObjectBuilder.getDescriptor();
if (xmlDescriptor.isSequencedObject()) {
unmarshalContext = new SequencedUnmarshalContext();
} else {
unmarshalContext = ObjectUnmarshalContext.getInstance();
}
currentObject = this.xmlReader.getCurrentObject(session, selfRecordMapping);
if (currentObject == null) {
currentObject = treeObjectBuilder.buildNewInstance();
}
if (xmlDescriptor.getLocationAccessor() != null && xmlReader.getLocator() != null) {
// Check to see if this Descriptor isLocationAware
// Store the snapshot of the current documentLocator
xmlLocation = new Locator2Impl(xmlReader.getLocator());
}
Object parentRecordCurrentObject = null;
if (null != this.parentRecord) {
parentRecordCurrentObject = parentRecord.getCurrentObject();
}
Unmarshaller.Listener xmlUnmarshalListener = unmarshaller.getUnmarshalListener();
if (null != xmlUnmarshalListener) {
if (null == this.parentRecord) {
xmlUnmarshalListener.beforeUnmarshal(currentObject, null);
} else {
xmlUnmarshalListener.beforeUnmarshal(currentObject, parentRecordCurrentObject);
}
}
if (null == parentRecord) {
this.xmlReader.newObjectEvent(currentObject, null, selfRecordMapping);
} else {
this.xmlReader.newObjectEvent(currentObject, parentRecordCurrentObject, selfRecordMapping);
}
List containerValues = treeObjectBuilder.getContainerValues();
if (null != containerValues) {
int containerSize = containerValues.size();
containerInstances = new Object[containerSize];
populatedContainerValues = new ArrayList(containerSize);
}
if (null != xPathNode.getSelfChildren()) {
int selfChildrenSize = xPathNode.getSelfChildren().size();
selfRecords = new ArrayList<>(selfChildrenSize);
for (int x = 0; x < selfChildrenSize; x++) {
NodeValue nv = xPathNode.getSelfChildren().get(x).getNodeValue();
if (null != nv) {
selfRecords.add(nv.buildSelfRecord(this, attributes));
}
}
}
} catch (EclipseLinkException e) {
if (null == xmlReader.getErrorHandler()) {
throw e;
} else {
SAXParseException saxParseException = new SAXParseException(null, getDocumentLocator(), e);
xmlReader.getErrorHandler().error(saxParseException);
}
}
}
use of org.eclipse.persistence.internal.oxm.NodeValue in project eclipselink by eclipse-ee4j.
the class XMLChoiceCollectionMapping method writeFromObjectIntoRow.
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) throws DescriptorException {
if (this.isReadOnly()) {
return;
}
Object attributeValue = getAttributeValueFromObject(object);
List<XMLEntry> nestedRows = new ArrayList<>();
XMLRecord record = (XMLRecord) row;
// First determine which Field is associated with each value:
if (null != attributeValue) {
ContainerPolicy cp = getContainerPolicy();
Object iterator = cp.iteratorFor(attributeValue);
if (null != iterator) {
while (cp.hasNext(iterator)) {
Object value = cp.next(iterator, session);
value = convertObjectValueToDataValue(value, session, record.getMarshaller());
NodeValue associatedNodeValue = null;
XMLField associatedField = null;
Object fieldValue = value;
if (value instanceof XMLRoot) {
XMLRoot rootValue = (XMLRoot) value;
String localName = rootValue.getLocalName();
String namespaceUri = rootValue.getNamespaceURI();
fieldValue = rootValue.getObject();
associatedField = getFieldForName(localName, namespaceUri);
if (associatedField == null) {
associatedField = getClassToFieldMappings().get(fieldValue.getClass());
}
} else {
associatedField = getClassToFieldMappings().get(value.getClass());
}
if (associatedField == null) {
// this may be a reference mapping
List<XMLField> sourceFields = classToSourceFieldsMappings.get(value.getClass());
if (sourceFields != null && sourceFields.size() > 0) {
DatabaseMapping xmlMapping = (DatabaseMapping) this.choiceElementMappings.get(sourceFields.get(0));
for (XMLField next : sourceFields) {
fieldValue = ((XMLCollectionReferenceMapping) xmlMapping).buildFieldValue(value, next, session);
XMLEntry entry = new XMLEntry();
entry.setValue(fieldValue);
entry.setXMLField(next);
nestedRows.add(entry);
}
}
} else {
DatabaseMapping xmlMapping = (DatabaseMapping) this.choiceElementMappings.get(associatedField);
if (xmlMapping.isAbstractCompositeCollectionMapping()) {
fieldValue = ((XMLCompositeCollectionMapping) xmlMapping).buildCompositeRow(fieldValue, session, row, writeType);
}
XMLEntry entry = new XMLEntry();
entry.setValue(fieldValue);
entry.setXMLField(associatedField);
nestedRows.add(entry);
}
}
}
}
row.put(getFields(), nestedRows);
}
use of org.eclipse.persistence.internal.oxm.NodeValue in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method endElement.
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
try {
if (null != selfRecords) {
for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
UnmarshalRecord selfRecord = selfRecords.get(x);
if (selfRecord != null) {
selfRecord.endElement(namespaceURI, localName, qName);
} else {
getFragmentBuilder().endSelfElement(namespaceURI, localName, qName);
}
}
}
if (-1 != unmappedLevel && unmappedLevel <= levelIndex) {
if (levelIndex == unmappedLevel) {
unmappedLevel = -1;
}
levelIndex--;
return;
}
NodeValue unmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
if (null != unmarshalNodeValue) {
boolean isIncludedInAttributeGroup = true;
if (unmarshalNodeValue.isMappingNodeValue()) {
Mapping mapping = ((MappingNodeValue) unmarshalNodeValue).getMapping();
isIncludedInAttributeGroup = this.unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName());
}
try {
if (isIncludedInAttributeGroup) {
unmarshalNodeValue.endElement(xPathFragment, this);
} else {
resetStringBuffer();
}
} catch (EclipseLinkException e) {
if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
throw e;
} else {
SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), getDocumentLocator(), e);
xmlReader.getErrorHandler().warning(saxParseException);
}
}
} else {
XPathNode textNode = xPathNode.getTextNode();
if (null != textNode && getStringBuffer().length() == 0) {
NodeValue textNodeUnmarshalNodeValue = textNode.getUnmarshalNodeValue();
if (textNode.isWhitespaceAware()) {
if (textNodeUnmarshalNodeValue.isMappingNodeValue()) {
Mapping mapping = ((MappingNodeValue) textNodeUnmarshalNodeValue).getMapping();
if (mapping.isAbstractDirectMapping() && isNil()) {
Object nullValue = ((DirectMapping) mapping).getNullValue();
if (!(Constants.EMPTY_STRING.equals(nullValue))) {
setAttributeValue(null, mapping);
this.removeNullCapableValue((NullCapableValue) textNodeUnmarshalNodeValue);
}
} else {
textNodeUnmarshalNodeValue.endElement(xPathFragment, this);
}
setNil(false);
}
} else {
// This means empty tag
if (textNodeUnmarshalNodeValue.isMappingNodeValue()) {
Mapping mapping = ((MappingNodeValue) textNodeUnmarshalNodeValue).getMapping();
if (mapping.isAbstractDirectMapping() && isNil()) {
Object nullValue = ((DirectMapping) mapping).getNullValue();
if (!(Constants.EMPTY_STRING.equals(nullValue))) {
setAttributeValue(null, mapping);
}
}
if (mapping.isAbstractDirectMapping() && !isNil() && ((DirectMapping) mapping).getNullPolicy().isNullRepresentedByXsiNil()) {
removeNullCapableValue((NullCapableValue) textNodeUnmarshalNodeValue);
}
}
}
}
}
XPathFragment xPathFragment = xPathNode.getXPathFragment();
if ((null != xPathFragment && xPathFragment.nameIsText()) || (xpathNodeIsMixedContent && xPathNode.getParent() != null)) {
xPathNode = xPathNode.getParent();
}
NodeValue xPathNodeUnmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
if (null != xPathNodeUnmarshalNodeValue && xPathNodeUnmarshalNodeValue.isContainerValue()) {
predictedNextXPathNode = xPathNode;
} else {
predictedNextXPathNode = xPathNode.getNextNode();
}
if (null != xPathNode.getParent()) {
xPathNode = xPathNode.getParent();
}
xpathNodeIsMixedContent = false;
unmarshalContext.endElement(this);
typeQName = null;
levelIndex--;
if (isNil() && levelIndex > 0) {
setNil(false);
}
if ((0 == levelIndex) && (null != parentRecord) && !isSelfRecord()) {
endDocument();
// don't endElement on, or pass control to, a 'self' parent
UnmarshalRecord pRec = parentRecord;
while (pRec.isSelfRecord()) {
pRec = pRec.getParentRecord();
}
pRec.endElement(namespaceURI, localName, qName);
xmlReader.setContentHandler(pRec);
xmlReader.setLexicalHandler(pRec);
}
} catch (EclipseLinkException e) {
if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
throw e;
} else {
Locator locator = xmlReader.getLocator();
SAXParseException saxParseException = new SAXParseException(null, getDocumentLocator(), e);
xmlReader.getErrorHandler().warning(saxParseException);
}
}
}
use of org.eclipse.persistence.internal.oxm.NodeValue in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method startElement.
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (currentObject == null) {
initializeRecord(atts);
}
XPathFragment xPathNodeXPathFragment = xPathNode.getXPathFragment();
if ((null != xPathNodeXPathFragment && xPathNodeXPathFragment.nameIsText()) || xpathNodeIsMixedContent) {
xpathNodeIsMixedContent = false;
NodeValue xPathNodeUnmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
if (null != xPathNodeUnmarshalNodeValue) {
boolean isIncludedInAttributeGroup = true;
if (xPathNodeUnmarshalNodeValue.isMappingNodeValue()) {
Mapping mapping = ((MappingNodeValue) xPathNodeUnmarshalNodeValue).getMapping();
isIncludedInAttributeGroup = this.unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName());
}
if (isIncludedInAttributeGroup) {
xPathNodeUnmarshalNodeValue.endElement(xPathFragment, this);
if (xPathNode.getParent() != null) {
xPathNode = xPathNode.getParent();
}
}
}
}
// schema locations etc.
if (null == rootElementName && null == rootElementLocalName && parentRecord == null) {
rootElementLocalName = localName;
rootElementName = qName;
rootElementNamespaceUri = namespaceURI;
schemaLocation = atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.SCHEMA_LOCATION);
noNamespaceSchemaLocation = atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.NO_NS_SCHEMA_LOCATION);
}
try {
if (null != selfRecords) {
for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
UnmarshalRecord selfRecord = selfRecords.get(x);
if (selfRecord == null) {
getFragmentBuilder().startElement(namespaceURI, localName, qName, atts);
} else {
selfRecord.startElement(namespaceURI, localName, qName, atts);
}
}
}
if (unmappedLevel != -1 && unmappedLevel <= levelIndex) {
levelIndex++;
return;
}
XPathNode node = null;
if (null != predictedNextXPathNode) {
XPathFragment xpf = predictedNextXPathNode.getXPathFragment();
if (null != xpf && xPathNode == predictedNextXPathNode.getParent() && (localName == xpf.getLocalName() || localName.equals(xpf.getLocalName())) && (namespaceURI == xpf.getNamespaceURI() || namespaceURI.equals(xpf.getNamespaceURI())) && null == xpf.getPredicate() && !xpf.containsIndex()) {
updateXPathFragment(qName, localName, namespaceURI);
node = predictedNextXPathNode;
}
}
if (null == node) {
node = getNonAttributeXPathNode(namespaceURI, localName, qName, atts);
}
if (null == node) {
NodeValue parentNodeValue = xPathNode.getUnmarshalNodeValue();
if ((null == xPathNode.getXPathFragment()) && (parentNodeValue != null)) {
XPathFragment parentFragment = new XPathFragment();
parentFragment.setNamespaceAware(isNamespaceAware());
if (namespaceURI != null && namespaceURI.length() == 0) {
parentFragment.setLocalName(qName);
parentFragment.setNamespaceURI(null);
} else {
parentFragment.setLocalName(localName);
parentFragment.setNamespaceURI(namespaceURI);
}
if (parentNodeValue.startElement(parentFragment, this, atts)) {
levelIndex++;
} else {
// UNMAPPED CONTENT
startUnmappedElement(namespaceURI, localName, qName, atts);
return;
}
} else {
// UNMAPPED CONTENT
levelIndex++;
startUnmappedElement(namespaceURI, localName, qName, atts);
return;
}
} else {
xPathNode = node;
unmarshalContext.startElement(this);
levelIndex++;
if (xmlReader.getMediaType().isApplicationXML()) {
String xsiNilValue = atts.getValue(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, Constants.SCHEMA_NIL_ATTRIBUTE);
if (xsiNilValue != null) {
setNil(xsiNilValue.equals(Constants.BOOLEAN_STRING_TRUE) || xsiNilValue.equals("1"));
}
}
if (node.getNullCapableValue() != null) {
getNullCapableValues().add(node.getNullCapableValue());
}
NodeValue nodeValue = node.getUnmarshalNodeValue();
if (null != nodeValue) {
boolean isIncludedInAttributeGroup = true;
if (nodeValue.isMappingNodeValue()) {
Mapping mapping = ((MappingNodeValue) nodeValue).getMapping();
isIncludedInAttributeGroup = this.unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName());
}
if (!isIncludedInAttributeGroup || !nodeValue.startElement(xPathFragment, this, atts)) {
// UNMAPPED CONTENT
startUnmappedElement(namespaceURI, localName, qName, atts);
return;
}
}
// Handle Attributes
if (xPathNode.getAttributeChildren() != null || xPathNode.getAnyAttributeNodeValue() != null || selfRecords != null) {
for (int i = 0, size = atts.getLength(); i < size; i++) {
String attNamespace = atts.getURI(i);
String attLocalName = atts.getLocalName(i);
String value = atts.getValue(i);
NodeValue attributeNodeValue = null;
// attributes
if ((attLocalName == null) || (attLocalName.length() == 0)) {
String qname = atts.getQName(i);
if (qname != null) {
int qnameLength = qname.length();
if (qnameLength > 0) {
int idx = qname.indexOf(Constants.COLON);
if (idx > 0) {
attLocalName = qname.substring(idx + 1, qnameLength);
String attPrefix = qname.substring(0, idx);
if (attPrefix.equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) {
attNamespace = javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
}
} else {
attLocalName = qname;
if (attLocalName.equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) {
attNamespace = javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
}
}
}
}
}
// Look for any Self-Mapping nodes that may want this attribute.
if (this.selfRecords != null) {
for (int j = 0; j < selfRecords.size(); j++) {
UnmarshalRecord nestedRecord = selfRecords.get(j);
if (nestedRecord != null) {
attributeNodeValue = nestedRecord.getAttributeChildNodeValue(attNamespace, attLocalName);
if (attributeNodeValue != null) {
attributeNodeValue.attribute(nestedRecord, attNamespace, attLocalName, value);
}
}
}
}
if (attributeNodeValue == null) {
attributeNodeValue = this.getAttributeChildNodeValue(attNamespace, attLocalName);
try {
if (attributeNodeValue != null) {
if (attributeNodeValue.isMappingNodeValue()) {
Mapping mapping = ((MappingNodeValue) attributeNodeValue).getMapping();
if (!unmarshalAttributeGroup.containsAttributeInternal(mapping.getAttributeName())) {
continue;
}
}
attributeNodeValue.attribute(this, attNamespace, attLocalName, value);
} else {
if (xPathNode.getAnyAttributeNodeValue() != null) {
xPathNode.getAnyAttributeNodeValue().attribute(this, attNamespace, attLocalName, value);
}
}
} catch (EclipseLinkException e) {
if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
throw e;
} else {
SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), getDocumentLocator(), e);
xmlReader.getErrorHandler().warning(saxParseException);
}
}
}
}
}
}
if (prefixesForFragment != null) {
this.prefixesForFragment.clear();
}
} catch (EclipseLinkException e) {
if ((null == xmlReader) || (null == xmlReader.getErrorHandler())) {
throw e;
} else {
SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), getDocumentLocator(), e);
xmlReader.getErrorHandler().error(saxParseException);
}
}
}
use of org.eclipse.persistence.internal.oxm.NodeValue in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method characters.
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (currentObject == null) {
return;
}
try {
int strBufferInitialLength = -1;
if (null != selfRecords) {
strBufferInitialLength = getStringBuffer().length();
for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
UnmarshalRecord selfRecord = selfRecords.get(x);
if (selfRecord != null) {
selfRecord.characters(ch, start, length);
} else {
getFragmentBuilder().characters(ch, start, length);
}
}
}
if (-1 != unmappedLevel && unmappedLevel <= levelIndex) {
return;
}
XPathNode textNode = xPathNode.getTextNode();
if (null == textNode) {
textNode = xPathNode.getAnyNode();
if (textNode != null) {
xpathNodeIsMixedContent = true;
this.xPathFragment.setLocalName(null);
this.xPathFragment.setNamespaceURI(null);
if (0 == length) {
return;
}
}
}
if (null != textNode) {
if (textNode.getUnmarshalNodeValue().isMixedContentNodeValue()) {
String tmpString = new String(ch, start, length);
if (!textNode.isWhitespaceAware() && tmpString.trim().length() == 0) {
return;
}
}
xPathNode = textNode;
unmarshalContext.characters(this);
}
NodeValue unmarshalNodeValue = xPathNode.getUnmarshalNodeValue();
if (null != unmarshalNodeValue && !unmarshalNodeValue.isWrapperNodeValue()) {
if (strBufferInitialLength == -1) {
getStringBuffer().append(ch, start, length);
} else {
StrBuffer strBuffer = getStringBuffer();
if (strBufferInitialLength == strBuffer.length()) {
strBuffer.append(ch, start, length);
}
}
}
} catch (EclipseLinkException e) {
if (null == xmlReader.getErrorHandler()) {
throw e;
} else {
SAXParseException saxParseException = new SAXParseException(null, getDocumentLocator(), e);
xmlReader.getErrorHandler().error(saxParseException);
}
}
}
Aggregations