List of usage examples for org.springframework.expression Expression getExpressionString
String getExpressionString();
From source file:au.edu.uws.eresearch.cr8it.SpringIntegrationUtils.java
/** * Helper Method to dynamically determine and display input and output * directories as defined in the Spring Integration context. * * @param context Spring Application Context *///w w w .jav a2 s . com public static void displayDirectories(final ApplicationContext context) { final File inDir = (File) new DirectFieldAccessor(context.getBean(FileReadingMessageSource.class)) .getPropertyValue("directory"); final Map<String, FileWritingMessageHandler> fileWritingMessageHandlers = context .getBeansOfType(FileWritingMessageHandler.class); final List<String> outputDirectories = new ArrayList<String>(); for (final FileWritingMessageHandler messageHandler : fileWritingMessageHandlers.values()) { final Expression outDir = (Expression) new DirectFieldAccessor(messageHandler) .getPropertyValue("destinationDirectoryExpression"); outputDirectories.add(outDir.getExpressionString()); } final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("\n========================================================="); stringBuilder.append("\n"); stringBuilder.append("\n Input directory is : '" + inDir.getAbsolutePath() + "'"); for (final String outputDirectory : outputDirectories) { stringBuilder.append("\n Output directory is: '" + outputDirectory + "'"); } stringBuilder.append("\n\n========================================================="); logger.info(stringBuilder.toString()); }
From source file:org.mule.module.spel.ExpressionFactoryTest.java
public void testCreate() { MuleRegistry muleRegistry = mock(MuleRegistry.class); MuleContext context = mock(MuleContext.class); when(context.getRegistry()).thenReturn(muleRegistry); MuleMessage message = new DefaultMuleMessage(null, context); message.setPayload("a payload"); ExpressionFactory expressionFactory = new ExpressionFactory(); Expression expression = expressionFactory.create("'hello'"); expressionFactory.dispose();//from w w w . j a v a 2s. c om assertEquals("'hello'", expression.getExpressionString()); }
From source file:org.craftercms.core.util.template.impl.spel.SpELStringTemplateCompiler.java
@Override public CompiledTemplate compile(IdentifiableStringTemplateSource templateSource) throws TemplateException { String id = templateSource.getId(); String source = templateSource.getSource(); try {//from w w w .java2 s. c o m Expression expression = expressionCache.get(id); if (expression == null || !expression.getExpressionString().equals(source)) { expression = parser.parseExpression(source, parserContext); expressionCache.put(id, expression); } return new SpElCompiledTemplate(expression, evalContext); } catch (Exception e) { throw new TemplateException("Unable to compile SpEL template:\n" + source, e); } }
From source file:org.jasig.irclog.SpelEventFormatter.java
@SuppressWarnings("unchecked") public void setFormatExpressions(Properties expressions) { this.formatExpressions.clear(); for (final Map.Entry<Object, Object> expressionItr : expressions.entrySet()) { final String key = (String) expressionItr.getKey(); final Class<IrcEvent> eventClass; try {/*from w ww. j a v a 2s . c o m*/ eventClass = (Class<IrcEvent>) Class.forName(key); } catch (ClassNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } final String expressionText = (String) expressionItr.getValue(); final Expression expression = this.expressionParser.parseExpression(expressionText); this.logger.debug("Compiled expression '" + expression.getExpressionString() + " for " + eventClass); this.formatExpressions.put(eventClass, expression); } }
From source file:org.craftercms.security.processors.impl.UrlAccessRestrictionCheckingProcessor.java
protected boolean isAccessAllowed(HttpServletRequest request, Expression expression) { Object value = expression.getValue(createExpressionRoot(request)); if (!(value instanceof Boolean)) { throw new IllegalStateException( "Expression " + expression.getExpressionString() + " should return a " + "boolean value"); }/* ww w .j a v a 2 s. c o m*/ return (Boolean) value; }
From source file:org.jasig.irclog.SpelEventFormatter.java
@Override public String formatEvent(IrcEvent event) { final Expression expression = this.formatExpressions.get(event.getClass()); if (expression == null) { logger.warn("No Expression configured for event " + event + ". event.toString() will be returned"); return event.toString(); }//from www . j a v a 2 s .c o m final String message = expression.getValue(event, String.class); this.logger.trace("Formatted '" + expression.getExpressionString() + "' to '" + message); return message; }
From source file:org.icescrum.core.security.MethodScrumExpressionHandler.java
@SuppressWarnings("unchecked") public Object filter(Object filterTarget, Expression filterExpression, EvaluationContext ctx) { MethodScrumExpressionRoot rootObject = (MethodScrumExpressionRoot) ctx.getRootObject().getValue(); List retainList;/*ww w . j a v a 2s.com*/ if (logger.isDebugEnabled()) { logger.debug("Filtering with expression: " + filterExpression.getExpressionString()); } if (filterTarget instanceof Collection) { Collection collection = (Collection) filterTarget; retainList = new ArrayList(collection.size()); if (logger.isDebugEnabled()) { logger.debug("Filtering collection with " + collection.size() + " elements"); } for (Object filterObject : (Collection) filterTarget) { rootObject.setFilterObject(filterObject); if (ExpressionUtils.evaluateAsBoolean(filterExpression, ctx)) { retainList.add(filterObject); } } if (logger.isDebugEnabled()) { logger.debug("Retaining elements: " + retainList); } collection.clear(); collection.addAll(retainList); return filterTarget; } if (filterTarget.getClass().isArray()) { Object[] array = (Object[]) filterTarget; retainList = new ArrayList(array.length); if (logger.isDebugEnabled()) { logger.debug("Filtering collection with " + array.length + " elements"); } for (int i = 0; i < array.length; i++) { rootObject.setFilterObject(array[i]); if (ExpressionUtils.evaluateAsBoolean(filterExpression, ctx)) { retainList.add(array[i]); } } if (logger.isDebugEnabled()) { logger.debug("Retaining elements: " + retainList); } Object[] filtered = (Object[]) Array.newInstance(filterTarget.getClass().getComponentType(), retainList.size()); for (int i = 0; i < retainList.size(); i++) { filtered[i] = retainList.get(i); } return filtered; } throw new IllegalArgumentException( "Filter target must be a collection or array type, but was " + filterTarget); }
From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java
@Test public void statementExpressionCanBeCustomized() { String queryDsl = "Select(FOO.BAR).From(FOO)"; Expression expression = new SpelExpressionParser().parseExpression(queryDsl); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(context, "statement-expression:" + queryDsl); context.register(Conf.class); context.refresh();//from w ww . j av a 2s. co m CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class); assertThat(properties.getStatementExpression().getExpressionString(), equalTo(expression.getExpressionString())); context.close(); }
From source file:fr.xebia.management.statistics.ProfileAspect.java
@Around(value = "execution(* *(..)) && @annotation(profiled)", argNames = "pjp,profiled") public Object profileInvocation(ProceedingJoinPoint pjp, Profiled profiled) throws Throwable { logger.trace("> profileInvocation({},{}", pjp, profiled); MethodSignature jointPointSignature = (MethodSignature) pjp.getStaticPart().getSignature(); // COMPUTE SERVICE STATISTICS NAME Expression nameAsExpression = profiledMethodNameAsExpressionByMethod.get(jointPointSignature.getMethod()); if (nameAsExpression == null) { if (StringUtils.hasLength(profiled.name())) { String nameAsStringExpression = profiled.name(); nameAsExpression = expressionParser.parseExpression(nameAsStringExpression, parserContext); } else {//from w ww . j a v a 2s . c om String fullyQualifiedMethodName = getFullyQualifiedMethodName(// jointPointSignature.getDeclaringTypeName(), // jointPointSignature.getName(), // this.classNameStyle); nameAsExpression = new LiteralExpression(fullyQualifiedMethodName); } } String serviceStatisticsName; if (nameAsExpression instanceof LiteralExpression) { // Optimization : prevent useless objects instantiations serviceStatisticsName = nameAsExpression.getExpressionString(); } else { serviceStatisticsName = nameAsExpression.getValue(new RootObject(pjp), String.class); } // LOOKUP SERVICE STATISTICS ServiceStatistics serviceStatistics = serviceStatisticsByName.get(serviceStatisticsName); if (serviceStatistics == null) { // INSTIANCIATE NEW SERVICE STATISTICS ServiceStatistics newServiceStatistics = new ServiceStatistics(// new ObjectName(this.jmxDomain + ":type=ServiceStatistics,name=" + serviceStatisticsName), // profiled.businessExceptionsTypes(), profiled.communicationExceptionsTypes()); newServiceStatistics.setSlowInvocationThresholdInMillis(profiled.slowInvocationThresholdInMillis()); newServiceStatistics .setVerySlowInvocationThresholdInMillis(profiled.verySlowInvocationThresholdInMillis()); int maxActive; if (StringUtils.hasLength(profiled.maxActiveExpression())) { maxActive = expressionParser.parseExpression(profiled.maxActiveExpression(), parserContext) .getValue(new RootObject(pjp), Integer.class); } else { maxActive = profiled.maxActive(); } newServiceStatistics.setMaxActive(maxActive); newServiceStatistics.setMaxActiveSemaphoreAcquisitionMaxTimeInNanos(TimeUnit.NANOSECONDS .convert(profiled.maxActiveSemaphoreAcquisitionMaxTimeInMillis(), TimeUnit.MILLISECONDS)); ServiceStatistics previousServiceStatistics = serviceStatisticsByName.putIfAbsent(serviceStatisticsName, newServiceStatistics); if (previousServiceStatistics == null) { serviceStatistics = newServiceStatistics; mbeanExporter.registerManagedResource(serviceStatistics); } else { serviceStatistics = previousServiceStatistics; } } // INVOKE AND PROFILE INVOCATION long nanosBefore = System.nanoTime(); Semaphore semaphore = serviceStatistics.getMaxActiveSemaphore(); if (semaphore != null) { boolean acquired = semaphore.tryAcquire( serviceStatistics.getMaxActiveSemaphoreAcquisitionMaxTimeInNanos(), TimeUnit.NANOSECONDS); if (!acquired) { serviceStatistics.incrementServiceUnavailableExceptionCount(); throw new ServiceUnavailableException("Service '" + serviceStatisticsName + "' is unavailable: " + serviceStatistics.getCurrentActive() + " invocations of are currently running"); } } serviceStatistics.incrementCurrentActiveCount(); try { Object returned = pjp.proceed(); return returned; } catch (Throwable t) { serviceStatistics.incrementExceptionCount(t); throw t; } finally { if (semaphore != null) { semaphore.release(); } serviceStatistics.decrementCurrentActiveCount(); long deltaInNanos = System.nanoTime() - nanosBefore; serviceStatistics.incrementInvocationCounterAndTotalDurationWithNanos(deltaInNanos); if (logger.isDebugEnabled()) { logger.debug("< profileInvocation({}): {}ns", serviceStatisticsName, deltaInNanos); } } }