use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.
the class ValidatorListCommandTest method doTest.
private String doTest(boolean verbose) throws Exception {
CamelContext context = new DefaultCamelContext();
EndpointValidatorDefinition evd = new EndpointValidatorDefinition();
evd.setType("xml:foo");
evd.setUri("direct:validator");
context.getValidators().add(evd);
PredicateValidatorDefinition pvd = new PredicateValidatorDefinition();
pvd.setType(this.getClass());
pvd.setExpression(new ExpressionDefinition(ExpressionBuilder.bodyExpression()));
context.getValidators().add(pvd);
CustomValidatorDefinition cvd = new CustomValidatorDefinition();
cvd.setType("custom");
cvd.setClassName(MyValidator.class.getName());
context.getValidators().add(cvd);
context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
context.start();
CamelController controller = new DummyCamelController(context);
OutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os);
ValidatorListCommand command = new ValidatorListCommand(null, false, verbose, false);
command.execute(controller, ps, null);
String out = os.toString();
assertNotNull(out);
LOG.info("\n\n{}\n", out);
context.stop();
return out;
}
use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.
the class CreateModelFromXmlTest method assertNamespacesPresent.
private void assertNamespacesPresent(RoutesDefinition routesDefinition, Map<String, String> expectedNamespaces) {
for (RouteDefinition route : routesDefinition.getRoutes()) {
Iterator<ExpressionNode> it = filterTypeInOutputs(route.getOutputs(), ExpressionNode.class);
if (it.hasNext()) {
ExpressionNode en = it.next();
ExpressionDefinition ed = en.getExpression();
NamespaceAware na = null;
Expression exp = ed.getExpressionValue();
if (exp != null && exp instanceof NamespaceAware) {
na = (NamespaceAware) exp;
} else if (ed instanceof NamespaceAware) {
na = (NamespaceAware) ed;
}
assertNotNull(na);
assertEquals(expectedNamespaces, na.getNamespaces());
} else {
fail("Expected to find at least one ExpressionNode in route");
}
}
}
use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.
the class ProcessorDefinition method createOutputsProcessorImpl.
protected Processor createOutputsProcessorImpl(RouteContext routeContext, Collection<ProcessorDefinition<?>> outputs) throws Exception {
List<Processor> list = new ArrayList<Processor>();
for (ProcessorDefinition<?> output : outputs) {
// allow any custom logic before we create the processor
output.preCreateProcessor();
// resolve properties before we create the processor
ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), output);
// resolve constant fields (eg Exchange.FILE_NAME)
ProcessorDefinitionHelper.resolveKnownConstantFields(output);
// also resolve properties and constant fields on embedded expressions
ProcessorDefinition<?> me = (ProcessorDefinition<?>) output;
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);
}
}
Processor processor = createProcessor(routeContext, output);
// inject id
if (processor instanceof IdAware) {
String id = output.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
((IdAware) processor).setId(id);
}
if (output instanceof Channel && processor == null) {
continue;
}
Processor channel = wrapChannel(routeContext, processor, output);
list.add(channel);
}
// if more than one output wrap than in a composite processor else just keep it as is
Processor processor = null;
if (!list.isEmpty()) {
if (list.size() == 1) {
processor = list.get(0);
} else {
processor = createCompositeProcessor(routeContext, list);
}
}
return processor;
}
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 predicate best possible.
* <p/>
* This implementation will use types such as {@link SimpleExpression}, {@link XPathExpression} etc.
* if the given predicate is detect as such a type.
*
* @param predicate the predicate
* @return a definition which describes the predicate
*/
public static ExpressionDefinition toExpressionDefinition(Predicate predicate) {
if (predicate instanceof SimpleBuilder) {
SimpleBuilder builder = (SimpleBuilder) predicate;
// we keep the original expression by using the constructor that accepts an expression
SimpleExpression answer = new SimpleExpression(builder);
answer.setExpression(builder.getText());
return answer;
} else if (predicate instanceof XPathBuilder) {
XPathBuilder builder = (XPathBuilder) predicate;
// we keep the original expression by using the constructor that accepts an expression
XPathExpression answer = new XPathExpression(builder);
answer.setExpression(builder.getText());
return answer;
} else if (predicate instanceof ValueBuilder) {
// ValueBuilder wraps the actual predicate so unwrap
ValueBuilder builder = (ValueBuilder) predicate;
Expression expression = builder.getExpression();
if (expression instanceof Predicate) {
predicate = (Predicate) expression;
}
}
if (predicate instanceof ExpressionDefinition) {
return (ExpressionDefinition) predicate;
}
return new ExpressionDefinition(predicate);
}
use of org.apache.camel.model.language.ExpressionDefinition in project camel by apache.
the class ModelHelper method getNamespaceAwareFromExpression.
private static NamespaceAware getNamespaceAwareFromExpression(ExpressionNode expressionNode) {
ExpressionDefinition ed = expressionNode.getExpression();
NamespaceAware na = null;
Expression exp = ed.getExpressionValue();
if (exp instanceof NamespaceAware) {
na = (NamespaceAware) exp;
} else if (ed instanceof NamespaceAware) {
na = (NamespaceAware) ed;
}
return na;
}
Aggregations