Hi,
On 02.12.2009, at 17:08, Sebastian Heib wrote:
> Hi,
>
> I have an iPojo component that asks the user for some input data. This data
> is then provided as a service for other bundles. So far - no problem. But I
> only want to provide the data for other components, AFTER the user entered
> something (so as soon as there is actually data available), and not while the
> user is still entering data (as the provided data would be empty in this
> case).
>
> But as my component must be valid for the user to enter something, the
> service is also immediately available. This results in the consuming
> component to get valid as well, but without the actual data (this is NOT what
> I want, I want the consuming component to get valid as soon as there is real
> data available). I tried to write a handler for this case that checks if the
> user input data is actually valid. Is this the way to go? Or is there an
> easier way? How can I re-check the provided service within my handler
> (currently I check it once in the 'start' method, but how to I know if
> something changed on the service side?)?
There is several way to do that.
- Doing a handler will work obviously, but this is really dependent to your
case.
- Using the lifecycle controller (@Controller) which allow you to invalid your
instance until the configuration (here the user input) is correct
- Having an instance taking the user input and when it's done, creating another
instance (which provides the service) with the user entry as parameter (i.e.
configuration). Something like:
@Requires(filter="factory.name=my.second.component")
Factory myFactory;
public void receiveUserInput(String input) {
Properties conf = new Properties();
conf.put("user.input", input);
try {
myFactory.createComponentInstance(conf);
} catch (UnacceptableConfiguration e) {
e.printStackTrace();
} catch (MissingHandlerException e) {
e.printStackTrace();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
Regards,
Clement
>
> Thanks,
> Sebastian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>