Skip to content

Commit

Permalink
[NOISSUE]
Browse files Browse the repository at this point in the history
add convenience method
  • Loading branch information
jj committed Feb 26, 2019
1 parent 2338269 commit 74de78e
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import net.shibboleth.utilities.java.support.xml.ParserPool;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.config.InitializationException;
import org.opensaml.core.xml.XMLObject;
Expand All @@ -15,6 +16,7 @@
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.core.xml.io.Unmarshaller;
import org.opensaml.core.xml.io.UnmarshallerFactory;
import org.opensaml.core.xml.io.UnmarshallingException;
import org.opensaml.saml.saml2.metadata.EntityDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -130,6 +132,17 @@ public EntityDescriptor unmarshalFromXml(byte[] entityDescriptorXml) throws Exce
}
}

public <T> T unmarshallFromXml(byte[] xml, Class<T> type) throws IOException, XMLParserException, UnmarshallingException {
try (InputStream is = ByteSource.wrap(xml).openBufferedStream()) {
Document d = this.parserPool.parse(is);
Unmarshaller unmarshaller = this.unmarshallerFactory.getUnmarshaller(d.getDocumentElement());
if (unmarshaller != null) {
return type.cast(unmarshaller.unmarshall(d.getDocumentElement()));
}
return null;
}
}

// TODO: yeah, I'm not happy with this...
public <T extends XMLObject> T buildDefaultInstanceOfType(Class<T> type) {
try {
Expand Down

0 comments on commit 74de78e

Please sign in to comment.