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();
}
}
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());
}
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());
}
}
}
}
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);
}
}
}
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;
}
Aggregations