diff --git a/src/main/java/com/solab/iso8583/parse/ConfigParser.java b/src/main/java/com/solab/iso8583/parse/ConfigParser.java index 03f6b9c..f099555 100644 --- a/src/main/java/com/solab/iso8583/parse/ConfigParser.java +++ b/src/main/java/com/solab/iso8583/parse/ConfigParser.java @@ -50,21 +50,37 @@ public class ConfigParser { private final static Logger log = LoggerFactory.getLogger(ConfigParser.class); + /** Creates a message factory configured from the default file, which is j8583.xml + * located in the root of the classpath, using the specified ClassLoader. */ + public static MessageFactory createDefault( + ClassLoader loader) throws IOException { + if (loader.getResource("j8583.xml") == null) { + log.warn("ISO8583 ConfigParser cannot find j8583.xml, returning empty message factory"); + return new MessageFactory(); + } else { + return createFromClasspathConfig(loader, "j8583.xml"); + } + } + /** Creates a message factory configured from the default file, which is j8583.xml - * located in the root of the classpath. */ - public static MessageFactory createDefault() throws IOException { - if (MessageFactory.class.getClassLoader().getResource("j8583.xml") == null) { - log.warn("ISO8583 ConfigParser cannot find j8583.xml, returning empty message factory"); - return new MessageFactory(); - } else { - return createFromClasspathConfig("j8583.xml"); - } + * located in the root of the classpath, using the MessageFactory's + * ClassLoader. */ + public static MessageFactory createDefault() throws IOException { + return createDefault(MessageFactory.class.getClassLoader()); } - /** Creates a message factory from the specified path inside the classpath. */ - public static MessageFactory createFromClasspathConfig(String path) throws IOException { - InputStream ins = MessageFactory.class.getClassLoader().getResourceAsStream(path); - MessageFactory mfact = new MessageFactory(); + /** Creates a message factory from the specified path inside the classpath, + * using the specified ClassLoader. */ + public static MessageFactory createFromClasspathConfig( + String path) throws IOException { + return createFromClasspathConfig(MessageFactory.class.getClassLoader(), path); + } + /** Creates a message factory from the specified path inside the classpath, + * using MessageFactory's ClassLoader. */ + public static MessageFactory createFromClasspathConfig( + ClassLoader loader, String path) throws IOException { + InputStream ins = loader.getResourceAsStream(path); + MessageFactory mfact = new MessageFactory(); if (ins != null) { log.debug("ISO8583 Parsing config from classpath file {}", path); try { @@ -79,8 +95,8 @@ public class ConfigParser { } /** Creates a message factory from the file located at the specified URL. */ - public static MessageFactory createFromUrl(URL url) throws IOException { - MessageFactory mfact = new MessageFactory(); + public static MessageFactory createFromUrl(URL url) throws IOException { + MessageFactory mfact = new MessageFactory(); InputStream stream = url.openStream(); try { parse(mfact, stream); @@ -200,7 +216,7 @@ public class ConfigParser { * if you have a MessageFactory created using Spring for example. */ public static void configureFromDefault( MessageFactory mfact) throws IOException { - if (MessageFactory.class.getClassLoader().getResource("j8583.xml") == null) { + if (mfact.getClass().getClassLoader().getResource("j8583.xml") == null) { log.warn("ISO8583 config file j8583.xml not found!"); } else { configureFromClasspathConfig(mfact, "j8583.xml"); @@ -224,7 +240,7 @@ public class ConfigParser { * Spring-bound instances of MessageFactory for example. */ public static void configureFromClasspathConfig( MessageFactory mfact, String path) throws IOException { - InputStream ins = MessageFactory.class.getClassLoader().getResourceAsStream(path); + InputStream ins = mfact.getClass().getClassLoader().getResourceAsStream(path); if (ins != null) { log.debug("ISO8583 Parsing config from classpath file {}", path); try {