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.impl;
018    
019    import org.apache.camel.Exchange;
020    import org.apache.camel.Expression;
021    import org.apache.camel.Processor;
022    import org.apache.camel.RouteNode;
023    import org.apache.camel.Traceable;
024    import org.apache.camel.model.ProcessorDefinition;
025    
026    /**
027     * A default implementation of the {@link org.apache.camel.RouteNode}
028     *
029     * @version 
030     */
031    public class DefaultRouteNode implements RouteNode {
032    
033        private Expression expression;
034        private Processor processor;
035        private ProcessorDefinition<?> processorDefinition;
036    
037        public DefaultRouteNode(ProcessorDefinition<?> processorDefinition, Processor processor) {
038            this.processor = processor;
039            this.processorDefinition = processorDefinition;
040        }
041    
042        public DefaultRouteNode(ProcessorDefinition<?> processorDefinition, Expression expression) {
043            this.processorDefinition = processorDefinition;
044            this.expression = expression;
045        }
046    
047        public Processor getProcessor() {
048            return processor;
049        }
050    
051        public ProcessorDefinition<?> getProcessorDefinition() {
052            return processorDefinition;
053        }
054    
055        @SuppressWarnings("deprecation")
056        public String getLabel(Exchange exchange) {
057            if (expression != null) {
058                return expression.evaluate(exchange, String.class);
059            }
060    
061            Processor target = processor;
062            if (target != null && target instanceof Traceable) {
063                Traceable trace = (Traceable) target;
064                return trace.getTraceLabel();
065            }
066            
067            // Compatiblity for old Traceable interface
068            if (target != null && target instanceof org.apache.camel.processor.Traceable) {
069                org.apache.camel.processor.Traceable trace = (org.apache.camel.processor.Traceable) target;
070                return trace.getTraceLabel();
071            }
072    
073            // default then to definition
074            return processorDefinition.getLabel();
075        }
076    
077        public boolean isAbstract() {
078            return processor == null;
079        }
080    
081        @Override
082        public String toString() {
083            return "RouteNode[" + processorDefinition + "]";
084        }
085    }