On mac JAVA_HOME is detected by using the following code:
But this does not work in collaboration with Using "Java preferences" to change the actual java version to use as "CurrentJDK" does not change once you update the "java applications" order.
There is an alternative (at least on Leopard) for determining current java home that is based on Java Preferences by using an apple provided script. So, as a replacement fo rthe code above the following could be used.
Could also be taht this is teh first attempt and if fails use the current way of determining home.