Red Squirrel Reflections
Dave Hoover explores the psychology of software development

Dave Hoover

All [Atom]
Craftsmanship [Atom]
Dynamic [Atom]
Intersection [Atom]
Learning [Atom]
Links [Atom]
Polyglot [Atom]
Projects [Atom]
XP [Atom]
Old Blog

Obtivian Blogs

Andy Maleh
Colin Harris
Fred Polgardy
Jim Breen
Kevin Taylor
Todd Webb
Turner King
Tyler Jennings


March 2009 (1)
January 2009 (1)
December 2008 (1)
October 2008 (3)
September 2008 (1)
June 2008 (4)
April 2008 (3)
March 2008 (1)
February 2008 (1)
August 2007 (1)
July 2007 (1)
June 2007 (1)
May 2007 (4)
April 2007 (3)
March 2007 (5)
February 2007 (6)
January 2007 (6)
December 2006 (10)
November 2006 (5)
October 2006 (8)
September 2006 (8)
August 2006 (5)
July 2006 (12)
June 2006 (7)
May 2006 (5)
April 2006 (5)
March 2006 (4)
February 2006 (2)
January 2006 (5)
December 2005 (5)
November 2005 (3)
October 2005 (3)
September 2005 (6)
August 2005 (4)
July 2005 (7)
June 2005 (14)
May 2005 (6)
April 2005 (8)
March 2005 (9)
February 2005 (11)
January 2005 (16)
Old Archives


Thu, 27 Jan 2005

Try, Fail, Learn, Fail...

Darren has a quick thought about the esssence of programming and it captures some of what I love about my job.

A couple quotes that build on this theme...

"If we can get introduced to our ignorance, isn't that something worth celebrating?" --The New Peoplemaking, p. 220, Virginia Satir

"Self-examination is hard, but I believe we can learn more from studying our failures than from our successes." --Project Retrospectives, p. 175, Norm Kerth

"Success, while it may provide encouragement, build confidence, and be joy filled, often teaches an insidious lesson -- to have a high opinion of self. It is from failure that amazing growth and grace so often come, provided only that we can recognize it, admit it, learn from it, rise above it, and try again." --Birth of the Chaordic Age, p. 71, Dee Hock

[/links] permanent link

Quote Manager Project -- Day 9

An ongoing pet project blog...

I'm trying to hook my new, more tested/able AddButtonActionListener into the QuoteManagerPanel and having some difficulties. Everything compiles but when I inject this anonymous Manager into QuoteManagerPanel, I get nothing after filling out the quote form and clicking 'Add'...

        Manager manager = new Manager() {
            public void newQuote(Quote quote) {
        QuoteManagerPanel quoterManager = new QuoteManagerPanel(manager);
I get something when I print out quote.source.title, but the text property is blank. it! The problem is that when I create my AddButtonActionListener, I pass in the value of the quote text then and there. Like this:
    public QuoteManagerPanel(Manager manager) {
        setLayout(new GridBagLayout());

        for (int i = 0; i < NUMBER_OF_AUTHORS; i++)
            authorPanels[i] = new PersonPanel("Author " + (i + 1));

        ActionListener actionListener = new AddButtonActionListener(manager,
At that point, the field is blank. The simplest thing right now would be to pass in the JTextField rather than the String. I'll change the tests and see what happens... Ah, that's better.

To complete my current task, I need to add a quote to an XML file. A Manager can handle that. I want to start with a test...


import com.redsquirrel.quotes.gui.Manager;
import com.redsquirrel.quotes.model.Person;
import com.redsquirrel.quotes.model.Quote;
import com.redsquirrel.quotes.model.Source;
import org.jmock.MockObjectTestCase;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.util.ArrayList;
import java.util.Collection;

public class XmlQuoteManagerTest extends MockObjectTestCase {
    public void testShouldWriteXmlWhenGivenNewQuote() throws ParserConfigurationException, IOException, SAXException {
        String text = "Program to an interface, not an implementation.";
        String isbn = "0201633612";
        String title = "Design Patterns";
        String firstName = "Gang";
        String lastName = "of Four";
        String url = "";
        Collection authors = new ArrayList(1);
        authors.add(new Person(firstName, lastName, url));
        Quote quote = new Quote(text, new Source(title, "", isbn), authors, null);

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse("stub.xml");

        assertEquals(0, document.getElementsByTagName("quote").getLength());

        Manager manager = new XmlQuoteManager(document);

        assertEquals(1, document.getElementsByTagName("quote").getLength());

Here's stubs.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>

The test simply checks to make sure the document has gone from zero to one quote. I'll start by letting IDEA create the XmlQuoteManager. The test fails. To get the test to pass I need to add an element of type "quote". Shoot, I'm not sure how to do that. In my spike I simply updated an attribute of an existing Node. Here's where I'm stuck...

import com.redsquirrel.quotes.gui.Manager;
import com.redsquirrel.quotes.model.Quote;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class XmlQuoteManager implements Manager {
    private final Document document;

    public XmlQuoteManager(Document document) {
        this.document = document;

    public void newQuote(Quote quote) {
        Node root = document.getElementsByTagName("quotes").item(0);

        Node quoteNode = ????
Time to experiment. I don't feel like RTFM right now. Famous last words, I know...

[/projects/quotes] permanent link

powered by blosxom