| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.el.impl.commons; |
| 17 | |
|
| 18 | |
import java.util.List; |
| 19 | |
|
| 20 | |
import javax.faces.application.Application; |
| 21 | |
import javax.servlet.jsp.el.ELException; |
| 22 | |
import javax.servlet.jsp.el.FunctionMapper; |
| 23 | |
import javax.servlet.jsp.el.VariableResolver; |
| 24 | |
|
| 25 | |
import org.apache.commons.el.ArraySuffix; |
| 26 | |
import org.apache.commons.el.ComplexValue; |
| 27 | |
import org.apache.commons.el.Logger; |
| 28 | |
import org.apache.commons.el.PropertySuffix; |
| 29 | |
import org.apache.commons.el.ValueSuffix; |
| 30 | |
import org.seasar.teeda.core.el.ExpressionProcessor; |
| 31 | |
import org.seasar.teeda.core.el.Replacer; |
| 32 | |
import org.seasar.teeda.core.util.ApplicationUtil; |
| 33 | |
import org.seasar.teeda.core.util.PropertyResolverUtil; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public class ComplexValueReplacer implements Replacer { |
| 39 | |
|
| 40 | |
private ExpressionProcessor processor_; |
| 41 | |
|
| 42 | 82 | public ComplexValueReplacer(ExpressionProcessor processor) { |
| 43 | 82 | processor_ = processor; |
| 44 | 82 | } |
| 45 | |
|
| 46 | |
public void replace(Object expression) { |
| 47 | 39 | ComplexValue complexValue = (ComplexValue) expression; |
| 48 | 39 | Application application = ApplicationUtil.getApplicationFromContext(); |
| 49 | 39 | List suffixes = complexValue.getSuffixes(); |
| 50 | 82 | for (int i = 0; i < suffixes.size(); i++) { |
| 51 | 43 | ValueSuffix valueSuffix = (ValueSuffix) suffixes.get(i); |
| 52 | 43 | if (isSuitablePropertySuffix(valueSuffix)) { |
| 53 | 39 | PropertySuffix propertySuffix = (PropertySuffix) valueSuffix; |
| 54 | 39 | suffixes.set(i, new JsfPropertySuffix(propertySuffix, |
| 55 | |
application, processor_)); |
| 56 | 4 | } else if (isSuitableArraySuffix(valueSuffix)) { |
| 57 | 4 | ArraySuffix arraySuffix = (ArraySuffix) valueSuffix; |
| 58 | 4 | suffixes.set(i, new JsfArraySuffix(arraySuffix, application, |
| 59 | |
processor_)); |
| 60 | |
} else { |
| 61 | 0 | throw new IllegalStateException(); |
| 62 | |
} |
| 63 | |
} |
| 64 | 39 | } |
| 65 | |
|
| 66 | |
private static boolean isSuitablePropertySuffix(ValueSuffix valueSuffix) { |
| 67 | 43 | return (valueSuffix instanceof PropertySuffix) |
| 68 | |
&& !(valueSuffix instanceof JsfPropertySuffix); |
| 69 | |
} |
| 70 | |
|
| 71 | |
private static boolean isSuitableArraySuffix(ValueSuffix valueSuffix) { |
| 72 | 4 | return (valueSuffix instanceof ArraySuffix) |
| 73 | |
&& !(valueSuffix instanceof JsfArraySuffix); |
| 74 | |
} |
| 75 | |
|
| 76 | |
public static class JsfArraySuffix extends ArraySuffix { |
| 77 | |
private Application application_; |
| 78 | |
|
| 79 | |
private ExpressionProcessor processor_; |
| 80 | |
|
| 81 | |
public JsfArraySuffix(ArraySuffix suffix, Application application, |
| 82 | |
ExpressionProcessor processor) { |
| 83 | 4 | super(suffix.getIndex()); |
| 84 | 4 | Object o = getIndex(); |
| 85 | 4 | processor_ = processor; |
| 86 | 4 | application_ = application; |
| 87 | 4 | processor_.processExpression(o, o.getClass()); |
| 88 | 4 | } |
| 89 | |
|
| 90 | |
public Object evaluate(Object base, VariableResolver resolver, |
| 91 | |
FunctionMapper mapper, Logger logger) throws ELException { |
| 92 | 6 | if (base == null) { |
| 93 | 0 | return null; |
| 94 | |
} |
| 95 | 6 | Object indexValue = getIndex().evaluate(resolver, mapper, logger); |
| 96 | 6 | if (indexValue == null) { |
| 97 | 0 | return null; |
| 98 | |
} |
| 99 | 6 | Integer index = processor_.toIndex(base, indexValue); |
| 100 | 6 | return PropertyResolverUtil.getValue(application_, base, |
| 101 | |
indexValue, index); |
| 102 | |
} |
| 103 | |
|
| 104 | |
} |
| 105 | |
|
| 106 | |
public static class JsfPropertySuffix extends PropertySuffix { |
| 107 | |
private Application application_; |
| 108 | |
|
| 109 | |
private ExpressionProcessor processor_; |
| 110 | |
|
| 111 | |
public JsfPropertySuffix(PropertySuffix propertySuffix, |
| 112 | |
Application application, ExpressionProcessor processor) { |
| 113 | 39 | super(propertySuffix.getName()); |
| 114 | 39 | application_ = application; |
| 115 | 39 | processor_ = processor; |
| 116 | 39 | } |
| 117 | |
|
| 118 | |
public Object evaluate(Object base, VariableResolver resolver, |
| 119 | |
FunctionMapper mapper, Logger logger) throws ELException { |
| 120 | 32 | if (base == null) { |
| 121 | 0 | return null; |
| 122 | |
} |
| 123 | 32 | String indexValue = getName(); |
| 124 | 32 | if (indexValue == null) { |
| 125 | 0 | return null; |
| 126 | |
} |
| 127 | 32 | Integer index = processor_.toIndex(base, indexValue); |
| 128 | 32 | return PropertyResolverUtil.getValue(application_, base, |
| 129 | |
indexValue, index); |
| 130 | |
} |
| 131 | |
} |
| 132 | |
} |