Skip to main content

Objects and Strings and the Wrangling Thereof

Posted by ljnelson on August 27, 2007 at 10:49 AM PDT

See if this little scenario sounds familiar.

You're rolling along on some application somewhere, and you've decided to put some information in a Properties file somewhere. You realize that you're beginning to encode a lot of information in a property setting, so much so that you realize that really what you're doing is building up a rather complicated Object. You feel like you've done this before.

Or this one:

You're working on a Swing application, and you need to validate the input from the user. Great, you say, I'll use a JFormattedTextField, and then I'll...I'll...I' the...documentation...which features lots of...hmm...factories...and AbstractFormatters...and still more formats and navigation thingees and...I think I'll go get some coffee.

Or this one:

You're halfway through developing a complicated and enterprisey validation framework and you stop abruptly, realizing that there has to be a better way!

Starting with this blog entry I'd like to cover the many, many different ways to edit, format and build up different kinds of Objects that are provided by the Java platform.

Why should you think about turning Objects into Strings? Or Strings into Objects? Or all the other ways that a user might send input to you?

For me, the answer is that whether you're developing on the desktop or on the Web, you are constantly accepting free-form user input in the form of text. In some cases, you have control over this text, and in other cases you do not, but in all cases you often need to turn that text into things like dates, colors, fonts,, custom domain objects and the like. Wouldn't it be nice to come up with a standard set of tools that would manage this kind of conversion for you in a pluggable manner? Wouldn't it be even better if most of that heavy lifting were done for you by the base platform? Well, it is.

In this entry, I'll cover java.beans.PropertyEditor

Related Topics >>