[java-opensaml COMMIT] in /trunk/opensaml-core/src: main/java/org/opensaml/core/xml/util/XMLObjectSupport.java test/j...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Jun 17 19:39:04 EDT 2015
Author: putmanb
Date: Wed Jun 17 19:39:04 2015
New Revision: 4307
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4307&view=rev
Log:
OSJ-122: XMLObjectSupport buildXMLObject methods should use buildOrThrow paradigm
Modified:
trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
trunk/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java
Modified: trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java?rev=4307&r1=4306&r2=4307&view=diff
==============================================================================
--- trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java (original)
+++ trunk/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java Wed Jun 17 19:39:04 2015
@@ -402,15 +402,12 @@
* Build an XMLObject based on the element name.
*
* @param elementName the element name
- * @return an XMLObject, or null if no provider registered
+ * @return an XMLObject
+ * @throws XMLRuntimeException if the required builder can not be obtained
*/
public static XMLObject buildXMLObject(QName elementName) {
- XMLObjectBuilder<?> builder = getProviderRegistry().getBuilderFactory().getBuilder(elementName);
- if (builder != null) {
- return builder.buildObject(elementName);
- } else {
- return null;
- }
+ XMLObjectBuilder<?> builder = getProviderRegistry().getBuilderFactory().getBuilderOrThrow(elementName);
+ return builder.buildObject(elementName);
}
/**
@@ -418,15 +415,12 @@
*
* @param elementName the element name
* @param typeName the xsi:type
- * @return an XMLObject, or null if no provider registered
+ * @return an XMLObject
+ * @throws XMLRuntimeException if the required builder can not be obtained
*/
public static XMLObject buildXMLObject(QName elementName, QName typeName) {
- XMLObjectBuilder<?> builder = getProviderRegistry().getBuilderFactory().getBuilder(elementName);
- if (builder != null) {
- return builder.buildObject(elementName, typeName);
- } else {
- return null;
- }
+ XMLObjectBuilder<?> builder = getProviderRegistry().getBuilderFactory().getBuilderOrThrow(elementName);
+ return builder.buildObject(elementName, typeName);
}
/**
@@ -483,8 +477,13 @@
* Obtain the XMLObject provider registry.
*
* @return the configured XMLObject provider registry
+ * @throws XMLRuntimeException if the registry is not available
*/
private static XMLObjectProviderRegistry getProviderRegistry() {
- return ConfigurationService.get(XMLObjectProviderRegistry.class);
+ XMLObjectProviderRegistry registry = ConfigurationService.get(XMLObjectProviderRegistry.class);
+ if (registry == null) {
+ throw new XMLRuntimeException("XMLObjectProviderRegistry was not available from the ConfigurationService");
+ }
+ return registry;
}
}
Modified: trunk/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java?rev=4307&r1=4306&r2=4307&view=diff
==============================================================================
--- trunk/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java (original)
+++ trunk/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java Wed Jun 17 19:39:04 2015
@@ -17,14 +17,18 @@
package org.opensaml.core.xml.util;
+import javax.xml.namespace.QName;
+
import org.testng.annotations.Test;
import org.testng.Assert;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.XMLRuntimeException;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.core.xml.io.UnmarshallingException;
import org.opensaml.core.xml.mock.SimpleXMLObject;
import org.opensaml.core.xml.mock.SimpleXMLObjectBuilder;
+import org.opensaml.core.xml.schema.XSString;
import org.opensaml.core.xml.util.XMLObjectSupport;
/**
@@ -108,5 +112,33 @@
"Cloned object was not the new Document root");
}
+ @Test
+ public void testBuildXMLObject() {
+ try {
+ XMLObjectSupport.buildXMLObject(simpleXMLObjectQName);
+ } catch (Exception e) {
+ Assert.fail("Expected XMLObject could not be built");
+ }
+
+ try {
+ XMLObjectSupport.buildXMLObject(simpleXMLObjectQName, XSString.TYPE_NAME);
+ } catch (Exception e) {
+ Assert.fail("Expected XMLObject could not be built");
+ }
+
+ try {
[... 16 lines stripped ...]
More information about the commits
mailing list