1 package org.bitbucket.jrsofty.parser.logging.api; 2 3 import org.bitbucket.jrsofty.parser.logging.util.LogLineFormatException; 4 5 /** 6 * Interface for creating LogParserFactory implementations. 7 * 8 * @author jrsofty 9 * 10 */ 11 public interface LogParserFactory { 12 13 /** 14 * Provides the default parser factory. 15 * 16 * @return the DefaultLogParserFactory implementation of this interface. 17 */ 18 public static LogParserFactory createDefaultInstance() { 19 return new DefaultLogParserFactory(); 20 21 } 22 23 /** 24 * Creates an instance of the LogParser Implementation. 25 * 26 * @param format 27 * a String with the formatting tokens for describing the expected log line format to 28 * match. 29 * @param clazz 30 * a class that has implemented the LogEntry interface and has fields mapped with the 31 * LogElementMapping annotations matching the tokens in the format param. 32 * @return An instance of the LogParser. 33 * @throws LogLineFormatException 34 * when the formatting tokens are invalid or cannot be used. 35 * @throws IllegalClassException 36 * when the class object cannot be instanced, or reflected, or when the 37 * LogElementMapping annotations are missing. 38 */ 39 LogParser createParserForFormat(String format, Class<?> clazz) 40 throws LogLineFormatException, IllegalClassException; 41 42 class DefaultLogParserFactory implements LogParserFactory { 43 44 @Override 45 public LogParser createParserForFormat(final String format, final Class<?> clazz) 46 throws LogLineFormatException, IllegalClassException { 47 final DefaultLogParser defaultParser = new DefaultLogParser(format, clazz); 48 return defaultParser; 49 } 50 51 } 52 53 }