Search in sources :

Example 1 with ExpressionDefinition

use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.

the class ValidatorBuilder method withExpression.

/**
     * Set the {@link Expression} to be used for the predicate {@link Validator}.
     * @see {@link PredicateValidatorDefinition}, {@link ProcessorValidator}
     * 
     * @param expression validation expression
     */
public ValidatorBuilder withExpression(@AsPredicate Expression expression) {
    resetType();
    this.expression = new ExpressionDefinition(expression);
    return this;
}
Also used : ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 2 with ExpressionDefinition

use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.

the class ValidatorBuilder method withExpression.

/**
     * Set the {@link Predicate} to be used for the predicate {@link Validator}.
     * @see {@link PredicateValidatorDefinition}, {@link ProcessorValidator}
     * 
     * @param predicate validation predicate
     */
public ValidatorBuilder withExpression(@AsPredicate Predicate predicate) {
    resetType();
    this.expression = new ExpressionDefinition(predicate);
    return this;
}
Also used : ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 3 with ExpressionDefinition

use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.

the class ExpressionNodeHelper method toExpressionDefinition.

/**
     * Determines which {@link ExpressionDefinition} describes the given expression best possible.
     * <p/>
     * This implementation will use types such as {@link SimpleExpression}, {@link XPathExpression} etc.
     * if the given expression is detect as such a type.
     *
     * @param expression the expression
     * @return a definition which describes the expression
     */
public static ExpressionDefinition toExpressionDefinition(Expression expression) {
    if (expression instanceof SimpleBuilder) {
        SimpleBuilder builder = (SimpleBuilder) expression;
        // we keep the original expression by using the constructor that accepts an expression
        SimpleExpression answer = new SimpleExpression(builder);
        answer.setExpression(builder.getText());
        answer.setResultType(builder.getResultType());
        return answer;
    } else if (expression instanceof XPathBuilder) {
        XPathBuilder builder = (XPathBuilder) expression;
        // we keep the original expression by using the constructor that accepts an expression
        XPathExpression answer = new XPathExpression(builder);
        answer.setExpression(builder.getText());
        answer.setResultType(builder.getResultType());
        return answer;
    } else if (expression instanceof ValueBuilder) {
        // ValueBuilder wraps the actual expression so unwrap
        ValueBuilder builder = (ValueBuilder) expression;
        expression = builder.getExpression();
    }
    if (expression instanceof ExpressionDefinition) {
        return (ExpressionDefinition) expression;
    }
    return new ExpressionDefinition(expression);
}
Also used : XPathExpression(org.apache.camel.model.language.XPathExpression) ValueBuilder(org.apache.camel.builder.ValueBuilder) SimpleBuilder(org.apache.camel.builder.SimpleBuilder) XPathBuilder(org.apache.camel.builder.xml.XPathBuilder) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition) SimpleExpression(org.apache.camel.model.language.SimpleExpression)

Example 4 with ExpressionDefinition

use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.

the class ProcessorDefinition method makeProcessorImpl.

private Processor makeProcessorImpl(RouteContext routeContext) throws Exception {
    Processor processor = null;
    // allow any custom logic before we create the processor
    preCreateProcessor();
    // resolve properties before we create the processor
    ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), this);
    // resolve constant fields (eg Exchange.FILE_NAME)
    ProcessorDefinitionHelper.resolveKnownConstantFields(this);
    // also resolve properties and constant fields on embedded expressions
    ProcessorDefinition<?> me = (ProcessorDefinition<?>) this;
    if (me instanceof ExpressionNode) {
        ExpressionNode exp = (ExpressionNode) me;
        ExpressionDefinition expressionDefinition = exp.getExpression();
        if (expressionDefinition != null) {
            // resolve properties before we create the processor
            ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), expressionDefinition);
            // resolve constant fields (eg Exchange.FILE_NAME)
            ProcessorDefinitionHelper.resolveKnownConstantFields(expressionDefinition);
        }
    }
    // at first use custom factory
    if (routeContext.getCamelContext().getProcessorFactory() != null) {
        processor = routeContext.getCamelContext().getProcessorFactory().createProcessor(routeContext, this);
    }
    // fallback to default implementation if factory did not create the processor
    if (processor == null) {
        processor = createProcessor(routeContext);
    }
    // inject id
    if (processor instanceof IdAware) {
        String id = this.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
        ((IdAware) processor).setId(id);
    }
    if (processor == null) {
        // no processor to make
        return null;
    }
    return wrapProcessor(routeContext, processor);
}
Also used : InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor) Processor(org.apache.camel.Processor) IdAware(org.apache.camel.spi.IdAware) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 5 with ExpressionDefinition

use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.

the class ProcessorDefinition method pollEnrich.

/**
     * The <a href="http://camel.apache.org/content-enricher.html">Content Enricher EIP</a>
     * enriches an exchange with additional data obtained from a <code>resourceUri</code>
     * using a {@link org.apache.camel.PollingConsumer} to poll the endpoint.
     * <p/>
     * The difference between this and {@link #enrich(String)} is that this uses a consumer
     * to obtain the additional data, where as enrich uses a producer.
     * <p/>
     * The timeout controls which operation to use on {@link org.apache.camel.PollingConsumer}.
     * If timeout is negative, we use <tt>receive</tt>. If timeout is 0 then we use <tt>receiveNoWait</tt>
     * otherwise we use <tt>receive(timeout)</tt>.
     *
     * @param expression             to use an expression to dynamically compute the endpoint to poll from
     * @param timeout                timeout in millis to wait at most for data to be available.
     * @param aggregationStrategyRef Reference of aggregation strategy to aggregate input data and additional data.
     * @param aggregateOnException   whether to call {@link org.apache.camel.processor.aggregate.AggregationStrategy#aggregate(org.apache.camel.Exchange, org.apache.camel.Exchange)} if
     *                               an exception was thrown.
     * @return the builder
     * @see org.apache.camel.processor.PollEnricher
     */
@SuppressWarnings("unchecked")
public Type pollEnrich(@AsEndpointUri Expression expression, long timeout, String aggregationStrategyRef, boolean aggregateOnException) {
    PollEnrichDefinition pollEnrich = new PollEnrichDefinition();
    pollEnrich.setExpression(new ExpressionDefinition(expression));
    pollEnrich.setTimeout(timeout);
    pollEnrich.setAggregationStrategyRef(aggregationStrategyRef);
    pollEnrich.setAggregateOnException(aggregateOnException);
    addOutput(pollEnrich);
    return (Type) this;
}
Also used : XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Aggregations

ExpressionDefinition (org.apache.camel.model.language.ExpressionDefinition)11 Expression (org.apache.camel.Expression)3 Processor (org.apache.camel.Processor)2 SimpleBuilder (org.apache.camel.builder.SimpleBuilder)2 ValueBuilder (org.apache.camel.builder.ValueBuilder)2 XPathBuilder (org.apache.camel.builder.xml.XPathBuilder)2 SimpleExpression (org.apache.camel.model.language.SimpleExpression)2 XPathExpression (org.apache.camel.model.language.XPathExpression)2 InterceptEndpointProcessor (org.apache.camel.processor.InterceptEndpointProcessor)2 IdAware (org.apache.camel.spi.IdAware)2 NamespaceAware (org.apache.camel.spi.NamespaceAware)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlAccessorType (javax.xml.bind.annotation.XmlAccessorType)1 CamelContext (org.apache.camel.CamelContext)1 Channel (org.apache.camel.Channel)1 Predicate (org.apache.camel.Predicate)1