|
Red Squirrel Reflections
Dave Hoover explores the psychology of software development
|
|
Thu, 27 Jan 2005Darren 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 Quote Manager Project -- Day 9 An ongoing pet project blog...
I'm trying to hook my new, more tested/able
Manager manager = new Manager() {
public void newQuote(Quote quote) {
System.out.println(quote.text);
}
};
QuoteManagerPanel quoterManager = new QuoteManagerPanel(manager);
I get something when I print out quote.source.title,
but the text property is blank.
Hmmm...got 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,
quoteText.getText(),
sourcePanel,
authorPanels,
quoterPanel);
addButton.addActionListener(actionListener);
layoutForm();
}
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
package com.redsquirrel.com.quotes.xml;
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.io.IOException;
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 = "http://c2.com/cgi/wiki?GangOfFour";
Collection
Here's stubs.xml:
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="sample.xsl"?> <quotes> </quotes>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...
package com.redsquirrel.com.quotes.xml;
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 = ????
root.appendChild(quoteNode);
}
}
Time to experiment. I don't feel like RTFM right now.
Famous last words, I know...
|