geronimo-el_1.0_spec/src/main/java/javax/el/BeanELResolver.java [35:289]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class BeanELResolver extends ELResolver {

	private final boolean readOnly;

	private final ConcurrentCache<String, BeanProperties> cache = new ConcurrentCache<String, BeanProperties>(
			1000);

	public BeanELResolver() {
		this.readOnly = false;
	}

	public BeanELResolver(boolean readOnly) {
		this.readOnly = readOnly;
	}

	public Object getValue(ELContext context, Object base, Object property)
			throws NullPointerException, PropertyNotFoundException, ELException {
		if (context == null) {
			throw new NullPointerException();
		}
		if (base == null || property == null) {
			return null;
		}

		context.setPropertyResolved(true);
		Method m = this.property(context, base, property).read(context);
		try {
			return m.invoke(base, (Object[]) null);
		} catch (IllegalAccessException e) {
			throw new ELException(e);
		} catch (InvocationTargetException e) {
			throw new ELException(message(context, "propertyReadError",
					new Object[] { base.getClass().getName(),
							property.toString() }), e.getCause());
		} catch (Exception e) {
			throw new ELException(e);
		}
	}

	public Class<?> getType(ELContext context, Object base, Object property)
			throws NullPointerException, PropertyNotFoundException, ELException {
		if (context == null) {
			throw new NullPointerException();
		}
		if (base == null || property == null) {
			return null;
		}

		context.setPropertyResolved(true);
		return this.property(context, base, property).getPropertyType();
	}

	public void setValue(ELContext context, Object base, Object property,
			Object value) throws NullPointerException,
			PropertyNotFoundException, PropertyNotWritableException,
			ELException {
		if (context == null) {
			throw new NullPointerException();
		}
		if (base == null || property == null) {
			return;
		}

		context.setPropertyResolved(true);

		if (this.readOnly) {
			throw new PropertyNotWritableException(message(context,
					"resolverNotWriteable", new Object[] { base.getClass()
							.getName() }));
		}

		Method m = this.property(context, base, property).write(context);
		try {
			m.invoke(base, value);
		} catch (IllegalAccessException e) {
			throw new ELException(e);
		} catch (InvocationTargetException e) {
			throw new ELException(message(context, "propertyWriteError",
					new Object[] { base.getClass().getName(),
							property.toString() }), e.getCause());
		} catch (Exception e) {
			throw new ELException(e);
		}
	}

	public boolean isReadOnly(ELContext context, Object base, Object property)
			throws NullPointerException, PropertyNotFoundException, ELException {
		if (context == null) {
			throw new NullPointerException();
		}
		if (base == null || property == null) {
			return false;
		}

		context.setPropertyResolved(true);
		return this.readOnly
				|| this.property(context, base, property).isReadOnly();
	}

	public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
		if (context == null) {
			throw new NullPointerException();
		}

		if (base == null) {
			return null;
		}

		try {
			BeanInfo info = Introspector.getBeanInfo(base.getClass());
			PropertyDescriptor[] pds = info.getPropertyDescriptors();
            for (PropertyDescriptor pd : pds) {
                pd.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
                pd.setValue(TYPE, pd.getPropertyType());
            }
            return Arrays.asList((FeatureDescriptor[]) pds).iterator();
		} catch (IntrospectionException e) {
			//
		}

		return null;
	}

	public Class<?> getCommonPropertyType(ELContext context, Object base) {
		if (context == null) {
			throw new NullPointerException();
		}

		if (base != null) {
			return Object.class;
		}

		return null;
	}

	protected final static class BeanProperties {
		private final Map<String, BeanProperty> properties;

		private final Class<?> type;

		public BeanProperties(Class<?> type) throws ELException {
			this.type = type;
			this.properties = new HashMap<String, BeanProperty>();
			try {
				BeanInfo info = Introspector.getBeanInfo(this.type);
				PropertyDescriptor[] pds = info.getPropertyDescriptors();
                for (PropertyDescriptor pd : pds) {
                    this.properties.put(pd.getName(), new BeanProperty(
                            type, pd));
                }
            } catch (IntrospectionException ie) {
				throw new ELException(ie);
			}
		}

		private BeanProperty get(ELContext ctx, String name) {
			BeanProperty property = this.properties.get(name);
			if (property == null) {
				throw new PropertyNotFoundException(message(ctx,
						"propertyNotFound",
						new Object[] { type.getName(), name }));
			}
			return property;
		}

        public BeanProperty getBeanProperty(String name) {
            return get(null, name);
        }
        
        private Class<?> getType() {
            return type;
        }
	}

    protected final static class BeanProperty {
		private final Class<?> type;

		private final Class<?> owner;

		private final PropertyDescriptor descriptor;

		private Method read;

		private Method write;

		public BeanProperty(Class<?> owner, PropertyDescriptor descriptor) {
			this.owner = owner;
			this.descriptor = descriptor;
			this.type = descriptor.getPropertyType();
		}

		public Class getPropertyType() {
			return this.type;
		}

		public boolean isReadOnly() {
		    return this.write == null
		        && (null == (this.write = getMethod(this.owner, descriptor.getWriteMethod())));
		}

		public Method getWriteMethod() {
			return write(null);
		}

		public Method getReadMethod() {
			return this.read(null);
		}

        private Method write(ELContext ctx) {
			if (this.write == null) {
				this.write = getMethod(this.owner, descriptor.getWriteMethod());
				if (this.write == null) {
					throw new PropertyNotFoundException(message(ctx,
							"propertyNotWritable", new Object[] {
									type.getName(), descriptor.getName() }));
				}
			}
			return this.write;
		}

		private Method read(ELContext ctx) {
			if (this.read == null) {
				this.read = getMethod(this.owner, descriptor.getReadMethod());
				if (this.read == null) {
					throw new PropertyNotFoundException(message(ctx,
							"propertyNotReadable", new Object[] {
									type.getName(), descriptor.getName() }));
				}
			}
			return this.read;
		}
	}

	private BeanProperty property(ELContext ctx, Object base,
			Object property) {
		Class<?> type = base.getClass();
		String prop = property.toString();

		BeanProperties props = this.cache.get(type.getName());
		if (props == null || type != props.getType()) {
			props = new BeanProperties(type);
			this.cache.put(type.getName(), props);
		}

		return props.get(ctx, prop);
	}

	private static Method getMethod(Class type, Method m) {
		if (m == null || Modifier.isPublic(type.getModifiers())) {
			return m;
		}
		Class[] inf = type.getInterfaces();
		Method mp;
        for (Class anInf : inf) {
            try {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



geronimo-el_2.2_spec/src/main/java/javax/el/BeanELResolver.java [37:291]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class BeanELResolver extends ELResolver {

    private final boolean readOnly;

    private final ConcurrentCache<String, BeanProperties> cache = new ConcurrentCache<String, BeanProperties>(
            1000);

    public BeanELResolver() {
        this.readOnly = false;
    }

    public BeanELResolver(boolean readOnly) {
        this.readOnly = readOnly;
    }

    public Object getValue(ELContext context, Object base, Object property)
            throws NullPointerException, PropertyNotFoundException, ELException {
        if (context == null) {
            throw new NullPointerException();
        }
        if (base == null || property == null) {
            return null;
        }

        context.setPropertyResolved(true);
        Method m = this.property(context, base, property).read(context);
        try {
            return m.invoke(base, (Object[]) null);
        } catch (IllegalAccessException e) {
            throw new ELException(e);
        } catch (InvocationTargetException e) {
            throw new ELException(message(context, "propertyReadError",
                    new Object[] { base.getClass().getName(),
                            property.toString() }), e.getCause());
        } catch (Exception e) {
            throw new ELException(e);
        }
    }

    public Class<?> getType(ELContext context, Object base, Object property)
            throws NullPointerException, PropertyNotFoundException, ELException {
        if (context == null) {
            throw new NullPointerException();
        }
        if (base == null || property == null) {
            return null;
        }

        context.setPropertyResolved(true);
        return this.property(context, base, property).getPropertyType();
    }

    public void setValue(ELContext context, Object base, Object property,
            Object value) throws NullPointerException,
            PropertyNotFoundException, PropertyNotWritableException,
            ELException {
        if (context == null) {
            throw new NullPointerException();
        }
        if (base == null || property == null) {
            return;
        }

        context.setPropertyResolved(true);

        if (this.readOnly) {
            throw new PropertyNotWritableException(message(context,
                    "resolverNotWriteable", new Object[] { base.getClass()
                            .getName() }));
        }

        Method m = this.property(context, base, property).write(context);
        try {
            m.invoke(base, value);
        } catch (IllegalAccessException e) {
            throw new ELException(e);
        } catch (InvocationTargetException e) {
            throw new ELException(message(context, "propertyWriteError",
                    new Object[] { base.getClass().getName(),
                            property.toString() }), e.getCause());
        } catch (Exception e) {
            throw new ELException(e);
        }
    }

    public boolean isReadOnly(ELContext context, Object base, Object property)
            throws NullPointerException, PropertyNotFoundException, ELException {
        if (context == null) {
            throw new NullPointerException();
        }
        if (base == null || property == null) {
            return false;
        }

        context.setPropertyResolved(true);
        return this.readOnly
                || this.property(context, base, property).isReadOnly();
    }

    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
        if (context == null) {
            throw new NullPointerException();
        }

        if (base == null) {
            return null;
        }

        try {
            BeanInfo info = Introspector.getBeanInfo(base.getClass());
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
            for (PropertyDescriptor pd : pds) {
                pd.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
                pd.setValue(TYPE, pd.getPropertyType());
            }
            return Arrays.asList((FeatureDescriptor[]) pds).iterator();
        } catch (IntrospectionException e) {
            //
        }

        return null;
    }

    public Class<?> getCommonPropertyType(ELContext context, Object base) {
        if (context == null) {
            throw new NullPointerException();
        }

        if (base != null) {
            return Object.class;
        }

        return null;
    }

    protected final static class BeanProperties {
        private final Map<String, BeanProperty> properties;

        private final Class<?> type;

        public BeanProperties(Class<?> type) throws ELException {
            this.type = type;
            this.properties = new HashMap<String, BeanProperty>();
            try {
                BeanInfo info = Introspector.getBeanInfo(this.type);
                PropertyDescriptor[] pds = info.getPropertyDescriptors();
                for (PropertyDescriptor pd : pds) {
                    this.properties.put(pd.getName(), new BeanProperty(
                            type, pd));
                }
            } catch (IntrospectionException ie) {
                throw new ELException(ie);
            }
        }

        private BeanProperty get(ELContext ctx, String name) {
            BeanProperty property = this.properties.get(name);
            if (property == null) {
                throw new PropertyNotFoundException(message(ctx,
                        "propertyNotFound",
                        new Object[] { type.getName(), name }));
            }
            return property;
        }

        public BeanProperty getBeanProperty(String name) {
            return get(null, name);
        }

        private Class<?> getType() {
            return type;
        }
    }

    protected final static class BeanProperty {
        private final Class<?> type;

        private final Class<?> owner;

        private final PropertyDescriptor descriptor;

        private Method read;

        private Method write;

        public BeanProperty(Class<?> owner, PropertyDescriptor descriptor) {
            this.owner = owner;
            this.descriptor = descriptor;
            this.type = descriptor.getPropertyType();
        }

        public Class getPropertyType() {
            return this.type;
        }

        public boolean isReadOnly() {
            return this.write == null
                && (null == (this.write = getMethod(this.owner, descriptor.getWriteMethod())));
        }

        public Method getWriteMethod() {
            return write(null);
        }

        public Method getReadMethod() {
            return this.read(null);
        }

        private Method write(ELContext ctx) {
            if (this.write == null) {
                this.write = getMethod(this.owner, descriptor.getWriteMethod());
                if (this.write == null) {
                    throw new PropertyNotFoundException(message(ctx,
                            "propertyNotWritable", new Object[] {
                                    type.getName(), descriptor.getName() }));
                }
            }
            return this.write;
        }

        private Method read(ELContext ctx) {
            if (this.read == null) {
                this.read = getMethod(this.owner, descriptor.getReadMethod());
                if (this.read == null) {
                    throw new PropertyNotFoundException(message(ctx,
                            "propertyNotReadable", new Object[] {
                                    type.getName(), descriptor.getName() }));
                }
            }
            return this.read;
        }
    }

    private BeanProperty property(ELContext ctx, Object base,
            Object property) {
        Class<?> type = base.getClass();
        String prop = property.toString();

        BeanProperties props = this.cache.get(type.getName());
        if (props == null || type != props.getType()) {
            props = new BeanProperties(type);
            this.cache.put(type.getName(), props);
        }

        return props.get(ctx, prop);
    }

    private static Method getMethod(Class type, Method m) {
        if (m == null || Modifier.isPublic(type.getModifiers())) {
            return m;
        }
        Class[] inf = type.getInterfaces();
        Method mp;
        for (Class anInf : inf) {
            try {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



