1 package net.sf.logdistiller.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.text.ParseException;
18
19 import net.sf.logdistiller.LogEvent;
20
21
22
23
24
25
26 public abstract class LogEventBuilder
27 {
28 protected abstract LogEvent newEvent( LogEvent.Factory factory, String curLine, Object... objects )
29 throws ParseException;
30
31 public LogEvent buildLogEvent( LogEvent.Factory factory, int lineNumber, String curLine, Object... objects )
32 {
33 try
34 {
35 return newEvent( factory, curLine, objects );
36 }
37 catch ( ParseException pe )
38 {
39 throw newRuntimeException( lineNumber, curLine, pe );
40 }
41 catch ( RuntimeException re )
42 {
43 throw newRuntimeException( lineNumber, curLine, re );
44 }
45 }
46
47 private RuntimeException newRuntimeException( int lineNumber, String curLine, Throwable t )
48 {
49 String message;
50 if ( lineNumber > 0 )
51 {
52 message = "error while parsing line #" + lineNumber + " '" + curLine + "'";
53 }
54 else
55 {
56 message = "error while parsing '" + curLine + "'";
57 }
58
59 return new RuntimeException( message, t );
60 }
61 }