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.XmlElement; 023 import javax.xml.bind.annotation.XmlRootElement; 024 import javax.xml.bind.annotation.XmlTransient; 025 026 import org.apache.camel.Endpoint; 027 import org.apache.camel.ExchangePattern; 028 import org.apache.camel.Expression; 029 import org.apache.camel.Processor; 030 import org.apache.camel.processor.WireTapProcessor; 031 import org.apache.camel.spi.RouteContext; 032 033 /** 034 * Represents an XML <wireTap/> element 035 * 036 * @version $Revision: 758152 $ 037 */ 038 @XmlRootElement(name = "wireTap") 039 @XmlAccessorType(XmlAccessType.FIELD) 040 public class WireTapDefinition extends SendDefinition<WireTapDefinition> { 041 042 @XmlTransient 043 private Processor newExchangeProcessor; 044 045 @XmlAttribute(name = "processorRef", required = false) 046 private String newExchangeProcessorRef; 047 048 @XmlElement(name = "body", required = false) 049 private ExpressionSubElementDefinition newExchangeExpression; 050 051 public WireTapDefinition() { 052 } 053 054 public WireTapDefinition(String uri) { 055 setUri(uri); 056 } 057 058 public WireTapDefinition(Endpoint endpoint) { 059 setEndpoint(endpoint); 060 } 061 062 @Override 063 public Processor createProcessor(RouteContext routeContext) throws Exception { 064 Endpoint endpoint = resolveEndpoint(routeContext); 065 WireTapProcessor answer = new WireTapProcessor(endpoint, getPattern()); 066 067 if (newExchangeProcessorRef != null) { 068 newExchangeProcessor = routeContext.lookup(newExchangeProcessorRef, Processor.class); 069 } 070 answer.setNewExchangeProcessor(newExchangeProcessor); 071 if (newExchangeExpression != null) { 072 answer.setNewExchangeExpression(newExchangeExpression.createExpression(routeContext)); 073 } 074 075 return answer; 076 } 077 078 public ExchangePattern getPattern() { 079 return ExchangePattern.InOnly; 080 } 081 082 @Override 083 public String toString() { 084 return "WireTap[" + getLabel() + "]"; 085 } 086 087 @Override 088 public String getShortName() { 089 return "wireTap"; 090 } 091 092 public Processor getNewExchangeProcessor() { 093 return newExchangeProcessor; 094 } 095 096 public void setNewExchangeProcessor(Processor processor) { 097 this.newExchangeProcessor = processor; 098 } 099 100 public String getNewExchangeProcessorRef() { 101 return newExchangeProcessorRef; 102 } 103 104 public void setNewExchangeProcessorRef(String ref) { 105 this.newExchangeProcessorRef = ref; 106 } 107 108 public ExpressionSubElementDefinition getNewExchangeExpression() { 109 return newExchangeExpression; 110 } 111 112 public void setNewExchangeExpression(ExpressionSubElementDefinition expression) { 113 this.newExchangeExpression = expression; 114 } 115 116 public void setNewExchangeExpression(Expression expression) { 117 this.newExchangeExpression = new ExpressionSubElementDefinition(expression); 118 } 119 120 }