Search in sources :

Example 11 with XMLRoot

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

the class SDODataObject method _getOpenContentPropertiesWithXMLRoots.

/**
 * INTERNAL:
 * This function is implemented by SDOType.setOpen() in a mapping setGet/SetMethodName call
 * @return
 */
public List _getOpenContentPropertiesWithXMLRoots() {
    List returnList = new ArrayList();
    for (int i = 0, size = openContentProperties.size(); i < size; i++) {
        SDOProperty next = (SDOProperty) openContentProperties.get(i);
        XMLRoot root = new XMLRoot();
        String localName = next.getXPath();
        if (next.getType() != null) {
            if (!next.getType().isDataType()) {
                String uri = next.getUri();
                root.setNamespaceURI(uri);
            } else {
                String uri = next.getUri();
                root.setNamespaceURI(uri);
            }
        }
        root.setLocalName(localName);
        Object value = get(next);
        if (next.isMany()) {
            for (int j = 0, sizel = ((List) value).size(); j < sizel; j++) {
                XMLRoot nextRoot = new XMLRoot();
                nextRoot.setNamespaceURI(root.getNamespaceURI());
                nextRoot.setLocalName(root.getLocalName());
                Object nextItem = ((List) value).get(j);
                if ((next.getType() != null) && (next.getType().getXmlDescriptor() == null)) {
                    nextItem = XMLConversionManager.getDefaultXMLManager().convertObject(nextItem, String.class);
                }
                nextRoot.setObject(nextItem);
                returnList.add(nextRoot);
            }
        } else {
            if ((next.getType() != null) && (next.getType().getXmlDescriptor() == null)) {
                value = XMLConversionManager.getDefaultXMLManager().convertObject(value, String.class);
            }
            root.setObject(value);
            returnList.add(root);
        }
    }
    return returnList;
}
Also used : XMLRoot(org.eclipse.persistence.oxm.XMLRoot) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DataObject(commonj.sdo.DataObject) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject)

Example 12 with XMLRoot

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

the class SDOSequence method convertToSetting.

private Setting convertToSetting(Property property, Object value) {
    SDOProperty sdoProperty = (SDOProperty) property;
    DatabaseMapping mapping = sdoProperty.getXmlMapping();
    Setting setting = new Setting();
    SDOType sdoType = dataObject.getType();
    XMLDescriptor xmlDescriptor = sdoType.getXmlDescriptor();
    if (null == mapping) {
        setting.setObject(dataObject);
        mapping = xmlDescriptor.getMappingForAttributeName("openContentProperties");
        setting.setMapping(mapping);
        XMLRoot xmlRoot = new XMLRoot();
        if (value instanceof XMLRoot) {
            xmlRoot.setLocalName(((XMLRoot) value).getLocalName());
            xmlRoot.setNamespaceURI(((XMLRoot) value).getNamespaceURI());
            xmlRoot.setObject(((XMLRoot) value).getObject());
        } else {
            xmlRoot.setLocalName(sdoProperty.getName());
            xmlRoot.setNamespaceURI(sdoProperty.getUri());
            xmlRoot.setObject(value);
            // do not set schema type for global properties
            SDOTypeHelper hlpr = (SDOTypeHelper) dataObject.getType().getHelperContext().getTypeHelper();
            if (hlpr.getOpenContentProperty(sdoProperty.getUri(), sdoProperty.getName()) == null) {
                QName schemaTypeQName = hlpr.getXSDTypeFromSDOType(property.getType());
                if (schemaTypeQName != null && schemaTypeQName != XMLConstants.STRING_QNAME) {
                    xmlRoot.setSchemaType(schemaTypeQName);
                }
            }
        }
        setting.setValue(xmlRoot, false);
    } else {
        setting = convertToSetting(mapping, value);
    }
    return setting;
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) QName(javax.xml.namespace.QName) Setting(org.eclipse.persistence.oxm.sequenced.Setting) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 13 with XMLRoot

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

the class SDOSequence method remove.

private void remove(Setting setting) {
    CoreMapping mapping = setting.getMapping();
    if (null != mapping) {
        Property property = null;
        if (null == setting.getName()) {
            XMLRoot xmlRoot = (XMLRoot) setting.getValue();
            if (null != xmlRoot) {
                property = dataObject.getInstanceProperty(xmlRoot.getLocalName());
                valuesToSettings.remove(new Key(property, setting.getValue()));
            }
        } else {
            property = dataObject.getInstanceProperty(mapping.getAttributeName());
            valuesToSettings.remove(new Key(property, setting.getValue()));
        }
        if (property.isMany()) {
            ListWrapper listWrapper = (ListWrapper) dataObject.getList(property);
            listWrapper.remove(setting.getValue(), false, false);
        } else {
            dataObject.unset(property, false, false);
        }
    } else if (setting.getName() != null && setting.getName().equals(TEXT_XPATH)) {
        // Handle "text()"
        dataObject._setModified(true);
    }
    List<Setting> children = setting.getChildren();
    if (null != children) {
        int childrenSize = children.size();
        for (int x = 0; x < childrenSize; x++) {
            remove(children.get(x));
        }
    }
}
Also used : XMLRoot(org.eclipse.persistence.oxm.XMLRoot) Setting(org.eclipse.persistence.oxm.sequenced.Setting) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) Property(commonj.sdo.Property)

Example 14 with XMLRoot

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

the class SDOXMLHelperDelegate method load.

/**
 * Creates and returns an XMLDocument from the inputSource.
 * The InputSource will be closed after reading.
 * By default does not perform XSD validation.
 * @param inputSource specifies the InputSource to read from
 * @param locationURI specifies the URI of the document for relative schema locations
 * @param options implementation-specific options.
 * @return the new XMLDocument loaded
 * @throws IOException for stream exceptions.
 * @throws RuntimeException for errors in XML parsing or
 *    implementation-specific validation.
 */
@Override
public XMLDocument load(InputSource inputSource, String locationURI, Object options) throws IOException {
    // get XMLUnmarshaller once - as we may create a new instance if this helper isDirty=true
    XMLUnmarshaller anXMLUnmarshaller = getXmlUnmarshaller(options);
    Object unmarshalledObject = null;
    if (options == null) {
        try {
            unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
        } catch (XMLMarshalException xmlException) {
            handleXMLMarshalException(xmlException);
        }
    } else {
        try {
            DataObject optionsDataObject = (DataObject) options;
            try {
                SDOType theType = (SDOType) optionsDataObject.get(SDOConstants.TYPE_LOAD_OPTION);
                try {
                    if (theType != null) {
                        if (theType.isDataType()) {
                            theType = (SDOType) ((SDOTypeHelper) this.aHelperContext.getTypeHelper()).getWrappersHashMap().get(theType.getQName());
                        }
                        if (theType != null) {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource, theType.getImplClass());
                        } else {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
                        }
                    } else {
                        unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
                    }
                } catch (XMLMarshalException xmlException) {
                    handleXMLMarshalException(xmlException);
                }
            } catch (ClassCastException ccException) {
                throw SDOException.typePropertyMustBeAType(ccException);
            }
        } catch (ClassCastException ccException) {
            throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
        }
    }
    if (unmarshalledObject instanceof XMLRoot) {
        XMLRoot xmlRoot = (XMLRoot) unmarshalledObject;
        XMLDocument xmlDocument = createDocument((DataObject) ((XMLRoot) unmarshalledObject).getObject(), ((XMLRoot) unmarshalledObject).getNamespaceURI(), ((XMLRoot) unmarshalledObject).getLocalName());
        if (xmlRoot.getEncoding() != null) {
            xmlDocument.setEncoding(xmlRoot.getEncoding());
        }
        if (xmlRoot.getXMLVersion() != null) {
            xmlDocument.setXMLVersion(xmlRoot.getXMLVersion());
        }
        xmlDocument.setSchemaLocation(xmlRoot.getSchemaLocation());
        xmlDocument.setNoNamespaceSchemaLocation(xmlRoot.getNoNamespaceSchemaLocation());
        return xmlDocument;
    } else if (unmarshalledObject instanceof DataObject) {
        String localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXmlDescriptor().getDefaultRootElement();
        if (localName == null) {
            localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXsdLocalName();
        }
        return createDocument((DataObject) unmarshalledObject, ((DataObject) unmarshalledObject).getType().getURI(), localName);
    } else if (unmarshalledObject instanceof XMLDocument) {
        return (XMLDocument) unmarshalledObject;
    }
    return null;
}
Also used : DataObject(commonj.sdo.DataObject) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) SDOType(org.eclipse.persistence.sdo.SDOType) DataObject(commonj.sdo.DataObject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) SDOXMLDocument(org.eclipse.persistence.sdo.SDOXMLDocument) XMLDocument(commonj.sdo.helper.XMLDocument)

Example 15 with XMLRoot

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

the class SDOXMLHelperDelegate method load.

@Override
public XMLDocument load(Source source, String locationURI, Object options) throws IOException {
    // get XMLUnmarshaller once - as we may create a new instance if this helper isDirty=true
    XMLUnmarshaller anXMLUnmarshaller = getXmlUnmarshaller(options);
    Object unmarshalledObject = null;
    if (options == null) {
        try {
            unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
        } catch (XMLMarshalException xmlException) {
            handleXMLMarshalException(xmlException);
        }
    } else {
        try {
            DataObject optionsDataObject = (DataObject) options;
            try {
                SDOType theType = (SDOType) optionsDataObject.get(SDOConstants.TYPE_LOAD_OPTION);
                try {
                    if (theType != null) {
                        if (theType.isDataType()) {
                            theType = (SDOType) ((SDOTypeHelper) this.aHelperContext.getTypeHelper()).getWrappersHashMap().get(theType.getQName());
                        }
                        if (theType != null) {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(source, theType.getImplClass());
                        } else {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
                        }
                    } else {
                        unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
                    }
                } catch (XMLMarshalException xmlException) {
                    handleXMLMarshalException(xmlException);
                }
            } catch (ClassCastException ccException) {
                throw SDOException.typePropertyMustBeAType(ccException);
            }
        } catch (ClassCastException ccException) {
            throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
        }
    }
    if (unmarshalledObject instanceof XMLRoot) {
        XMLRoot xmlRoot = (XMLRoot) unmarshalledObject;
        XMLDocument xmlDocument = createDocument((DataObject) ((XMLRoot) unmarshalledObject).getObject(), ((XMLRoot) unmarshalledObject).getNamespaceURI(), ((XMLRoot) unmarshalledObject).getLocalName());
        if (xmlRoot.getEncoding() != null) {
            xmlDocument.setEncoding(xmlRoot.getEncoding());
        }
        if (xmlRoot.getXMLVersion() != null) {
            xmlDocument.setXMLVersion(xmlRoot.getXMLVersion());
        }
        xmlDocument.setSchemaLocation(xmlRoot.getSchemaLocation());
        xmlDocument.setNoNamespaceSchemaLocation(xmlRoot.getNoNamespaceSchemaLocation());
        return xmlDocument;
    } else if (unmarshalledObject instanceof DataObject) {
        DataObject unmarshalledDataObject = (DataObject) unmarshalledObject;
        String localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXmlDescriptor().getDefaultRootElement();
        if (localName == null) {
            localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXsdLocalName();
        }
        return createDocument(unmarshalledDataObject, unmarshalledDataObject.getType().getURI(), localName);
    } else if (unmarshalledObject instanceof XMLDocument) {
        return (XMLDocument) unmarshalledObject;
    }
    return null;
}
Also used : DataObject(commonj.sdo.DataObject) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) SDOType(org.eclipse.persistence.sdo.SDOType) DataObject(commonj.sdo.DataObject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) SDOXMLDocument(org.eclipse.persistence.sdo.SDOXMLDocument) XMLDocument(commonj.sdo.helper.XMLDocument)

Aggregations

XMLRoot (org.eclipse.persistence.oxm.XMLRoot)126 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)34 Document (org.w3c.dom.Document)28 SAXException (org.xml.sax.SAXException)17 StringWriter (java.io.StringWriter)16 Person (org.eclipse.persistence.testing.oxm.xmlroot.Person)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 Vector (java.util.Vector)11 Node (org.w3c.dom.Node)11 QName (javax.xml.namespace.QName)10 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)10 Element (org.w3c.dom.Element)10 StringReader (java.io.StringReader)9 InputSource (org.xml.sax.InputSource)9 DataObject (commonj.sdo.DataObject)8 JAXBException (jakarta.xml.bind.JAXBException)8 InputStream (java.io.InputStream)8 MalformedURLException (java.net.MalformedURLException)8 XMLStreamException (javax.xml.stream.XMLStreamException)8