private Object getValue(Object value, UnmarshalRecord unmarshalRecord) { if(converter instanceof XMLConverter) { return ((XMLConverter) converter).convertDataValueToObjectValue(value, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller()); } return converter.convertDataValueToObjectValue(value, unmarshalRecord.getSession()); }
public XMLTransformationRecord(String rootName, UnmarshalRecord owner) { super(rootName); owningRecord = owner; session = owner.getSession(); resolver = new NamespaceResolver(); initializeNamespaceMaps(); } public String resolveNamespacePrefix(String prefix) {
public Object getObjectValueFromDataHandler(DataHandler handler, Class cls) { return XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(handler, cls, record.getSession()); }
public void addAttributeValue(UnmarshalRecord unmarshalRecord, ContainerValue containerValue, Object value, Object collection) { containerValue.getContainerPolicy().addInto(value, collection, unmarshalRecord.getSession()); }
/** * Handle attribute operation. Here we will create and populate an * org.eclipse.persistence.internal.oxm.Reference instance to be used during * the mapping resolution stage. In particular, the primary key value * for this element will be added to the Reference object's map of * target primary key values - based on the target key field name. Note * that if a reference already exists for the xmlCollectionReferenceMapping's * source object instance, we will simply add to the target pk value list. * The Reference object is stored on the ReferenceResolver associated with * the UnmarshalRecord's session. */ public void attribute(UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) { if (value != null) { Object realValue = xmlField.convertValueBasedOnSchemaType(value, (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(),unmarshalRecord); // build a reference which will be resolved after unmarshalling is complete xmlCollectionReferenceMapping.buildReference(unmarshalRecord, xmlField, realValue, unmarshalRecord.getSession()); } }
/** * Handle attribute operation. Here we will create and populate an * org.eclipse.persistence.internal.oxm.Reference instance to be used during * the mapping resolution stage. In particular, the primary key value * for this element will be added to the Reference object's list of * target primary key values. Note that if a reference already exists * for the xmlObjectReferenceMapping's source object instance, we will * simply add to the target pk value list. The Reference object will * is stored on the ReferenceResolver associated with the UnmarshalRecord's * session. */ public void attribute(UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) { if (value != null) { Object realValue = xmlField.convertValueBasedOnSchemaType(value, (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(),unmarshalRecord); // build a reference which will be resolved after unmarshalling is complete xmlObjectReferenceMapping.buildReference(unmarshalRecord, xmlField, realValue, unmarshalRecord.getSession()); } }
public void attribute(UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) { DirectMapContainerPolicy cp = (DirectMapContainerPolicy) xmlAnyAttributeMapping.getContainerPolicy(); Object containerInstance = unmarshalRecord.getContainerInstance(this); boolean includeAttribute = true; if(!xmlAnyAttributeMapping.isNamespaceDeclarationIncluded() && XMLConstants.XMLNS_URL.equals(namespaceURI)){ includeAttribute = false; }else if(!xmlAnyAttributeMapping.isSchemaInstanceIncluded() && XMLConstants.SCHEMA_INSTANCE_URL.equals(namespaceURI)){ includeAttribute = false; } if(includeAttribute){ QName key = new QName(namespaceURI, localName); cp.addInto(key, value, containerInstance, unmarshalRecord.getSession()); } }
public void attribute(UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) { unmarshalRecord.removeNullCapableValue(this); XMLField xmlField = (XMLField) xmlDirectMapping.getField(); Object realValue = xmlField.convertValueBasedOnSchemaType(value, (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(), unmarshalRecord); // Perform operations on the object based on the null policy Object convertedValue = xmlDirectMapping.getAttributeValue(realValue, unmarshalRecord.getSession(), unmarshalRecord); xmlDirectMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), convertedValue); }
protected void endElementProcessText(UnmarshalRecord unmarshalRecord, Converter converter, XPathFragment xPathFragment, Object collection) { Object value = unmarshalRecord.getStringBuffer().toString(); if(converter != null) { if(converter instanceof XMLConverter){ value = ((XMLConverter)converter).convertDataValueToObjectValue(value, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller()); }else{ value = converter.convertDataValueToObjectValue(value, unmarshalRecord.getSession()); } } unmarshalRecord.resetStringBuffer(); if (!XMLConstants.EMPTY_STRING.equals(value)) { QName qname = unmarshalRecord.getTypeQName(); if (qname != null) { Class theClass = (Class) XMLConversionManager.getDefaultXMLTypes().get(qname); if (theClass != null) { value = ((XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager()).convertObject(value, theClass, qname); } } setOrAddAttributeValue(unmarshalRecord, value, xPathFragment, collection); } }
protected void setOrAddAttributeValueForKeepAsElement(SAXFragmentBuilder builder, XMLMapping mapping, XMLConverter converter, UnmarshalRecord unmarshalRecord, boolean isCollection, Object collection) { Object node = builder.getNodes().remove(builder.getNodes().size() -1); if (converter != null) { node = converter.convertDataValueToObjectValue(node, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller()); } if (isCollection) { if(collection != null){ unmarshalRecord.addAttributeValue((ContainerValue) this, node, collection); }else{ unmarshalRecord.addAttributeValue((ContainerValue) this, node); } } else { unmarshalRecord.setAttributeValue(node, (DatabaseMapping) mapping); } }
@Override protected void processEmptyElement() throws SAXException { // Remove original startElement event as it has been precluded by the nodeValue call below getEvents().remove(0); // Prerequisite: We know that (nullPolicy.isNullRepresentedByEmptyNode() || nullPolicy.isNullRepresentedByXsiNil()) is true // Null: Set the object to null on the node value if we are empty with inrben=true nodeValue.setNullValue(getParent().getCurrentObject(), getParent().getSession()); executeEvents(getParent()); }
/** * @override * @param xPathFragment * @param unmarshalRecord * @param atts */ public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) { if (xmlField.getLastXPathFragment().isAttribute()) { if (!this.xmlCollectionReferenceMapping.usesSingleNode()) { String namespaceURI = xmlField.getLastXPathFragment().getNamespaceURI(); String value; if (namespaceURI == null) { value = atts.getValue(xmlField.getLastXPathFragment().getLocalName()); } else { value = atts.getValue(namespaceURI, xmlField.getLastXPathFragment().getLocalName()); } xmlCollectionReferenceMapping.buildReference(unmarshalRecord, xmlField, value, unmarshalRecord.getSession()); return true; } } return true; }
public void attribute(UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) { XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(); Object objectValue = xmlField.convertValueBasedOnSchemaType(value, xmlConversionManager, unmarshalRecord); // PUT VALUE INTO A RECORD KEYED ON XMLFIELD if (null == unmarshalRecord.getTransformationRecord()) { unmarshalRecord.setTransformationRecord(new XMLTransformationRecord("ROOT", unmarshalRecord)); } unmarshalRecord.getTransformationRecord().put(xmlField, objectValue); }
public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) { XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField(); if (xmlField.getLastXPathFragment().nameIsText()) { String type = atts.getValue(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE); if (null != type) { String namespaceURI = null; int colonIndex = type.indexOf(XMLConstants.COLON); if (colonIndex > -1) { String prefix = type.substring(0, colonIndex); namespaceURI = unmarshalRecord.resolveNamespacePrefix(prefix); type = type.substring(colonIndex + 1); } unmarshalRecord.setTypeQName(new QName(namespaceURI, type)); } if (xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByXsiNil() && xmlCompositeDirectCollectionMapping.getNullPolicy().valueIsNull(atts)) { getContainerPolicy().addInto(null, unmarshalRecord.getContainerInstance(this), unmarshalRecord.getSession()); } } else if (xmlField.getLastXPathFragment().isAttribute()) { if (!this.xmlCompositeDirectCollectionMapping.usesSingleNode()) { String namespaceURI = xmlField.getLastXPathFragment().getNamespaceURI(); if (namespaceURI == null) { namespaceURI = XMLConstants.EMPTY_STRING; } String value = atts.getValue(namespaceURI, xmlField.getLastXPathFragment().getLocalName()); Object collection = unmarshalRecord.getContainerInstance(this); addUnmarshalValue(unmarshalRecord, value, collection); } } return true; }
/** * Handle endElement operation. Here we will create and populate an * org.eclipse.persistence.internal.oxm.Reference instance to be used during * the mapping resolution stage. In particular, the primary key value * for this element will be added to the Reference object's list of * target primary key values. Note that if a reference already exists * for the xmlObjectReferenceMapping's source object instance, we will * simply add to the target pk value list. The Reference object will * is stored on the ReferenceResolver associated with the UnmarshalRecord's * session. */ public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) { if (!xmlField.getLastXPathFragment().nameIsText()) { return; } Object value = unmarshalRecord.getStringBuffer().toString(); unmarshalRecord.resetStringBuffer(); XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(); if (unmarshalRecord.getTypeQName() != null) { Class typeClass = xmlField.getJavaClass(unmarshalRecord.getTypeQName()); value = xmlConversionManager.convertObject(value, typeClass, unmarshalRecord.getTypeQName()); } else { value = xmlField.convertValueBasedOnSchemaType(value, xmlConversionManager, unmarshalRecord); } // build a reference which will be resolved after unmarshalling is complete xmlObjectReferenceMapping.buildReference(unmarshalRecord, xmlField, value, unmarshalRecord.getSession()); }
private void addUnmarshalValue(UnmarshalRecord unmarshalRecord, Object value, Object collection) { if (null == value) { return; } if (xmlCompositeDirectCollectionMapping.getNullPolicy().isNullRepresentedByXsiNil() && xmlCompositeDirectCollectionMapping.getNullPolicy().valueIsNull(unmarshalRecord.getAttributes())) { return; } if ((!isWhitespaceAware() && XMLConstants.EMPTY_STRING.equals(value))) { return; } XMLField xmlField = (XMLField) xmlCompositeDirectCollectionMapping.getField(); XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(); if (unmarshalRecord.getTypeQName() != null) { Class typeClass = xmlField.getJavaClass(unmarshalRecord.getTypeQName()); value = xmlConversionManager.convertObject(value, typeClass, unmarshalRecord.getTypeQName()); } else { value = xmlField.convertValueBasedOnSchemaType(value, xmlConversionManager, unmarshalRecord); } if (xmlCompositeDirectCollectionMapping.hasValueConverter()) { if (xmlCompositeDirectCollectionMapping.getValueConverter() instanceof XMLConverter) { value = ((XMLConverter) xmlCompositeDirectCollectionMapping.getValueConverter()).convertDataValueToObjectValue(value, unmarshalRecord.getSession(), unmarshalRecord.getUnmarshaller()); } else { value = xmlCompositeDirectCollectionMapping.getValueConverter().convertDataValueToObjectValue(value, unmarshalRecord.getSession()); } } unmarshalRecord.addAttributeValue(this, value, collection); }
/** * Handle endElement operation. Here we will create and populate an * org.eclipse.persistence.internal.oxm.Reference instance to be used during * the mapping resolution stage. In particular, the primary key value * for this element will be added to the Reference object's map of * target primary key values - based on the target key field name. Note * that if a reference already exists for the xmlCollectionReferenceMapping's * source object instance, we will simply add to the target pk value list. * The Reference object is stored on the ReferenceResolver associated with * the UnmarshalRecord's session. */ public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) { if (!xmlField.getLastXPathFragment().nameIsText()) { return; } Object value = unmarshalRecord.getStringBuffer().toString(); unmarshalRecord.resetStringBuffer(); XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(); if (unmarshalRecord.getTypeQName() != null) { Class typeClass = xmlField.getJavaClass(unmarshalRecord.getTypeQName()); value = xmlConversionManager.convertObject(value, typeClass, unmarshalRecord.getTypeQName()); } else { value = xmlField.convertValueBasedOnSchemaType(value, xmlConversionManager, unmarshalRecord); } // build a reference which will be resolved after unmarshalling is complete xmlCollectionReferenceMapping.buildReference(unmarshalRecord, xmlField, value, unmarshalRecord.getSession()); }
/** * Handle swaRef and inline attribute cases. */ public void attribute(UnmarshalRecord unmarshalRecord, String URI, String localName, String value) { unmarshalRecord.removeNullCapableValue(this); XMLField xmlField = (XMLField) xmlBinaryDataMapping.getField(); XPathFragment lastFragment = xmlField.getLastXPathFragment(); Object fieldValue = null; if (xmlBinaryDataMapping.isSwaRef()) { if (unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller() != null) { if (xmlBinaryDataMapping.getAttributeClassification() == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) { fieldValue = unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller().getAttachmentAsDataHandler(value); } else { fieldValue = unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller().getAttachmentAsByteArray(value); } xmlBinaryDataMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(fieldValue, xmlBinaryDataMapping.getAttributeClassification(), unmarshalRecord.getSession())); } } else { // value should be base64 binary string fieldValue = ((XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager()).convertSchemaBase64ToByteArray(value); xmlBinaryDataMapping.setAttributeValueInObject(unmarshalRecord.getCurrentObject(), XMLBinaryDataHelper.getXMLBinaryDataHelper().convertObject(fieldValue, xmlBinaryDataMapping.getAttributeClassification(), unmarshalRecord.getSession())); } }
public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) { unmarshalRecord.removeNullCapableValue(this); XMLField xmlField = (XMLField) xmlDirectMapping.getField(); if (!xmlField.getLastXPathFragment().nameIsText()) { return; } Object value; if(unmarshalRecord.getStringBuffer().length() == 0) { value = this.getMapping().getNullValue(); } else { value = unmarshalRecord.getStringBuffer().toString(); } unmarshalRecord.resetStringBuffer(); XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(); if (unmarshalRecord.getTypeQName() != null) { Class typeClass = xmlField.getJavaClass(unmarshalRecord.getTypeQName()); value = xmlConversionManager.convertObject(value, typeClass, unmarshalRecord.getTypeQName()); } else { value = xmlField.convertValueBasedOnSchemaType(value, xmlConversionManager,unmarshalRecord); } Object convertedValue = xmlDirectMapping.getAttributeValue(value, unmarshalRecord.getSession(), unmarshalRecord); unmarshalRecord.setAttributeValue(convertedValue, xmlDirectMapping); }
public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) { Object value = unmarshalRecord.getStringBuffer().toString(); boolean isCDATA = unmarshalRecord.isBufferCDATA(); unmarshalRecord.resetStringBuffer(); XMLField toWrite = xmlField; if(xmlField.isCDATA() != isCDATA) { toWrite = new XMLField(xmlField.getName()); toWrite.setNamespaceResolver(xmlField.getNamespaceResolver()); toWrite.setIsCDATA(isCDATA); } //xmlField.setIsCDATA(isCDATA); XMLConversionManager xmlConversionManager = (XMLConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(); if (unmarshalRecord.getTypeQName() != null) { Class typeClass = xmlField.getJavaClass(unmarshalRecord.getTypeQName()); value = xmlConversionManager.convertObject(value, typeClass, unmarshalRecord.getTypeQName()); } else { value = xmlField.convertValueBasedOnSchemaType(value, xmlConversionManager, unmarshalRecord); } // PUT VALUE INTO A RECORD KEYED ON XMLFIELD if (null == unmarshalRecord.getTransformationRecord()) { unmarshalRecord.setTransformationRecord(new XMLTransformationRecord("ROOT", unmarshalRecord)); } unmarshalRecord.getTransformationRecord().put(toWrite, value); } }