Sometimes Microsoft ‘gets it’ My iPhone
Feb 17

Femtocontainer — The IoC container built into the JDK

Java, Lightweight Containers, Tech Add comments

Sam has wisely seen that Java has a version of IoC via the java.beans.XMLEncoder/XMLDecoder classes.

Take a look at Sam’s XML config:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE javabeans SYSTEM "http://www.javarants.com/schemas/javabeans.dtd">
<java version="1.4.2" class="java.beans.XMLDecoder">
<object id="cityFinder" class="com.sampullara.jbioc.CityScape">
<void property="cityMap">
<object class="java.util.HashMap">
<void method="put">
<string>LDN</string>
<string>London</string>
</void>
<void method="put">
<string>FFT</string>
<string>Frankfurt</string>
</void>
</object>
</void>
</object>
<object id="region" class="com.sampullara.jbioc.RegionInfo">
<void property="cityFinder"><object idref="cityFinder"/></void>
<void property="regions">
<object class="java.util.ArrayList">
<void method="add"><string>Europe</string></void>
<void method="add"><string>America</string></void>
</object>
</void>
</object>
</java>

Now, you may not be a big fan of the Spring XML config, but this is even closer to the bone. It really does shout out “WHY ARE WE USING XML FOR THIS AND NOT JUST CODE!” (especially a dynamic language).

Also, although it does allow some dependency injection, it is basic. It doesn’t support the layers of components/services like HiveMind.

And IoC itself is only part of the picture. The real power of Spring is that it has practical stuff that you can use out of the box! Great find though Sam!

One Response to “Femtocontainer — The IoC container built into the JDK”

  1. Sam Pullara Says:

    Its just a Java scripting language with a really verbose syntax. With all the help IDEs give you these days, I’m starting to wonder why all the config stuff isn’t just in code. It seems like a much better way to do it. Its a good question to take to the JCP.

    As for the layers of components and services, wait till I do my article on java.beans.beancontext.BeanContext. Its hard to believe what they have squirreled away in rt.jar.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'cricket'