Invoices… right under my nose…
September 24th, 2008
I'm slightly embarrassed about my choice for invoicing mentioned in a previous post. I hastily went with the first one listed when I should have looked at the second page of the google search. All this time, it's been right under my nose. I use it on a daily basis. It's GnuCash.
BambooInvoice Installed
September 15th, 2008
I do some free-lance development work and decided I needed some software to help me bill/invoice my clients. But just as important, I needed to keep history so that when tax time comes around, I have a record of all the clients I've billed and all the payments I've received. I did a google search for "invoice software open source" and thought I'd test drive the first one on the list: BambooInvoice. Continue Reading »
3D is Back…
September 11th, 2008
It seems that 3D is on its way back! And not a moment too soon. First off, there are movies in my local theaters: "Fly Me to the Moon," "Journey to Center of the Earth." Apparently several of our theaters have adopted Real D technologies without having to build-out a new theater. I've only seen "Fly Me to the Moon" and it was fun, but really lacked in story development. The 3D aspect, however, was awesome, the rockets launching, spacecraft floating, flies dancing, all looked great.
I've also discovered that these 3D technologies are coming to the Home-theater and to my PC. Check out 3D Roundup for some great current news on the subject. I've added 3D Roundup to my list of permanent bookmarks. It's exciting to see all of this cool stuff happening, and hopefully I can be a part of it.
The Real Transformers
June 14th, 2007
I was checking out some videos on YouTube today and came across this one. I love this video. Basically, it's a stop-motion animation using transformer action figures. If you're a fan of the Transformers (from way back), you'll like this video.
I must say that the dialog was a bit lacking and the sound needs a little work too, but it's still worth it. Another great day online!
Side Note: Man, I really need to upgrade my Wordpress. I'd love to be able to embed the movie on this page. Anyway...
Enum as an XML Attribute with XStream
December 8th, 2006
I am the type of developer that uses existing 3rd-party solutions whenever possible. Lately, I've been using XStream for object persistance in a standalone Java application. So far, I must say that I'm extremely impressed with how well this API is put together and also with its simplicity. Exporting an entire object tree is as simple as new XStream().toXML(myObjectTree);
One of the great features of XStream is its ability for customization of the XML. I began customizing my XML and ran into a slight snag (not a bug, but a snag). I couldn't figure out how to get an enum field to output as an attribute rather than a child element. Example Java class:
class Card {
int val;
Type type;enum Type {
HEARTS, CLUBS, DIAMONDS, SPADES
}
}
Now let's export it:
void export(List<Card> cards) {
XStream xs = new XStream();
xs.alias("cards", List.class);
xs.alias("card", Card.class);
xs.useAttributeFor("val", int.class);
xs.useAttributeFor("type", Type.class);System.out.print(xs.toXML(cards));
}
Executing the above code will produce the following XML:
<cards>
<card val="1">
<type>SPADES</type>
</card>
</cards>
As you can see, the type field is not properly used as an attribute like I instructed: xs.useAttributeFor("type", Type.class); The reason? Well, I wasn't sure, so, being the lazy developer I am, I trolled around Google, et. al. to find if someone else had this problem. Nothing. And after a few minutes of poking around in the XStream documentation, I was at a loss. I sent an email describing my problem to the users' mailing list, expecting to wait a day or so for an answer. Supprisingly, I recieved an answer within a few hours, from the project lead himself.
Jörg informed me that attribute converters must be of type SingleValueConverter. Attributes are single text values and don't need all of that other object (un)ravelling stuff. Jörg also pointed me to an issue that had been opened in the project's bug tracking system just a few days ago that also described this.
The solution, at the moment, is to simply create a specific converter for my Enum types that is a SingleValueConverter. The code for this is below:
public class SingleValueEnumConverter extends AbstractSingleValueConverter {
private final Class enumType;
public SingleValueEnumConverter(Class type) {
this.enumType = type;
}public boolean canConvert(Class c) {
return c.equals(enumType);
}public Object fromString(String value) {
return Enum.valueOf(enumType, value);
}
}
And to modify the XStream example above:
XStream xs = new XStream();
xs.alias("cards", List.class);
xs.alias("card", Card.class);
xs.useAttributeFor("val", int.class);
xs.useAttributeFor("type", Type.class);xs.registerConverter(new SingleValueEnumConverter(Card.Type.class));
System.out.print(xs.toXML(cards));
And now the XML looks like this:
<cards>
<card val="1" type="SPADES"/>
</cards>
So as you can see, this was exactly what I needed. I love coding in a world where we have such a large community of people willing to take a few minutes of their time to guide you in the right direction. Great job XStream!
