private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException { if (expressionString.isEmpty()) { return new LiteralExpression(""); } Expression[] expressions = parseExpressions(expressionString, context); if (expressions.length == 1) { return expressions[0]; } else { return new CompositeStringExpression(expressionString, expressions); } }
expressions.add(new LiteralExpression(expressionString.substring(startIdx, prefixIndex))); expressions.add(new LiteralExpression(expressionString.substring(startIdx))); startIdx = expressionString.length();
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException { if (expressionString.isEmpty()) { return new LiteralExpression(""); } Expression[] expressions = parseExpressions(expressionString, context); if (expressions.length == 1) { return expressions[0]; } else { return new CompositeStringExpression(expressionString, expressions); } }
expressions.add(new LiteralExpression(expressionString.substring(startIdx, prefixIndex))); expressions.add(new LiteralExpression(expressionString.substring(startIdx))); startIdx = expressionString.length();
/** * @param remoteTimeout the remoteTimeout to set */ public void setRemoteTimeout(long remoteTimeout) { this.remoteTimeoutExpression = new LiteralExpression("" + remoteTimeout); }
@Test public void testSetValue() { try { LiteralExpression lEx = new LiteralExpression("somevalue"); lEx.setValue(new StandardEvaluationContext(), "flibble"); fail("Should have got an exception that the value cannot be set"); } catch (EvaluationException ee) { // success, not allowed - whilst here, check the expression value in the exception assertEquals("somevalue", ee.getExpressionString()); } try { LiteralExpression lEx = new LiteralExpression("somevalue"); lEx.setValue(new Rooty(), "flibble"); fail("Should have got an exception that the value cannot be set"); } catch (EvaluationException ee) { // success, not allowed - whilst here, check the expression value in the exception assertEquals("somevalue", ee.getExpressionString()); } try { LiteralExpression lEx = new LiteralExpression("somevalue"); lEx.setValue(new StandardEvaluationContext(), new Rooty(), "flibble"); fail("Should have got an exception that the value cannot be set"); } catch (EvaluationException ee) { // success, not allowed - whilst here, check the expression value in the exception assertEquals("somevalue", ee.getExpressionString()); } }
/** * Constructor which sets the {@link #destinationDirectoryExpression} using * a {@link LiteralExpression}. * @param destinationDirectory Must not be null * @see #FileWritingMessageHandler(Expression) */ public FileWritingMessageHandler(File destinationDirectory) { Assert.notNull(destinationDirectory, "Destination directory must not be null."); this.destinationDirectoryExpression = new LiteralExpression(destinationDirectory.getPath()); }
/** * A {@code String} representation of a MongoDb {@link Query} (e.g., query("{'name' : 'Bob'}")). * Please refer to MongoDb documentation for more query samples * see <a href="http://www.mongodb.org/display/DOCS/Querying">MongoDB Docs</a> * This property is mutually exclusive with 'queryExpression' property. * @param query the MongoDb {@link Query} string representation to use. * @return the spec */ public MongoDbOutboundGatewaySpec query(String query) { this.target.setQueryExpression(new LiteralExpression(query)); return this; }
/** * Set the max number of results to retrieve from the database. Defaults to * 0, which means that all possible objects shall be retrieved. * @param maxNumberOfResults Must not be negative. * @see javax.persistence.Query#setMaxResults(int) */ public void setMaxNumberOfResults(int maxNumberOfResults) { this.setMaxResultsExpression(new LiteralExpression("" + maxNumberOfResults)); }
/** * Create an {@link HttpControllerEndpointSpec} builder for request-reply gateway * based on the provided MVC {@code viewName} and {@code path} array for mapping. * @param viewName the MVC view name to build in the end of request. * @param path the path mapping URIs (e.g. "/myPath.do"). * @return the HttpControllerEndpointSpec instance */ public static HttpControllerEndpointSpec inboundControllerGateway(String viewName, String... path) { Assert.isTrue(StringUtils.hasText(viewName), "View name must not be empty"); return inboundControllerGateway(new LiteralExpression(viewName), path); }
/** * Specifies the key for the Redis store. If an expression is needed, then call * {@link #setKeyExpression(Expression)} instead of this method (they are mutually exclusive). * If neither setter is called, the default expression will be 'headers.{@link RedisHeaders#KEY}'. * @param key The key. * @see #setKeyExpression */ public void setKey(String key) { Assert.hasText(key, "key must not be empty"); this.setKeyExpression(new LiteralExpression(key)); }
/** * Specify the full path to the remote directory. * * @param remoteDirectory The remote directory. */ public void setRemoteDirectory(String remoteDirectory) { this.remoteDirectoryExpression = new LiteralExpression(remoteDirectory); evaluateRemoteDirectory(); }
/** * Specify a remote directory path. * @param remoteDirectory the remote directory path. * @return the current Spec */ public S remoteDirectory(String remoteDirectory) { this.target.setRemoteDirectoryExpression(new LiteralExpression(remoteDirectory)); return _this(); }
/** * Specify a remote directory path. * @param temporaryRemoteDirectory the temporary remote directory path * @return the current Spec */ public S temporaryRemoteDirectory(String temporaryRemoteDirectory) { this.target.setTemporaryRemoteDirectoryExpression(new LiteralExpression(temporaryRemoteDirectory)); return _this(); }
@Test public void testGetValueType() throws Exception { LiteralExpression lEx = new LiteralExpression("somevalue"); assertEquals(String.class, lEx.getValueType()); assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext())); assertEquals(String.class, lEx.getValueType(new Rooty())); assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext(), new Rooty())); assertEquals(String.class, lEx.getValueTypeDescriptor().getType()); assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType()); assertEquals(String.class, lEx.getValueTypeDescriptor(new Rooty()).getType()); assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType()); }
@Test public void testGetValue() throws Exception { LiteralExpression lEx = new LiteralExpression("somevalue"); checkString("somevalue", lEx.getValue()); checkString("somevalue", lEx.getValue(String.class)); EvaluationContext ctx = new StandardEvaluationContext(); checkString("somevalue", lEx.getValue(ctx)); checkString("somevalue", lEx.getValue(ctx, String.class)); checkString("somevalue", lEx.getValue(new Rooty())); checkString("somevalue", lEx.getValue(new Rooty(), String.class)); checkString("somevalue", lEx.getValue(ctx, new Rooty())); checkString("somevalue", lEx.getValue(ctx, new Rooty(),String.class)); assertEquals("somevalue", lEx.getExpressionString()); assertFalse(lEx.isWritable(new StandardEvaluationContext())); assertFalse(lEx.isWritable(new Rooty())); assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty())); }
/** * Create a synchronizer with the {@link SessionFactory} used to acquire * {@link org.springframework.integration.file.remote.session.Session} instances. * @param sessionFactory The session factory. */ public FtpInboundFileSynchronizer(SessionFactory<FTPFile> sessionFactory) { super(sessionFactory); doSetRemoteDirectoryExpression(new LiteralExpression(null)); // NOSONAR - LE can actually handle null ok doSetFilter(new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "ftpMessageSource")); }
@Test public void literalExpression() { Expression expression = new LiteralExpression("foo"); ExpressionEvaluatingMessageSource<String> source = new ExpressionEvaluatingMessageSource<String>(expression, String.class); source.setBeanFactory(mock(BeanFactory.class)); Message<?> message = source.receive(); assertNotNull(message); assertEquals("foo", message.getPayload()); }
@Test public void testResultStartingFromThirdRecordForNativeQuery() { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setNativeQuery("select * from Student s"); jpaExecutor.setFirstResultExpression(new LiteralExpression("2")); jpaExecutor.setBeanFactory(this.beanFactory); jpaExecutor.afterPropertiesSet(); List<?> results = (List<?>) jpaExecutor.poll(MessageBuilder.withPayload("").build()); assertNotNull(results); assertEquals(1, results.size()); }
@Test public void testResultStartingFromThirdRecordUsingEntity() { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setEntityClass(StudentDomain.class); jpaExecutor.setFirstResultExpression(new LiteralExpression("2")); jpaExecutor.setBeanFactory(this.beanFactory); jpaExecutor.afterPropertiesSet(); List<?> results = (List<?>) jpaExecutor.poll(MessageBuilder.withPayload("").build()); assertNotNull(results); assertEquals(1, results.size()); }