use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class SDOSequence method convertToSetting.
private Setting convertToSetting(DatabaseMapping mapping, Object value) {
XMLDescriptor xmlDescriptor = (XMLDescriptor) mapping.getDescriptor();
NamespaceResolver nsResolver = xmlDescriptor.getNamespaceResolver();
Setting rootSetting = new Setting();
XMLField xmlField = (XMLField) mapping.getField();
if (xmlField == null) {
if (mapping instanceof XMLObjectReferenceMapping) {
xmlField = (XMLField) ((XMLObjectReferenceMapping) mapping).getFields().get(0);
} else if (mapping instanceof XMLCollectionReferenceMapping) {
xmlField = (XMLField) ((XMLCollectionReferenceMapping) mapping).getFields().get(0);
}
}
Setting setting = rootSetting;
if (xmlField != null) {
XPathFragment xPathFragment = xmlField.getXPathFragment();
rootSetting = convertToSetting(xPathFragment, nsResolver);
setting = rootSetting;
while (xPathFragment.getNextFragment() != null) {
xPathFragment = xPathFragment.getNextFragment();
Setting childSetting = convertToSetting(xPathFragment, nsResolver);
setting.addChild(childSetting);
setting = childSetting;
}
}
setting.setObject(dataObject);
setting.setMapping(mapping);
setting.setValue(value, false);
return rootSetting;
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method setUpXMLDirectMapping.
protected XMLDirectMapping setUpXMLDirectMapping(String columnName, QName qName, NamingConventionTransformer nct, Class<?> attributeClass, int jdbcType, boolean isPk) {
XMLDirectMapping xdm = null;
// figure out if binary attachments are required
boolean binaryAttach = false;
String attachmentType = null;
if (BASE_64_BINARY_QNAME.equals(qName)) {
// use primitive byte[] array, not object Byte[] array
attributeClass = APBYTE;
for (OperationModel om : dbwsBuilder.operations) {
if (om.isTableOperation()) {
TableOperationModel tom = (TableOperationModel) om;
if (tom.getBinaryAttachment()) {
binaryAttach = true;
if (MTOM_STR.equalsIgnoreCase(tom.getAttachmentType())) {
attachmentType = MTOM_STR;
} else {
attachmentType = SWAREF_STR;
}
// only need one operation to require attachments
break;
}
if (tom.additionalOperations != null && tom.additionalOperations.size() > 0) {
for (OperationModel om2 : tom.additionalOperations) {
if (om2.isProcedureOperation()) {
ProcedureOperationModel pom = (ProcedureOperationModel) om2;
if (pom.getBinaryAttachment()) {
binaryAttach = true;
if (MTOM_STR.equalsIgnoreCase(tom.getAttachmentType())) {
attachmentType = MTOM_STR;
} else {
attachmentType = SWAREF_STR;
}
break;
}
}
}
}
}
}
XMLBinaryDataMapping xbdm = new XMLBinaryDataMapping();
if (binaryAttach) {
if (attachmentType.equals(SWAREF_STR)) {
xbdm.setSwaRef(true);
qName = XMLConstants.SWA_REF_QNAME;
}
} else {
xbdm.setShouldInlineBinaryData(true);
}
xbdm.setMimeType(DEFAULT_ATTACHMENT_MIMETYPE);
xdm = xbdm;
} else {
xdm = new XMLDirectMapping();
}
String fieldName = nct.generateElementAlias(columnName);
xdm.setAttributeName(fieldName);
xdm.setAttributeClassificationName(attributeClass.getName());
String xPath = EMPTY_STRING;
ElementStyle style = nct.styleForElement(columnName);
if (style == ATTRIBUTE) {
xPath += AT_SIGN + fieldName;
} else if (style == ELEMENT) {
xPath += fieldName;
}
if (style == ELEMENT && attributeClass != APBYTE) {
xPath += SLASH_TEXT;
}
xdm.setXPath(xPath);
XMLField xmlField = (XMLField) xdm.getField();
xmlField.setSchemaType(qName);
if (isPk) {
xmlField.setRequired(true);
} else {
AbstractNullPolicy nullPolicy = xdm.getNullPolicy();
nullPolicy.setNullRepresentedByEmptyNode(false);
nullPolicy.setMarshalNullRepresentation(XSI_NIL);
nullPolicy.setNullRepresentedByXsiNil(true);
xdm.setNullPolicy(nullPolicy);
}
return xdm;
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class SDOMarshalListener method marshalNilAttribute.
private void marshalNilAttribute(SDOProperty property, DOMRecord row) {
// Marshal out xsi:nil=true
NamespaceResolver resolver = null;
if (property.getContainingType() != null) {
resolver = property.getContainingType().getXmlDescriptor().getNamespaceResolver();
}
if (null == resolver) {
resolver = typeHelper.getNamespaceResolver();
}
String xsiPrefix = resolver.resolveNamespaceURI(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
if ((xsiPrefix == null) || xsiPrefix.equals(SDOConstants.EMPTY_STRING)) {
NamespaceResolver nsResolverWithXsi = new NamespaceResolver();
copyNamespaces(resolver, nsResolverWithXsi);
resolver = nsResolverWithXsi;
xsiPrefix = resolver.generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
resolver.put(xsiPrefix, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
}
String xPath = getXPathForProperty(property, true, resolver);
xPath = xPath + "/@" + xsiPrefix + XMLConstants.COLON + XMLConstants.SCHEMA_NIL_ATTRIBUTE;
XMLField field = new XMLField(xPath);
field.setNamespaceResolver(resolver);
row.put(field, XMLConstants.BOOLEAN_STRING_TRUE);
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class SDOMarshalListener method beforeMarshal.
@Override
public void beforeMarshal(Object obj) {
if (obj instanceof SDOChangeSummary) {
SDOChangeSummary changeSummary = ((SDOChangeSummary) obj);
// CREATED - build a list of xpaths to write to the created attribute
// this must be done dynamically because the xpath is relative to the marshalledObject
// so it can't be calculated until we know what object is being marshalled
List createdSet = changeSummary.getCreated();
List xpaths = new ArrayList(createdSet.size());
String rootElementName = this.marshalledObjectRootQName.getLocalPart();
String rootNamespaceUri = this.marshalledObjectRootQName.getNamespaceURI();
if (rootNamespaceUri != null && !rootNamespaceUri.equals(XMLConstants.EMPTY_STRING)) {
org.eclipse.persistence.internal.oxm.NamespaceResolver resolver = getRootMarshalRecord().getNamespaceResolver();
if (resolver != null) {
String prefix = resolver.resolveNamespaceURI(this.marshalledObjectRootQName.getNamespaceURI());
if (prefix != null) {
rootElementName = prefix + XMLConstants.COLON + rootElementName;
}
}
}
if ((createdSet != null) && (createdSet.size() > 0)) {
Iterator anIterator = createdSet.iterator();
SDODataObject nextCreatedDO = null;
while (anIterator.hasNext()) {
// get path to the changeSummaryRoot (may not be the root marshalled object - may be internal)
nextCreatedDO = ((SDODataObject) anIterator.next());
String nextPath = getPathFromAncestor(nextCreatedDO, (SDODataObject) marshalledObject, changeSummary);
// Add sdoRef attribute...all modified objects written should have this
if (nextPath == SDOConstants.EMPTY_STRING) {
// if this is the root, just put the root element
xpaths.add(SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + //
SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName);
} else {
xpaths.add(SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + //
SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + nextPath);
}
}
}
changeSummary.setCreatedXPaths(xpaths);
// Build xpathToCS
String xpathMarshalledObjToCS = getPathFromAncestor(changeSummary.getRootObject(), (SDODataObject) marshalledObject, changeSummary);
String xpathChangeSumProp = getXPathForProperty(changeSummary.getRootObject().getType().getChangeSummaryProperty());
String xpathToCS = SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName;
// check if the CS is at the local-cs-root or is in a child property
if ((xpathMarshalledObjToCS != null) && !xpathMarshalledObjToCS.equals(SDOConstants.EMPTY_STRING)) {
// SDO_XPATH_TO_ROOT)) {
// CS is not on the root
xpathToCS = xpathToCS + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + xpathMarshalledObjToCS;
}
xpathToCS = //
xpathToCS + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + xpathChangeSumProp + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT;
// MODIFIED && DELETED
List deletedXPaths = new ArrayList();
Document document = XMLPlatformFactory.getInstance().getXMLPlatform().createDocument();
Element csNode = null;
List modifiedItems = changeSummary.getModified();
int modifiedSize = modifiedItems.size();
List newNodes = new ArrayList(modifiedSize);
SDODataObject nextModifiedDO = null;
// Iterate through CS modified items
for (int i = 0; i < modifiedSize; i++) {
nextModifiedDO = (SDODataObject) modifiedItems.get(i);
String sdoPrefix = typeHelper.getPrefix(SDOConstants.SDO_URL);
// List unsetPropNames = new ArrayList();
String uri = getURI(nextModifiedDO);
String qualifiedName = getQualifiedName(nextModifiedDO);
String sdoRefPrefix = SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT;
if (uri == null) {
csNode = document.createElement(qualifiedName);
} else {
csNode = document.createElementNS(uri, qualifiedName);
}
String nextPath = getPathFromAncestor(nextModifiedDO, (SDODataObject) marshalledObject, changeSummary);
// Add sdoRef attribute...all modified objects written should have this
if (nextPath == SDOConstants.EMPTY_STRING) {
// if this is the root, just put the root element
csNode.setAttributeNS(SDOConstants.SDO_URL, //
sdoPrefix + //
SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + //
SDOConstants.CHANGESUMMARY_REF, sdoRefPrefix + rootElementName);
} else {
csNode.setAttributeNS(SDOConstants.SDO_URL, //
sdoPrefix + //
SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + //
SDOConstants.CHANGESUMMARY_REF, sdoRefPrefix + rootElementName + "/" + nextPath);
}
// Bug6346754 Add all namespaces if they are not yet declared above.
Vector namespaces = nextModifiedDO.getType().getXmlDescriptor().getNonNullNamespaceResolver().getNamespaces();
for (int j = 0; j < namespaces.size(); j++) {
Namespace next = (Namespace) namespaces.get(j);
if (declareNamespace(next.getNamespaceURI(), next.getPrefix(), changeSummary.getRootObject())) {
csNode.setAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, javax.xml.XMLConstants.XMLNS_ATTRIBUTE + XMLConstants.COLON + next.getPrefix(), next.getNamespaceURI());
}
}
List nextDOSettings = changeSummary.getOldValues(nextModifiedDO);
DOMRecord row = new DOMRecord(csNode);
Session session = ((SDOXMLHelper) typeHelper.getHelperContext().getXMLHelper()).getXmlContext().getSession();
row.setSession((AbstractSession) session);
// Iterate through SDOSettings for the current modified Object
SDOSetting nextSetting = null;
for (int j = 0; j < nextDOSettings.size(); j++) {
nextSetting = (SDOSetting) nextDOSettings.get(j);
if (nextSetting.isSet()) {
if (!nextSetting.getProperty().getType().isDataType()) {
if (nextSetting.getProperty().isMany()) {
List values = (List) nextSetting.getValue();
for (int k = 0; k < values.size(); k++) {
doMarshal(//
nextSetting.getProperty(), //
(DataObject) values.get(k), changeSummary, csNode, nextModifiedDO, deletedXPaths, xpathToCS, sdoPrefix, rootElementName);
}
} else {
doMarshal(//
nextSetting.getProperty(), //
(DataObject) nextSetting.getValue(), changeSummary, csNode, nextModifiedDO, deletedXPaths, xpathToCS, sdoPrefix, rootElementName);
}
} else {
// This writes out simple values
Object value = nextSetting.getValue();
if (value == null) {
// Marshal out xsi:nil=true
marshalNilAttribute(nextSetting.getProperty(), row);
} else {
String xPath = getXPathForProperty(nextSetting.getProperty());
XMLField field = new XMLField(xPath);
field.setNamespaceResolver(typeHelper.getNamespaceResolver());
row.put(field, value);
}
}
}
}
List unsetPropNames = changeSummary.getUnsetProps(nextModifiedDO);
if (!unsetPropNames.isEmpty()) {
XMLConversionManager xmlConversionManager = ((SDOXMLHelper) typeHelper.getHelperContext().getXMLHelper()).getXmlConversionManager();
String unsetPropsString = xmlConversionManager.convertObject(unsetPropNames, String.class);
csNode.setAttributeNS(SDOConstants.SDO_URL, //
sdoPrefix + //
SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + SDOConstants.CHANGESUMMARY_UNSET, unsetPropsString);
}
newNodes.add(csNode);
}
changeSummary.setDeletedXPaths(deletedXPaths);
changeSummary.setModifiedDoms(newNodes);
}
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class SDOMarshalListener method doMarshal.
private //
void doMarshal(//
SDOProperty prop, //
DataObject value, //
SDOChangeSummary cs, Element csNode, SDODataObject modifiedObject, List deletedXPaths, String xpathToCS, String sdoPrefix, String rootElementName) {
if (value == null) {
// Marshal out xsi:nil=true
DOMRecord row = new DOMRecord(csNode);
Session session = ((SDOXMLHelper) typeHelper.getHelperContext().getXMLHelper()).getXmlContext().getSession();
row.setSession((AbstractSession) session);
marshalNilAttribute(prop, row);
return;
}
boolean isDeleted = false;
// Do we need a second map or can we just check the values of the deleted map
Object original = cs.getReverseDeletedMap().get(value);
if ((original != null) && cs.isDeleted((DataObject) original)) {
isDeleted = true;
}
String qualifiedName = getXPathForProperty(prop);
String uri = null;
if (prop.isOpenContent()) {
uri = prop.getUri();
} else {
uri = ((XMLField) prop.getXmlMapping().getField()).getXPathFragment().getNamespaceURI();
}
if (isDeleted) {
String pathToNode = getPathFromAncestor(((SDODataObject) original), modifiedObject, cs);
String containerPath = null;
containerPath = getQualifiedName(modifiedObject);
deletedXPaths.add(xpathToCS + containerPath + SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + pathToNode);
XMLRoot xmlroot = new XMLRoot();
// set the object to the deep copy
xmlroot.setObject(value);
xmlroot.setNamespaceURI(uri);
xmlroot.setLocalName(qualifiedName);
xmlMarshaller.marshal(xmlroot, csNode);
} else {
// need sdoref
Element modifiedElement = null;
if (uri == null) {
modifiedElement = csNode.getOwnerDocument().createElement(qualifiedName);
} else {
modifiedElement = csNode.getOwnerDocument().createElementNS(uri, qualifiedName);
}
csNode.appendChild(modifiedElement);
String nextPath = getPathFromAncestor((SDODataObject) original, (SDODataObject) marshalledObject, cs);
// Add sdoRef attribute...all modified objects written should have this
if (nextPath == SDOConstants.EMPTY_STRING) {
// if this is the root, just put the root element
modifiedElement.setAttributeNS(SDOConstants.SDO_URL, //
sdoPrefix + //
SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + //
SDOConstants.CHANGESUMMARY_REF, SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + //
SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName);
} else {
modifiedElement.setAttributeNS(SDOConstants.SDO_URL, //
sdoPrefix + //
SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + //
SDOConstants.CHANGESUMMARY_REF, SDOConstants.SDO_CHANGESUMMARY_REF_PATH_PREFIX + //
SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + rootElementName + "/" + nextPath);
}
// Added for bug 6346754
if ((((SDODataObject) original).getContainmentProperty() != null) && ((SDODataObject) original).getContainmentProperty().getType().isDataObjectType()) {
// may also need xsi:type
String schemaContext = ((SDOType) value.getType()).getXmlDescriptor().getSchemaReference().getSchemaContext();
QName schemaContextQName = ((SDOType) value.getType()).getXmlDescriptor().getSchemaReference().getSchemaContextAsQName(((SDOType) value.getType()).getXmlDescriptor().getNonNullNamespaceResolver());
if (schemaContext != null) {
String typeValue = schemaContext.substring(1, schemaContext.length());
String schemaInstancePrefix = ((SDOType) value.getType()).getXmlDescriptor().getNonNullNamespaceResolver().resolveNamespaceURI(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
// may or may not need the xmlns declaration added.
String schemaContextUri = schemaContextQName.getNamespaceURI();
String schemaContextPrefix = ((SDOType) value.getType()).getXmlDescriptor().getNonNullNamespaceResolver().resolveNamespaceURI(schemaContextUri);
if (schemaContextPrefix != null) {
modifiedElement.setAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, javax.xml.XMLConstants.XMLNS_ATTRIBUTE + XMLConstants.COLON + schemaContextPrefix, schemaContextQName.getNamespaceURI());
}
modifiedElement.setAttributeNS(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, schemaInstancePrefix + XMLConstants.COLON + XMLConstants.SCHEMA_TYPE_ATTRIBUTE, typeValue);
}
}
}
}
Aggregations