001 package org.codehaus.groovy.control.messages; 002 003 import java.io.PrintWriter; 004 005 import org.codehaus.groovy.control.Janitor; 006 import org.codehaus.groovy.control.ProcessingUnit; 007 import org.codehaus.groovy.control.SourceUnit; 008 import org.codehaus.groovy.syntax.SyntaxException; 009 010 011 012 /** 013 * A base class for compilation messages. 014 * 015 * @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a> 016 * 017 * @version $Id: Message.java,v 1.2 2005/06/09 19:51:59 blackdrag Exp $ 018 */ 019 020 public abstract class Message 021 { 022 023 024 /** 025 * Writes the message to the specified PrintWriter. The supplied 026 * ProcessingUnit is the unit that holds this Message. 027 */ 028 029 public abstract void write( PrintWriter writer, Janitor janitor ); 030 031 032 /** 033 * A synonyn for write( writer, owner, null ). 034 */ 035 036 public final void write( PrintWriter writer) 037 { 038 write( writer, null ); 039 } 040 041 042 043 //--------------------------------------------------------------------------- 044 // FACTORY METHODS 045 046 047 /** 048 * Creates a new Message from the specified text. 049 */ 050 051 public static Message create( String text, ProcessingUnit owner ) 052 { 053 return new SimpleMessage( text, owner ); 054 } 055 056 057 058 /** 059 * Creates a new Message from the specified text. 060 */ 061 062 public static Message create( String text, Object data, ProcessingUnit owner ) 063 { 064 return new SimpleMessage( text, data, owner); 065 } 066 067 068 069 /** 070 * Creates a new Message from the specified SyntaxException. 071 */ 072 073 public static Message create( SyntaxException error, SourceUnit owner ) 074 { 075 return new SyntaxErrorMessage( error, owner ); 076 } 077 078 079 080 081 } 082 083 084 085