dev@glassfish.java.net

Re: Using HK2 _at_Configured... how can I read "body content"?

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Mon, 29 Jun 2009 13:41:02 -0700

Hi Tim,

Thanks for the response... after I put the annotation up on the parent
instead of in the child @Configured Content class, it worked (mostly).
I can't seem to get it to both ready the body content AND attributes
from the tag. When I do, I get this exception:

Caused by: java.lang.ClassCastException:
org.jvnet.hk2.config.Dom$NodeChild cannot be cast to
org.jvnet.hk2.config.Dom$LeafChild
    at org.jvnet.hk2.config.Dom.rawLeafElement(Dom.java:463)
    at org.jvnet.hk2.config.Dom.leafElement(Dom.java:336)
    at
org.glassfish.admingui.common.gadget.GadgetModuleInjector.element_setText(GadgetModuleInjector.java:54)
    at
org.glassfish.admingui.common.gadget.GadgetModuleInjector.inject(GadgetModuleInjector.java:19)
    at
org.glassfish.admingui.common.gadget.GadgetModuleInjector.inject(GadgetModuleInjector.java:9)
    at org.jvnet.hk2.config.ConfigModel.inject(ConfigModel.java:193)
    at org.jvnet.hk2.config.Dom.inject(Dom.java:678)
    at
org.jvnet.hk2.config.ConfiguredWomb.injectConfig(ConfiguredWomb.java:84)
    at
org.jvnet.hk2.config.ConfiguredWomb.initialize(ConfiguredWomb.java:79)
    at org.jvnet.hk2.config.ConfiguredWomb.get(ConfiguredWomb.java:70)
    at
com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
    at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
    at
com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
    at
org.glassfish.admingui.common.gadget.GadgetHandlers.getGadgetModule(GadgetHandlers.java:107)
    at
org.glassfish.admingui.common.gadget.GadgetHandlers.getGadgetModule(GadgetHandlers.java:86)
    ... 47 more

This is what I have:

    @Element("Content")
    void setContent(GadgetContent content)

    @Element("Content")
    void setText(String text)

GadgetContent is a @Configured object which declares it's attributes
(such as "type"). GadgetContent gets populated correctly if I omit the
setText() method above (then I can't get access to the body content).
The setText works correctly and returns the body content if I omit the
setContent method above... then I can't get access to the attributes on
the element: <Content type="html">body content</Content>

For now I can probably do without the attributes and just not support
that feature... but if you or anyone else has the answer to how to read
BOTH attributes and body text for an element, I'd greatly appreciate it! :)

Thanks again Tim, you got me much closer!

Ken


Tim Quinn wrote:
> Hi, Ken.
>
> For an example, look at web/gui-plugin-common EnvEntry. It has
> subelements EnvEntryName, EnvEntryType, EnvEntryValue and Description
> all of which expose their values as the text body.
>
> Basically,
>
> @Configured
> interface KensElement {
>
> @Element
> String getContent();
> void setContent(String content);
> }
>
> should do it.
>
> - Tim
>
> Ken Paulsen wrote:
>>
>> Can someone point me in the right direction to read body content
>> using HK2's @Configured/_at_Attribute/etc infrastructure? Or is this
>> not possible?
>>
>> Specifically, I want to read "Hello World!" from something like:
>>
>> <Content type="html">
>> <![CDATA[
>> Hello, world!
>> ]]>
>> </Content>
>>
>> Thanks in advance!
>>
>> Ken
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>