Search in sources :

Example 91 with NamespaceResolver

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

the class ContainmentProject method getChildDescriptor.

private XMLDescriptor getChildDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child.class);
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:containment");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:child");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(schemaReference);
    XMLDirectMapping mapping = new XMLDirectMapping();
    mapping.setAttributeName("value");
    mapping.setXPath("tns:value/text()");
    xmlDescriptor.addMapping(mapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 92 with NamespaceResolver

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

the class ContainmentProject method getRootDescriptor.

private XMLDescriptor getRootDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Root.class);
    xmlDescriptor.setDefaultRootElement("tns:root-element");
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:root");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(schemaReference);
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:containment");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping();
    mapping.setReferenceClass(Child.class);
    if (mapping.getInverseReferenceMapping() != null) {
        mapping.getInverseReferenceMapping().setAttributeName("container");
    }
    mapping.setAttributeName("childProperty");
    mapping.setXPath("tns:child");
    xmlDescriptor.addMapping(mapping);
    XMLCompositeCollectionMapping mapping2 = new XMLCompositeCollectionMapping();
    mapping2.setReferenceClass(Child.class);
    if (mapping.getInverseReferenceMapping() != null) {
        mapping2.getInverseReferenceMapping().setAttributeName("container");
    }
    mapping2.setAttributeName("childCollectionProperty");
    mapping2.setXPath("tns:child-many");
    mapping2.getContainerPolicy().setContainerClass(ArrayList.class);
    xmlDescriptor.addMapping(mapping2);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 93 with NamespaceResolver

use of org.eclipse.persistence.oxm.NamespaceResolver 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);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 94 with NamespaceResolver

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

the class SDOTypesGenerator method getURIForPrefix.

private String getURIForPrefix(String prefix) {
    String uri = null;
    for (int i = namespaceResolvers.size() - 1; i >= 0; i--) {
        NamespaceResolver next = namespaceResolvers.get(i);
        uri = next.resolveNamespacePrefix(prefix);
        if ((uri != null) && !uri.equals(SDOConstants.EMPTY_STRING)) {
            break;
        }
    }
    if (null == uri) {
        throw SDOException.prefixUsedButNotDefined(prefix);
    }
    return uri;
}
Also used : NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 95 with NamespaceResolver

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

the class SDOTypesGenerator method addRootElementToDescriptor.

private void addRootElementToDescriptor(SDOProperty p, String targetNamespace, String xsdName) {
    if (!p.getType().isDataType()) {
        String prefix = null;
        if (targetNamespace != null && !XMLConstants.EMPTY_STRING.equals(targetNamespace)) {
            NamespaceResolver nr = p.getType().getXmlDescriptor().getNamespaceResolver();
            if (nr != null) {
                prefix = nr.resolveNamespaceURI(targetNamespace);
                if (null == prefix) {
                    prefix = nr.generatePrefix();
                    nr.put(prefix, targetNamespace);
                }
            }
        }
        if ((prefix == null) || prefix.equals(SDOConstants.EMPTY_STRING)) {
            p.getType().getXmlDescriptor().addRootElement(xsdName);
        } else {
            p.getType().getXmlDescriptor().addRootElement(// 
            prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + xsdName);
        }
    } else {
        // Types from Schema: isDataType() == true so:
        // - find the SDOWrapperType from TypeHelper's WrappersHashMap
        // - set the root element name on it
        // - add the descriptor to XMLContext's DescriptorsByQName map
        // See also: SDOTypeHelperDelegate:defineOpenContentProperty
        SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
        SDOWrapperType wrapperType = (SDOWrapperType) typeHelper.getWrappersHashMap().get(p.getType().getQName());
        XMLDescriptor d = wrapperType.getXmlDescriptor(p.getXsdType());
        if (wrapperType != null) {
            d.addRootElement(xsdName);
            QName descriptorQname = new QName(targetNamespace, xsdName);
            ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().addDescriptorByQName(descriptorQname, d);
        }
    }
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) QName(javax.xml.namespace.QName) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Aggregations

NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)227 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)142 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)74 XMLField (org.eclipse.persistence.oxm.XMLField)36 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)36 Document (org.w3c.dom.Document)35 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)23 QName (javax.xml.namespace.QName)20 InputStream (java.io.InputStream)17 StringReader (java.io.StringReader)17 StringWriter (java.io.StringWriter)17 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)16 InputSource (org.xml.sax.InputSource)14 Element (org.w3c.dom.Element)13 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)12 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)12 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)10 HashMap (java.util.HashMap)9 Project (org.eclipse.persistence.sessions.Project)9 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)8