View Javadoc

1   package cz.cuni.amis.pogamut.base.communication.parser.impl.yylex;
2   
3   import com.google.inject.Inject;
4   
5   import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
6   import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
7   import cz.cuni.amis.pogamut.base.utils.logging.LogCategory;
8   import cz.cuni.amis.utils.ExceptionToString;
9   import java.util.logging.Level;
10  
11  /**
12   * Interface for reporting of Yylex exceptions.
13   * @author Jimmy
14   */
15  public interface IYylexObserver {
16  
17  	/**
18  	 * Called whenever exception occures in the Yylex caused by OUR miscoding.
19  	 * (Note that we're not hacking Yylex code to report all it's exceptions
20  	 * through this observer - we will call this observer only from our 
21  	 * parts of the code from yylex.java)
22  	 * 
23  	 * @param e never null
24  	 * @param info never null
25  	 */
26  	public void exception(Exception e, String info);
27  	
28  	/**
29  	 * Called when some mischief happens but the parser recovers. (Like
30  	 * wrong parsing of the message, skipping to next...)
31  	 * @param info
32  	 */
33  	public void warning(String info);
34  		
35  	/**
36  	 * Default implementation of the IYylexObserver logging everything into AgentLogger.platform()
37  	 * log category.
38  	 *  
39  	 * @author Jimmy
40  	 */
41  	@AgentScoped
42  	public static class LogObserver implements IYylexObserver {
43  		
44  		private LogCategory log;
45  		
46  		@Inject
47  		public LogObserver(IAgentLogger agentLogger) {
48  			log = agentLogger.getCategory("Yylex");
49  		}
50  
51  		@Override
52  		public void exception(Exception e, String info) {
53  			if (log.isLoggable(Level.SEVERE)) log.severe(ExceptionToString.process(info, e));
54  		}
55  
56  		@Override
57  		public void warning(String info) {
58  			if (log.isLoggable(Level.WARNING)) log.warning(info);
59  		}
60  		
61  	}
62  
63  }