public static EvaluationContext buildEvaluationContext( Map<String, Method> functionMethodMap, Map<String, Object> attributeMap) { VariableMapper vMapper = buildVariableMapper(attributeMap); FunctionMapper fMapper = buildFunctionMapper(functionMethodMap); EsfingeELContext context = new EsfingeELContext(fMapper, vMapper, new ArrayELResolver(), new ListELResolver(), new MapELResolver(), new BeanELResolver()); return new EvaluationContext(context, fMapper, vMapper); }
private ELContext createELContext(final ELResolver resolver, final FunctionMapper functionMapper, final VariableMapper variableMapper) { return new ELContext() { @Override public ELResolver getELResolver() { return resolver; } @Override public FunctionMapper getFunctionMapper() { return functionMapper; } @Override public VariableMapper getVariableMapper() { return variableMapper; } }; }
@Override public Class<?> getType(EvaluationContext ctx) throws ELException { FunctionMapper fnMapper = ctx.getFunctionMapper(); // quickly validate again for this request if (fnMapper == null) { throw new ELException(MessageFactory.get("error.fnMapper.null")); } Method m = fnMapper.resolveFunction(this.prefix, this.localName); if (m == null) { throw new ELException(MessageFactory.get("error.fnMapper.method", this.getOutputName())); } return m.getReturnType(); }
public Class getType(EvaluationContext ctx) throws ELException { FunctionMapper fnMapper = ctx.getFunctionMapper(); // quickly validate again for this request if (fnMapper == null) { throw new ELException(MessageFactory.get("error.fnMapper.null")); } Method m = fnMapper.resolveFunction(this.prefix, this.localName); if (m == null) { throw new ELException(MessageFactory.get("error.fnMapper.method", this.getOutputName())); } return m.getReturnType(); }
/** * */ public ValueExpressionImpl(String expr, Node node, FunctionMapper fnMapper, VariableMapper varMapper, Class expectedType) { this.expr = expr; this.node = node; this.fnMapper = fnMapper; this.varMapper = varMapper; this.expectedType = expectedType; }
/** * Validates the syntax of all ${} expressions within the given string. * @param where the approximate location of the expressions in the JSP page * @param expressions a string containing zero or more "${}" expressions * @param err an error dispatcher to use * @deprecated now delegated to the org.apache.el Package */ public static void validateExpressions(Mark where, String expressions, Class expectedType, FunctionMapper functionMapper, ErrorDispatcher err) throws JasperException { // try { // // JspUtil.expressionEvaluator.parseExpression( expressions, // expectedType, functionMapper ); // } // catch( ELParseException e ) { // err.jspError(where, "jsp.error.invalid.expression", expressions, // e.toString() ); // } // catch( ELException e ) { // err.jspError(where, "jsp.error.invalid.expression", expressions, // e.toString() ); // } }
/** * */ public ExpressionBuilder(String expression, ELContext ctx) throws ELException { this.expression = expression; FunctionMapper ctxFn = ctx.getFunctionMapper(); VariableMapper ctxVar = ctx.getVariableMapper(); if (ctxFn != null) { this.fnMapper = new FunctionMapperFactory(ctxFn); } if (ctxVar != null) { this.varMapper = new VariableMapperFactory(ctxVar); } }
public CdiResolver() { context = new javax.el.ELContext() { @Override public VariableMapper getVariableMapper() { return null; } @Override public FunctionMapper getFunctionMapper() { return null; } @Override public javax.el.ELResolver getELResolver() { return getWrappedResolver(); } }; }
public static MethodExpression getMethodExpression( String expression, PageContext pageContext, FunctionMapper functionMap, Class expectedType, Class[] paramTypes) { ELContextImpl elctxt = (ELContextImpl)pageContext.getELContext(); elctxt.setFunctionMapper(functionMap); ExpressionFactory expFactory = getExpressionFactory(pageContext); return expFactory.createMethodExpression( elctxt, expression, expectedType, paramTypes); }
/** * Validates the syntax of all EL expressions within the given string. * @param where the approximate location of the expressions in the JSP page * @param expressions a string containing an EL expressions * @param err an error dispatcher to use */ public static void validateExpressions(Mark where, String expressions, FunctionMapper functionMapper, ErrorDispatcher err) throws JasperException { try { ELContextImpl elContext = new ELContextImpl(null); elContext.setFunctionMapper(functionMapper); getExpressionFactory().createValueExpression( elContext, expressions, Object.class); } catch( ELException e ) { err.jspError(where, "jsp.error.invalid.expression", expressions, e.toString() ); } }
/** * */ public ValueExpressionImpl(String expr, Node node, FunctionMapper fnMapper, VariableMapper varMapper, Class<?> expectedType) { this.expr = expr; this.node = node; this.fnMapper = fnMapper; this.varMapper = varMapper; this.expectedType = expectedType; }
private ExtendedELContext createELContext(final ELResolver resolver, final FunctionMapper functionMapper, final VariableMapper variableMapper, final ConstantResolver constantResolver) { return new ExtendedELContext() { @Override public ELResolver getELResolver() { return resolver; } @Override public FunctionMapper getFunctionMapper() { return functionMapper; } @Override public VariableMapper getVariableMapper() { return variableMapper; } @Override public ConstantResolver getConstantResolver() { return constantResolver; } }; }
public Object getValue(EvaluationContext ctx) throws ELException { FunctionMapper fnMapper = ctx.getFunctionMapper(); // quickly validate again for this request if (fnMapper == null) { throw new ELException(MessageFactory.get("error.fnMapper.null")); } Method m = fnMapper.resolveFunction(this.prefix, this.localName); if (m == null) { throw new ELException(MessageFactory.get("error.fnMapper.method", this.getOutputName())); } // If no params, there are no children, jjtGetNumChildren returns 0 if no children, not NPE Object[] params = new Object[this.jjtGetNumChildren()]; for (int i = 0; i < this.jjtGetNumChildren(); i++) { params[i] = this.children[i].getValue(ctx); } return ReflectionUtil.invokeMethod(null, m, params); }
public static ProctorLoadResult verifyAndConsolidate(@Nonnull final TestMatrixArtifact testMatrix, final String matrixSource, @Nonnull final Map<String, TestSpecification> requiredTests, @Nonnull final FunctionMapper functionMapper, final ProvidedContext providedContext) { final ProctorLoadResult result = verify(testMatrix, matrixSource, requiredTests, functionMapper, providedContext); final Map<String, ConsumableTestDefinition> definedTests = testMatrix.getTests(); // Remove any invalid tests so that any required ones will be replaced with default values during the // consolidation below (just like missing tests). Any non-required tests can safely be ignored. for (final String invalidTest: result.getTestsWithErrors()) { // TODO - mjs - gross that this depends on the mutability of the returned map, but then so does the // consolidate method below. definedTests.remove(invalidTest); } consolidate(testMatrix, requiredTests); return result; }
/** * Factory method to do the setup and transformation of inputs * * @param matrix a {@link TestMatrixArtifact} loaded by ProctorLoader * @param loadResult a {@link ProctorLoadResult} which contains result of validation of test definition * @param functionMapper a given el {@link FunctionMapper} * @return constructed Proctor object */ @Nonnull public static Proctor construct(@Nonnull final TestMatrixArtifact matrix, ProctorLoadResult loadResult, FunctionMapper functionMapper) { final ExpressionFactory expressionFactory = RuleEvaluator.EXPRESSION_FACTORY; final Map<String, TestChooser<?>> testChoosers = Maps.newLinkedHashMap(); final Map<String, String> versions = Maps.newLinkedHashMap(); for (final Entry<String, ConsumableTestDefinition> entry : matrix.getTests().entrySet()) { final String testName = entry.getKey(); final ConsumableTestDefinition testDefinition = entry.getValue(); final TestType testType = testDefinition.getTestType(); final TestChooser<?> testChooser; if (TestType.RANDOM.equals(testType)) { testChooser = new RandomTestChooser(expressionFactory, functionMapper, testName, testDefinition); } else { testChooser = new StandardTestChooser(expressionFactory, functionMapper, testName, testDefinition); } testChoosers.put(testName, testChooser); versions.put(testName, testDefinition.getVersion()); } return new Proctor(matrix, loadResult, testChoosers); }
@Nonnull ELContext createELContext(@Nonnull final VariableMapper variableMapper) { return new ELContext() { @Nonnull @Override public ELResolver getELResolver() { return elResolver; } @Nonnull @Override public FunctionMapper getFunctionMapper() { return functionMapper; } @Nonnull @Override public VariableMapper getVariableMapper() { return variableMapper; } }; }
static RandomTestChooser initializeRandomTestChooser(final List<Range> ranges, final List<TestBucket> buckets) { final ExpressionFactory expressionFactory = new ExpressionFactoryImpl(); final FunctionMapper functionMapper = RuleEvaluator.FUNCTION_MAPPER; final ConsumableTestDefinition testDefinition = new ConsumableTestDefinition(); testDefinition.setConstants(Collections.<String, Object>emptyMap()); testDefinition.setBuckets(buckets); final List<Allocation> allocations = Lists.newArrayList(); allocations.add(new Allocation("${}", ranges)); testDefinition.setAllocations(allocations); final RandomTestChooser rtc = new RandomTestChooser(expressionFactory, functionMapper, "testName", testDefinition); return rtc; }
@Override public FunctionMapper getFunctionMapper() { if (functions.isEmpty()) { return null; } else { return new FunctionMapper() { @Override public Method resolveFunction(String prefix, String localName) { if (!ArrayUtils.contains(JSTL_FUNCTIONS, localName) && !ArrayUtils.contains(functionsArray, localName)) { createViolation(element.getStartLinePosition(), "Fix this expression: Unknown function \"" + localName + "\"."); } // we only care about the check. return null; } }; } }
/** * @param expr * @param node * @param fnMapper * @param expectedType * @param paramTypes */ public MethodExpressionImpl(String expr, Node node, FunctionMapper fnMapper, VariableMapper varMapper, Class<?> expectedType, Class<?>[] paramTypes) { super(); this.expr = expr; this.node = node; this.fnMapper = fnMapper; this.varMapper = varMapper; this.expectedType = expectedType; this.paramTypes = paramTypes; }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.expr = in.readUTF(); String type = in.readUTF(); if (!"".equals(type)) { this.expectedType = ReflectionUtil.forName(type); } this.paramTypes = ReflectionUtil.toTypeArray(((String[]) in .readObject())); this.fnMapper = (FunctionMapper) in.readObject(); this.varMapper = (VariableMapper) in.readObject(); }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.expr = in.readUTF(); String type = in.readUTF(); if (!"".equals(type)) { this.expectedType = ReflectionUtil.forName(type); } this.fnMapper = (FunctionMapper) in.readObject(); this.varMapper = (VariableMapper) in.readObject(); }
@Override public FunctionMapper getFunctionMapper() { // Because we're only really being used to pass // to an ELResolver, no FunctionMapper is needed return null; }
/** * @param expr * @param node * @param fnMapper * @param expectedType * @param paramTypes */ public MethodExpressionImpl(String expr, Node node, FunctionMapper fnMapper, VariableMapper varMapper, Class expectedType, Class[] paramTypes) { super(); this.expr = expr; this.node = node; this.fnMapper = fnMapper; this.varMapper = varMapper; this.expectedType = expectedType; this.paramTypes = paramTypes; }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.expr = in.readUTF(); String type = in.readUTF(); if (!"".equals(type)) { this.expectedType = ReflectionUtil.forName(type); } this.paramTypes = ReflectionUtil.toTypeArray(((String[]) in .readObject())); this.fnMapper = (FunctionMapper) in.readObject(); this.varMapper = (VariableMapper) in.readObject(); }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.expr = in.readUTF(); String type = in.readUTF(); if (!"".equals(type)) { this.expectedType = ReflectionUtil.forName(type); } this.fnMapper = (FunctionMapper) in.readObject(); this.varMapper = (VariableMapper) in.readObject(); }
public ELContextImpl() { this(ELResolverImpl.getDefaultResolver()); if (Globals.IS_SECURITY_ENABLED) { functionMapper = new FunctionMapper() { public Method resolveFunction(String prefix, String localName) { return null; } }; } else { functionMapper = NullFunctionMapper; } }