[java-opensaml COMMIT] in /trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io: AbstractXMLObjectMarshaller.ja...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Jun 6 16:28:24 BST 2012
Author: rdw
Date: Wed Jun 6 16:28:24 2012
New Revision: 3055
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3055&view=rev
Log:
Provide support in the base class handlers for dealing with unknown attributes for AttributeExtensibleXMLObjects
Modified:
trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java
trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectUnmarshaller.java
Modified: trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java?rev=3055&r1=3054&r2=3055&view=diff
==============================================================================
--- trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java (original)
+++ trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectMarshaller.java Wed Jun 6 16:28:24 2012
@@ -18,6 +18,7 @@
package org.opensaml.core.xml.io;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -25,16 +26,19 @@
import javax.xml.parsers.ParserConfigurationException;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.xml.AttributeSupport;
import net.shibboleth.utilities.java.support.xml.ElementSupport;
import net.shibboleth.utilities.java.support.xml.NamespaceSupport;
import net.shibboleth.utilities.java.support.xml.QNameSupport;
import net.shibboleth.utilities.java.support.xml.XmlConstants;
+import org.opensaml.core.xml.AttributeExtensibleXMLObject;
import org.opensaml.core.xml.Namespace;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -478,4 +482,23 @@
domCachingObject.releaseParentDOM(true);
}
}
+
+ /**
+ * @param endpoint
+ * @param domElement
+ */
+ protected void marshallUnknownAttributes(AttributeExtensibleXMLObject xmlObject, Element domElement) {
+ Attr attribute;
+ for (Entry<QName, String> entry : xmlObject.getUnknownAttributes().entrySet()) {
+ attribute = AttributeSupport.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
+ attribute.setValue(entry.getValue());
+ domElement.setAttributeNodeNS(attribute);
+ if (XMLObjectProviderRegistrySupport.isIDAttribute(entry.getKey())
+ || xmlObject.getUnknownAttributes().isIDAttribute(entry.getKey())) {
+ attribute.getOwnerElement().setIdAttributeNode(attribute, true);
+ }
+ }
+
+ }
+
}
Modified: trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectUnmarshaller.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectUnmarshaller.java?rev=3055&r1=3054&r2=3055&view=diff
==============================================================================
--- trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectUnmarshaller.java (original)
+++ trunk/opensaml-core/src/main/java/org/opensaml/core/xml/io/AbstractXMLObjectUnmarshaller.java Wed Jun 6 16:28:24 2012
@@ -24,6 +24,7 @@
import net.shibboleth.utilities.java.support.xml.QNameSupport;
import net.shibboleth.utilities.java.support.xml.XmlConstants;
+import org.opensaml.core.xml.AttributeExtensibleXMLObject;
import org.opensaml.core.xml.Namespace;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBuilder;
@@ -395,4 +396,18 @@
protected void processElementContent(XMLObject xmlObject, String elementContent) {
log.debug("Ignorning unknown element content {}", elementContent);
}
+
+ /**
+ * Called to store unrecognised attributes, if the object supports that. It is expected that the
+ * objects marshaller will have checked and dealt with for known attributes before calling this.
+ * @param xmlObject The object which support anyAttribute.
+ * @param attribute The attribute in question.
+ */
+ protected void processUnknownAttribute(AttributeExtensibleXMLObject xmlObject, Attr attribute) {
+ QName attribQName = QNameSupport.getNodeQName(attribute);
+ if (attribute.isId()) {
+ xmlObject.getUnknownAttributes().registerID(attribQName);
+ }
+ xmlObject.getUnknownAttributes().put(attribQName, attribute.getValue());
+ }
}
More information about the commits
mailing list