[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: MC tools
alesj
do-not-reply at jboss.com
Mon Jun 15 08:08:24 EDT 2009
"flavia.rainone at jboss.com" wrote :
| But, of course, I can't change the meta data classes, adding a method that generates the XML form of each one of them. So, how can I get rid of my if instanceof statements and still generate proper XML for every meta data type?
|
| I guess I missed what you're trying to tell me. So, please, elaborate :)
I don't know the name of the pattern, but it's trivial to do it. ;-)
Instead of changing the classes, you can write proper adapters / delegates.
e.g. (pseudo code)
| // T --> SMD side metadata type; e.g. ServiceInjectionValueMetaData
| // U --> BMD side metadata type; e.g. AbstractInjectionValueMetaData
| interface SMD2BMD<T, U>
| {
| Class<T> mappingClass();
|
| U toBMD(T t);
|
| String toXML(U u);
| }
|
Where now instead of multiple ifs, you would simply do something like this:
| Map<?, ?> adapters = ...;
| SMD2BMD s2b = adapters.get(smd.getClass());
| if (s2b == null)
| {
| // no exact mapping class match, lets iterate
| for (Class key : adapters.keySet())
| {
| if (key.isInstance(smd))
| {
| s2b = adapters.get(key);
| break;
| }
| }
| if (s2b == null)
| throw new IllegalArgumentException("No such mapping " + smd);
| }
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4237634#4237634
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4237634
More information about the jboss-dev-forums
mailing list