use of javax.el.ELResolver in project tomcat70 by apache.
the class AstValue method getTarget.
private final Target getTarget(EvaluationContext ctx) throws ELException {
// evaluate expr-a to value-a
Object base = this.children[0].getValue(ctx);
// if our base is null (we know there are more properties to evaluate)
if (base == null) {
throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.base", this.children[0].getImage()));
}
// set up our start/end
Object property = null;
int propCount = this.jjtGetNumChildren();
int i = 1;
// Evaluate any properties or methods before our target
ELResolver resolver = ctx.getELResolver();
while (i < propCount) {
if (i + 2 < propCount && this.children[i + 1] instanceof AstMethodParameters) {
// Method call not at end of expression
base = resolver.invoke(ctx, base, this.children[i].getValue(ctx), null, ((AstMethodParameters) this.children[i + 1]).getParameters(ctx));
i += 2;
} else if (i + 2 == propCount && this.children[i + 1] instanceof AstMethodParameters) {
// Method call at end of expression
ctx.setPropertyResolved(false);
property = this.children[i].getValue(ctx);
i += 2;
if (property == null) {
throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
}
} else if (i + 1 < propCount) {
// Object with property not at end of expression
property = this.children[i].getValue(ctx);
ctx.setPropertyResolved(false);
base = resolver.getValue(ctx, base, property);
i++;
} else {
// Object with property at end of expression
ctx.setPropertyResolved(false);
property = this.children[i].getValue(ctx);
i++;
if (property == null) {
throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
}
}
if (base == null) {
throw new PropertyNotFoundException(MessageFactory.get("error.unreachable.property", property));
}
}
Target t = new Target();
t.base = base;
t.property = property;
return t;
}
use of javax.el.ELResolver in project tomcat70 by apache.
the class JspApplicationContextImpl method createELContext.
public ELContextImpl createELContext(JspContext context) {
if (context == null) {
throw new IllegalArgumentException("JspContext was null");
}
// create ELContext for JspContext
final ELResolver r = this.createELResolver();
ELContextImpl ctx;
if (Constants.IS_SECURITY_ENABLED) {
ctx = AccessController.doPrivileged(new PrivilegedAction<ELContextImpl>() {
@Override
public ELContextImpl run() {
return new ELContextImpl(r);
}
});
} else {
ctx = new ELContextImpl(r);
}
ctx.putContext(JspContext.class, context);
// alert all ELContextListeners
ELContextEvent event = new ELContextEvent(ctx);
for (int i = 0; i < this.contextListeners.size(); i++) {
this.contextListeners.get(i).contextCreated(event);
}
return ctx;
}
use of javax.el.ELResolver in project tomee by apache.
the class OpenEJBLifecycle method initializeServletContext.
public static void initializeServletContext(final ServletContext servletContext, final WebBeansContext context) {
if (context == null || !context.getBeanManagerImpl().isInUse()) {
return;
}
final ELAdaptor elAdaptor = context.getService(ELAdaptor.class);
final ELResolver resolver = elAdaptor.getOwbELResolver();
// Application is configured as JSP
if (context.getOpenWebBeansConfiguration().isJspApplication()) {
logger.debug("Application is configured as JSP. Adding EL Resolver.");
setJspELFactory(servletContext, resolver);
}
// Add BeanManager to the 'javax.enterprise.inject.spi.BeanManager' servlet context attribute
servletContext.setAttribute(BeanManager.class.getName(), context.getBeanManagerImpl());
}
use of javax.el.ELResolver in project tomee by apache.
the class TomEEELInvocationHandlerTest method canCreateInvocationHandler.
@Test
public void canCreateInvocationHandler() {
final DatabaseIdentityStoreDefinition annotation = Color.class.getAnnotation(DatabaseIdentityStoreDefinition.class);
final ELProcessor elProcessor = new ELProcessor();
final ELResolver elResolver = bm().getELResolver();
elProcessor.getELManager().addELResolver(elResolver);
// small trick because of the @Vetoed bellow - OWB won't pick it up
// so we will register one ourselves into the processor so it is resolved
elProcessor.defineBean("color", new Color());
final DatabaseIdentityStoreDefinition proxiedAnnotation = TomEEELInvocationHandler.of(DatabaseIdentityStoreDefinition.class, annotation, elProcessor);
Assert.assertEquals("select password from caller where name = ?", proxiedAnnotation.callerQuery());
Assert.assertEquals(90, proxiedAnnotation.priority());
Assert.assertEquals("90", proxiedAnnotation.priorityExpression());
Assert.assertArrayEquals(new IdentityStore.ValidationType[] { IdentityStore.ValidationType.VALIDATE }, proxiedAnnotation.useFor());
Assert.assertEquals("select group_name from caller_groups where caller_name = ?", proxiedAnnotation.groupsQuery());
final String[] hashAlgorithmParameters = proxiedAnnotation.hashAlgorithmParameters();
Assert.assertArrayEquals(new String[] { "Pbkdf2PasswordHash.Iterations=3072", "${color.dyna}" }, hashAlgorithmParameters);
final Set<String> evaluatedHashParameters = stream(hashAlgorithmParameters).flatMap(s -> toStream(eval(elProcessor, s, Object.class))).collect(toSet());
System.out.println(evaluatedHashParameters);
final Map<String, String> parametersMap = evaluatedHashParameters.stream().collect(toMap(s -> (String) s.substring(0, s.indexOf('=')), s -> (String) eval(elProcessor, s.substring(s.indexOf('=') + 1), String.class)));
System.out.println(parametersMap);
}
use of javax.el.ELResolver in project Payara by payara.
the class WeldContextListenerTest method testcontextInitialized.
@Test
public void testcontextInitialized() throws Exception {
EasyMockSupport mockSupport = new EasyMockSupport();
ELResolver elResolver = mockSupport.createMock(ELResolver.class);
ExpressionFactory expressionFactory = mockSupport.createMock(ExpressionFactory.class);
StandardContext servletContext = new StandardContext();
servletContext.getServletContext();
ServletContextEvent servletContextEvent = mockSupport.createMock(ServletContextEvent.class);
BeanManager beanManager = mockSupport.createMock(BeanManager.class);
JspApplicationContextImpl jspApplicationContext = new JspApplicationContextImpl(servletContext);
expect(beanManager.getELResolver()).andReturn(elResolver);
expect(beanManager.wrapExpressionFactory(isA(ExpressionFactory.class))).andReturn(expressionFactory);
mockSupport.replayAll();
WeldContextListener weldContextListener = getWeldContextListener(beanManager, jspApplicationContext);
weldContextListener.contextInitialized(servletContextEvent);
assertSame(expressionFactory, jspApplicationContext.getExpressionFactory());
validateJspApplicationContext(jspApplicationContext, elResolver);
mockSupport.verifyAll();
mockSupport.resetAll();
}
Aggregations