javax.el

## Class BeanNameELResolver

- java.lang.Object
- - javax.el.ELResolver
  - - javax.el.BeanNameELResolver

    public class BeanNameELResolver
    extends ELResolver

An `ELResolver` for resolving user or container managed beans.

A `BeanNameResolver` is required for its proper operation. The following example creates an `ELResolver` that resolves the name "bean" to an instance of MyBean.

>      ELResovler elr = new BeanNameELResolver(new BeanNameResolver {
>         public boolean isNameResolved(String beanName) {
>            return "bean".equals(beanName);
>         }
>         public Object getBean(String beanName) {
>            return "bean".equals(beanName)? new MyBean(): null;
>         }
>      });

Since:
  EL 3.0

### Field Summary

### Fields inherited from class javax.el.ELResolver

`RESOLVABLE_AT_DESIGN_TIME, TYPE`

### Constructor Summary

Constructors
Constructor and Description
`BeanNameELResolver(BeanNameResolver beanNameResolver)` Constructor

### Method Summary

Methods
`java.lang.Class<?>` `getCommonPropertyType(ELContext context, java.lang.Object base)` Always returns `String.class`, since a bean name is a String.
`java.util.Iterator<java.beans.FeatureDescriptor>` `getFeatureDescriptors(ELContext context, java.lang.Object base)` Always returns `null`, since there is no reason to iterate through a list of one element: bean name.
`java.lang.Class<?>` `getType(ELContext context, java.lang.Object base, java.lang.Object property)` If the base is null and the property is a name resolvable by the BeanNameResolver, return the type of the bean.
`java.lang.Object` `getValue(ELContext context, java.lang.Object base, java.lang.Object property)` If the base object is `null` and the property is a name that is resolvable by the BeanNameResolver, returns the value resolved by the BeanNameResolver.
`boolean` `isReadOnly(ELContext context, java.lang.Object base, java.lang.Object property)` If the base is null and the property is a name resolvable by the BeanNameResolver, attempts to determine if the bean is writable.
`void` `setValue(ELContext context, java.lang.Object base, java.lang.Object property, java.lang.Object value)` If the base is null and the property is a name that is resolvable by the BeanNameResolver, the bean in the BeanNameResolver is set to the given value.

### Methods inherited from class javax.el.ELResolver

`convertToType, invoke`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### BeanNameELResolver

    public BeanNameELResolver(BeanNameResolver beanNameResolver)

Constructor

Parameters:
  `beanNameResolver` - The `BeanNameResolver` that resolves a bean name.

### Method Detail

#### getValue

    public java.lang.Object getValue(ELContext context,
                            java.lang.Object base,
                            java.lang.Object property)

If the base object is `null` and the property is a name that is resolvable by the BeanNameResolver, returns the value resolved by the BeanNameResolver.

If name is resolved by the BeanNameResolver, the `propertyResolved` property of the `ELContext` object must be set to `true` by this resolver, before returning. If this property is not `true` after this method is called, the caller should ignore the return value.

Specified by:
  `getValue` in class `ELResolver`
Parameters:
  `context` - The context of this evaluation.
  `base` - `null`
  `property` - The name of the bean.
Returns:
  If the `propertyResolved` property of `ELContext` was set to `true`, then the value of the bean with the given name. Otherwise, undefined.
Throws:
  `java.lang.NullPointerException` - if context is `null`.
  `ELException` - if an exception was thrown while performing the property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.

#### setValue

    public void setValue(ELContext context,
                java.lang.Object base,
                java.lang.Object property,
                java.lang.Object value)

If the base is null and the property is a name that is resolvable by the BeanNameResolver, the bean in the BeanNameResolver is set to the given value.

If the name is resolvable by the BeanNameResolver, or if the BeanNameResolver allows creating a new bean, the `propertyResolved` property of the `ELContext` object must be set to `true` by the resolver, before returning. If this property is not `true` after this method is called, the caller can safely assume no value has been set.

Specified by:
  `setValue` in class `ELResolver`
Parameters:
  `context` - The context of this evaluation.
  `base` - `null`
  `property` - The name of the bean
  `value` - The value to set the bean with the given name to.
Throws:
  `java.lang.NullPointerException` - if context is `null`
  `PropertyNotWritableException` - if the BeanNameResolver does not allow the bean to be modified.
  `ELException` - if an exception was thrown while attempting to set the bean with the given name. The thrown exception must be included as the cause property of this exception, if available.

#### getType

    public java.lang.Class<?> getType(ELContext context,
                             java.lang.Object base,
                             java.lang.Object property)

If the base is null and the property is a name resolvable by the BeanNameResolver, return the type of the bean.

If the name is resolvable by the BeanNameResolver, the `propertyResolved` property of the `ELContext` object must be set to `true` by the resolver, before returning. If this property is not `true` after this method is called, the caller can safely assume no value has been set.

Specified by:
  `getType` in class `ELResolver`
Parameters:
  `context` - The context of this evaluation.
  `base` - `null`
  `property` - The name of the bean.
Returns:
  If the `propertyResolved` property of `ELContext` was set to `true`, then the type of the bean with the given name. Otherwise, undefined.
Throws:
  `java.lang.NullPointerException` - if context is `null`.
  `ELException` - if an exception was thrown while performing the property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.

#### isReadOnly

    public boolean isReadOnly(ELContext context,
                     java.lang.Object base,
                     java.lang.Object property)

If the base is null and the property is a name resolvable by the BeanNameResolver, attempts to determine if the bean is writable.

If the name is resolvable by the BeanNameResolver, the `propertyResolved` property of the `ELContext` object must be set to `true` by the resolver, before returning. If this property is not `true` after this method is called, the caller can safely assume no value has been set.

Specified by:
  `isReadOnly` in class `ELResolver`
Parameters:
  `context` - The context of this evaluation.
  `base` - `null`
  `property` - The name of the bean.
Returns:
  If the `propertyResolved` property of `ELContext` was set to `true`, then `true` if the property is read-only or `false` if not; otherwise undefined.
Throws:
  `java.lang.NullPointerException` - if context is `null`.
  `ELException` - if an exception was thrown while performing the property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.

#### getFeatureDescriptors

    public java.util.Iterator<java.beans.FeatureDescriptor> getFeatureDescriptors(ELContext context,
                                                                         java.lang.Object base)

Always returns `null`, since there is no reason to iterate through a list of one element: bean name.

Specified by:
  `getFeatureDescriptors` in class `ELResolver`
Parameters:
  `context` - The context of this evaluation.
  `base` - `null`.
Returns:
  `null`.
See Also:
  `FeatureDescriptor`

#### getCommonPropertyType

    public java.lang.Class<?> getCommonPropertyType(ELContext context,
                                           java.lang.Object base)

Always returns `String.class`, since a bean name is a String.

Specified by:
  `getCommonPropertyType` in class `ELResolver`
Parameters:
  `context` - The context of this evaluation.
  `base` - `null`.
Returns:
  `String.class`.