Search in sources :

Example 11 with NamespaceResolver

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

the class MarshalRecord method getStringForQName.

protected String getStringForQName(QName qName) {
    if (null == qName) {
        return null;
    }
    String namespaceURI = qName.getNamespaceURI();
    if (null == namespaceURI || 0 == namespaceURI.length()) {
        if (getNamespaceResolver() != null && getNamespaceResolver().getDefaultNamespaceURI() != null) {
            // need to add a default namespace declaration.
            defaultNamespaceDeclaration(namespaceURI);
        }
        return qName.getLocalPart();
    } else {
        NamespaceResolver namespaceResolver = getNamespaceResolver();
        if (namespaceResolver == null) {
            throw XMLMarshalException.namespaceResolverNotSpecified(namespaceURI);
        }
        if (namespaceURI.equals(namespaceResolver.getDefaultNamespaceURI())) {
            return qName.getLocalPart();
        }
        String prefix = namespaceResolver.resolveNamespaceURI(namespaceURI);
        if (null == prefix) {
            if (namespaceURI.equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
                prefix = namespaceResolver.generatePrefix(Constants.SCHEMA_PREFIX);
            } else {
                prefix = namespaceResolver.generatePrefix();
            }
            namespaceDeclaration(prefix, namespaceURI);
        }
        if (Constants.EMPTY_STRING.equals(prefix)) {
            return qName.getLocalPart();
        }
        return prefix + Constants.COLON + qName.getLocalPart();
    }
}
Also used : NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver)

Example 12 with NamespaceResolver

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

the class UnmarshalRecordImpl method get.

@Override
public Object get(CoreField key) {
    Field xmlField = this.convertToXMLField(key);
    XPathFragment lastFragment = xmlField.getLastXPathFragment();
    String namespaceURI = lastFragment.getNamespaceURI();
    if (namespaceURI == null) {
        NamespaceResolver namespaceResolver = xmlField.getNamespaceResolver();
        namespaceURI = Constants.EMPTY_STRING;
        if (null != namespaceResolver && !(lastFragment.isAttribute() && lastFragment.getPrefix() == null)) {
            namespaceURI = namespaceResolver.resolveNamespacePrefix(lastFragment.getPrefix());
            if (null == namespaceURI) {
                namespaceURI = Constants.EMPTY_STRING;
            }
        }
    }
    if (isNamespaceAware()) {
        return attributes.getValue(namespaceURI, lastFragment.getLocalName());
    }
    return attributes.getValue(lastFragment.getLocalName());
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) CoreField(org.eclipse.persistence.internal.core.helper.CoreField) NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver) UnmarshalNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.UnmarshalNamespaceResolver) StackUnmarshalNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.StackUnmarshalNamespaceResolver) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Example 13 with NamespaceResolver

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

the class XMLFragmentReader method endPrefixMappings.

/**
 * If there is a temporary namespace resolver for a given element,
 * each entry contains a prefix that requires an endPrefixMapping
 * event to be triggered
 */
@Override
protected void endPrefixMappings(Element elem) throws SAXException {
    NamespaceResolver tmpresolver = getTempResolver(elem);
    if (tmpresolver != null) {
        ContentHandler contentHandler = getContentHandler();
        String defaultNamespace = tmpresolver.getDefaultNamespaceURI();
        if (null != defaultNamespace) {
            contentHandler.endPrefixMapping(Constants.EMPTY_STRING);
        }
        if (tmpresolver.hasPrefixesToNamespaces()) {
            for (Entry<String, String> entry : tmpresolver.getPrefixesToNamespaces().entrySet()) {
                contentHandler.endPrefixMapping(entry.getKey());
            }
        }
    }
}
Also used : NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver) ContentHandler(org.xml.sax.ContentHandler)

Example 14 with NamespaceResolver

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

the class XMLFragmentReader method handleNewNamespaceDeclaration.

@Override
protected void handleNewNamespaceDeclaration(Element elem, String prefix, String namespaceURI) {
    String uri = resolveNamespacePrefix(prefix);
    if (uri == null || !uri.equals(namespaceURI)) {
        NamespaceResolver tmpresolver = getTempResolver(elem);
        tmpresolver.put(prefix, namespaceURI);
        if (!nsresolverList.contains(tmpresolver)) {
            nsresolverList.add(tmpresolver);
        }
    }
}
Also used : NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver)

Example 15 with NamespaceResolver

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

the class XMLFragmentReader method getTempResolver.

/**
 * Returns the namespace resolver in the map of temporary namespace
 * resolvers for a given element
 *
 * @return the namespace resolver in the map for elem, or a new
 * resolver if none exists
 */
protected NamespaceResolver getTempResolver(Element elem) {
    NamespaceResolver tmpresolver = tmpresolverMap.get(elem);
    if (tmpresolver == null) {
        tmpresolver = new NamespaceResolver();
        tmpresolverMap.put(elem, tmpresolver);
    }
    return tmpresolver;
}
Also used : NamespaceResolver(org.eclipse.persistence.internal.oxm.NamespaceResolver)

Aggregations

NamespaceResolver (org.eclipse.persistence.internal.oxm.NamespaceResolver)20 ArrayList (java.util.ArrayList)3 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)3 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 Node (org.w3c.dom.Node)3 CoreDescriptor (org.eclipse.persistence.core.descriptors.CoreDescriptor)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)2 JAXBException (org.eclipse.persistence.exceptions.JAXBException)2 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)2 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)2 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)2 Field (org.eclipse.persistence.internal.oxm.mappings.Field)2 StackUnmarshalNamespaceResolver (org.eclipse.persistence.internal.oxm.record.namespaces.StackUnmarshalNamespaceResolver)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 IOException (java.io.IOException)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)1