org.apache.el.lang.ELSupport Java Examples
The following examples show how to use
org.apache.el.lang.ELSupport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Stream.java From Tomcat8-Source-Read with MIT License | 6 votes |
public Stream filter(final LambdaExpression le) { Iterator<Object> downStream = new OpIterator() { @Override protected void findNext() { while (iterator.hasNext()) { Object obj = iterator.next(); if (ELSupport.coerceToBoolean(null, le.invoke(obj), true).booleanValue()) { next = obj; foundNext = true; break; } } } }; return new Stream(downStream); }
Example #2
Source File: AstValue.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void setValue(EvaluationContext ctx, Object value) throws ELException { Target t = getTarget(ctx); ctx.setPropertyResolved(false); ELResolver resolver = ctx.getELResolver(); // coerce to the expected type Class<?> targetClass = resolver.getType(ctx, t.base, t.property); resolver.setValue(ctx, t.base, t.property, ELSupport.coerceToType(ctx, value, targetClass)); if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", t.base, t.property)); } }
Example #3
Source File: AstValue.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void setValue(EvaluationContext ctx, Object value) throws ELException { Target t = getTarget(ctx); ctx.setPropertyResolved(false); ELResolver resolver = ctx.getELResolver(); // coerce to the expected type Class<?> targetClass = resolver.getType(ctx, t.base, t.property); if (COERCE_TO_ZERO == true || !isAssignable(value, targetClass)) { resolver.setValue(ctx, t.base, t.property, ELSupport.coerceToType(value, targetClass)); } else { resolver.setValue(ctx, t.base, t.property, value); } if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", t.base, t.property)); } }
Example #4
Source File: AstValue.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void setValue(EvaluationContext ctx, Object value) throws ELException { Target t = getTarget(ctx); ctx.setPropertyResolved(false); ELResolver resolver = ctx.getELResolver(); // coerce to the expected type Class<?> targetClass = resolver.getType(ctx, t.base, t.property); if (COERCE_TO_ZERO == true || !isAssignable(value, targetClass)) { resolver.setValue(ctx, t.base, t.property, ELSupport.coerceToType(value, targetClass)); } else { resolver.setValue(ctx, t.base, t.property, value); } if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", t.base, t.property)); } }
Example #5
Source File: AstCompositeExpression.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public Object getValue(EvaluationContext ctx) throws ELException { StringBuilder sb = new StringBuilder(16); Object obj = null; if (this.children != null) { for (int i = 0; i < this.children.length; i++) { obj = this.children[i].getValue(ctx); if (obj != null) { sb.append(ELSupport.coerceToString(obj)); } } } return sb.toString(); }
Example #6
Source File: ValueExpressionLiteral.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public Object getValue(ELContext context) { if (this.expectedType != null) { return ELSupport.coerceToType(this.value, this.expectedType); } return this.value; }
Example #7
Source File: MethodExpressionLiteral.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public Object invoke(ELContext context, Object[] params) throws ELException { if (this.expectedType != null) { return ELSupport.coerceToType(this.expr, this.expectedType); } else { return this.expr; } }
Example #8
Source File: ReflectionUtil.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private static boolean isCoercibleFrom(Object src, Class<?> target) { // TODO: This isn't pretty but it works. Significant refactoring would // be required to avoid the exception. try { ELSupport.coerceToType(src, target); } catch (ELException e) { return false; } return true; }
Example #9
Source File: ValueExpressionImpl.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public Object getValue(ELContext context) throws PropertyNotFoundException, ELException { EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, this.varMapper); Object value = this.getNode().getValue(ctx); if (this.expectedType != null) { return ELSupport.coerceToType(value, this.expectedType); } return value; }
Example #10
Source File: AstCompositeExpression.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public Object getValue(EvaluationContext ctx) throws ELException { StringBuilder sb = new StringBuilder(16); Object obj = null; if (this.children != null) { for (int i = 0; i < this.children.length; i++) { obj = this.children[i].getValue(ctx); if (obj != null) { sb.append(ELSupport.coerceToString(obj)); } } } return sb.toString(); }
Example #11
Source File: ValueExpressionLiteral.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public Object getValue(ELContext context) { if (this.expectedType != null) { return ELSupport.coerceToType(this.value, this.expectedType); } return this.value; }
Example #12
Source File: ValueExpressionImpl.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public Object getValue(ELContext context) throws PropertyNotFoundException, ELException { EvaluationContext ctx = new EvaluationContext(context, this.fnMapper, this.varMapper); Object value = this.getNode().getValue(ctx); if (this.expectedType != null) { return ELSupport.coerceToType(value, this.expectedType); } return value; }
Example #13
Source File: TestCollectionOperations.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testCount02() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue( "[].stream().count()", Object.class); Assert.assertTrue("Result: " + result.toString(), ELSupport.equals(null, Long.valueOf(0), result)); }
Example #14
Source File: TestCollectionOperations.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testCount01() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue( "[1,2,3,4,5].stream().count()", Object.class); Assert.assertTrue("Result: " + result.toString(), ELSupport.equals(null, Long.valueOf(5), result)); }
Example #15
Source File: TestCollectionOperations.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testSum02() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue( "[].stream().sum()", Object.class); Assert.assertTrue("Result: " + result.toString(), ELSupport.equals(null, Long.valueOf(0), result)); }
Example #16
Source File: TestCollectionOperations.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testSum01() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue( "[1,2,3,4,5].stream().sum()", Object.class); Assert.assertTrue("Result: " + result.toString(), ELSupport.equals(null, Long.valueOf(15), result)); }
Example #17
Source File: TestCollectionOperations.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testAverage02() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue( "[1,2,3,4,5,6].stream().average()", Object.class); Number average = (Number) ((Optional) result).get(); Assert.assertTrue("Result: " + average.toString(), ELSupport.equals(null, Double.valueOf(3.5), average)); }
Example #18
Source File: TestCollectionOperations.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testAverage01() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue( "[1,2,3,4,5].stream().average()", Object.class); Number average = (Number) ((Optional) result).get(); Assert.assertTrue("Result: " + average.toString(), ELSupport.equals(null, Long.valueOf(3), average)); }
Example #19
Source File: ReflectionUtil.java From Tomcat8-Source-Read with MIT License | 5 votes |
private static boolean isCoercibleFrom(EvaluationContext ctx, Object src, Class<?> target) { // TODO: This isn't pretty but it works. Significant refactoring would // be required to avoid the exception. try { ELSupport.coerceToType(ctx, src, target); } catch (ELException e) { return false; } return true; }
Example #20
Source File: ReflectionUtil.java From tomcatsrc with Apache License 2.0 | 5 votes |
private static boolean isCoercibleFrom(Object src, Class<?> target) { // TODO: This isn't pretty but it works. Significant refactoring would // be required to avoid the exception. try { ELSupport.coerceToType(src, target); } catch (ELException e) { return false; } return true; }
Example #21
Source File: MethodExpressionLiteral.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public Object invoke(ELContext context, Object[] params) throws ELException { if (this.expectedType != null) { return ELSupport.coerceToType(this.expr, this.expectedType); } else { return this.expr; } }
Example #22
Source File: AstCompositeExpression.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public Object getValue(EvaluationContext ctx) throws ELException { StringBuilder sb = new StringBuilder(16); Object obj = null; if (this.children != null) { for (int i = 0; i < this.children.length; i++) { obj = this.children[i].getValue(ctx); if (obj != null) { sb.append(ELSupport.coerceToString(ctx, obj)); } } } return sb.toString(); }
Example #23
Source File: ExpressionFactoryImpl.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public Object coerceToType(Object obj, Class<?> type) { return ELSupport.coerceToType(obj, type); }
Example #24
Source File: AstValue.java From tomcatsrc with Apache License 2.0 | 4 votes |
private Object[] convertArgs(Object[] src, Method m) { Class<?>[] types = m.getParameterTypes(); if (types.length == 0) { // Treated as if parameters have been provided so src is ignored return EMPTY_ARRAY; } int paramCount = types.length; if (m.isVarArgs() && paramCount > 1 && (src == null || paramCount > src.length) || !m.isVarArgs() && (paramCount > 0 && src == null || src != null && src.length != paramCount)) { String srcCount = null; if (src != null) { srcCount = Integer.toString(src.length); } String msg; if (m.isVarArgs()) { msg = MessageFactory.get("error.invoke.tooFewParams", m.getName(), srcCount, Integer.toString(paramCount)); } else { msg = MessageFactory.get("error.invoke.wrongParams", m.getName(), srcCount, Integer.toString(paramCount)); } throw new IllegalArgumentException(msg); } if (src == null) { // Must be a varargs method with a single parameter. // Use a new array every time since the called code could modify the // contents of the array return new Object[1]; } Object[] dest = new Object[paramCount]; for (int i = 0; i < paramCount - 1; i++) { dest[i] = ELSupport.coerceToType(src[i], types[i]); } if (m.isVarArgs()) { Object[] varArgs = (Object[]) Array.newInstance( m.getParameterTypes()[paramCount - 1].getComponentType(), src.length - (paramCount - 1)); for (int i = 0; i < src.length - (paramCount - 1); i ++) { varArgs[i] = ELSupport.coerceToType(src[paramCount - 1 + i], types[paramCount - 1].getComponentType()); } dest[paramCount - 1] = varArgs; } else { dest[paramCount - 1] = ELSupport.coerceToType( src[paramCount - 1], types[paramCount - 1]); } return dest; }
Example #25
Source File: TestELEvaluation.java From tomcatsrc with Apache License 2.0 | 4 votes |
private void compareBoth(String msg, int expected, Object o1, Object o2){ int i1 = ELSupport.compare(o1, o2); int i2 = ELSupport.compare(o2, o1); assertEquals(msg,expected, i1); assertEquals(msg,expected, -i2); }
Example #26
Source File: TestELEvaluation.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
private void compareBoth(String msg, int expected, Object o1, Object o2){ int i1 = ELSupport.compare(o1, o2); int i2 = ELSupport.compare(o2, o1); assertEquals(msg,expected, i1); assertEquals(msg,expected, -i2); }
Example #27
Source File: ExpressionFactoryImpl.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public Object coerceToType(Object obj, Class<?> type) { return ELSupport.coerceToType(obj, type); }
Example #28
Source File: AstValue.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
private Object[] convertArgs(Object[] src, Method m) { Class<?>[] types = m.getParameterTypes(); if (types.length == 0) { // Treated as if parameters have been provided so src is ignored return EMPTY_ARRAY; } int paramCount = types.length; if (m.isVarArgs() && paramCount > 1 && (src == null || paramCount > src.length) || !m.isVarArgs() && (paramCount > 0 && src == null || src != null && src.length != paramCount)) { String srcCount = null; if (src != null) { srcCount = Integer.toString(src.length); } String msg; if (m.isVarArgs()) { msg = MessageFactory.get("error.invoke.tooFewParams", m.getName(), srcCount, Integer.toString(paramCount)); } else { msg = MessageFactory.get("error.invoke.wrongParams", m.getName(), srcCount, Integer.toString(paramCount)); } throw new IllegalArgumentException(msg); } if (src == null) { // Must be a varargs method with a single parameter. // Use a new array every time since the called code could modify the // contents of the array return new Object[1]; } Object[] dest = new Object[paramCount]; for (int i = 0; i < paramCount - 1; i++) { dest[i] = ELSupport.coerceToType(src[i], types[i]); } if (m.isVarArgs()) { Object[] varArgs = (Object[]) Array.newInstance( m.getParameterTypes()[paramCount - 1].getComponentType(), src.length - (paramCount - 1)); for (int i = 0; i < src.length - (paramCount - 1); i ++) { varArgs[i] = ELSupport.coerceToType(src[paramCount - 1 + i], types[paramCount - 1].getComponentType()); } dest[paramCount - 1] = varArgs; } else { dest[paramCount - 1] = ELSupport.coerceToType( src[paramCount - 1], types[paramCount - 1]); } return dest; }
Example #29
Source File: TestELEvaluation.java From Tomcat8-Source-Read with MIT License | 4 votes |
private void compareBoth(String msg, int expected, Object o1, Object o2){ int i1 = ELSupport.compare(null, o1, o2); int i2 = ELSupport.compare(null, o2, o1); Assert.assertEquals(msg,expected, i1); Assert.assertEquals(msg,expected, -i2); }
Example #30
Source File: ExpressionFactoryImpl.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public Object coerceToType(Object obj, Class<?> type) { return ELSupport.coerceToType(null, obj, type); }