Hi, Jason,
thanks for your reply. That will at least help me to get a working
solution. However, I am not quite sure whether I expressed myself
right. Sorry, if not.
My ideal solution would be to have something like
<plugins>
<plugin>
<artifactId>myPlugin</artifactId>
<configuration>
<myComponent hint="foo">
.. <- XML snippet
</myComponent>
</configuration>
</plugin>
</plugins>
Not quite sure, but I think that's a bit more than you wrote, because
I've got to catch Maven's automatisms at some point.
Any idea for this variant?
Thanks,
Jochen
On Tue, Aug 11, 2009 at 5:15 AM, Jason van Zyl<[email protected]> wrote:
>
> On 10-Aug-09, at 1:32 PM, Jochen Wiedmann wrote:
>
>> Hi,
>>
>> in a plugin, I'd like to select a component dynamically. Basically,
>> I'd like to have something along these lines:
>>
>> <configuration>
>> <myComponent hint="foo">
>> ...
>> </myComponent>
>> </configuration>
>>
>> The idea is to use the hint for looking up the "myComponent" bean and
>> use the XML fragment between <myComponent> and <myComponent> to
>> configure the bean.
>>
>> Is that possible? Any other ideas how to achieve my goal?
>>
>
> // Lookup you unconfigured component
> //
> Foo component = container.lookup( Foo.class, "myComponent" );
>
> // Create a PlexusConfiguration to use against your component and populate
> as necessary
> // by adding elements and attributes. Use autocomplete in your IDE to find
> out what's available.
> PlexusConfiguration configuration = new XmlPlexusConfiguration(
> "configuration" );
>
> // Look up the default component configurator which is used internally to
> configure component.
> //
> ComponentConfigurator configurator = container.lookup( Configurator.class );
>
> // I assume you're in a plugin so you'll need the classrealm of the plugin
> itself
> // which you can access through the mojoExecution using the ${mojoExecution}
> expression
> ClassRealm pluginRealm =
> mojoExecution.getMojoDescriptor().getPluginDescriptor().getClassRealm();
>
> // Use the configurator to configure the component
> configurator.configureComponent( component, configuration, pluginRealm );
>
> You might want to make your own implementation of the PlexusConfiguration if
> you're going to use another source other then XML. Internally in Plexus the
> configuration can come from any source but in Maven it's primarily XML but
> you're not restricted to XML.
>
>> Thanks,
>>
>> Jochen
>>
>> --
>> Base64 decoding, 300% faster than sun.misc.BASE64Decoder:
>> http://archive.netbsd.se/?ml=commons-dev&a=2008-05&t=7522166
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
> Thanks,
>
> Jason
>
> ----------------------------------------------------------
> Jason van Zyl
> Founder, Apache Maven
> http://twitter.com/jvanzyl
> http://twitter.com/SonatypeNexus
> http://twitter.com/SonatypeM2E
> ----------------------------------------------------------
>
> People develop abstractions by generalizing from concrete examples.
> Every attempt to determine the correct abstraction on paper without
> actually developing a running system is doomed to failure. No one
> is that smart. A framework is a resuable design, so you develop it by
> looking at the things it is supposed to be a design of. The more examples
> you look at, the more general your framework will be.
>
> -- Ralph Johnson & Don Roberts, Patterns for Evolving Frameworks
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--
Base64 decoding, 300% faster than sun.misc.BASE64Decoder:
http://archive.netbsd.se/?ml=commons-dev&a=2008-05&t=7522166
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]