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 javax.xml.bind.annotation.XmlAccessType;
020 import javax.xml.bind.annotation.XmlAccessorType;
021 import javax.xml.bind.annotation.XmlAttribute;
022 import javax.xml.bind.annotation.XmlRootElement;
023
024 import org.apache.camel.Expression;
025 import org.apache.camel.Processor;
026 import org.apache.camel.builder.ExpressionBuilder;
027 import org.apache.camel.builder.ExpressionClause;
028 import org.apache.camel.model.language.ExpressionDefinition;
029 import org.apache.camel.processor.RecipientList;
030 import org.apache.camel.spi.RouteContext;
031
032 /**
033 * Represents an XML <recipientList/> element
034 *
035 * @version $Revision: 750806 $
036 */
037 @XmlRootElement(name = "recipientList")
038 @XmlAccessorType(XmlAccessType.FIELD)
039 public class RecipientListDefinition extends ExpressionNode {
040
041 @XmlAttribute(required = false)
042 private String delimiter;
043
044 public RecipientListDefinition() {
045 }
046
047 public RecipientListDefinition(ExpressionDefinition expression) {
048 super(expression);
049 }
050
051 public RecipientListDefinition(Expression expression) {
052 super(expression);
053 }
054
055 @Override
056 public String toString() {
057 return "RecipientList[" + getExpression() + "]";
058 }
059
060 @Override
061 public String getShortName() {
062 return "recipientList";
063 }
064
065 @Override
066 public Processor createProcessor(RouteContext routeContext) throws Exception {
067 Expression expression = getExpression().createExpression(routeContext);
068
069 // add a tokenizer if we have a delimiter
070 if (delimiter != null) {
071 expression = ExpressionBuilder.tokenizeExpression(expression, delimiter);
072 }
073
074 return new RecipientList(expression);
075 }
076
077 // Fluent API
078 //-------------------------------------------------------------------------
079 /**
080 * Set the expression that RecipientListType will use
081 * @return the builder
082 */
083 public ExpressionClause<RecipientListDefinition> expression() {
084 return ExpressionClause.createAndSetExpression(this);
085 }
086
087 // Properties
088 //-------------------------------------------------------------------------
089
090 public String getDelimiter() {
091 return delimiter;
092 }
093
094 public void setDelimiter(String delimiter) {
095 this.delimiter = delimiter;
096 }
097 }