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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations