/**
 * using an XML flatfile
 */
public class ForumLog implements java.io.Serializable {
    private java.io.File file;
    private java.util.List log=new java.util.LinkedList();
    public ForumLog() {
	new ForumLog("default-forum.xml");
    }
    public ForumLog(String filename) {
	file=new java.io.File(filename);
	try {
	    file.createNewFile();
	}catch(java.io.IOException ioe) {
	    System.out.println(ioe);
	}
    }

    public static class Data {//move to Forum or separate class or not (setCommentNumber)
	private String name;//name of author
	private int commentNumber; //determined when logged
	private String comment;//the comment to log
	public Data(String name, String comment) {//used by Forum
	    this.name=name;
	    this.comment=comment;
	}
	private Data(String name, int commentNumber, String comment) {//used by ForumLog
	    this.name=name;
	    this.commentNumber=commentNumber;
	    this.comment=comment;
	}
	public String getName(){
	    return name;
	}
	public int getCommentNumber() {
	    return commentNumber;
	}
	public String getComment(){
	    return comment;
	}
	private void setCommentNumber(int commentNumber){
	    this.commentNumber=commentNumber;
	}
	public String toString() {
	    return "[name="+name+", commentNumber="+commentNumber+", comment="+comment+"]";
	}
    }

    public void logEntry(Data entry) {
	entry.setCommentNumber(log.size()+1);
	log.add(entry);
    }

    public Data getEntry(int entryNumber) {
	return (Data)log.get(entryNumber);
    }

    public int entryCount() {
	return log.size();
    }

    public String toString() {
	return log.toString();
    }

    public static void main(String args[]) {
	ForumLog ff=new ForumLog();
	ff.logEntry(new Data("Mike","My comment 1"));
	ff.logEntry(new Data("Mr. Head","My other comment"));
	System.out.println(ff);
    }
}

