Array of String as parameter

View: New views
4 Messages — Rating Filter:   Alert me  

Array of String as parameter

by hackaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am using HiveMind 1.1. Could I pass an array of String as parameter? If so what is its lightweight instance initialization syntax?

Re: Array of String as parameter

by Raffael Herzog-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Dienstag, 22. Januar 2008 08.43:51 schrieb hackaton:
> I am using HiveMind 1.1. Could I pass an array of String as parameter? If
> so what is its lightweight instance initialization syntax?

You could register a property editor for String[]. Unfortunately, there's no
way to ensure that such an editor will be registered before any other
HiveMind service is instanciated. You could e.g. create a configuration
point where one can register new property editors. You could then create a
contribution to hivemind.Startup that registers those contributed editors.
However, using this method, you'll have to be aware that there's no
guarantee that the new property editors are available in any class that
gets instantiated directly or indirectly through hivemind.Startup or
hivemind.EagerLoad.

If this is not acceptible, you'll have to register your editors in the
bootstrapper before you build the registry.

Cheers,
   Raffi

--
The difference between theory and practice is that in theory, there is
no difference, but in practice, there is.

herzog@... · Jabber: herzog@...
PGP Key 0x5FFDB5DB5D1FF5F4 · http://keyserver.pgp.com

Re: Array of String as parameter

by Raffael Herzog-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Dienstag, 22. Januar 2008 12.51:17 schrieb Raffael Herzog:
> Am Dienstag, 22. Januar 2008 08.43:51 schrieb hackaton:
> > I am using HiveMind 1.1. Could I pass an array of String as parameter?
> > If so what is its lightweight instance initialization syntax?

[Use a property editor]

I forgot to mention: You can also contribute a translator to hivemind.Trans-
lators, but this will only work for contributions, not e.g. for <set/> in
<construct/> (which I suppose is what you want to do).

Cheers,
   Raffi

--
The difference between theory and practice is that in theory, there is
no difference, but in practice, there is.

herzog@... · Jabber: herzog@...
PGP Key 0x5FFDB5DB5D1FF5F4 · http://keyserver.pgp.com

Re: Array of String as parameter

by hackaton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I took your first approach. As I am totally new to hivemind, the follow concepts are new to me; it worked for me but I just want to make sure I understand them correctly :

a)"…register a property editor…"
b)"…contribution to hivemind.Startup…"

For point a)
Extended the java.beans.PropertyEditorSupport and override the setAsText to convert String to a String array

For point b)
1)Added a PropertyEditorLoader class by implement the Runnable to call the PropertyEditorManager.registerEditor as:
PropertyEditorManager.registerEditor(String[].class, StringArrayPropertyEditor.class);

2) Wire them as

<service-point id="PropertyEditorLoader" interface="java.lang.Runnable">
    <create-instance class="PropertyEditorLoader" />
</service-point>

<contribution configuration-id="hivemind.Startup">
    <startup object="service:PropertyEditorLoader"/>
</contribution>
...

Finally, all services should get the PropertyEditorLoader ready except those instantiated directly or indirectly through hivemind.Startup or hivemind.EagerLoad.

Raffael Herzog-2 wrote:
Am Dienstag, 22. Januar 2008 08.43:51 schrieb hackaton:
> I am using HiveMind 1.1. Could I pass an array of String as parameter? If
> so what is its lightweight instance initialization syntax?

You could register a property editor for String[]. Unfortunately, there's no
way to ensure that such an editor will be registered before any other
HiveMind service is instanciated. You could e.g. create a configuration
point where one can register new property editors. You could then create a
contribution to hivemind.Startup that registers those contributed editors.
However, using this method, you'll have to be aware that there's no
guarantee that the new property editors are available in any class that
gets instantiated directly or indirectly through hivemind.Startup or
hivemind.EagerLoad.

If this is not acceptible, you'll have to register your editors in the
bootstrapper before you build the registry.