el-next@uel.java.net

Re: Namespaced bases

From: Pete Muir <pmuir_at_redhat.com>
Date: Mon, 12 Apr 2010 11:56:10 +0100

On 9 Apr 2010, at 19:11, Kin-man Chung wrote:

> On 04/09/10 06:47, Pete Muir wrote:
>> The CDI spec calls for namespaced bean names (see section 2.5). It says
>>
>> "A bean may have a bean EL name. A bean with an EL name may be referred to by its name in Unified EL expressions. A valid bean EL name is a period-separated list of valid EL identifiers.
>>
>> The following strings are valid EL names:
>>
>> * org.mydomain.myapp.settings
>> * orderManager"
>>
> Just need to make sure I understand, and showing my ignorance about CDI:
>
> The expression #{org.mydomain.myapp.settings.standard} actually means getting the property "standard" from the bean
>
> org.mydomain.myapp.settings, right?

Exactly.

> How can this work with the current EL? Wouldn't the expression be parsed as getting the bean "org" and then get its property "mydomain", and then its property "myapp" etc?

We know up front (at deployment time) all bean names (and their namespaces) in a CDI module. Before checking if the property matches a bean, we check if the property matches the root of a namespace (and the base is null). If it does we return a Namespace object, otherwise we try to return the bean or say we can't resolve anything.

Once we have resolved a root namespace, we get passed a base. If the base is a Namespace, we can then inspect the possible nodes of the namespace that it can have. If one matches, we return that Namespace object. Otherwise we try to resolve a bean (if this fails we say we can't resolve anything). And so on.

This works reasonably well (and quickly) as we know the tree of namespaces up front, it wouldn't work so well if we didn't have this info...