Vita Rara: A Life Uncommon

Using Dynamic Method Invocation to "Script" Java


Although Java isn't thought of as a dynamic language now a days, what with Ruby and Groovy being all the rage, Java does have support for dynamic features. (See my previous blog post on the subject and the solution I came up with.)

A Use Case for Dynamic Java

Currently I'm wrapping about a hundred EJB 2.1 LocalHome classes in DAO's, and having them transform local EJB entities into POJO's. Much of the code is largely boiler plate. Actually it's mind numbingly boiler plate. Here's a sample of wrapping a finder:

What's Wrong with Java's Dynamic Dispatch or "How I Implemented sendMessage()"


(Related article using this technique to "script" some Java objects: article.)

The following code quickly illustrates an issue with the Reflection API's in the Java language. At run time finding methods on classes requires that the types passed to Class#findMethod() exactly match those found in the method declaration. The JavaDoc and language spec refers to these as the "formal parameter types".

The issue is, I have a method that takes an A, and I have an object of B that extends A. If you run the following code it will fail, being unable to find the method.

Closures and Bindings in Groovy

Categories: |

You can learn something every day. That's what is so nice about being a software developer.

Today I was looking at some Grails code, seeing how some of the metaprogramming features of Groovy are used in the framework. After poking around I decided to look at the ServicesGrailsPlugin to see how the automatic wiring of services was done, and ran across the following code:

def doWithSpring = {
  application.serviceClasses.each { serviceClass ->
      def scope = serviceClass.getPropertyValue("scope")

    "${serviceClass.fullName}ServiceClass"(MethodInvokingFactoryBean) {
      targetObject = ref("grailsApplication", true)

Yes the JVM is a Multi-Language Platform

Categories: |

Although talk about multiple languages running on the JVM has grown over the past few years, the reality of it really hit home with me this morning. I turned to one of my employees who has been doing JVM development for me since April of last year. The interesting thing is probably 95% of the JVM work he has done isn't in Java, it's in Groovy. Here's to the multi-language Java platform and a thank you to those developers who are making it a reality.

Ruby Metaprogramming: Declaratively Adding Methods to a Class

Categories: |

In this brief piece I will examine Ruby's support for metaprogramming and how to define class level methods that add instance methods to our class implementations at run time.

Over the past few months I've been learning Ruby on Rails. One of the most attractive features of Rails its declarative style of defining relationships and validations on models; and filters on actions.

A simple example of this declarative style:

class Party < ActiveRecord::Base
  has_many :addresses

This class defines a Party model that can have many addresses. The simple "has_many :addresses" declaration is a great example of the power of Ruby. This simple statement adds a number of methods to our Party class, and allows us to easily manage relationships between our parties and their addresses.

Setup (RESTful) Authentication First


Well, I've learned a lesson, so learn from me, and don't repeat it. If you're going to use either of the Rails authentication plugins (restful_authentication or acts_as_authenticated), just set them up first, before you start into your own user models, etc. It's much easier that way.

Thank You Zed


Dear Zed,

About that long Ruby on Rails rant against its core developers, the Rails community, those of us coming late to the party from other languages and platforms, and just about everyone else in sight... ok, credit where credit is due, Obie Fernandez and Mingle came in for some praise. Anyway, I won't hash it all out again. I really don't care. I will say though I strongly disagree with how you went about it. Bile is bile, and what you wrote is bile. I'm reasonably qualified in the taxonomy of Internet writing to make the identification. (Yes, I've written my share of flames, but none quite so base as yours.)

How I Use Rails Migrations for a New Project


Yesterday I started a new Rails project and it got me thinking about how I use migrations at the start of a project. I generally start with models and migrations when I begin a new project.

My usage of migrations tends to differ in the first day(s) of a Rails project. I will frequently roll the version of the data schema between 0 and the current version. I do this because if I forget a field/property on a model I don't define a new migration to add it, I just roll the schema back to 0 (rake db:migrate VERSION=0), change the create table migration, and then do a rake db:migrate to bring the schema right up to date. I find this the most pragmatic method early on and I continue to use it until I can't.

The Future That Has Already Happened

Categories: | | | | | |

January second's Daily Drucker dealt with the future, but not as most business prognosticators or futurists might. As Drucker states it, "The important thing is to identify the 'future that has already happened...'"

The action point for the day is to identifying those trends in our market that have already happened, write about their longevity and their effect on our life and organization.

Software as a Service For the Rest of Us

Over the past few years, and particularly in 2007 Software as a Service (Saas) has really broken out and has become a force in the software industry. The first large scale SaaS offering that really broke through to my consciousness was, then for me came Basecamp from represented a high level enterprise offering, with a high level of complexity and expense. Basecamp brought software as a service home to us all.

The Daily Drucker

Categories: |

For the Holidays I picked up a copy of "The Daily Drucker" (Barnes and Noble,, a daily reader with short excepts from the great corpus of Peter Drucker's life long writing.

For those who have read widely of Drucker's work "The Daily Drucker" would likely be a nice reminder of the high points of his management philosophy. For those coming to Drucker for the first time it will serve as a good introduction.