protected QName buildQNameFromString(String stringValue, XMLRecord record){ int index = stringValue.lastIndexOf(XMLConstants.COLON); if(index > -1) { String prefix = stringValue.substring(0, index); String localName = stringValue.substring(index + 1); String namespaceURI = record.resolveNamespacePrefix(prefix); return new QName(namespaceURI, localName, prefix); } else { String namespaceURI = record.resolveNamespacePrefix(XMLConstants.EMPTY_STRING); if(namespaceURI == null){ namespaceURI = record.resolveNamespacePrefix(null); } return new QName(namespaceURI, stringValue); } }
public void writeSingleValue(Object value, Object parent, XMLRecord record, AbstractSession session) { Object element = convertObjectValueToDataValue(value, session, record.getMarshaller()); record.add(this.getField(), element); }
/** * INTERNAL: * Clone the row and its values. */ public DOMRecord clone() { DOMRecord clone = (DOMRecord)super.clone(); if (clone != null) { clone.setDOM((Element)dom.cloneNode(true)); } return clone; }
public void configureNestedRow(AbstractRecord parent, AbstractRecord child) { XMLRecord parentRecord = (XMLRecord) parent; XMLRecord childRecord = (XMLRecord) child; childRecord.setUnmarshaller(parentRecord.getUnmarshaller()); childRecord.setOwningObject(parentRecord.getCurrentObject()); }
public AbstractRecord createRecordFor(Object attributeValue, XMLField xmlField, XMLRecord parentRecord, XMLMapping mapping) { DocumentPreservationPolicy policy = parentRecord.getDocPresPolicy(); Element newNode = null; if(policy != null) { newNode = (Element)policy.getNodeForObject(attributeValue); } if(newNode == null) { newNode = XPathEngine.getInstance().createUnownedElement(parentRecord.getDOM(), xmlField); if(xmlField.isSelfField()) { policy.addObjectToCache(attributeValue, newNode, mapping); } else { policy.addObjectToCache(attributeValue, newNode); } } XMLRecord nestedRecord = new DOMRecord(newNode); nestedRecord.setMarshaller(parentRecord.getMarshaller()); nestedRecord.setLeafElementType(parentRecord.getLeafElementType()); parentRecord.setLeafElementType(null); nestedRecord.setDocPresPolicy(policy); return nestedRecord; }
/** * Build the nested row into the parent dom. */ public AbstractRecord buildRow(Object object, AbstractSession session, DatabaseField xmlField, XMLRecord parentRecord, boolean addXsiType) { if (isXmlDescriptor() && ((XMLDescriptor)getDescriptor()).shouldPreserveDocument()) { Vector pk = extractPrimaryKeyFromObject(object, session); if ((pk == null) || (pk.size() == 0)) { pk = new Vector(); pk.addElement(new WeakObjectWrapper(object)); } CacheKey cacheKey = session.getIdentityMapAccessorInstance().getCacheKeyForObject(pk, getDescriptor().getJavaClass(), getDescriptor()); if ((cacheKey != null) && (cacheKey.getRecord() != null)) { XMLRecord nestedRecord = (XMLRecord)cacheKey.getRecord(); nestedRecord.setMarshaller(parentRecord.getMarshaller()); nestedRecord.setLeafElementType(parentRecord.getLeafElementType()); parentRecord.setLeafElementType(null); return buildIntoNestedRow(nestedRecord, object, session, addXsiType); } } Element newNode = XPathEngine.getInstance().createUnownedElement(parentRecord.getDOM(), (XMLField)xmlField); XMLRecord nestedRecord = new DOMRecord(newNode); nestedRecord.setNamespaceResolver(parentRecord.getNamespaceResolver()); nestedRecord.setMarshaller(parentRecord.getMarshaller()); nestedRecord.setLeafElementType(parentRecord.getLeafElementType()); parentRecord.setLeafElementType(null); return buildIntoNestedRow(nestedRecord, object, session, addXsiType); }
AbstractSession session = context.getSession(descriptor); if (xmlRow != null) { isRootDocumentFragment = (xmlRow.getDOM().getNodeType() == Node.DOCUMENT_FRAGMENT_NODE); xmlRow.setMarshaller(this); if (this.attachmentMarshaller != null) { xmlRow.setXOPPackage(this.attachmentMarshaller.isXOPPackage()); ((Element) xmlRow.getDOM()).setAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, javax.xml.XMLConstants.XMLNS_ATTRIBUTE + XMLConstants.COLON + xmlRootPrefix, xmlRootUri); copyNamespaces(resolver, xmlRow.getNamespaceResolver()); document = xmlRow.getDocument(); object = ((Root) object).getObject(); xmlRow.setSession(objectSession); xmlRow.addXsiTypeAndClassIndicatorIfRequired(descriptor, null, null, originalObject, object, isXMLRoot, true); xmlRow.setMarshaller(this); if (shouldCallSetAttributeNS && !isRootDocumentFragment) { ((Element) xmlRow.getDOM()).setAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, javax.xml.XMLConstants.XMLNS_ATTRIBUTE + XMLConstants.COLON + XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); document = xmlRow.getDocument();
public AbstractRecord createRecordFor(Object attributeValue, Field xmlField, XMLRecord parentRecord, Mapping mapping) { DocumentPreservationPolicy policy = parentRecord.getDocPresPolicy(); Element newNode = null; if(policy != null) { newNode = (Element)policy.getNodeForObject(attributeValue); } if(newNode == null) { newNode = XPathEngine.getInstance().createUnownedElement(parentRecord.getDOM(), xmlField); if(policy !=null ){ if(xmlField.isSelfField()) { policy.addObjectToCache(attributeValue, newNode, mapping); } else { policy.addObjectToCache(attributeValue, newNode); } } } DOMRecord nestedRecord = new DOMRecord(newNode); nestedRecord.setMarshaller(parentRecord.getMarshaller()); nestedRecord.setLeafElementType(parentRecord.getLeafElementType()); parentRecord.setLeafElementType((XPathQName)null); nestedRecord.setDocPresPolicy(policy); nestedRecord.setXOPPackage(parentRecord.isXOPPackage()); nestedRecord.setReferenceResolver(((DOMRecord) parentRecord).getReferenceResolver()); return nestedRecord; }
((XMLRecord) rowFromDatabase).setSession(session); if (hasClassExtractor() || shouldUseClassNameAsIndicator()) { return super.classFromRow(rowFromDatabase, session); boolean namespaceAware = ((XMLRecord) rowFromDatabase).isNamespaceAware(); String indicatorValue = (String)indicator; int index = -1; if(namespaceAware){ index = indicatorValue.indexOf(((XMLRecord)rowFromDatabase).getNamespaceSeparator()); String uri = ((XMLRecord)rowFromDatabase).resolveNamespacePrefix(null); if (uri == null && ((XMLRecord)rowFromDatabase).getNamespaceResolver() != null) { uri = ((XMLRecord)rowFromDatabase).getNamespaceResolver().getDefaultNamespaceURI(); String prefix = indicatorValue.substring(0, index); String localPart = indicatorValue.substring(index + 1); String uri = ((XMLRecord)rowFromDatabase).resolveNamespacePrefix(prefix); if (uri != null) { XPathQName qname = new XPathQName(uri, localPart, namespaceAware);
if (fieldValue == null) { if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); return container != null ? container : cp.containerInstance(); if (fieldValues == null) { if (reuseContainer) { Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); return container != null ? container : cp.containerInstance(); Object currentObject = ((XMLRecord) row).getCurrentObject(); Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject); result = container != null ? container : cp.containerInstance(); XMLUnmarshaller unmarshaller = ((XMLRecord) row).getUnmarshaller(); if (element instanceof String) { if (this.isSwaRef() && (unmarshaller.getAttachmentUnmarshaller() != null)) { if (getNullPolicy().valueIsNull((Element) record.getDOM())) { fieldValue = null; record.setSession(executionSession); XMLField field = new XMLField(xpath); field.setNamespaceResolver(tempResolver); String includeValue = (String) record.get(field); if (element != null && includeValue != null) {
public void writeSingleValue(Object value, Object parent, XMLRecord record, AbstractSession session) { Object attributeValue = convertObjectValueToDataValue(value, session, record.getMarshaller()); org.w3c.dom.Document doc = record.getDocument(); Node root = record.getDOM(); NodeList children = ((Node) attributeValue).getChildNodes(); for(int i=0,childrenLength=children.getLength();i<childrenLength; i++){ }else{ record.put(this.getField(), attributeValue); record.put(this.getField(), fieldValue);
public void writeSingleValue(Object attributeValue, Object parent, XMLRecord record, AbstractSession session) { XMLMarshaller marshaller = record.getMarshaller(); attributeValue = convertObjectValueToDataValue(attributeValue, session, record.getMarshaller()); XMLField field = (XMLField) getField(); if (field.getLastXPathFragment().isAttribute()) { record.put(field, value); } catch (ClassCastException cce) { throw XMLMarshalException.invalidSwaRefAttribute(getAttributeClassification().getName()); XMLBinaryDataHelper.EncodedData data = XMLBinaryDataHelper.getXMLBinaryDataHelper().getBytesForBinaryValue(attributeValue, record.getMarshaller(), getMimeType(parent)); String base64Value = ((XMLConversionManager) session.getDatasourcePlatform().getConversionManager()).buildBase64StringFromBytes(data.getData()); record.put(field, base64Value); if (record.isXOPPackage() && !isSwaRef() && !shouldInlineBinaryData()) { record.put(textField, bytes); record.put(xpathField, c_id); Object obj = record.getIndicatingNoEntry(incField); if (!prefixAlreadyDefined && obj != null && obj instanceof DOMRecord) { if (((DOMRecord) obj).getDOM().getNodeType() == Node.ELEMENT_NODE) { textField.setNamespaceResolver(field.getNamespaceResolver()); textField.setSchemaType(field.getSchemaType()); record.put(textField, c_id); } catch (Exception ex) { textField.setSchemaType(field.getSchemaType());
AbstractSession session = xmlContext.getSession(descriptor); if (xmlRow != null) { isRootDocumentFragment = (xmlRow.getDOM().getNodeType() == Node.DOCUMENT_FRAGMENT_NODE); xmlRow.setMarshaller(this); if (getAttachmentMarshaller() != null) { xmlRow.setXOPPackage(getAttachmentMarshaller().isXOPPackage()); ((Element) xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL, XMLConstants.XMLNS + XMLConstants.COLON + xmlRootPrefix, xmlRootUri); copyNamespaces(resolver, xmlRow.getNamespaceResolver()); document = xmlRow.getDocument(); Element docElement = document.getDocumentElement(); xmlRow.getNamespaceResolver().put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL); ((Element) xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL, XMLConstants.XMLNS + XMLConstants.COLON + XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL); String typeValue = descriptor.getSchemaReference().getSchemaContext(); typeValue = typeValue.substring(1); xsiTypefield.setNamespaceResolver(xmlRow.getNamespaceResolver()); XPathEngine.getInstance().create(xsiTypefield, docElement, typeValue, session); xmlRow.setMarshaller(this); if (shouldCallSetAttributeNS && !isRootDocumentFragment) { ((Element) xmlRow.getDOM()).setAttributeNS(XMLConstants.XMLNS_URL, XMLConstants.XMLNS + XMLConstants.COLON + XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL); document = xmlRow.getDocument();
public AbstractRecord createRecordFor(Object object, DocumentPreservationPolicy docPresPolicy, String rootName, String rootUri) { Element cachedNode = null; XMLRecord record = null; if(docPresPolicy != null) { cachedNode = (Element)docPresPolicy.getNodeForObject(object); } if(cachedNode == null) { record = new DOMRecord(rootName, rootUri); docPresPolicy.addObjectToCache(object, record.getDOM()); } else { record = new DOMRecord(cachedNode); } record.setDocPresPolicy(docPresPolicy); return record; }
private Object convertToSimpleTypeIfPresent(Object toReturn, XMLRecord nestedRow, AbstractSession executionSession){ Node textchild = ((Element) nestedRow.getDOM()).getFirstChild(); String stringValue = null; if ((textchild != null) && (textchild.getNodeType() == Node.TEXT_NODE)) { stringValue = ((Text) textchild).getNodeValue(); if(stringValue != null && getKeepAsElementPolicy() != UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT && getKeepAsElementPolicy()!=UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT){ toReturn = stringValue; } } if ((stringValue == null) || stringValue.length() == 0) { return toReturn; } String type = ((Element) nestedRow.getDOM()).getAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE); if ((null != type) && type.length() > 0) { XPathFragment typeFragment = new XPathFragment(type); String namespaceURI = nestedRow.resolveNamespacePrefix(typeFragment.getPrefix()); QName schemaTypeQName = new QName(namespaceURI, typeFragment.getLocalName()); Class theClass = (Class) XMLConversionManager.getDefaultXMLTypes().get(schemaTypeQName); if (theClass != null) { toReturn = ((XMLConversionManager) executionSession.getDatasourcePlatform().getConversionManager()).convertObject(stringValue, theClass, schemaTypeQName); } } return toReturn; }
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException { List<XMLEntry> values = ((DOMRecord)row).getValuesIndicatingNoEntry(this.getFields()); Object container = getContainerPolicy().containerInstance(values.size()); for(XMLEntry next:values) { Field valueField = next.getXMLField(); DatabaseMapping nextMapping = (DatabaseMapping)this.choiceElementMappings.get(valueField); if(nextMapping.isAbstractCompositeCollectionMapping()) { XMLCompositeCollectionMapping xmlMapping = (XMLCompositeCollectionMapping)nextMapping; Object value = xmlMapping.buildObjectFromNestedRow((AbstractRecord)next.getValue(), joinManager, sourceQuery, executionSession, isTargetProtected); value = convertDataValueToObjectValue(value, executionSession, ((XMLRecord) row).getUnmarshaller()); getContainerPolicy().addInto(value, container, executionSession); } else if(nextMapping instanceof XMLCompositeDirectCollectionMapping){ XMLCompositeDirectCollectionMapping xmlMapping = (XMLCompositeDirectCollectionMapping)nextMapping; Object value = next.getValue(); value = convertDataValueToObjectValue(value, executionSession, ((XMLRecord) row).getUnmarshaller()); getContainerPolicy().addInto(value, container, executionSession); } } ArrayList<XMLMapping> processedMappings = new ArrayList<XMLMapping>(); for(XMLMapping mapping:choiceElementMappings.values()) { if(((DatabaseMapping)mapping).isObjectReferenceMapping() && ((DatabaseMapping)mapping).isCollectionMapping() && !(processedMappings.contains(mapping))) { ((XMLCollectionReferenceMapping)mapping).readFromRowIntoObject(row, joinManager, ((XMLRecord)row).getCurrentObject(), cacheKey, sourceQuery, executionSession, isTargetProtected, container); processedMappings.add(mapping); } } return container; }
public AbstractRecord buildRow(AbstractRecord databaseRow, Object object, AbstractSession session, boolean wasXMLRoot) { XMLRecord row = (XMLRecord)databaseRow; row.setSession(session); XMLMarshaller marshaller = row.getMarshaller(); if ((marshaller != null) && (marshaller.getMarshalListener() != null)) { marshaller.getMarshalListener().beforeMarshal(object); if (!ctx.equals(xmlDescriptor.getDefaultRootElementType())) { row.add(xmlDescriptor.getInheritancePolicy().getClassIndicatorField(), xmlRef.getSchemaContext().substring(1)); addNamespaceDeclarations((row).getDocument());
public AbstractRecord buildRow(AbstractRecord databaseRow, Object object, AbstractSession session, boolean wasXMLRoot) { XMLRecord row = (XMLRecord)databaseRow; row.setSession(session); XMLMarshaller marshaller = row.getMarshaller(); if ((marshaller != null) && (marshaller.getMarshalListener() != null)) { marshaller.getMarshalListener().beforeMarshal(object); } addNamespaceDeclarations((row).getDocument()); writeOutMappings(row, object, session); // If this descriptor has multiple tables then we need to append the // primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(row); } if ((marshaller != null) && (marshaller.getMarshalListener() != null)) { marshaller.getMarshalListener().afterMarshal(object); } return row; }
/** * Marshal a namespace declaration for the given prefix and url * @param prefix * @param namespaceURI */ public void namespaceDeclaration(String prefix, String namespaceURI){ String existingPrefix = getNamespaceResolver().resolveNamespaceURI(namespaceURI); if(existingPrefix == null || (existingPrefix != null && !existingPrefix.equals(XMLConstants.EMPTY_STRING) && !existingPrefix.equals(prefix))){ XMLField xmlField = new XMLField("@" + javax.xml.XMLConstants.XMLNS_ATTRIBUTE + XMLConstants.COLON + prefix); xmlField.setNamespaceResolver(getNamespaceResolver()); xmlField.getXPathFragment().setNamespaceURI(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI); add(xmlField, namespaceURI); } }
/** * Build and return a database row that contains a foreign key for the specified reference * object. This will be stored in the nested row(s). */ protected XMLRecord extractKeyRowFromReferenceObject(Object object, AbstractSession session, XMLRecord parentRecord) { Element newNode = XPathEngine.getInstance().createUnownedElement(parentRecord.getDOM(), getForeignKeyGroupingElement()); XMLRecord result = new DOMRecord(newNode); result.setSession(session); for (int i = 0; i < this.getSourceForeignKeyFields().size(); i++) { DatabaseField fkField = (DatabaseField)getSourceForeignKeyFields().get(i); if (object == null) { result.add(fkField, null); } else { DatabaseField pkField = (DatabaseField)this.getSourceForeignKeysToTargetKeys().get(fkField); Object value = this.getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(object, pkField, session); result.add(fkField, value); } } return result; }