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.management.InstrumentationProcessor;
024 import org.apache.camel.model.ProcessorDefinition;
025 import org.apache.camel.processor.Traceable;
026
027 /**
028 * A default implementation of the {@link org.apache.camel.RouteNode}
029 *
030 * @version $Revision: 836224 $
031 */
032 public class DefaultRouteNode implements RouteNode {
033
034 private Expression expression;
035 private Processor processor;
036 private ProcessorDefinition<?> processorDefinition;
037
038 public DefaultRouteNode(ProcessorDefinition<?> processorDefinition, Processor processor) {
039 this.processor = processor;
040 this.processorDefinition = processorDefinition;
041 }
042
043 public DefaultRouteNode(ProcessorDefinition<?> processorDefinition, Expression expression) {
044 this.processorDefinition = processorDefinition;
045 this.expression = expression;
046 }
047
048 public Processor getProcessor() {
049 return processor;
050 }
051
052 public ProcessorDefinition<?> getProcessorDefinition() {
053 return processorDefinition;
054 }
055
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) {
063 // can be wrapped
064 if (target instanceof InstrumentationProcessor) {
065 target = ((InstrumentationProcessor) target).getProcessor();
066 }
067
068 if (target instanceof Traceable) {
069 Traceable trace = (Traceable) target;
070 return trace.getTraceLabel();
071 }
072 }
073
074 // default then to definition
075 return processorDefinition.getLabel();
076 }
077
078 public boolean isAbstract() {
079 return processor == null;
080 }
081
082 @Override
083 public String toString() {
084 return "RouteNode[" + processorDefinition + "]";
085 }
086 }