dev@glassfish.java.net

Re: Habitat.getComponent default

From: Tim Quinn <Timothy.Quinn_at_Sun.COM>
Date: Fri, 14 Aug 2009 18:54:07 -0500

I believe habitat.getComponent(X.class) returns the first inhabitant of
type X registered in the habitat, as opposed to one with no name.

I don't know whether getComponent *should* do this or not. It all
depends on what the meaning of the word "should" is (to paraphrase!).

I hesitate to say whether or not having the HTMLActionReport register
with an explicit name will break anything or not. Seems like it
shouldn't harm anything, but ...

- Tim

Bill Shannon wrote:
> I'm fixing:
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=9015
>
> The core problem is that AdminAdapter tries to map various strings
> to a corresponding ActionReport class. The strings it tries to
> map are:
>
> User Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3)
> Gecko/2008092414 Firefox/3.0.3
> Accept: text/html
> Accept: application/xhtml+xml
> Accept: application/xml;q=0.9
> Accept: */*;q=0.8
>
> In each case it calls habitat.getComponent with ActionReport.class
> and a name that's the string above *after* the '/'.
>
> (Really this is pretty lame and it ought to be doing a better parse
> of the string and using the text before the '/' and less text after
> the '/'.)
>
> The various ActionReport subclasses have @Service(name = "XXX"),
> where XXX is expected to match the string.
>
> That is, except for the HTMLActionReport, which has no name.
>
> If all the above lookups fail, AdminAdapter calls
> habitat.getComponent(ActionReport.class).
>
> It looks like it's assuming that it's going to get the one with no name.
> It doesn't. It gets the new XMLContentActionReport that I added to support
> getting command metadata. And that surprising match causes failures
> later on, which results in no output for the request.
>
> The simple fix seems to be to change HTMLActionReport to have
> @Service(name = "html")
> Any idea if that will break anything else?
>
> Is it possible that Habitat.getComponent is actually what's broken in
> this case? *Should* it be returning the component with no name?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
>