public static <T> T decode(Class<T> clazz,
File configuration,
String artemisHome,
String artemisInstance,
URI artemisURIInstance) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance("org.apache.activemq.artemis.dto");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
sf.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false);
InputStream xsdStream = XmlUtil.class.getClassLoader().getResourceAsStream("org.apache.activemq/dto/activemq.xsd");
StreamSource xsdSource = new StreamSource(xsdStream);
Schema schema = sf.newSchema(xsdSource);
unmarshaller.setSchema(schema);
Properties props = new Properties(System.getProperties());
if (artemisHome != null) {
props.put("artemis.home", artemisHome);
}
if (artemisInstance != null) {
props.put("artemis.instance", artemisInstance);
}
if (artemisURIInstance != null) {
props.put("artemis.URI.instance", artemisURIInstance.toString());
}
XMLStreamReader reader = factory.createXMLStreamReader(new FileInputStream(configuration));
reader = new PropertiesFilter(reader, props);
return clazz.cast(unmarshaller.unmarshal(reader));
}