001: /* XelELResolver.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Fri Aug 31 19:39:41 2007, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zkmax.xel.el21;
020:
021: import java.util.Iterator;
022:
023: import javax.el.ArrayELResolver;
024: import javax.el.BeanELResolver;
025: import javax.el.CompositeELResolver;
026: import javax.el.ELContext;
027: import javax.el.ELException;
028: import javax.el.ELResolver;
029: import javax.el.ListELResolver;
030: import javax.el.MapELResolver;
031: import javax.el.PropertyNotFoundException;
032: import javax.el.PropertyNotWritableException;
033: import javax.el.ResourceBundleELResolver;
034:
035: import org.zkoss.xel.VariableResolver;
036:
037: /**
038: * A simple implementation of {@link ELResolver}.
039: *
040: * @since 3.0.0
041: */
042: public final class XelELResolver extends ELResolver {
043: private static final ELResolver DEFAULT = new CompositeELResolver();
044:
045: static {
046: ((CompositeELResolver) DEFAULT).add(new MapELResolver());
047: ((CompositeELResolver) DEFAULT)
048: .add(new ResourceBundleELResolver());
049: ((CompositeELResolver) DEFAULT).add(new ListELResolver());
050: ((CompositeELResolver) DEFAULT).add(new ArrayELResolver());
051: ((CompositeELResolver) DEFAULT).add(new BeanELResolver());
052: }
053:
054: private final VariableResolver _resolver;
055:
056: /** Constructor.
057: */
058: public XelELResolver(VariableResolver resolver) {
059: _resolver = resolver;
060: }
061:
062: //ELResolver//
063: public Object getValue(ELContext ctx, Object base, Object property)
064: throws PropertyNotFoundException, ELException {
065: if (ctx == null)
066: throw new IllegalArgumentException();
067:
068: if (base == null) {
069: ctx.setPropertyResolved(true);
070: if (property != null)
071: return _resolver.resolveVariable(property.toString());
072: }
073:
074: return ctx.isPropertyResolved() ? null : DEFAULT.getValue(ctx,
075: base, property);
076: }
077:
078: public Class getType(ELContext ctx, Object base, Object property)
079: throws PropertyNotFoundException, ELException {
080: if (ctx == null)
081: throw new IllegalArgumentException();
082:
083: if (base == null) {
084: ctx.setPropertyResolved(true);
085: if (property != null) {
086: Object obj = _resolver.resolveVariable(property
087: .toString());
088: return obj != null ? obj.getClass() : null;
089: }
090: }
091:
092: return ctx.isPropertyResolved() ? null : DEFAULT.getType(ctx,
093: base, property);
094: }
095:
096: public void setValue(ELContext ctx, Object base, Object property,
097: Object value) throws PropertyNotFoundException,
098: PropertyNotWritableException, ELException {
099: if (ctx == null)
100: throw new IllegalArgumentException();
101:
102: if (base == null) {
103: ctx.setPropertyResolved(true);
104: throw new PropertyNotWritableException();
105: }
106:
107: if (!ctx.isPropertyResolved())
108: DEFAULT.setValue(ctx, base, property, value);
109: }
110:
111: public boolean isReadOnly(ELContext ctx, Object base,
112: Object property) throws PropertyNotFoundException,
113: ELException {
114: if (ctx == null)
115: throw new IllegalArgumentException();
116:
117: if (base == null) {
118: ctx.setPropertyResolved(true);
119: return true;
120: }
121:
122: return DEFAULT.isReadOnly(ctx, base, property);
123: }
124:
125: public Iterator getFeatureDescriptors(ELContext ctx, Object base) {
126: return DEFAULT.getFeatureDescriptors(ctx, base);
127: }
128:
129: public Class getCommonPropertyType(ELContext ctx, Object base) {
130: return base == null ? String.class : DEFAULT
131: .getCommonPropertyType(ctx, base);
132: }
133: }
|