dev@glassfish.java.net

Re: programmatic config changes

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Fri, 20 Mar 2009 16:41:07 -0700

you are not in a transaction because you use the "service" variable
which is still the read-only value. To be able to mutate your config
object, you should use the "param" passed to the method.
so replace
> service.getHttpListener().clear();
with
> param.getHttpListener().clear();

and it should do it...

jerome

On Mar 20, 2009, at 1:36 PM, Justin Lee wrote:

> In my test, i'm trying to programmatically add/remove elements from
> the schema. However, the following code snippet always results in
> an exception complaining about not being in a transaction. Stepping
> through the code I come to org/jvnet/hk2/config/ConfigBean.java:165
> where I get an AbstractList in which all the mutators throw
> exceptions. I don't seem to be to doing anything terribly different
> from, say, DeleteHttpListener but perhaps there's some bootstrapping
> that I'm missing. Can someone point me in the right direction here?
>
> final HttpService service = habitat.getComponent(HttpService.class);
> ConfigSupport.apply(new SingleConfigCode<HttpService>() {
> public Object run(HttpService param) throws PropertyVetoException,
> TransactionFailure {
> service.getHttpListener().clear();
> return null;
> }
> }, service);
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>