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.model.ProcessorDefinition; 024 import org.apache.camel.processor.Traceable; 025 026 /** 027 * A default implementation of the {@link org.apache.camel.RouteNode} 028 * 029 * @version $Revision: 788766 $ 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 public String getLabel(Exchange exchange) { 056 if (expression != null) { 057 return expression.evaluate(exchange, String.class); 058 } 059 060 if (processor != null) { 061 if (processor instanceof Traceable) { 062 Traceable trace = (Traceable) processor; 063 return trace.getTraceLabel(); 064 } 065 processor.toString(); 066 } 067 068 // default then to definition 069 return processorDefinition.getLabel(); 070 } 071 072 public boolean isAbstract() { 073 return processor == null; 074 } 075 076 @Override 077 public String toString() { 078 return "RouteNode[" + processorDefinition + "]"; 079 } 080 081 }