Hello all,

        I'm playing with hivemind 1.1-alpha AdapterRegistry and now that I got
some simple example working, I'm asking myself a question I can't find
an answer :)
        Is there a way to do- kind of - recursion with the AdaptaterRegistry? I
explain myself: suppose I want to create an XmlAdapter service with this
interface :

public interface XmlAdapter {
        toXml (Object o);
}

I could define then :

public class StringAdapter {
        public String toXml (Object o) {
                String value = (String) o;
                return value.trim();
        }
}

This works fine for "converting" a String to XML.
But now suppose I got this object to adapt :

public class Name {
        private String firstName;
        private String lastName;
        // + getters & setters
}

A great trick would be to be able to do something like this :

public class NameAdapter {
        public String toXml (Object o) {
                Name value = (Name) o;
                String ret = new String("<Name><FirstName>");

                // Here do some trick to get a StringAdapter from the registry

                ret.append(stringAdapter.toXml(value.getFirstName()));
                ret.append("</FirstName><LastName>");
                ret.append(stringAdapter.toXml(value.getLastName()));
                ret.append("</LastName></Name>");
                return ret;
        }
}

Of course I tried to inject the service in
itself but this leads only to nullpointerexception ( well, I expected
something like this anyway...).

So, is there a way to do this ? Or should I try another way ? ( with
the new Chain service maybe ? )

thanks in advance for any help/pointers,

Olivier. 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to