001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.model; 018 019 import java.util.ArrayList; 020 import java.util.List; 021 022 import javax.xml.bind.annotation.XmlAccessType; 023 import javax.xml.bind.annotation.XmlAccessorType; 024 import javax.xml.bind.annotation.XmlElement; 025 import javax.xml.bind.annotation.XmlElementRef; 026 027 import org.apache.camel.Expression; 028 import org.apache.camel.Predicate; 029 import org.apache.camel.Processor; 030 import org.apache.camel.impl.RouteContext; 031 import org.apache.camel.model.language.ExpressionType; 032 import org.apache.camel.processor.FilterProcessor; 033 034 /** 035 * A base class for nodes which contain an expression and a number of outputs 036 * 037 * @version $Revision: $ 038 */ 039 @XmlAccessorType(XmlAccessType.FIELD) 040 public class ExpressionNode extends ProcessorType { 041 @XmlElementRef 042 private List<InterceptorType> interceptors = new ArrayList<InterceptorType>(); 043 @XmlElementRef 044 private ExpressionType expression; 045 @XmlElementRef 046 private List<ProcessorType> outputs = new ArrayList<ProcessorType>(); 047 048 public ExpressionNode() { 049 } 050 051 public ExpressionNode(ExpressionType expression) { 052 this.expression = expression; 053 } 054 055 public ExpressionNode(Expression expression) { 056 setExpression(new ExpressionType(expression)); 057 } 058 059 public ExpressionNode(Predicate predicate) { 060 setExpression(new ExpressionType(predicate)); 061 } 062 063 public List<InterceptorType> getInterceptors() { 064 return interceptors; 065 } 066 067 public void setInterceptors(List<InterceptorType> interceptors) { 068 this.interceptors = interceptors; 069 } 070 071 public ExpressionType getExpression() { 072 return expression; 073 } 074 075 public void setExpression(ExpressionType expression) { 076 this.expression = expression; 077 } 078 079 public List<ProcessorType> getOutputs() { 080 return outputs; 081 } 082 083 public void setOutputs(List<ProcessorType> outputs) { 084 this.outputs = outputs; 085 } 086 087 protected FilterProcessor createFilterProcessor(RouteContext routeContext) throws Exception { 088 Processor childProcessor = routeContext.createProcessor(this); 089 return new FilterProcessor(getExpression().createPredicate(routeContext), childProcessor); 090 } 091 092 @Override 093 protected void configureChild(ProcessorType output) { 094 if (isInheritErrorHandler()) { 095 output.setErrorHandlerBuilder(getErrorHandlerBuilder()); 096 } 097 } 098 }