Skip to end of metadata
Go to start of metadata

It is a normal design that a module accepts as a parameter a java.util.Map instance and just uses the "Map.get()" method to get certain values. For example:

It would then be quite easy to call someApi if we've got a Map instance (such as HashMap, Properties etc).

It becomes a problem is when we do not have a Map instance. We may sometimes only have an object of proprietary type with similar Map semantics, for example:

In order to call someApi using an instance of PropertyMap, we will need an adapter.

What's annoying is that the java.util.Map interface is quite fat. Implementing all of the declared methods is a pain. Dimple can help here.

The first step is to create an adapter class:

There's no need to implement the irrelevant methods. One tip to avoid typo is to make PropertyMapAdapter "implements Map" first, you can then use the IDE to generate the method stubs that you want to implement.
Remove the "implements Map" after you are done to make the class instantiable.

There's just one step left to create the Map instance we need by using dimple:


Created by benyu
On Thu Dec 21 10:26:15 CST 2006
Using TimTam

Labels
  • None