Search in sources :

Example 31 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class SDOUnmarshalListener method afterUnmarshal.

/**
 * @param target assumed to be non-null
 * @param parent may be null, indicating target is root object
 */
@Override
public void afterUnmarshal(Object target, Object parent) {
    SDODataObject targetDataObject;
    // assume target is DataObject or ChangeSummary
    try {
        targetDataObject = (SDODataObject) target;
    } catch (ClassCastException ccex) {
        // each time we hit a ChangeSummary store it to process later and set its root
        // object - this is because we can't fully process the cs's because they have
        // references that can't be resolved until the full tree is built
        SDOChangeSummary sdoChangeSummary = (SDOChangeSummary) target;
        sdoChangeSummary.setRootDataObject((DataObject) parent);
        getChangeSummaries().add(sdoChangeSummary);
        return;
    }
    // if getType is sequenced, then update values to settings map
    if (targetDataObject.getType().isSequenced()) {
        targetDataObject.getSequence().afterUnmarshal();
    }
    // the last object that will hit the afterUnmarshal method
    if (parent == null && null != changeSummaries) {
        XMLUnmarshaller unmarshaller = null;
        for (int i = 0, changeSummariesSize = changeSummaries.size(); i < changeSummariesSize; i++) {
            SDOChangeSummary nextCS = changeSummaries.get(i);
            // Set logging to true until finished building modified list.
            boolean loggingValue = nextCS.isLoggingMapping();
            nextCS.setLogging(true);
            // CREATES
            // For each xpath in the create attribute convert it to an sdo path and execute it against the root
            // dataobject to get the dataobject being pointed to and set that dataobject to be created
            List xpaths = nextCS.getCreatedXPaths();
            for (int j = 0, xpathsSize = xpaths.size(); j < xpathsSize; j++) {
                String nextXPath = (String) xpaths.get(j);
                String sdoPath = convertXPathToSDOPath(nextXPath);
                SDODataObject nextCreatedDO = targetDataObject.getDataObject(sdoPath);
                if (nextCreatedDO == null) {
                    int nextSlash = sdoPath.indexOf('/');
                    if (nextSlash != -1) {
                        sdoPath = sdoPath.substring(nextSlash + 1);
                    } else {
                        sdoPath = "/";
                    }
                    nextCreatedDO = targetDataObject.getDataObject(sdoPath);
                }
                if (nextCreatedDO != null) {
                    nextCreatedDO._setCreated(true);
                    nextCS.getOldContainers().remove(nextCreatedDO);
                } else {
                    throw SDOException.errorProcessingXPath(nextXPath);
                }
            }
            // clear the createxpaths list that was read in from XML
            nextCS.setCreatedXPaths(null);
            // MODIFIED
            List modifiedDoms = nextCS.getModifiedDoms();
            for (int j = 0, modifiedDomsSize = modifiedDoms.size(); j < modifiedDomsSize; j++) {
                Element nextNode = (Element) modifiedDoms.get(j);
                String refValue = nextNode.getAttributeNS(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY_REF);
                if ((refValue == null) || (refValue.length() == 0)) {
                    throw SDOException.missingRefAttribute();
                }
                // nextModifiedDO is the real modified current data object
                String sdoPath = convertXPathToSDOPath(refValue);
                SDODataObject nextModifiedDO = targetDataObject.getDataObject(sdoPath);
                // if it failed, try peeling off the first fragment (may be the root
                if (nextModifiedDO == null) {
                    int nextSlash = sdoPath.indexOf('/');
                    if (nextSlash != -1) {
                        sdoPath = sdoPath.substring(nextSlash + 1);
                    } else {
                        sdoPath = "/";
                    }
                    nextModifiedDO = targetDataObject.getDataObject(sdoPath);
                }
                String unsetValue = nextNode.getAttributeNS(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY_UNSET);
                List unsetValueList = new ArrayList();
                if ((unsetValue != null) && (unsetValue.length() > 0)) {
                    XMLConversionManager xmlConversionManager = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlConversionManager();
                    unsetValueList = xmlConversionManager.convertObject(unsetValue, List.class);
                }
                if (nextModifiedDO != null) {
                    nextModifiedDO._setModified(true);
                    SDOCSUnmarshalListener listener = new SDOCSUnmarshalListener(nextModifiedDO.getType().getHelperContext(), true);
                    if (null == unmarshaller) {
                        unmarshaller = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().createUnmarshaller();
                    }
                    unmarshaller.setUnmarshalListener(listener);
                    unmarshaller.getProperties().put("sdoHelperContext", aHelperContext);
                    unmarshaller.setUnmappedContentHandlerClass(SDOUnmappedContentHandler.class);
                    Object unmarshalledNode = unmarshaller.unmarshal(nextNode, nextModifiedDO.getType().getXmlDescriptor().getJavaClass());
                    // unmarshalledDO is the modified dataobject from the changesummary xml
                    SDODataObject unmarshalledDO = null;
                    // Assumption: unmarshalledNode should always be either an instance of XMLRoot or DataObject
                    if (unmarshalledNode instanceof XMLRoot) {
                        unmarshalledDO = (SDODataObject) ((XMLRoot) unmarshalledNode).getObject();
                    } else if (unmarshalledNode instanceof DataObject) {
                        unmarshalledDO = (SDODataObject) unmarshalledNode;
                    }
                    List modifiedProps = new ArrayList();
                    Node n = nextNode.getFirstChild();
                    TypeHelper typeHelper = aHelperContext.getTypeHelper();
                    while (n != null) {
                        if (n.getNodeType() == Node.ELEMENT_NODE) {
                            String propName = n.getLocalName();
                            Property nextProp = unmarshalledDO.getInstanceProperty(propName);
                            if (nextProp == null) {
                                nextProp = typeHelper.getOpenContentProperty(n.getNamespaceURI(), propName);
                            }
                            if (!modifiedProps.contains(nextProp)) {
                                modifiedProps.add(nextProp);
                            }
                        }
                        n = n.getNextSibling();
                    }
                    // instead of iterating over all props can we just check elements in cs and get appropriate properties from DO
                    for (int k = 0, modifiedPropsSize = modifiedProps.size(); k < modifiedPropsSize; k++) {
                        SDOProperty nextProp = (SDOProperty) modifiedProps.get(k);
                        if (!nextProp.getType().isDataType()) {
                            if (nextProp.isMany()) {
                                // original value is the list from the changesummary xml
                                List originalValue = unmarshalledDO.getList(nextProp);
                                List newList = new ArrayList();
                                List toDelete = new ArrayList();
                                List indexsToDelete = new ArrayList();
                                for (int l = 0, originalValueSize = originalValue.size(); l < originalValueSize; l++) {
                                    SDODataObject nextInList = (SDODataObject) originalValue.get(l);
                                    String sdoRef = nextInList._getSdoRef();
                                    if (sdoRef != null) {
                                        // if sdoRef is not null then object is modified
                                        String sdoRefPath = convertXPathToSDOPath(sdoRef);
                                        int nextSlash = sdoRefPath.indexOf('/');
                                        if (nextSlash != -1) {
                                            sdoRefPath = sdoRefPath.substring(nextSlash + 1);
                                        } else {
                                            sdoRefPath = "/";
                                        }
                                        newList.add(targetDataObject.getDataObject(sdoRefPath));
                                    } else {
                                        // if sdo ref is null there is a deleted object
                                        toDelete.add(nextInList);
                                        indexsToDelete.add(l);
                                        newList.add(nextInList);
                                    }
                                }
                                // lw is the list from the real current data object
                                ListWrapper lw = ((ListWrapper) nextModifiedDO.getList(nextProp));
                                int indexsToDeleteSize = indexsToDelete.size();
                                if (indexsToDeleteSize > 0) {
                                    // after this loop, lw will have the entire list when logging was turned on
                                    nextCS.pauseLogging();
                                    for (int m = 0; m < indexsToDeleteSize; m++) {
                                        int toDeleteIndex = (Integer) indexsToDelete.get(m);
                                        SDODataObject nextToDelete = (SDODataObject) toDelete.get(m);
                                        lw.add(toDeleteIndex, nextToDelete);
                                    }
                                    nextCS.setPropertyInternal(nextModifiedDO, nextProp, lw);
                                    SDOSequence nextSeq = ((SDOSequence) nextCS.getOriginalSequences().get(nextModifiedDO));
                                    nextCS.resumeLogging();
                                    nextModifiedDO._setModified(true);
                                    for (int m = indexsToDeleteSize - 1; m >= 0; m--) {
                                        int toDeleteIndex = (Integer) indexsToDelete.get(m);
                                        SDODataObject nextToDelete = (SDODataObject) toDelete.get(m);
                                        if (nextSeq != null) {
                                            nextSeq.addSettingWithoutModifyingDataObject(-1, nextProp, nextToDelete);
                                        }
                                        nextToDelete.resetChanges();
                                        lw.remove(toDeleteIndex);
                                    }
                                }
                                nextCS.getOriginalElements().put(lw, newList);
                            } else {
                                SDODataObject value = unmarshalledDO.getDataObject(nextProp);
                                if (value != null) {
                                    String sdoRef = value._getSdoRef();
                                    if (sdoRef != null) {
                                        // modified
                                        nextModifiedDO._setModified(true);
                                    } else {
                                        // deleted
                                        value._setChangeSummary(nextCS);
                                        nextModifiedDO._setModified(true);
                                        nextCS.pauseLogging();
                                        boolean wasSet = nextModifiedDO.isSet(nextProp);
                                        Object existingValue = nextModifiedDO.get(nextProp);
                                        // grab index of nextProp's Setting for use during setting below
                                        Sequence nextModifiedDOSequence = nextModifiedDO.getSequence();
                                        int settingIdx = -1;
                                        if (nextModifiedDOSequence != null) {
                                            settingIdx = ((SDOSequence) nextModifiedDOSequence).getIndexForProperty(nextProp);
                                        }
                                        value._setContainmentPropertyName(null);
                                        value._setContainer(null);
                                        nextModifiedDO.set(nextProp, value);
                                        nextCS.setPropertyInternal(nextModifiedDO, nextProp, value);
                                        SDOSequence nextSeq = ((SDOSequence) nextCS.getOriginalSequences().get(nextModifiedDO));
                                        if (nextSeq != null) {
                                            nextSeq.addSettingWithoutModifyingDataObject(-1, nextProp, value);
                                        }
                                        nextCS.resumeLogging();
                                        nextModifiedDO._setModified(true);
                                        value.resetChanges();
                                        value.delete();
                                        if (wasSet) {
                                            // need to add at the right pos in the list, not at the end
                                            nextModifiedDO.set(nextProp, existingValue, false);
                                            if (settingIdx != -1) {
                                                nextModifiedDO.getSequence().addSettingWithoutModifyingDataObject(settingIdx, nextProp, existingValue);
                                            }
                                        } else {
                                            nextModifiedDO.unset(nextProp);
                                        }
                                    }
                                } else {
                                    nextModifiedDO._setModified(true);
                                    nextCS.setPropertyInternal(nextModifiedDO, nextProp, null);
                                }
                            }
                        } else {
                            nextModifiedDO._setModified(true);
                            Object value = unmarshalledDO.get(nextProp);
                            if (nextProp.isMany()) {
                                Property theProp = nextModifiedDO.getInstanceProperty(nextProp.getName());
                                if (theProp == null) {
                                    Property newProp = nextModifiedDO.defineOpenContentProperty(nextProp.getName(), new ArrayList(), nextProp.getType());
                                    nextModifiedDO.set(newProp, new ArrayList());
                                    theProp = newProp;
                                }
                                List lw = nextModifiedDO.getList(theProp.getName());
                                nextCS.setPropertyInternal(nextModifiedDO, theProp, lw);
                                nextCS.getOriginalElements().put(lw, ((ListWrapper) value).getCurrentElements());
                            } else {
                                nextCS.setPropertyInternal(nextModifiedDO, nextProp, value);
                            }
                        }
                    }
                    for (int k = 0, unsetValueListSize = unsetValueList.size(); k < unsetValueListSize; k++) {
                        SDOProperty nextProp = unmarshalledDO.getInstanceProperty((String) unsetValueList.get(k));
                        if (nextProp != null) {
                            Object oldValue = null;
                            if (nextProp.getType().isDataType() || nextProp.isMany()) {
                                // to get default
                                oldValue = unmarshalledDO.get(nextProp);
                            }
                            nextModifiedDO._setModified(true);
                            nextCS.setPropertyInternal(nextModifiedDO, nextProp, oldValue);
                            nextCS.unsetPropertyInternal(nextModifiedDO, nextProp);
                        } else {
                            nextProp = nextModifiedDO.getInstanceProperty((String) unsetValueList.get(k));
                            nextModifiedDO._setModified(true);
                            nextCS.setPropertyInternal(nextModifiedDO, nextProp, null);
                            nextCS.unsetPropertyInternal(nextModifiedDO, nextProp);
                        }
                    }
                } else {
                    throw SDOException.errorProcessingXPath(refValue);
                }
            }
            // clear modified doms list
            nextCS.setModifiedDoms(null);
            // clear deleted xpaths list
            nextCS.setDeletedXPaths(null);
            List created = nextCS.getCreated();
            for (int j = 0, createdSize = created.size(); j < createdSize; j++) {
                SDODataObject next = (SDODataObject) created.get(j);
                Property containmentProperty = next.getContainmentProperty();
                if (containmentProperty != null && containmentProperty.isMany()) {
                    SDODataObject container = next.getContainer();
                    ListWrapper list = (ListWrapper) container.get(containmentProperty);
                    if (!(nextCS.getOriginalElements().containsKey(list))) {
                        // if there was an object created as part of a list, and that list is not
                        // already in the original elements map. Add an empty list to the map.
                        nextCS.getOriginalElements().put(list, new ArrayList());
                    }
                }
            }
            nextCS.setLogging(loggingValue);
        }
        // reset changeSummary list - we are done with it
        changeSummaries = null;
    }
}
Also used : TypeHelper(commonj.sdo.helper.TypeHelper) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Sequence(commonj.sdo.Sequence) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) ArrayList(java.util.ArrayList) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 32 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class SDOTypesGenerator method startNewComplexType.

private SDOType startNewComplexType(String targetNamespace, String sdoTypeName, String xsdLocalName, ComplexType complexType) {
    SDOType currentType;
    if (null == complexType.getName()) {
        currentType = createSDOTypeForName(targetNamespace, sdoTypeName, xsdLocalName);
    } else {
        currentType = getGeneratedTypesByXsdQName().get(new QName(targetNamespace, complexType.getName()));
    }
    if (complexType.isMixed()) {
        currentType.setMixed(true);
        currentType.setSequenced(true);
    // currentType.setOpen(true); Remove as part of SDO JIRA-106
    }
    if (complexType.getAnyAttribute() != null) {
        currentType.setOpen(true);
    }
    currentType.setAbstract(complexType.isAbstractValue());
    currentType.setDataType(false);
    String value = complexType.getAttributesMap().get(SDOConstants.SDOXML_ALIASNAME_QNAME);
    if (value != null) {
        XMLConversionManager xmlConversionManager = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlConversionManager();
        java.util.List names = xmlConversionManager.convertObject(value, java.util.List.class);
        currentType.setAliasNames(names);
    }
    String sequencedValue = complexType.getAttributesMap().get(SDOConstants.SDOXML_SEQUENCE_QNAME);
    if (sequencedValue != null) {
        currentType.setSequenced(Boolean.parseBoolean(sequencedValue));
    }
    Annotation annotation = complexType.getAnnotation();
    if (annotation != null) {
        java.util.List documentation = annotation.getDocumentation();
        if ((documentation != null) && (documentation.size() > 0)) {
            currentType.setInstanceProperty(SDOConstants.DOCUMENTATION_PROPERTY, documentation);
        }
    }
    currentType.preInitialize(packageName, namespaceResolvers);
    if (complexType.getAnnotation() != null) {
        currentType.setAppInfoElements(complexType.getAnnotation().getAppInfo());
    }
    return currentType;
}
Also used : QName(javax.xml.namespace.QName) SDOType(org.eclipse.persistence.sdo.SDOType) Annotation(org.eclipse.persistence.internal.oxm.schema.model.Annotation) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 33 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class SDOSchemaGenerator method buildElement.

private Element buildElement(Property property, NestedParticle nestedParticle) {
    SDOProperty sdoProperty = (SDOProperty) property;
    Element elem = new Element();
    String xsdLocalName = sdoProperty.getXsdLocalName();
    if (xsdLocalName != null) {
        elem.setName(xsdLocalName);
    } else {
        elem.setName(sdoProperty.getName());
    }
    elem.setMinOccurs(Occurs.ZERO);
    elem.setNillable(sdoProperty.isNullable());
    if ((sdoProperty.getAppInfoElements() != null) && (sdoProperty.getAppInfoElements().size() > 0)) {
        Annotation annotation = new Annotation();
        annotation.setAppInfo(sdoProperty.getAppInfoElements());
        elem.setAnnotation(annotation);
    }
    // process default values that are defined in the schema (not via primitive numeric Object wrapped pseudo defaults)
    if (sdoProperty.isDefaultSet()) {
        if (!sdoProperty.isMany() && sdoProperty.getType().isDataType()) {
            XMLConversionManager xmlConversionManager = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlConversionManager();
            elem.setDefaultValue(xmlConversionManager.convertObject(sdoProperty.getDefault(), ClassConstants.STRING, sdoProperty.getXsdType()));
        }
    }
    addSimpleComponentAnnotations(elem, sdoProperty, true);
    /*
         When containment is true, then DataObjects of that Type will appear as nested elements in an XML document.
        When containment is false and the property's type is a DataObject, a URI reference
        to the element containing the DataObject is used and an sdo:propertyType
        declaration records the target type. Values in XML documents will be of the form
        "#xpath" where the xpath is an SDO DataObject XPath subset. It is typical to
        customize the declaration to IDREF if the target element has an attribute with type
        customized to ID.

        [TYPE.NAME] is the type of the element. If property.type.dataType is true,
        [TYPE.NAME] is the name of the XSD built in SimpleType corresponding to
        property.type, where the prefix is for the xsd namespace. Otherwise,
        [TYPE.NAME] is property.type.name where the tns: prefix is determined by the
        namespace declaration for the Type's URI.
         */
    Type schemaSDOType = null;
    QName schemaType = sdoProperty.getXsdType();
    if (schemaType != null) {
        schemaSDOType = aHelperContext.getTypeHelper().getType(schemaType.getNamespaceURI(), schemaType.getLocalPart());
        if ((sdoProperty.getType() == SDOConstants.SDO_STRING) && (schemaSDOType != SDOConstants.SDO_STRING)) {
            String sdoXmlPrefix = getPrefixForURI(SDOConstants.SDOXML_URL);
            QName qname = new QName(SDOConstants.SDOXML_URL, SDOConstants.SDOXML_STRING_NAME, sdoXmlPrefix);
            elem.getAttributesMap().put(qname, "true");
        }
    }
    if (!sdoProperty.isContainment() && !sdoProperty.getType().isDataType()) {
        schemaType = SDOConstants.ANY_URI_QNAME;
    }
    Type propertyType = sdoProperty.getType();
    if (propertyType != null) {
        if (sdoProperty.getContainingType() != null) {
            addTypeToListIfNeeded(sdoProperty.getContainingType(), propertyType);
        }
        if (schemaType == null) {
            schemaType = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getXSDTypeFromSDOType(propertyType);
        }
        // get url for prefix in namespace resolver and map sure it is added to the schema if necessary
        if (schemaType != null) {
            elem.setType(getPrefixStringForURI(schemaType.getNamespaceURI()) + schemaType.getLocalPart());
            if (schemaSDOType != null) {
                addTypeToListIfNeeded(sdoProperty.getContainingType(), schemaSDOType);
            }
        } else if ((propertyType.getURI() == null) || (propertyType.getURI().equalsIgnoreCase(generatedSchema.getTargetNamespace()))) {
            String xsdTypeLocalName = ((SDOType) propertyType).getXsdLocalName();
            if (xsdTypeLocalName != null) {
                elem.setType(xsdTypeLocalName);
            } else {
                elem.setType(propertyType.getName());
            }
        } else {
            String nameString = null;
            String xsdTypeLocalName = ((SDOType) propertyType).getXsdLocalName();
            if (xsdTypeLocalName != null) {
                nameString = xsdTypeLocalName;
            } else {
                nameString = propertyType.getName();
            }
            elem.setType(getPrefixStringForURI(propertyType.getURI()) + nameString);
        }
    } else {
        elem.setType("anyURI");
    }
    if (sdoProperty.isMany()) {
        elem.setMaxOccurs(Occurs.UNBOUNDED);
    } else if (nestedParticle.getMaxOccurs() == Occurs.UNBOUNDED) {
        // this means property.isMany==false and the owning sequence of choice is unbounded Jira SDO-3
        String sdoXmlPrefix = getPrefixForURI(SDOConstants.SDOXML_URL);
        QName qname = new QName(SDOConstants.SDOXML_URL, SDOConstants.SDOXML_MANY, sdoXmlPrefix);
        elem.getAttributesMap().put(qname, "false");
    }
    return elem;
}
Also used : Type(commonj.sdo.Type) SDOType(org.eclipse.persistence.sdo.SDOType) QName(javax.xml.namespace.QName) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 34 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class SDOSchemaGenerator method buildAttribute.

private Attribute buildAttribute(Property property) {
    Attribute attr = new Attribute();
    String xsdLocalName = ((SDOProperty) property).getXsdLocalName();
    if (xsdLocalName != null) {
        attr.setName(xsdLocalName);
    } else {
        attr.setName(property.getName());
    }
    if ((((SDOProperty) property).getAppInfoElements() != null) && (((SDOProperty) property).getAppInfoElements().size() > 0)) {
        Annotation annotation = new Annotation();
        annotation.setAppInfo(((SDOProperty) property).getAppInfoElements());
        attr.setAnnotation(annotation);
    }
    // process default values that are defined in the schema (not via primitive numeric Object wrapped pseudo defaults)
    if (((SDOProperty) property).isDefaultSet()) {
        if (!property.isMany() && property.getType().isDataType()) {
            XMLConversionManager xmlConversionManager = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlConversionManager();
            attr.setDefaultValue(xmlConversionManager.convertObject(property.getDefault(), ClassConstants.STRING, ((SDOProperty) property).getXsdType()));
        }
    }
    addSimpleComponentAnnotations(attr, property, false);
    Type propertyType = property.getType();
    QName schemaType = ((SDOProperty) property).getXsdType();
    if (schemaType != null) {
        Type schemaSDOType = aHelperContext.getTypeHelper().getType(schemaType.getNamespaceURI(), schemaType.getLocalPart());
        if ((property.getType() == SDOConstants.SDO_STRING) && (schemaSDOType != SDOConstants.SDO_STRING)) {
            String sdoXmlPrefix = getPrefixForURI(SDOConstants.SDOXML_URL);
            QName qname = new QName(SDOConstants.SDOXML_URL, SDOConstants.SDOXML_STRING_NAME, sdoXmlPrefix);
            attr.getAttributesMap().put(qname, "true");
        }
    }
    if (!property.getType().isDataType()) {
        schemaType = SDOConstants.ANY_URI_QNAME;
    }
    if (propertyType != null) {
        if (property.getContainingType() != null) {
            addTypeToListIfNeeded(property.getContainingType(), propertyType);
        }
        if (schemaType == null) {
            schemaType = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getXSDTypeFromSDOType(propertyType);
        }
        if (schemaType != null) {
            attr.setType(getPrefixStringForURI(schemaType.getNamespaceURI()) + schemaType.getLocalPart());
        } else if ((propertyType.getURI() == null) || (propertyType.getURI().equalsIgnoreCase(generatedSchema.getTargetNamespace()))) {
            String xsdTypeLocalName = ((SDOType) propertyType).getXsdLocalName();
            if (xsdTypeLocalName != null) {
                attr.setType(xsdTypeLocalName);
            } else {
                attr.setType(propertyType.getName());
            }
        } else {
            String nameString = null;
            String xsdTypeLocalName = ((SDOType) propertyType).getXsdLocalName();
            if (xsdTypeLocalName != null) {
                nameString = xsdTypeLocalName;
            } else {
                nameString = propertyType.getName();
            }
            attr.setType(getPrefixStringForURI(propertyType.getURI()) + nameString);
        }
    // get url for prefix in namespace resolver and map sure it is added to the schema if necessary
    /*
            if (schemaType != null) {
            attr.setType(getPrefixStringForURI(schemaType.getNamespaceURI()) + schemaType.getLocalPart());
            } else {
            attr.setType(propertyType.getName());
            }*/
    }
    return attr;
}
Also used : Type(commonj.sdo.Type) SDOType(org.eclipse.persistence.sdo.SDOType) QName(javax.xml.namespace.QName) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Aggregations

XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)34 XMLField (org.eclipse.persistence.oxm.XMLField)12 QName (javax.xml.namespace.QName)10 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)8 ArrayList (java.util.ArrayList)6 Element (org.w3c.dom.Element)6 Time (java.sql.Time)4 Timestamp (java.sql.Timestamp)4 Vector (java.util.Vector)3 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)3 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)3 SDOType (org.eclipse.persistence.sdo.SDOType)3 DataObject (commonj.sdo.DataObject)2 Property (commonj.sdo.Property)2 Type (commonj.sdo.Type)2 DataHandler (jakarta.activation.DataHandler)2 List (java.util.List)2 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)2 XMLBinaryDataHelper (org.eclipse.persistence.internal.oxm.XMLBinaryDataHelper)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2