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.Collections;
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.XmlAttribute;
025    import javax.xml.bind.annotation.XmlRootElement;
026    
027    import org.apache.camel.Processor;
028    import org.apache.camel.processor.RoutingSlip;
029    import org.apache.camel.spi.RouteContext;
030    import org.apache.camel.util.ObjectHelper;
031    
032    /**
033     * Represents an XML <routingSlip/> element
034     */
035    @XmlRootElement(name = "routingSlip")
036    @XmlAccessorType(XmlAccessType.FIELD)
037    public class RoutingSlipDefinition extends ProcessorDefinition<ProcessorDefinition> {
038        public static final String DEFAULT_DELIMITER = ",";
039    
040        @XmlAttribute
041        private String headerName;
042        @XmlAttribute
043        private String uriDelimiter;
044    
045        public RoutingSlipDefinition() {
046            this(null, DEFAULT_DELIMITER);
047        }
048    
049        public RoutingSlipDefinition(String headerName) {
050            this(headerName, DEFAULT_DELIMITER);
051        }
052    
053        public RoutingSlipDefinition(String headerName, String uriDelimiter) {
054            setHeaderName(headerName);
055            setUriDelimiter(uriDelimiter);
056        }
057    
058        @Override
059        public String toString() {
060            return "RoutingSlip[headerName=" + getHeaderName() + ", uriDelimiter=" + getUriDelimiter() + "]";
061        }
062    
063        @Override
064        public String getShortName() {
065            return "routingSlip";
066        }
067    
068        @Override
069        public Processor createProcessor(RouteContext routeContext) throws Exception {
070            ObjectHelper.notEmpty(getHeaderName(), "headerName", this);
071            ObjectHelper.notEmpty(getUriDelimiter(), "uriDelimiter", this);
072            return new RoutingSlip(getHeaderName(), getUriDelimiter());
073        }
074    
075        @Override
076        @SuppressWarnings("unchecked")
077        public List<ProcessorDefinition> getOutputs() {
078            return Collections.EMPTY_LIST;
079        }
080    
081        public void setHeaderName(String headerName) {
082            this.headerName = headerName;
083        }
084    
085        public String getHeaderName() {
086            return this.headerName;
087        }
088    
089        public void setUriDelimiter(String uriDelimiter) {
090            this.uriDelimiter = uriDelimiter;
091        }
092    
093        public String getUriDelimiter() {
094            return uriDelimiter;
095        }
096    }